CN110995802A - Task processing method and device, storage medium and electronic device - Google Patents

Task processing method and device, storage medium and electronic device Download PDF

Info

Publication number
CN110995802A
CN110995802A CN201911158443.2A CN201911158443A CN110995802A CN 110995802 A CN110995802 A CN 110995802A CN 201911158443 A CN201911158443 A CN 201911158443A CN 110995802 A CN110995802 A CN 110995802A
Authority
CN
China
Prior art keywords
server
servers
task
information
capacity information
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.)
Pending
Application number
CN201911158443.2A
Other languages
Chinese (zh)
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 QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and 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 QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN201911158443.2A priority Critical patent/CN110995802A/en
Publication of CN110995802A publication Critical patent/CN110995802A/en
Pending legal-status Critical Current

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
    • 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
    • H04L67/1008Server selection for load balancing based on parameters of servers, e.g. available memory or workload

Abstract

The application discloses a task processing method and device, a storage medium and an electronic device. Wherein, the method comprises the following steps: receiving a first task request sent by a first client; selecting a first server for processing the first task request from a plurality of servers according to the residual capacity information of each server in the plurality of servers, wherein the residual capacity information of each server is used for representing the residual task processing capacity of each server; forwarding the first task request to the selected first server. By the method and the device, the technical problem that due to the fact that a load balancing mode in the related technology is adopted, the utilization rate of server resources is low due to unreasonable task allocation is solved, and the technical effects of improving the rationality of task allocation and improving the utilization rate of the server resources are achieved.

Description

