CN108696554B - Load balancing method and device - Google Patents

Load balancing method and device Download PDF

Info

Publication number
CN108696554B
CN108696554B CN201710227853.2A CN201710227853A CN108696554B CN 108696554 B CN108696554 B CN 108696554B CN 201710227853 A CN201710227853 A CN 201710227853A CN 108696554 B CN108696554 B CN 108696554B
Authority
CN
China
Prior art keywords
execution
server
execution server
target
tasks
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710227853.2A
Other languages
Chinese (zh)
Other versions
CN108696554A (en
Inventor
黎方
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201710227853.2A priority Critical patent/CN108696554B/en
Publication of CN108696554A publication Critical patent/CN108696554A/en
Application granted granted Critical
Publication of CN108696554B publication Critical patent/CN108696554B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1001Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
    • H04L67/1004Server selection for load balancing

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

The application discloses a load balancing method and device. One embodiment of the method comprises: receiving a starting instruction for a target task, wherein the starting instruction comprises a server identifier; determining the number of tasks currently allocated to each execution server in the plurality of execution servers and the preset maximum parallel execution task number supported by each execution server; in response to determining that the server identifier is not empty and that the number of tasks currently allocated to the execution server indicated by the server identifier is not less than the maximum number of parallel execution tasks supported by the execution server indicated by the server identifier, a target execution server in the plurality of execution servers is determined based on the number of tasks currently allocated to each execution server and the determined maximum number of parallel execution tasks, and the target task is sent to the target execution server. The implementation mode improves the load balancing effect and improves the resource utilization rate.

Description

Load balancing method and device
Technical Field
The present application relates to the field of computer technologies, and in particular, to the field of internet technologies, and in particular, to a load balancing method and apparatus.
Background
With the development of computer technology, a server cluster composed of a plurality of servers needs to be constructed in more and more scenes to realize task processing. Generally, it is necessary to perform reasonable task allocation on the servers in the server cluster to achieve the purpose of load balancing.
The existing load balancing method generally determines the load condition of each server at regular intervals, and then performs task allocation based on the determined load condition. However, the load situation of each server determined in the task allocation process in the conventional method is not the current real-time load situation, so that the conventional method has the problem of poor load balancing effect when the number of tasks is large and the concurrency is large.
Disclosure of Invention
An object of the embodiments of the present application is to provide an improved load balancing method and apparatus, so as to solve the technical problems mentioned in the above background.
In a first aspect, an embodiment of the present application provides a load balancing method, where a load balancing server is in communication connection with multiple execution servers, the method includes: receiving a starting instruction of the target task, wherein the starting instruction comprises a server identifier used for indicating an execution server which executes the target task in a plurality of execution servers; determining the number of tasks currently allocated to each execution server in the plurality of execution servers and the preset maximum parallel execution task number supported by each execution server; and in response to determining that the server identification is not empty and the number of the tasks currently allocated to the execution server indicated by the server identification is not less than the maximum number of parallel execution tasks supported by the execution server indicated by the server identification, determining a target execution server in the plurality of execution servers based on the determined number of the tasks currently allocated to each execution server and the determined number of each maximum parallel execution task, and sending the target task to the target execution server.
In some embodiments, the method further comprises: in response to determining that the server identification is empty, determining an execution server of the plurality of execution servers that is currently assigned the smallest number of tasks as a target execution server, and sending the target task to the target execution server.
In some embodiments, the method further comprises: and in response to determining that the number of the tasks currently allocated to the execution server indicated by the server identification is smaller than the maximum parallel execution task number supported by the execution server indicated by the server identification, determining the execution server indicated by the server identification as a target execution server, and sending the target tasks to the target execution server.
In some embodiments, determining a target execution server of the plurality of execution servers based on the number of tasks currently assigned to each execution server and the determined respective maximum number of parallel execution tasks comprises: for each execution server in a plurality of execution servers, determining the ratio of the number of tasks currently allocated to the execution server to the maximum number of parallel execution tasks of the execution server; and determining the execution server with the minimum ratio as the target execution server.
In some embodiments, after sending the target task to the target execution server, the method further comprises: and increasing the number of the tasks currently allocated to the target execution server by a preset numerical value and storing the number.
In some embodiments, after sending the target task to the target execution server, the method further comprises: and in response to receiving an execution completion message which is sent by the target execution server and used for indicating that the target task is executed and completed, reducing the number of the tasks currently allocated to the target execution server by a preset numerical value and storing the number.
In a second aspect, an embodiment of the present application provides a load balancing apparatus, where a load balancing server is communicatively connected to a plurality of execution servers, the apparatus includes: the system comprises a receiving unit, a processing unit and a processing unit, wherein the receiving unit is configured to receive a starting instruction of a target task, and the starting instruction comprises a server identifier used for indicating an execution server which executes the target task in a plurality of execution servers; the device comprises a determining unit, a processing unit and a processing unit, wherein the determining unit is configured to determine the number of tasks currently allocated to each execution server in a plurality of execution servers and the preset maximum parallel execution task number supported by each execution server; and the first sending unit is configured to respond to the fact that the server identification is not empty and the number of the tasks currently allocated to the execution server indicated by the server identification is not smaller than the maximum parallel execution task number supported by the execution server indicated by the server identification, determine a target execution server in the multiple execution servers based on the determined number of the tasks currently allocated to each execution server and the determined number of each maximum parallel execution task, and send the target tasks to the target execution server.
In some embodiments, the apparatus further comprises: and a second sending unit configured to determine, in response to determining that the server identifier is empty, an execution server, which is the smallest in number of tasks currently allocated among the plurality of execution servers, as a target execution server, and send the target task to the target execution server.
In some embodiments, the apparatus further comprises: and the third sending unit is configured to respond to the fact that the number of the tasks currently allocated to the execution server indicated by the server identification is smaller than the maximum parallel execution task number supported by the execution server indicated by the server identification, determine the execution server indicated by the server identification as the target execution server, and send the target tasks to the target execution server.
In some embodiments, the first sending unit is further configured to: for each execution server in a plurality of execution servers, determining the ratio of the number of tasks currently allocated to the execution server to the maximum number of parallel execution tasks of the execution server; and determining the execution server with the minimum ratio as the target execution server.
In some embodiments, the apparatus further comprises: the first storage unit is configured to increase and store the number of tasks currently allocated to the target execution server by a preset numerical value.
In some embodiments, the apparatus further comprises: and the second storage unit is configured to reduce the number of the tasks currently allocated to the target execution server by a preset numerical value and store the reduced number in response to receiving an execution completion message which is sent by the target execution server and used for indicating that the target task is executed and completed.
In a third aspect, an embodiment of the present application provides a load balancing server, including: one or more processors; a storage device, configured to store one or more programs, which when executed by the one or more processors, cause the one or more processors to implement the method according to any of the embodiments of the load balancing method described above.
The load balancing method and the device provided by the embodiment of the application receive a starting instruction for target tasks, which comprises a server identifier, then determine the number of the tasks currently allocated to each execution server and the maximum number of the parallel execution tasks supported by the execution server, finally determine the target execution server to send the target tasks to the target execution server in response to the condition that the server identifier is not empty and the number of the tasks currently allocated to the execution server indicated by the server identifier is not less than the maximum number of the parallel execution tasks supported by the execution server indicated by the server identifier, and distribute the tasks based on the real-time task condition of each execution server, thereby ensuring the accuracy and the real-time performance of the load condition of the obtained execution server, and further, the load balancing effect is improved, and the resource utilization rate is improved.
Drawings
Other features, objects and advantages of the present application will become more apparent upon reading of the following detailed description of non-limiting embodiments thereof, made with reference to the accompanying drawings in which:
FIG. 1 is an exemplary system architecture diagram in which the present application may be applied;
FIG. 2 is a flow diagram of one embodiment of a load balancing method according to the present application;
FIG. 3 is a schematic diagram of an application scenario of a load balancing method according to the present application;
FIG. 4 is a flow diagram of yet another embodiment of a load balancing method according to the present application;
FIG. 5 is a schematic block diagram of one embodiment of a load balancing apparatus according to the present application;
FIG. 6 is a schematic block diagram of a computer system suitable for use in implementing a server according to embodiments of the present application.
Detailed Description
The present application will be described in further detail with reference to the following drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the related invention are shown in the drawings.
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present application will be described in detail below with reference to the embodiments with reference to the attached drawings.
Fig. 1 shows an exemplary system architecture 100 to which the load balancing method or load balancing apparatus of the present application may be applied.
As shown in fig. 1, the system architecture 100 may include a load balancing server 101, a network 102, and execution servers 103, 104, 105. The network 102 serves as a medium for providing communication links between the load balancing server 101 and the execution servers 103, 104, 105. Network 102 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The load balancing server 101 may receive start instructions of various tasks, acquire current task conditions (for example, the number of currently assigned tasks, the maximum number of supported parallel execution tasks, and the like) of the execution servers 103, 104, and 105, analyze the acquired task conditions, and send the tasks to corresponding ones of the execution servers 103, 104, and 105 through the network 102 based on the processing results.
In addition, the system architecture 100 may further include a database 106, and the database 106 may be various types of databases for managing various data, such as a database (e.g., redis, etc.) for storing current task conditions of the execution servers 103, 104, 105. At this time, the load balancing server 101 may obtain the task status of the execution servers 103, 104, and 105 from the database 106 in real time.
The execution servers 103, 104, 105 may execute the tasks received from the load balancing server 101 in parallel. In addition, the execution servers 103, 104, 105 may also execute the received tasks in parallel, and each execution server 103, 104, 105 may be configured with a task queue for storing tasks that are allocated and not yet executed.
It should be noted that the load balancing method provided in the embodiment of the present application is generally executed by the load balancing server 101, and accordingly, the load balancing apparatus is generally disposed in the load balancing server 101.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of load balancing servers, networks, and execution servers, as desired for an implementation.
With continued reference to fig. 2, a flow 200 of one embodiment of a load balancing method according to the present application is shown. The load balancing method comprises the following steps:
step 201, receiving a starting instruction for a target task.
In this embodiment, an electronic device (for example, the load balancing server 101 shown in fig. 1) on which the load balancing method operates may receive a start instruction for a target task, where the start instruction may include a server identifier indicating an execution server that executes the target task, among a plurality of execution servers (for example, the execution servers 103, 104, and 105 shown in fig. 1) that are communicatively connected to the electronic device. It should be noted that each of the execution servers corresponds to a server identifier, and the server identifier may be used to indicate and distinguish the execution servers. Further, the server identification may be a name of the server, an IP address of the server, and/or a character string composed of arbitrary characters (e.g., numbers, letters, symbols, etc.), or the like. It should be noted that the target task may be any task to be processed, and the task may be executed by the execution server.
In practice, the electronic device and the execution servers may establish a connection through a wired connection or a wireless connection. It should be noted that the wireless connection means may include, but is not limited to, a 3G/4G connection, a WiFi connection, a bluetooth connection, a WiMAX connection, a Zigbee connection, a uwb (ultra wideband) connection, and other wireless connection means now known or developed in the future.
It should be noted that the start instruction may be sent to the electronic device in an automatic triggering manner or a manual triggering manner, which is not limited herein. The automatic triggering may be sending a start instruction every preset time duration, and the manual triggering may be sending a start instruction manually by a worker.
In step 202, the number of tasks currently allocated to each execution server in the plurality of execution servers and the preset maximum number of parallel execution tasks supported by each execution server are determined.
In this embodiment, after receiving the start instruction, the electronic device may obtain, from a database (e.g., the database 106 shown in fig. 1) connected to the electronic device, the number of tasks currently allocated to each of the multiple execution servers and a preset maximum number of parallel execution tasks supported by each execution server. Here, for each execution server, the number of tasks currently assigned to the execution server may be the sum of the number of tasks currently being executed and the number of tasks stored in the task queue of the execution server. Each execution server may correspond to a preset maximum number of parallel execution tasks, which may be determined based on a pre-configuration of the execution server. It should be noted that, the electronic device may directly obtain the number of tasks currently allocated to and the maximum number of parallel execution tasks from each execution server.
In practice, the aforementioned database may store various data associated with the respective execution servers. Illustratively, for each execution server, the database may store data in the form of key-value pairs having as a key the server identification of the execution server and as a value the number of tasks to which the execution server is currently assigned. Meanwhile, the database may further store data in the form of key value pairs, where the server identifier of the execution server is a key and the maximum number of parallel execution tasks corresponding to the execution server is a value. It should be noted that, for a newly deployed execution server, the initial value of the number of tasks allocated to the newly deployed execution server stored in the database is zero.
Step 203, in response to determining that the server identifier is not empty and the number of tasks currently allocated to the execution server indicated by the server identifier is not less than the maximum number of parallel execution tasks supported by the execution server indicated by the server identifier, determining a target execution server in the plurality of execution servers based on the determined number of tasks currently allocated to each execution server and the determined number of maximum parallel execution tasks, and sending the target task to the target execution server.
In this embodiment, the electronic device may first determine whether the server identifier received in step 201 is empty. Then, in response to determining that the server identifier is not empty, the electronic device may compare the number of tasks currently assigned to the execution server indicated by the server identifier with the maximum parallel execution number supported by the execution server determined in step 202. Thereafter, in response to determining that the number of tasks currently assigned by the execution server is not less than the maximum parallel execution number supported by the execution server, the electronic device may determine a target execution server of the plurality of execution servers based on the number of tasks currently assigned by each execution server determined in step 202 and the determined maximum parallel execution number of tasks. And finally, sending the target task to a target execution server.
In this embodiment, the electronic device determines the target execution server among the plurality of execution servers by performing numerical calculation on the number of tasks currently allocated to each execution server and the determined maximum parallel execution task numbers.
In some optional implementations of this embodiment, for each execution server in the plurality of execution servers, the electronic device may first determine a ratio of the number of tasks currently assigned to the execution server to the maximum number of parallel execution tasks of the execution server; then, the execution server with the minimum ratio is determined as the target execution server.
In some optional implementations of this embodiment, for each execution server in the plurality of execution servers, the electronic device may first determine a difference between a maximum number of parallel execution tasks of the execution server and a number of tasks currently assigned to the execution server; and then, determining the execution server with the minimum difference value as the target execution server.
In some optional implementations of this embodiment, for each execution server in the plurality of execution servers, the electronic device may first determine a difference between a maximum number of parallel execution tasks of the execution server and a number of tasks currently assigned to the execution server; then, determining the ratio of the difference value to the maximum parallel execution task number of the execution server; finally, the execution server with the minimum ratio is determined as the target execution server.
It should be noted that, the electronic device may further determine a target execution server in the execution servers based on preset other numerical operations, which is not described herein again.
With continued reference to fig. 3, fig. 3 is a schematic diagram of an application scenario of the load balancing method according to the present embodiment. In the application scenario of fig. 3, a load balancing server 301 first receives a start instruction with a server identifier to start execution 302; then, the load balancing server 301 determines the number 303 of tasks currently allocated to each execution server in the multiple execution servers and a preset maximum parallel execution task number 304 supported by each execution server; after determining that the server identifier is not empty and the number of tasks currently allocated to the execution server indicated by the server identifier is not less than the maximum number of parallel execution tasks supported by the execution server indicated by the server identifier, determining a target execution server 305 among the plurality of execution servers based on the number of tasks currently allocated to each execution server 303 and the determined maximum number of parallel execution tasks 304, and sending the target task 306 to the target execution server 305.
The method provided by the above embodiment of the present application determines the number of tasks currently allocated to each execution server and the maximum number of parallel execution tasks supported by each execution server by receiving a start instruction for a target task, which includes a server identifier, and finally determines the target execution server to send the target task to the target execution server in response to determining that the server identifier is not empty and that the number of tasks currently allocated to the execution server indicated by the server identifier is not less than the maximum number of parallel execution tasks supported by the execution server indicated by the server identifier, based on the number of tasks currently allocated to each execution server and the determined maximum number of parallel execution tasks, so as to distribute the tasks based on the real-time task condition of each execution server, thereby ensuring the accuracy and real-time performance of the load condition of the obtained execution server, and further, the load balancing effect is improved, and the resource utilization rate is improved.
With further reference to fig. 4, a flow 400 of yet another embodiment of a load balancing method is shown. The process 400 of the load balancing method includes the following steps:
step 401, receiving a starting instruction for a target task.
In this embodiment, an electronic device (for example, the load balancing server 101 shown in fig. 1) on which the load balancing method operates may receive a start instruction for a target task, where the start instruction may include a server identifier indicating an execution server that executes the target task, among a plurality of execution servers (for example, the execution servers 103, 104, and 105 shown in fig. 1) that are communicatively connected to the electronic device.
Step 402, determining the number of tasks currently allocated to each execution server in the plurality of execution servers and a preset maximum number of parallel execution tasks supported by each execution server.
In this embodiment, after receiving the start instruction, the electronic device may obtain, from a database (e.g., the database 106 shown in fig. 1) connected to the electronic device, the number of tasks currently allocated to each of the multiple execution servers and a preset maximum number of parallel execution tasks supported by each execution server. Here, for each execution server, the number of tasks currently assigned to the execution server may be the sum of the number of tasks currently being executed and the number of tasks stored in the task queue of the execution server.
Step 403, in response to determining that the server identifier is not empty and the number of tasks currently allocated to the execution server indicated by the server identifier is not less than the maximum number of parallel execution tasks supported by the execution server indicated by the server identifier, determining a ratio of the number of tasks currently allocated to each execution server to the maximum number of parallel execution tasks, determining the execution server corresponding to the minimum ratio in the determined ratios as a target execution server, and sending the target task to the target execution server.
In this embodiment, the electronic device may first determine whether the server identifier received in step 401 is empty. In response to determining that the server identification is empty, step 405 may be performed; in response to determining that the server identifier is not empty, the electronic device may compare the number of tasks currently assigned to the execution server indicated by the server identifier with a maximum number of parallel executions supported by the execution server. Step 406 may be performed in response to determining that the number of tasks currently assigned by the execution server is less than the maximum number of parallel executions supported by the execution server. In response to determining that the number of tasks currently assigned by the execution server is not less than the maximum number of parallel executions supported by the execution server, the electronic device may first determine a ratio of the number of tasks currently assigned by each of the plurality of execution servers to the maximum number of parallel executions of the execution server; and then, determining the execution server corresponding to the minimum ratio in the determined ratios as a target execution server, and sending the target task to the target execution server.
In response to determining that the server identifier is empty, determining an execution server with the smallest number of tasks currently allocated from the plurality of execution servers as a target execution server, and sending the target task to the target execution server, step 404.
In this embodiment, in response to determining that the server identifier received in step 401 is empty, the electronic device may determine, as a target execution server, an execution server with a smallest number of tasks currently allocated among the plurality of execution servers, and send the target task to the target execution server.
Step 405, in response to determining that the number of tasks currently allocated to the execution server indicated by the server identifier is smaller than the maximum number of parallel execution tasks supported by the execution server indicated by the server identifier, determining the execution server indicated by the server identifier as a target execution server, and sending the target tasks to the target execution server.
In this embodiment, in response to determining that the number of tasks currently allocated to the execution server indicated by the server identifier is smaller than the maximum number of parallel execution tasks supported by the execution server indicated by the server identifier, the electronic device may directly determine the execution server indicated by the server identifier as a target execution server, and send the target task to the target execution server.
And 406, increasing the number of the tasks currently allocated to the target execution server by a preset value and storing the number.
In this embodiment, after the step 404, the step 405, or the step 406 is completed, the electronic device may extract the number of the currently allocated tasks corresponding to the server identifier of the target server stored in the database, and store the number in the database after increasing a preset value, where in practice, the preset value may be 1.
Step 407, in response to receiving an execution completion message sent by the target execution server and used for indicating that the target task has been executed, subtracting a preset value from the number of tasks currently allocated to the target execution server and storing the subtracted value.
In this embodiment, in response to receiving an execution completion message sent by the target execution server and used for indicating that the target task has been executed and completed, the electronic device may extract the number of currently allocated tasks corresponding to the server identifier of the target server stored in the database, and store the extracted number in the database after subtracting a preset value, where in practice, the preset value may be 1.
As can be seen from fig. 4, compared with the embodiment corresponding to fig. 2, the flow 400 of the load balancing method in this embodiment highlights the processing step for the case that the received server identifier is empty, the processing step for the case that the number of tasks currently allocated to the execution server indicated by the server identifier is smaller than the maximum number of parallel execution tasks supported by the execution server indicated by the server identifier, and the step of updating the task related data after sending the target task to the target execution server. Therefore, the scheme described in the embodiment can realize task allocation under various conditions, further improve the effect of load balancing, and further improve the resource utilization rate.
With further reference to fig. 5, as an implementation of the methods shown in the above-mentioned figures, the present application provides an embodiment of a load balancing apparatus, which corresponds to the embodiment of the method shown in fig. 2, and which can be applied to various electronic devices.
As shown in fig. 5, the load balancing apparatus 500 according to this embodiment includes: a receiving unit 501, configured to receive a start instruction for a target task, where the start instruction includes a server identifier indicating an execution server that executes the target task, among the plurality of execution servers; a determining unit 502 configured to determine the number of tasks currently allocated to each execution server in the plurality of execution servers and a preset maximum number of parallel execution tasks supported by each execution server; a first sending unit 503, configured to, in response to determining that the server identifier is not empty and that the number of tasks currently allocated to the execution server indicated by the server identifier is not less than the maximum number of parallel execution tasks supported by the execution server indicated by the server identifier, determine a target execution server in the plurality of execution servers based on the number of tasks currently allocated to each execution server and the determined maximum number of parallel execution tasks, and send the target task to the target execution server.
In this embodiment, the load balancing apparatus 500 may receive a start instruction for a target task, where the start instruction may include a server identifier indicating an execution server that executes the target task, among a plurality of execution servers (e.g., the execution servers 103, 104, and 105 shown in fig. 1) communicatively connected to the load balancing apparatus 500.
In this embodiment, after receiving the start instruction, the determining unit 502 may obtain, from a database (e.g., the database 106 shown in fig. 1) connected to the load balancing apparatus 500, the number of tasks currently allocated to each of the plurality of execution servers and a preset maximum number of parallel execution tasks supported by each of the execution servers. Here, for each execution server, the number of tasks currently assigned to the execution server may be the sum of the number of tasks currently being executed and the number of tasks stored in the task queue of the execution server.
In this embodiment, the first sending unit 503 may first determine whether the received server identifier is empty. Then, in response to determining that the server identifier is not empty, the first sending unit 503 may compare the number of tasks currently allocated to the execution server indicated by the server identifier with the maximum parallel execution number supported by the execution server. Thereafter, in response to determining that the number of tasks currently assigned by the execution server is not less than the maximum parallel execution number supported by the execution server, the first sending unit 503 may determine a target execution server among the plurality of execution servers based on the number of tasks currently assigned by each execution server and the determined maximum parallel execution number of tasks. And finally, sending the target task to a target execution server. Here, the first sending unit 503 determines the target execution server among the plurality of execution servers by numerically calculating the number of tasks currently assigned to each execution server and the determined maximum number of parallel execution tasks.
In some optional implementations of this embodiment, the first sending unit 503 may be further configured to, for each execution server in the plurality of execution servers, determine a ratio of the number of tasks currently allocated to the execution server to the maximum number of parallel execution tasks of the execution server; and determining the execution server corresponding to the minimum ratio in the determined ratios as a target execution server.
In some optional implementations of the present embodiment, the load balancing apparatus 500 may further include a second sending unit (not shown in the figure). The second sending unit may be configured to, in response to determining that the server identifier is empty, determine, as a target execution server, an execution server that is the smallest in number of tasks currently allocated among the plurality of execution servers, and send the target task to the target execution server.
In some optional implementations of the present embodiment, the load balancing apparatus 500 may further include a third sending unit (not shown in the figure). The third sending unit may be configured to, in response to determining that the number of tasks currently allocated to the execution server indicated by the server identifier is smaller than the maximum number of parallel execution tasks supported by the execution server indicated by the server identifier, determine the execution server indicated by the server identifier as a target execution server, and send the target task to the target execution server.
In some optional implementations of the present embodiment, the load balancing apparatus 500 may further include a first storage unit (not shown in the figure). The first storage unit may be configured to increase and store the number of tasks currently allocated to the target execution server by a preset value.
In some optional implementations of the present embodiment, the load balancing apparatus 500 may further include a second storage unit (not shown in the figure). The second storage unit may be configured to, in response to receiving an execution completion message that is sent by the target execution server and indicates that the target task has been executed, subtract the preset value from the number of tasks currently allocated to the target execution server and store the subtracted result.
The device provided by the above embodiment of the present application receives a start instruction for a target task, which includes a server identifier, through a receiving unit 501, then a determining unit 502 determines the number of tasks currently allocated to each execution server and the maximum number of parallel execution tasks supported by each execution server, and finally a first sending unit 503 determines the target execution server to send the target task to the target execution server based on the number of tasks currently allocated to each execution server and the determined number of maximum parallel execution tasks supported by each execution server in response to determining that the server identifier is not empty and that the number of tasks currently allocated to each execution server indicated by the server identifier is not less than the maximum number of parallel execution tasks supported by each execution server indicated by the server identifier, so as to distribute the tasks based on the real-time task condition of each execution server, the accuracy and the real-time performance of the obtained load condition of the execution server are guaranteed, the load balancing effect is improved, and the resource utilization rate is improved.
Referring now to FIG. 6, shown is a block diagram of a computer system 600 suitable for use in implementing a server according to embodiments of the present application. The server shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU)601 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the system 600 are also stored. The CPU 601, ROM 602, and RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, a mouse, and the like; an output portion 607 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The driver 610 is also connected to the I/O interface 605 as needed. A removable medium 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 610 as necessary, so that a computer program read out therefrom is mounted in the storage section 608 as necessary.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611. The computer program performs the above-described functions defined in the method of the present application when executed by a Central Processing Unit (CPU) 601. It should be noted that the computer readable medium described herein can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present application, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present application may be implemented by software or hardware. The described units may also be provided in a processor, and may be described as: a processor includes a receiving unit, a determining unit, and a first transmitting unit. The names of these units do not in some cases constitute a limitation on the unit itself, and for example, a receiving unit may also be described as a "unit that receives a start instruction for a target task".
As another aspect, the present application also provides a computer-readable medium, which may be contained in the apparatus described in the above embodiments; or may be present separately and not assembled into the device. The computer readable medium carries one or more programs which, when executed by the apparatus, cause the apparatus to: receiving a starting instruction for a target task, wherein the starting instruction comprises a server identifier; determining the number of tasks currently allocated to each execution server in the plurality of execution servers and the preset maximum parallel execution task number supported by each execution server; in response to determining that the server identifier is not empty and that the number of tasks currently allocated to the execution server indicated by the server identifier is not less than the maximum number of parallel execution tasks supported by the execution server indicated by the server identifier, a target execution server in the plurality of execution servers is determined based on the number of tasks currently allocated to each execution server and the determined maximum number of parallel execution tasks, and the target task is sent to the target execution server.
The above description is only a preferred embodiment of the application and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the invention herein disclosed is not limited to the particular combination of features described above, but also encompasses other arrangements formed by any combination of the above features or their equivalents without departing from the spirit of the invention. For example, the above features may be replaced with (but not limited to) features having similar functions disclosed in the present application.