Task processing method and device, storage medium and electronic device
Technical Field
The present application relates to the field of computers, and in particular, to a method and an apparatus for processing a task, a storage medium, and an electronic apparatus.
Background
Currently, after receiving a request from a user, a server that handles the request may be selected from a plurality of servers through a load balancing algorithm. The existing load balancing algorithm is mainly divided into static and dynamic types.
Static load balancing algorithms assign tasks with a fixed probability, e.g., round robin algorithms, weighted round robin algorithms, etc.; the dynamic load balancing algorithm determines the assignment of tasks according to the real-time load status information of the server, such as a minimum connection method, a weighted minimum connection method, etc., wherein,
(1) polling method
The polling method is to allocate the requests of the users to the servers in turn (similar to the number of times of one, allocation in turn). The algorithm used by the polling mode is simple and has the advantage of absolute equalization. However, the task of allocation cannot be guaranteed to be justified because of the absolute balance of the request allocation.
(2) Stochastic method
The random method is to randomly select a server to distribute tasks. The random mode can ensure the dispersion of the request, thereby achieving the aim of balancing. Also, the random approach is stateless and does not require maintaining the last selection state and equalization factor. However, as the amount of tasks increases, its effect tends to be a partial disadvantage of the polling algorithm after polling.
(3) Method of minimum joining
The minimum connection method is to assign tasks to nodes that currently have the smallest number of connections. After a node receives a task, the number of connections of the node is added with 1, when the node fails, the weight of the failed node is set to be 0, and the task is not distributed to the node any more.
The minimum connection method is suitable for scenes with similar processing performance of each node. The task distribution unit smoothly distributes the task to the server. However, when the performance gap between the servers is large, the expected effect cannot be achieved.
Therefore, the load balancing method in the related art has the problem of low utilization rate of server resources due to unreasonable task allocation.
Disclosure of Invention
The embodiment of the application provides a task processing method and device, a storage medium and an electronic device, so as to at least solve the technical problem of low utilization rate of server resources caused by unreasonable task allocation in a load balancing mode in the related art.
According to an aspect of an embodiment of the present application, there is provided a method for processing a task, including: receiving a first task request sent by a first client; selecting a first server for processing a first task request from a plurality of servers according to the residual capacity information of each server in the plurality of servers, wherein the residual capacity information of each server is used for representing the residual task processing capacity of each server; the first task request is forwarded to the selected first server.
Optionally, before selecting a first server for processing the first task request from the plurality of servers according to the remaining capacity information of each of the plurality of servers, obtaining the operating state information of each of the plurality of servers; and determining the residual capacity information of each server according to the running state information of each server.
Optionally, determining the remaining capability information of each server according to the operation state information of each server includes: determining that the residual capacity information of a second server is target capacity information under the condition that the second server is determined to be abnormally operated according to the operation state information of the second server in the plurality of servers, wherein the abnormality comprises at least one of the following: the response delay time of the second server exceeds a preset time threshold, the memory occupancy rate of the second server exceeds a preset occupancy rate threshold, the second server has a locked thread, and the target capacity information is used for indicating that no task processing capacity remains.
Optionally, determining the remaining capability information of each server according to the operation state information of each server includes: performing weighted summation on sub-operation state information in the operation state information of each server to obtain a score corresponding to each server, wherein the score corresponding to each server is used for representing the remaining capacity information of each server, and the sub-operation state information comprises at least one of the following: response delay time, memory occupancy rate, and number of active threads.
Optionally, selecting a first server from the plurality of servers to process the first task request according to the remaining capacity information of each of the plurality of servers comprises: and selecting a first server with the score larger than or equal to a target score from the plurality of servers, wherein the target score is the score corresponding to the server with the highest score in the plurality of servers, or a preset score threshold.
Optionally, after forwarding the first task request to the selected first server, receiving an ability update message sent by the second server, where the ability update message carries current remaining ability information of the second server; and updating the residual capacity information of the second server by using the current residual capacity information.
Optionally, after the remaining capability information of the first server is updated by using the current remaining capability information, a second task request sent by the second client is received; selecting a third server for processing the second task request from the plurality of servers according to the updated residual capacity information of each server in the plurality of servers; and forwarding the second task request to the selected third server.
According to another aspect of the embodiments of the present application, there is also provided a processing apparatus for a task, including: the first receiving unit is used for receiving a first task request sent by a first client; the first selecting unit is used for selecting a first server for processing a first task request from a plurality of servers according to the residual capacity information of each server in the plurality of servers, wherein the residual capacity information of each server is used for representing the residual task processing capacity of each server; and the first sending unit is used for forwarding the first task request to the selected first server.
Optionally, the apparatus further comprises: an acquisition unit configured to acquire operating state information of each of the plurality of servers before selecting a first server that processes the first task request from the plurality of servers according to remaining capacity information of each of the plurality of servers; and the determining unit is used for determining the residual capacity information of each server according to the running state information of each server.
Optionally, the determining unit includes: the determining module is configured to determine that the remaining capability information of the second server is the target capability information when determining that the second server operates abnormally according to the operating state information of the second server in the plurality of servers, where the abnormality includes at least one of: the response delay time of the second server exceeds a preset time threshold, the memory occupancy rate of the second server exceeds a preset occupancy rate threshold, the second server has a locked thread, and the target capacity information is used for indicating that no task processing capacity remains.
Optionally, the determining unit includes: the summing module is configured to perform weighted summation on sub-operation state information in the operation state information of each server to obtain a score corresponding to each server, where the score corresponding to each server is used to represent remaining capability information of each server, and the sub-operation state information includes at least one of the following: response delay time, memory occupancy rate, and number of active threads.
Optionally, the first selecting unit includes: the selection module is used for selecting a first server with the score larger than or equal to a target score from the plurality of servers, wherein the target score is the score corresponding to the server with the highest score in the plurality of servers, or a preset score threshold.
Optionally, the apparatus further comprises: a second receiving unit, configured to receive an ability update message sent by a second server after forwarding the first task request to the selected first server, where the ability update message carries current remaining ability information of the second server; and the updating unit is used for updating the residual capacity information of the second server by using the current residual capacity information.
Optionally, the apparatus further comprises: a third receiving unit, configured to receive a second task request sent by a second client after updating the remaining capability information of the first server using the current remaining capability information; the second selecting unit is used for selecting a third server for processing the second task request from the plurality of servers according to the updated residual capacity information of each server in the plurality of servers; and the second sending unit is used for forwarding the second task request to the selected third server.
According to still another aspect of the embodiments of the present application, there is also provided a storage medium including a stored program that executes the above-described method when executed.
According to yet another aspect of the embodiments of the present application, there is also provided an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the above method through the computer program.
In the embodiment of the application, a first task request sent by a first client is received in a load balancing mode according to the residual processing capacity of a server; selecting a first server for processing a first task request from a plurality of servers according to the residual capacity information of each server in the plurality of servers, wherein the residual capacity information of each server is used for representing the residual task processing capacity of each server; the first task request is forwarded to the selected first server, and the task request is allocated to the processed server according to the remaining task processing capacity of the server, so that the purpose of allocating the task to the server with strong remaining processing capacity can be achieved, the rationality of task allocation is improved, the technical effect of improving the resource utilization rate of the server is achieved, and the technical problem of low resource utilization rate of the server caused by unreasonable task allocation in a load balancing mode in the related art is solved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
FIG. 1 is a block diagram of an alternative load balancer hardware configuration according to an embodiment of the present application;
FIG. 2 is a block diagram of an alternative network architecture according to an embodiment of the present application;
FIG. 3 is a flow chart diagram of an alternative task processing method according to an embodiment of the application;
FIG. 4 is a block diagram of an alternative network architecture according to an embodiment of the present application;
FIG. 5 is a flow chart of another alternative method of processing tasks according to an embodiment of the application; and
fig. 6 is a block diagram of a processing device for an optional task according to an embodiment of the present application.
Detailed Description
In order to make the technical solutions better understood by those skilled in the art, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only partial embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It should be noted that the terms "first," "second," and the like in the description and claims of this application and in the above-described drawings are used for distinguishing between similar clients and not necessarily for describing a particular order or sequence. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the application described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
According to one aspect of the embodiment of the application, a method for processing a task is provided. Alternatively, the processing method of the above task may be executed on a load balancer, a coordination server, or a similar control device. Taking an example of the operation on a load balancer, fig. 1 is a hardware structure block diagram of an alternative load balancer according to an embodiment of the present application. As shown in fig. 1, load balancer 10 may further include one or more (only one shown in fig. 1) processors 102 (processors 102 may include, but are not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), and a memory 104 for storing data. Optionally, the load balancer 10 may further include a transmission device 106 and an input/output device 108 for communication functions. It will be understood by those skilled in the art that the structure shown in fig. 1 is only an illustration, and does not limit the structure of the load balancer. For example, the load balancer 10 may also include more or fewer components than shown in fig. 1, or have a different configuration with equivalent functionality to that shown in fig. 1 or with more functionality than that shown in fig. 1.
The memory 104 can be used for storing computer programs, for example, software programs and modules of application software, such as computer programs corresponding to the processing methods of the tasks in the embodiments of the present application, and the processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, so as to implement the methods described above. The memory 104 may include high speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to the load balancer 10 via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission device 106 is used for receiving or transmitting data via a network. Specific examples of such networks may include wireless networks provided by the communications provider of the co-load balancer 10. In one example, the transmission device 106 includes a NIC (Network Interface Controller) that can be connected to other Network devices through a base station so as to communicate with the internet. In one example, the transmission device 106 may be an RF (Radio Frequency) module, which is used for communicating with the internet in a wireless manner.
The processing method of the task provided in the embodiment of the present application can also be operated in a network architecture as shown in fig. 2. As shown in fig. 2, the network architecture may include: the system comprises a plurality of clients (clients), a load balancer, a plurality of servers (servers) and a coordinating server (zookeeper, which can be a cloud server), wherein the plurality of clients and the load balancer, the load balancer and the plurality of servers can be connected through a network. The coordination function provided by the load balancer may be integrated into the load balancer. A database may be provided on or separate from the server for providing data storage services for the server.
Alternatively, the client may be, but is not limited to running in a terminal that is one of: PC (Personal Computer), cell phone, tablet, etc., including but not limited to at least one of the following: a wired network and a wireless network, wherein the wired network may include, but is not limited to, at least one of: a wide area network, a metropolitan area network, or a local area network, which may include, but is not limited to, at least one of: bluetooth, WiFi (Wireless Fidelity), etc.
The task processing method in the embodiment of the present application may be executed by the load balancer, may also be executed by the coordination server, and may also be executed by both the load balancer and the coordination server. Fig. 3 is a flowchart illustrating an optional task processing method according to an embodiment of the present application, and as shown in fig. 3, the method may include the following steps:
step S302, a first task request sent by a first client is received;
step S304, selecting a first server for processing a first task request from a plurality of servers according to the residual capacity information of each server in the plurality of servers, wherein the residual capacity information of each server is used for representing the residual task processing capacity of each server;
step S306, the first task request is forwarded to the selected first server.
Optionally, the processing method of the task may be applied to a process of dynamically performing load balancing, so as to provide cloud services.
For example, after receiving a task request from a user, the load balancer allocates the task to a server with a current remaining bearing capacity according to the current bearing capacity of the server, taking into account the state information of the server.
By the embodiment, a first task request sent by a first client is received; selecting a first server for processing a first task request from a plurality of servers according to the residual capacity information of each server in the plurality of servers, wherein the residual capacity information of each server is used for representing the residual task processing capacity of each server; the first task request is forwarded to the selected first server, so that the technical problem that the utilization rate of server resources is low due to unreasonable task allocation in a load balancing mode in the related technology is solved, the task allocation reasonableness is improved, and the utilization rate of the server resources is also improved.
The processing method of the task in the present embodiment is explained below with reference to fig. 3.
In step S302, a first task request sent by a first client is received.
Multiple clients can establish connection with the load balancer through the network, and the networks used by different clients can be the same or different. Multiple clients may send requests to the load balancer over the established connection, with task allocation by the load balancer.
The load balancer may receive a first task request sent by the first client, where the first client is one of the clients, and the first task request is a first request, and may be used to trigger generation of a task to be processed, or to request processing of a corresponding task.
In step S304, a first server for processing the first task request is selected from the plurality of servers according to the remaining capacity information of each of the plurality of servers, wherein the remaining capacity information of each server is used for indicating the remaining task processing capacity of each server.
The load balancer may also establish a connection with multiple servers through a network, the networks used by different servers may be the same or different, and the network used by the server and the load balancer may be the same or different as the network used by the client and the load balancer, which is not specifically limited in this embodiment.
The load balancer may periodically obtain or event-trigger the remaining capability information of each of the plurality of servers, and the obtained period may be determined according to configuration information, where the configuration information may be default configuration information or configuration information modified according to a received modification instruction. The event triggering the obtaining may be receiving a first task request (for example, obtaining the remaining capability information of each of the plurality of servers after receiving the first task request), receiving a capability update message sent by the server (for example, obtaining the remaining capability information of each of the plurality of servers after receiving the capability update message sent by the server), or monitoring a processing capability calculation event of the coordinating server (for example, obtaining the remaining capability information of each of the plurality of servers after obtaining the remaining capability information of each of the plurality of servers).
The plurality of servers may be all servers in the network, or may be a part of servers, and the part of servers may be servers specified by the configuration information (for example, clients that different servers may take charge of may not be completely the same, and each client may be provided with task processing services by the specified plurality of servers), or may be servers having the remaining processing capability among all servers. The above description is merely an example, and this is not specifically limited in this embodiment.
After receiving the first task request, the load balancer may first obtain the remaining capability information of each of the plurality of servers, where the obtaining may be from the stored capability information data, or from the coordination server, or according to the stored operating state information of each server.
As an alternative embodiment, before selecting the first server to process the first task request from the plurality of servers according to the remaining capacity information of each of the plurality of servers, the operation state information of each of the plurality of servers may be acquired; and determining the residual capacity information of each server according to the running state information of each server.
Therefore, before selecting a server to be processed for the first task request, the load balancer or the coordination server may first obtain the operation state information of each server, and determine the remaining capacity information of each server according to the operation state information of each server.
Optionally, for the case that the coordination server obtains the operation state information and obtains the remaining capability information, after the coordination server obtains the remaining capability information of each server, the remaining capability information of each server may be actively sent to the load balancer, or the load balancer may send a capability obtaining request for obtaining the remaining capability information of each server to the coordination server after monitoring the processing capability calculation event of the coordination server, or after receiving the first task request; and receiving the remaining capacity information of each server returned by the coordination server in response to the received capacity acquisition request.
Through the embodiment, the residual capacity information of the server is determined according to the running state information of the server, so that the accuracy of determining the residual capacity information can be ensured, and the reasonability of task allocation is further ensured.
The operating state of the server may be represented by a plurality of sub-operating states, which may include, but are not limited to, at least one of: active thread count, memory footprint, response delay.
The operational state of the server may include, but is not limited to: normal operation and abnormal operation.
As an optional implementation manner, determining the remaining capability information of each server according to the operation state information of each server includes: determining that the residual capacity information of a second server is target capacity information under the condition that the second server is determined to be abnormally operated according to the operation state information of the second server in the plurality of servers, wherein the abnormality comprises at least one of the following: the response delay time of the second server exceeds a preset time threshold, the memory occupancy rate of the second server exceeds a preset occupancy rate threshold, the second server has a locked thread, and the target capacity information is used for indicating that no task processing capacity remains.
If it is determined that a certain server (second server) operates abnormally according to the operating state information, the server has no processing capacity and cannot respond to the request of the client, and the remaining capacity information of the server can be set as target capacity information for indicating that no remaining task processing capacity exists.
The operational anomalies of the server may include, but are not limited to, at least one of: and when the response delay time exceeds a preset time threshold, the memory occupancy rate exceeds a preset occupancy rate threshold, locked threads exist, and the number of the current active threads is higher than a preset thread number threshold.
For example, if a worker machine (acting as the aforementioned server) requests a request queue or even a thread blocking stop response, the worker machine may be considered to be abnormally operated.
Through the embodiment, when the server runs abnormally, the residual task processing capacity of the server is set to be zero, so that the load balancer does not forward the request to the server any more, the task can be guaranteed not to be distributed to the server without the task processing capacity at present, the task processing efficiency is guaranteed, and the running load of the server is avoided being increased.
As another optional implementation, determining the remaining capacity information of each server according to the operation state information of each server includes: performing weighted summation on sub-operation state information in the operation state information of each server to obtain a score corresponding to each server, wherein the score corresponding to each server is used for representing the remaining capacity information of each server, and the sub-operation state information comprises at least one of the following: response delay time, memory occupancy rate, and number of active threads.
For different sub-operation states, the corresponding weights may be the same or different. Different weights can be given according to the priority, and for each server, the sub-operation state information of the server can be weighted and summed according to the corresponding weight to obtain the score corresponding to the server.
For example, zookeeper (acting as the aforementioned coordination server) may dynamically calculate the processing capability of a worker machine according to the operating condition of the current worker machine (acting as the aforementioned server), and calculate a score according to a priority and a weight (the weight may be dynamically obtained according to different service models):
(1) response delay (request average response time)
The weight of the response delay may be set to 80, e.g., an average response time of 8 ms, the response delay is scored as: the weight/time (80/8) is 10 (min). The longer the average response time, the lower the calculated score.
(2) Memory usage
The weight of the memory occupation (memory occupancy) can be set to 20, and the calculation method can be as follows: for example, when the JVM already uses 3G memory, does not use 3G memory, and the total system memory is 6G, the memory usage score is: 3G/6G 20 ═ 10 (min).
(3) Active threads
The weight of the active thread may be set to 100, and the calculation may be: for example, if the number of CPU cores of the current machine is 6 and the number of active threads is 50, the score of the active thread is: 6/50 × 100 is 12 (min).
And accumulating all the scores to obtain the score of the worker machine: 10+10+12 equals 32 (min). And calculating the scores of all the worker machines according to the mode, wherein the calculated scores can be used as judgment conditions of the processing capacity.
It should be noted that, when the current server (worker machine) has no processing capability (such as thread deadlock) and cannot respond to the client request, the cumulative score of the server may be set to 0. The weight corresponding to each sub-operational state is related to the priority of that sub-operational state (e.g., both may be positively correlated), and is related to the unit corresponding to that sub-operational state.
According to the embodiment, the scores corresponding to the servers are obtained by weighting and summing the sub-operation parameters of the servers, the operation state information can be quantized, and the accuracy of determining the residual task processing capacity of the servers is improved.
As an alternative embodiment, selecting a first server from the plurality of servers to process the first task request according to the remaining capacity information of each of the plurality of servers includes: and selecting a first server with the score larger than or equal to a target score from the plurality of servers, wherein the target score is the score corresponding to the server with the highest score in the plurality of servers, or a preset score threshold.
After obtaining the current scores for the respective servers, a first server to process the first task request may be selected from the plurality of servers. The selection may include at least one of: and selecting the server with the highest score, wherein the selection score exceeds a preset score threshold value.
For example, the server having the highest score may be selected from the plurality of servers as the server for processing the first task request, one of the plurality of servers having scores exceeding the score threshold may be selected as the server for processing the first task request, or the server having the highest score may be selected as the server for processing the first task request.
It should be noted that, when a certain server (worker machine) cannot work, the load balancer may be notified in real time, and the request is no longer forwarded to the server.
According to the embodiment, the server for processing the first task request is selected from the plurality of servers according to the scores of the servers in different selection modes, different task processing requirements can be met, and task allocation reasonability is guaranteed.
In step S306, the first task request is forwarded to the selected first server.
After selecting the server that processed the first task request, the load balancer may forward the first task request to the selected server.
The first server may perform task processing according to a priority of task processing after receiving the first task request. The priority of task processing may be: the priority of the receiving time (the earlier the receiving time is, the higher the processing priority is), the priority of the task type (different priorities may be given to different task types), the priority of the client (different types of clients may be given different priorities, or different clients may be given corresponding priorities).
As an optional implementation, after forwarding the first task request to the selected first server, a capability update message sent by the second server may be received, where the capability update message carries current remaining capability information of the second server; and updating the residual capacity information of the second server by using the current residual capacity information.
The running state of each server may change in real time during the running process (during the running process, the active thread count, the memory occupation, the response delay, etc. of the server may change as time advances). After the operation parameters are changed, the server can acquire the operation state information in real time and send the operation state information to the load balancer or the coordination server.
Optionally, the server may obtain the running state information in real time, perform weighted summation on each sub-running state information to obtain a score of each server, and send the obtained score to the load balancer or the coordination server.
Optionally, the server may further obtain the current operation state information or score after receiving the state information obtaining request or the score obtaining request of the load balancer or the coordination server, and send the obtained operation state information or score to the load balancer or the coordination server.
After obtaining the operating state information or the score of each server, the load balancer or the coordination server may update the current remaining capacity information of each server according to the obtained operating state information or the score.
For example, the second server may send a capability update message carrying current remaining capability information of the second server to the load balancer or the coordination server. And after receiving the capability updating message, updating the remaining capability information of the second server by using the current remaining capability information of the second server carried by the capability updating message.
It should be noted that the second server and the first server may be the same server or different servers, and the remaining capacity information performed by different servers of each server may be synchronous or asynchronous (the updating of the remaining capacity information of each server is independent and does not affect each other). Specifically, the setting may be performed according to needs, and this is not particularly limited in this embodiment.
By the embodiment, the residual capacity information is updated according to the capacity updating message sent by the server, so that the timeliness of updating the residual capacity information of the server can be ensured, and the task allocation reasonability is improved.
As an optional implementation, after the remaining capability information of the second server is updated by using the current remaining capability information, a second task request sent by the second client is received; selecting a third server for processing the second task request from the plurality of servers according to the updated residual capacity information of each server in the plurality of servers; and forwarding the second task request to the selected third server.
In addition to the first task request, the load balancer may receive task requests sent by the same or different clients.
The load balancer may receive a second task request sent by a second client (which may be the same client as the first client or a different client), select a third server (which may be the same as or different from the first server and/or the second server) that processes the second task request from the plurality of servers according to the updated remaining capacity information of each server, send the second task request to the third server, and process the second task request by the third server. The processing manner of the second task request is similar to that of the first task request, and is not described herein again.
It should be noted that, when the second task request is received, the remaining capacity information of one or more servers in the plurality of servers may or may not change, that is, the updated remaining capacity information may be the same as or different from the remaining capacity information before updating, and may be determined by combining with an actual scene.
According to the embodiment, the server for processing the current task request is selected from the plurality of servers according to the updated residual capacity information, so that the accuracy of server selection can be ensured, and the task allocation reasonability can be improved.
The following describes a processing method of the above task with reference to an alternative example. In this example, the load balancer dynamically determines the current active thread count, memory usage, and response delay of the server in a service management manner, thereby dynamically adjusting the load balancing policy.
The task processing method in this example may be applied to a network architecture as shown in fig. 4, where the client may be a client and the server is a worker machine. The coordination server is zookeeper and the load balancer is nginx (a high performance HTTP and reverse proxy web server).
As shown in fig. 5, the processing method of the task in the present example may include the steps of:
step S502, according to the running state of the server (worker machine), the processing capacity is calculated dynamically.
Different calculation weights can be assigned to different factors of the current worker, such as: active thread count, memory footprint, response delay, etc. And each worker machine can dynamically calculate the processing capacity according to the running state of the worker machine at that time.
In step S504, the computing power of the server is notified to the coordinator server (zookeeper) in real time.
Each worker machine can notify the zookeeper of the calculated processing capacity in real time.
Step S506, the load balancer (nginx) monitors the processing capability calculation event of the coordination server, and performs load balancing mode adjustment.
nginx can monitor zookeeper processing capacity calculation events to obtain the current residual processing capacity of each work machine. The load balancer can adjust the load balancing mode according to the current residual processing capacity of each work machine.
For example, the load balancer may determine a server for processing a next task according to the current remaining processing capacity of each work machine (this step may be performed before receiving the request of the client, or may be performed after receiving the request of the client).
According to the embodiment, dynamic calculation is carried out according to the active thread number, the memory occupation, the response delay and other factors of the client at the moment, so that the forwarding of the connection request of the load balancer is adjusted, the task is accurately distributed to worker machines with strong residual processing capacity, the performance of each worker machine can be fully utilized, and the total number of servers is reduced.
Through the above description of the embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present application.
According to another aspect of the embodiments of the present application, there is also provided a processing apparatus for a task that implements the processing method for the task described above. Fig. 6 is a block diagram of a processing device for optional tasks according to an embodiment of the present application, and as shown in fig. 6, the device may include:
(1) a first receiving unit 602, configured to receive a first task request sent by a first client;
(2) a first selecting unit 604, connected to the first receiving unit 602, configured to select a first server for processing a first task request from the multiple servers according to remaining capability information of each of the multiple servers, where the remaining capability information of each server is used to indicate a remaining task processing capability of each server;
(3) the first sending unit 606 is connected to the first selecting unit 604, and is configured to forward the first task request to the selected first server.
It should be noted that the first receiving unit 602 in this embodiment may be configured to execute step S302 in this embodiment, the first selecting unit 604 in this embodiment may be configured to execute step S304 in this embodiment, and the first sending unit 606 in this embodiment may be configured to execute step S306 in this embodiment.
Through the module, the technical problem that due to the fact that a load balancing mode in the related technology exists, the utilization rate of server resources is low due to unreasonable task allocation can be solved, and the technical effects of improving the rationality of task allocation and improving the utilization rate of the server resources are achieved.
As an alternative embodiment, the above apparatus further comprises:
(1) an acquisition unit configured to acquire operating state information of each of the plurality of servers before selecting a first server that processes the first task request from the plurality of servers according to remaining capacity information of each of the plurality of servers;
(2) and the determining unit is connected with the acquiring unit and used for determining the residual capacity information of each server according to the running state information of each server.
As an alternative embodiment, the determining unit comprises:
(1) the determining module is configured to determine that the remaining capability information of the second server is the target capability information when determining that the second server operates abnormally according to the operating state information of the second server in the plurality of servers, where the abnormality includes at least one of: the response delay time of the second server exceeds a preset time threshold, the memory occupancy rate of the second server exceeds a preset occupancy rate threshold, the second server has a locked thread, and the target capacity information is used for indicating that no task processing capacity remains.
As an alternative embodiment, the determining unit comprises:
(1) the summing module is configured to perform weighted summation on sub-operation state information in the operation state information of each server to obtain a score corresponding to each server, where the score corresponding to each server is used to represent remaining capability information of each server, and the sub-operation state information includes at least one of the following: response delay time, memory occupancy rate, and number of active threads.
As an alternative embodiment, the first selecting unit 604 includes:
(1) the selection module is used for selecting a first server with the score larger than or equal to a target score from the plurality of servers, wherein the target score is the score corresponding to the server with the highest score in the plurality of servers, or a preset score threshold.
As an alternative embodiment, the above apparatus further comprises:
(1) a second receiving unit, configured to receive an ability update message sent by a second server after forwarding the first task request to the selected first server, where the ability update message carries current remaining ability information of the second server;
(2) and the updating unit is connected with the second receiving unit and used for updating the residual capacity information of the second server by using the current residual capacity information.
As an alternative embodiment, the above apparatus further comprises:
(1) a third receiving unit, configured to receive a second task request sent by a second client after updating the remaining capability information of the first server using the current remaining capability information;
(2) the second selecting unit is connected with the third receiving unit and used for selecting a third server for processing the second task request from the plurality of servers according to the updated residual capacity information of each server in the plurality of servers;
(3) and the second sending unit is connected with the second selecting unit and used for forwarding the second task request to the selected third server.
It should be noted here that the modules described above are the same as the examples and application scenarios implemented by the corresponding steps, but are not limited to what is disclosed in the above embodiments. It should be noted that the modules described above as a part of the apparatus may be run in a hardware environment as shown in fig. 2, may be implemented by software, and may also be implemented by hardware, where the hardware environment includes a network environment.
According to still another aspect of an embodiment of the present application, there is also provided a storage medium. Alternatively, in the present embodiment, the storage medium may be used for a program code of a processing method for executing a task.
Optionally, in this embodiment, the storage medium may be located on at least one of a plurality of network devices in a network shown in the above embodiment.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps:
s1, receiving a first task request sent by a first client;
s2, selecting a first server for processing a first task request from a plurality of servers according to the residual capacity information of each server in the plurality of servers, wherein the residual capacity information of each server is used for representing the residual task processing capacity of each server;
s3, the first task request is forwarded to the selected first server.
Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment is not described herein again.
Optionally, in this embodiment, the storage medium may include, but is not limited to: various media capable of storing program codes, such as a usb disk, a ROM (Read-only Memory), a RAM (Random Access Memory), a removable hard disk, a magnetic disk, or an optical disk.
An embodiment of the present application further provides an electronic device, which includes a memory and a processor, where the memory stores a computer program, and the processor is configured to execute the computer program to perform the steps in any of the method embodiments described above.
Optionally, the electronic apparatus may further include a transmission device and an input/output device, wherein the transmission device is connected to the processor, and the input/output device is connected to the processor.
Optionally, in this embodiment, the processor may be configured to execute the following steps by a computer program:
s1, receiving a first task request sent by a first client;
s2, selecting a first server for processing a first task request from a plurality of servers according to the residual capacity information of each server in the plurality of servers, wherein the residual capacity information of each server is used for representing the residual task processing capacity of each server;
s3, the first task request is forwarded to the selected first server.
Optionally, for a specific example in this embodiment, reference may be made to the examples described in the above embodiment and optional implementation, and details of this example are not repeated.
The above-mentioned serial numbers of the embodiments of the present application are merely for description and do not represent the merits of the embodiments.
The integrated unit in the above embodiments, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in the above computer-readable storage medium. Based on such understanding, the technical solution of the present application may be substantially implemented or a part of or all or part of the technical solution contributing to the prior art may be embodied in the form of a software product stored in a storage medium, and including instructions for causing one or more computer devices (which may be personal computers, servers, network devices, or the like) to execute all or part of the steps of the method described in the embodiments of the present application.
In the above embodiments of the present application, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
In the several embodiments provided in the present application, it should be understood that the disclosed client may be implemented in other manners. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one type of division of logical functions, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, units or modules, and may be in an electrical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The foregoing is only a preferred embodiment of the present application and it should be noted that those skilled in the art can make several improvements and modifications without departing from the principle of the present application, and these improvements and modifications should also be considered as the protection scope of the present application.

Claims (10)

1. A method for processing a task, comprising:
receiving a first task request sent by a first client;
selecting a first server for processing the first task request from a plurality of servers according to the residual capacity information of each server in the plurality of servers, wherein the residual capacity information of each server is used for representing the residual task processing capacity of each server;
forwarding the first task request to the selected first server.
2. The method of claim 1, wherein before selecting the first server from the plurality of servers to handle the first task request based on the remaining capacity information of the each of the plurality of servers, the method further comprises:
acquiring running state information of each server in the plurality of servers;
and determining the residual capacity information of each server according to the running state information of each server.
3. The method of claim 2, wherein determining the remaining capacity information of each server according to the operating status information of each server comprises:
determining that the remaining capacity information of a second server is target capacity information under the condition that the second server is determined to be abnormally operated according to the operation state information of the second server in the plurality of servers, wherein the abnormality comprises at least one of the following: the response delay time of the second server exceeds a preset time threshold, the memory occupancy rate of the second server exceeds a preset occupancy rate threshold, the second server has a locked thread, and the target capacity information is used for indicating that no task processing capacity remains.
4. The method of claim 2, wherein determining the remaining capacity information of the each server according to the operating status information of the each server comprises:
performing weighted summation on sub-operation state information in the operation state information of each server to obtain a score corresponding to each server, wherein the score corresponding to each server is used for representing the remaining capacity information of each server, and the sub-operation state information includes at least one of the following: response delay time, memory occupancy rate, and number of active threads.
5. The method of claim 4, wherein selecting the first server from the plurality of servers to handle the first task request according to the remaining capacity information of the each of the plurality of servers comprises:
and selecting the first server with the score larger than or equal to a target score from the plurality of servers, wherein the target score is the score corresponding to the server with the highest score in the plurality of servers, or a preset score threshold.
6. The method according to any of claims 1 to 5, wherein after forwarding the first task request to the selected first server, the method further comprises:
receiving a capability updating message sent by a second server, wherein the capability updating message carries current remaining capability information of the second server;
and updating the residual capacity information of the second server by using the current residual capacity information.
7. The method of claim 6, wherein after updating the remaining capability information of the second server using the current remaining capability information, the method further comprises:
receiving a second task request sent by a second client;
selecting a third server for processing the second task request from the plurality of servers according to the updated residual capacity information of each server in the plurality of servers;
and forwarding the second task request to the selected third server.
8. A task processing apparatus, comprising:
the first receiving unit is used for receiving a first task request sent by a first client;
a first selecting unit, configured to select, according to remaining capacity information of each server of a plurality of servers, a first server that processes the first task request from the plurality of servers, where the remaining capacity information of each server is used to indicate a remaining task processing capacity of each server;
a first sending unit, configured to forward the first task request to the selected first server.
9. A computer-readable storage medium, comprising a stored program, wherein the program when executed performs the method of any of claims 1 to 7.
10. An electronic device comprising a memory and a processor, characterized in that the memory has stored therein a computer program, the processor being arranged to execute the method of any of claims 1 to 7 by means of the computer program.
CN201911158443.2A 2019-11-22 2019-11-22 Task processing method and device, storage medium and electronic device Pending CN110995802A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911158443.2A CN110995802A (en) 2019-11-22 2019-11-22 Task processing method and device, storage medium and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911158443.2A CN110995802A (en) 2019-11-22 2019-11-22 Task processing method and device, storage medium and electronic device