Claims (14)

1. A load balancing method for a load balancing server, the load balancing server communicatively coupled to a plurality of execution servers, the method comprising:
receiving a starting instruction of a target task, wherein the starting instruction comprises a server identification used for indicating an execution server in the plurality of execution servers, which executes the target task;
determining the number of tasks currently allocated to each execution server in the plurality of execution servers and a preset maximum parallel execution task number supported by each execution server, wherein for each execution server, the number of tasks currently allocated to the execution server is the sum of the number of tasks currently being executed and the number of tasks stored in a task queue of the execution server;
in response to determining that the server identifier is not empty and that the number of tasks currently allocated to the execution server indicated by the server identifier is not less than the maximum number of parallel execution tasks supported by the execution server indicated by the server identifier, determining a target execution server of the plurality of execution servers based on the determined number of tasks currently allocated to each execution server and the determined number of maximum parallel execution tasks, and sending the target task to the target execution server.
2. The method of load balancing according to claim 1, further comprising:
in response to determining that the server identifier is empty, determining an execution server of the plurality of execution servers that is currently assigned the smallest number of tasks as a target execution server, and sending the target task to the target execution server.
3. The method of load balancing according to claim 1, further comprising:
in response to determining that the number of tasks currently allocated to the execution server indicated by the server identifier is smaller than the maximum number of parallel execution tasks supported by the execution server indicated by the server identifier, determining the execution server indicated by the server identifier as a target execution server, and sending the target tasks to the target execution server.
4. The method according to claim 1, wherein the determining a target execution server of the plurality of execution servers based on the number of tasks currently allocated to each execution server and the determined maximum number of parallel execution tasks comprises:
for each execution server in the plurality of execution servers, determining the ratio of the number of tasks currently allocated to the execution server to the maximum number of parallel execution tasks of the execution server;
and determining the execution server with the minimum ratio as the target execution server.
5. The load balancing method according to any one of claims 1 to 4, wherein after said sending of the target task to the target execution server, the method further comprises:
and increasing the number of the tasks currently allocated to the target execution server by a preset numerical value and storing the number.
6. The load balancing method of claim 5, wherein after the sending the target task to the target execution server, the method further comprises:
and in response to receiving an execution completion message which is sent by the target execution server and used for indicating that the target task is executed and completed, subtracting the preset numerical value from the number of the tasks currently allocated to the target execution server and storing the subtracted number.
7. A load balancing apparatus for a load balancing server, the load balancing server communicatively coupled to a plurality of execution servers, the apparatus comprising:
a receiving unit, configured to receive a start instruction for a target task, where the start instruction includes a server identifier indicating an execution server, from among the plurality of execution servers, that executes the target task;
a determining unit, configured to determine the number of tasks currently allocated to each execution server in the plurality of execution servers and a preset maximum number of parallel execution tasks supported by each execution server, where, for each execution server, the number of tasks currently allocated to the execution server is the sum of the number of tasks currently being executed and the number of tasks stored in a task queue of the execution server;
a first sending unit, configured to, in response to determining that the server identifier is not empty and that the number of tasks currently allocated to the execution server indicated by the server identifier is not less than the maximum number of parallel execution tasks supported by the execution server indicated by the server identifier, determine a target execution server of the plurality of execution servers based on the determined number of tasks currently allocated to each execution server and the determined number of maximum parallel execution tasks, and send the target task to the target execution server.
8. The load balancing apparatus of claim 7, wherein the apparatus further comprises:
a second sending unit, configured to, in response to determining that the server identifier is empty, determine, as a target execution server, an execution server of the plurality of execution servers that is the smallest in number of tasks currently allocated thereto, and send the target task to the target execution server.
9. The load balancing apparatus of claim 7, wherein the apparatus further comprises:
and the third sending unit is configured to determine the execution server indicated by the server identifier as a target execution server and send the target task to the target execution server in response to determining that the number of tasks currently allocated to the execution server indicated by the server identifier is smaller than the maximum parallel execution task number supported by the execution server indicated by the server identifier.
10. The load balancing apparatus according to claim 7, wherein the first sending unit is further configured to:
for each execution server in the plurality of execution servers, determining the ratio of the number of tasks currently allocated to the execution server to the maximum number of parallel execution tasks of the execution server; and determining the execution server with the minimum ratio as the target execution server.
11. The load balancing apparatus according to any one of claims 7 to 10, wherein the apparatus further comprises:
and the first storage unit is configured to increase and store the number of tasks currently allocated to the target execution server by a preset numerical value.
12. The load balancing apparatus of claim 11, wherein the apparatus further comprises:
and the second storage unit is configured to reduce the number of tasks currently allocated to the target execution server by the preset value and store the reduced number in response to receiving an execution completion message which is sent by the target execution server and used for indicating that the target task is executed and completed.
13. A load-balancing server, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-6.
14. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1-6.
CN201710227853.2A 2017-04-10 2017-04-10 Load balancing method and device Active CN108696554B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710227853.2A CN108696554B (en) 2017-04-10 2017-04-10 Load balancing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710227853.2A CN108696554B (en) 2017-04-10 2017-04-10 Load balancing method and device