Publications (1)

Publication Number Publication Date
CN110995802A true CN110995802A (en) 2020-04-10

Family

ID=70086071

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911158443.2A Pending CN110995802A (en) 2019-11-22 2019-11-22 Task processing method and device, storage medium and electronic device

Country Status (1)

Country Link
CN (1) CN110995802A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111556126A (en) * 2020-04-24 2020-08-18 杭州浮云网络科技有限公司 Model management method, system, computer device and storage medium
CN111984416A (en) * 2020-08-26 2020-11-24 四川省有线广播电视网络股份有限公司 Performance improving method and system based on module competition

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105491138A (en) * 2015-12-15 2016-04-13 国网智能电网研究院 Load rate based graded triggering distributed load scheduling method
CN105871983A (en) * 2015-12-10 2016-08-17 乐视云计算有限公司 Method and device for selecting servers
EP3131268A1 (en) * 2012-11-01 2017-02-15 Microsoft Technology Licensing, LLC Load balancing in a content delivery network
CN107800756A (en) * 2017-03-13 2018-03-13 平安科技(深圳)有限公司 A kind of load-balancing method and load equalizer
CN109729131A (en) * 2018-04-12 2019-05-07 平安普惠企业管理有限公司 A kind of processing method of application request, device and router
CN109936606A (en) * 2017-12-18 2019-06-25 浙江宇视科技有限公司 Method for allocating tasks and device
US10355943B1 (en) * 2014-04-04 2019-07-16 8X8, Inc. Apparatus and methods of analyzing status of computing servers

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP3131268A1 (en) * 2012-11-01 2017-02-15 Microsoft Technology Licensing, LLC Load balancing in a content delivery network
US10355943B1 (en) * 2014-04-04 2019-07-16 8X8, Inc. Apparatus and methods of analyzing status of computing servers
CN105871983A (en) * 2015-12-10 2016-08-17 乐视云计算有限公司 Method and device for selecting servers
CN105491138A (en) * 2015-12-15 2016-04-13 国网智能电网研究院 Load rate based graded triggering distributed load scheduling method
CN107800756A (en) * 2017-03-13 2018-03-13 平安科技(深圳)有限公司 A kind of load-balancing method and load equalizer
CN109936606A (en) * 2017-12-18 2019-06-25 浙江宇视科技有限公司 Method for allocating tasks and device
CN109729131A (en) * 2018-04-12 2019-05-07 平安普惠企业管理有限公司 A kind of processing method of application request, device and router

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
周航慈: "《基于嵌入式实时操作系统的程序设计技术》", 31 January 2011 *
王青文: "关于物联网网络节点负载均衡性匹配研究", 《计算机仿真》 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111556126A (en) * 2020-04-24 2020-08-18 杭州浮云网络科技有限公司 Model management method, system, computer device and storage medium
CN111984416A (en) * 2020-08-26 2020-11-24 四川省有线广播电视网络股份有限公司 Performance improving method and system based on module competition
CN111984416B (en) * 2020-08-26 2024-04-19 中国广电四川网络股份有限公司 Performance improvement method and system based on module competition

Similar Documents

Publication Publication Date Title
CN109618002B (en) Micro-service gateway optimization method, device and storage medium
CN109347947A (en) A kind of method of load balancing, name server and cluster nas server
CN110830391A (en) Resource allocation method and device and cluster system
US11671332B2 (en) Adjusting triggers for automatic scaling of virtual network functions
CN109831524B (en) Load balancing processing method and device
CN116547958A (en) Method, system and computer readable medium for ranking process of network function selection
CN110365748A (en) Treating method and apparatus, storage medium and the electronic device of business datum
CN110166524B (en) Data center switching method, device, equipment and storage medium
CN112261120B (en) Cloud-side cooperative task unloading method and device for power distribution internet of things
CN114143270B (en) Bandwidth adjustment method and device
CN110995802A (en) Task processing method and device, storage medium and electronic device
Choi et al. An improvement on the weighted least-connection scheduling algorithm for load balancing in web cluster systems
KR101448413B1 (en) Method and apparatus for scheduling communication traffic in atca-based equipment
CN104301241B (en) A kind of SOA dynamic load distributing methods and system
CN116909735A (en) Calculation power scheduling method and device, server and storage medium
US9270746B2 (en) Scalable load balancing
CN110147277A (en) A kind of resource dynamic deployment method, device, server and storage medium
CN113328906A (en) Flow real-time monitoring method and device, storage medium and electronic equipment
CN115168017B (en) Task scheduling cloud platform and task scheduling method thereof
CN112398957B (en) Server scheduling method and device, storage medium and electronic equipment
CN114546646A (en) Processing method and processing apparatus
CN114936089A (en) Resource scheduling method, system, device and storage medium
JP4726846B2 (en) Accommodation control method and communication server system in communication server system
CN112153138A (en) Traffic scheduling method and device, electronic equipment and storage medium
CN111045805A (en) Method and device for rating task executor, computer equipment and storage medium

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20200410

RJ01 Rejection of invention patent application after publication