Publications (2)

Publication Number Publication Date
CN108696554A CN108696554A (en) 2018-10-23
CN108696554B true CN108696554B (en) 2021-11-30

Family

ID=63843190

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710227853.2A Active CN108696554B (en) 2017-04-10 2017-04-10 Load balancing method and device

Country Status (1)

Country Link
CN (1) CN108696554B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109885404B (en) * 2019-02-01 2021-07-20 新华三技术有限公司 Instruction processing method and device
CN112540796B (en) * 2019-09-23 2024-05-07 阿里巴巴集团控股有限公司 Instruction processing device, processor and processing method thereof
CN110618899B (en) * 2019-09-25 2022-02-22 浙江中控技术股份有限公司 Data storage method and device

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105871985A (en) * 2015-12-10 2016-08-17 乐视网信息技术(北京)股份有限公司 Data access request processing method and apparatus, server, client and system

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103188277B (en) * 2011-12-27 2016-05-18 中国电信股份有限公司 load energy consumption management system, method and server
CN102710615B (en) * 2012-05-15 2014-08-27 北京像素软件科技股份有限公司 Method for equalizing dynamic load of network game
CN102685237B (en) * 2012-05-16 2015-05-06 东南大学 Method for requesting session maintaining and dispatching in cluster environment
CN103457869A (en) * 2013-08-28 2013-12-18 北京星网锐捷网络技术有限公司 Conversation maintaining method and device
CN104780184A (en) * 2014-01-09 2015-07-15 华耀(中国)科技有限公司 Method of using geographical location information for load balancing
CN104811488B (en) * 2015-04-13 2018-09-25 深信服网络科技(深圳)有限公司 Session keeping method and system based on load-balancing device and load-balancing device
CN105072182A (en) * 2015-08-10 2015-11-18 北京佳讯飞鸿电气股份有限公司 Load balancing method, load balancer and user terminal
CN106453116B (en) * 2016-11-03 2019-11-26 上海斐讯数据通信技术有限公司 A kind of Smallest connection load-balancing method and system based on SDN

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105871985A (en) * 2015-12-10 2016-08-17 乐视网信息技术(北京)股份有限公司 Data access request processing method and apparatus, server, client and system

Also Published As

Publication number Publication date
CN108696554A (en) 2018-10-23

Similar Documents

Publication Publication Date Title
CN108182111B (en) Task scheduling system, method and device
CN109033001B (en) Method and apparatus for allocating GPUs
US10664390B2 (en) Optimizing execution order of system interval dependent test cases
US20180027061A1 (en) Method and apparatus for elastically scaling virtual machine cluster
CN110391938B (en) Method and apparatus for deploying services
CN108696554B (en) Load balancing method and device
CN109240802B (en) Request processing method and device
CN112506581A (en) Method and device for rendering small program, electronic equipment and readable storage medium
CN115617511A (en) Resource data processing method and device, electronic equipment and storage medium
CN109873731B (en) Test method, device and system
CN108399046B (en) File operation request processing method and device
CN109828830B (en) Method and apparatus for managing containers
CN113721811B (en) Popup window sending method, popup window sending device, electronic equipment and computer readable medium
CN109462491B (en) System, method and apparatus for testing server functionality
CN109842665B (en) Task processing method and device for task allocation server
CN111125503A (en) Method and apparatus for generating information
CN112131257B (en) Data query method and device
CN111694670B (en) Resource allocation method, apparatus, device and computer readable medium
CN113778850A (en) Data processing method and device, electronic equipment and computer readable medium
CN114817347A (en) Business approval method and device, electronic equipment and storage medium
CN114064403A (en) Task delay analysis processing method and device
CN109471574B (en) Method and device for configuring resources
CN111898061A (en) Method, device, electronic equipment and computer readable medium for searching network
CN112784139A (en) Query method, query device, electronic equipment and computer readable medium
CN112559001A (en) Method and device for updating application

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant