Cluster node task allocation method and device, storage medium and electronic device
By dynamically calculating the average response time of nodes in a distributed system and adjusting task allocation, the problems of resource waste and load imbalance in the prior art are solved, and load balancing between nodes and optimal response performance is achieved.
Patent Information
- Application Number
- CN202111566945.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-20
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2041-12-20
AI Technical Summary
The prior art cannot effectively manage computer nodes in different performance states in distributed systems, resulting in waste of resources and load imbalance.
By obtaining the response time consumed by each node within the preset statistical time period, calculating the average response time consumed, dynamically adjusting the task allocation based on this information, generating a virtual node to build a hash ring, and finally realizing the node task allocation plan.
Load balancing of different performance nodes is realized, resource waste is avoided, and optimal response performance of distributed systems is ensured.
Smart Images

Figure CN116302460B_ABST
Abstract
Description
Background Art
[0002] Nowadays, there are more and more high-concurrency and massive data processing scenarios. It is inevitable to achieve high availability and short latency of services, and distributed systems have come into being. A distributed system is a group of computers that are combined to provide services to the outside world. The more computers in a distributed system, the more computing and storage resources there are, and the faster the response speed. Although the distributed system solves the availability problem faced by a single-machine system through multiple working nodes, it introduces the problem of coordinating the working nodes within the distributed system. Commonly used load balancing strategies: consistent hashing algorithms, when there are computers with different performance and different states in the cluster, it is impossible to manage and allocate tasks differently, resulting in a waste of resources. How to distribute query requests and computing requests to achieve the best use of different computers has become a problem that must be solved by distributed systems.
[0003] There are two main related technologies in the industry. The first is to determine the weight value of each server in the server cluster based on the machine configuration information of each server in the cluster, and then determine the number of virtual nodes corresponding to the server in the hash ring according to the weight value, so as to achieve the effect of allocating query requests according to performance. However, simply recording the machine configuration cannot represent performance. For example, if multiple module components are deployed on a machine, or historical tasks are being executed, the performance will be reduced and cannot correspond to the recorded configuration. This solution may reduce the performance of the distributed system. The second is to use pheromone data packets to record information such as the machine utilization rate of the database server. The lower the utilization rate, the higher the pheromone concentration. According to the weight of the pheromone data packet, a corresponding proportion of virtual nodes is generated. However, the utilization rate does not reflect the performance of the machine. A high-performance node with a high utilization rate may perform better than an ordinary node with a low utilization rate. This solution cannot guarantee the fastest response.
[0004] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0005] The present disclosure provides a cluster node task allocation method and device, a storage medium and an electronic device, which at least to a certain extent overcome the problems of machine load imbalance caused by data skew of consistent hashing in related technologies and resource waste caused by lack of consideration of the performance of different nodes.
[0006] Other features and advantages of the present disclosure will become apparent from the following detailed description, or may be learned in part by the practice of the present disclosure.
[0007] According to one aspect of the present disclosure, a cluster node task allocation method is provided, including: obtaining the response time of each node in the cluster to a single request within a preset statistical time period; calculating the average response time of each node to a single request within the preset statistical time period based on the response time of each node to multiple requests within the preset statistical time period; determining the number of requests expected to be allocated to each node in the cluster based on the average response time of each node to a single request and the total number of requests currently to be allocated in the cluster; generating a corresponding number of virtual nodes according to the number of requests expected to be allocated to each node in the cluster, and constructing a hash ring; generating a node task allocation scheme for the cluster based on the hash ring, wherein the task allocation scheme is used to allocate request tasks to each node in the cluster.
[0008] In one embodiment of the present disclosure, after generating a node task allocation plan for the cluster according to the hash ring, the method further includes: loading the data files and memory indexes of the to-be-allocated requests into each node in the cluster according to the node task allocation plan.
[0009] In one embodiment of the present disclosure, after loading the data files and memory indexes of the requests to be allocated to each node in the cluster according to the node task allocation scheme, the method further includes: distributing the requests to be allocated to the corresponding nodes in the cluster.
[0010] In one embodiment of the present disclosure, the method also includes: periodically monitoring the average response time of each node; calculating the change in the average response time of each node between the current cycle and the previous cycle; when the change in the average response time exceeds a preset threshold, determining the number of requests expected to be allocated to each node in the cluster based on the average response time of each node in the current cycle and the total number of requests currently to be allocated in the cluster.
[0011] In one embodiment of the present disclosure, when the expected number of requests is input, the estimated number of allocated requests for each node is obtained according to the average response time of each node, including:
[0012] Input the expected number of requests, and use the dynamic programming equation to obtain the expected number of requests to be allocated to each node based on the average response time of each node; the dynamic programming equation calculation formula is: distribute[n][m]=distribute[n][m-1]+{local_minmum for
[0013] (distribute[n][m-1]+1)×cost[n]},
[0014] Where n represents a node, distribute[n][m] represents the number of requests allocated to a node in the mth step, distribute[n][m-1] represents the number of requests allocated to a node in the previous step of the mth step, {local_minmum for(distribute[n][m-1]+1)×cost[n]} represents taking the node with the lowest response time in the request, cost represents a one-dimensional array that records the time required for each node to complete a unit request, and cost[n] represents the response time required for a node to complete a unit request.
[0015] In one embodiment of the present disclosure, a heartbeat mechanism is applied to periodically monitor the average response time of each node.
[0016] In one embodiment of the present disclosure, before loading the data files and memory indexes of the request to be allocated to each node in the cluster according to the node task allocation scheme, it also includes: using the Raft algorithm to save the data files and memory indexes before the request to be allocated.
[0017] According to another aspect of the present disclosure, a cluster node task allocation device is provided, characterized in that it includes:
[0018] The time-consuming module is used to obtain the response time of each node in the cluster to a single request within a preset statistical time period;
[0019] The average time consumption calculation module is used to calculate the average response time consumption of each node to a single request within the preset statistical time period according to the response time consumption of each node to multiple requests within the preset statistical time period;
[0020] The estimated number of requests module is used to determine the estimated number of requests to be allocated to each node in the cluster based on the average response time of each node to a single request and the total number of requests currently to be allocated in the cluster;
[0021] A hash ring module is constructed to generate a corresponding number of virtual nodes according to the number of requests expected to be allocated to each node in the cluster, and to construct a hash ring;
[0022] The task allocation module is used to generate a node task allocation scheme for the cluster according to the hash ring, wherein the task allocation scheme is used to allocate request tasks to each node in the cluster.
[0023] According to another aspect of the present disclosure, there is provided an electronic device, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute the above-mentioned cluster node task allocation method by executing the executable instructions.
[0024] According to another aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned cluster node task allocation method is implemented.
[0025] The cluster node task allocation method and device, storage medium and electronic device provided by the embodiments of the present disclosure obtain the response time of each node in the cluster to a single request within a preset statistical time period; according to the response time of each node to multiple requests within the preset statistical time period, calculate the average response time of each node to a single request within the preset statistical time period; according to the average response time of each node to a single request and the total number of requests currently to be allocated in the cluster, determine the number of requests expected to be allocated to each node in the cluster; generate a corresponding number of virtual nodes according to the number of requests expected to be allocated to each node in the cluster, and construct a hash ring; according to the hash ring, generate a node task allocation plan for the cluster, wherein the task allocation plan is used to allocate request tasks to each node in the cluster. The present disclosure is based on the performance of each node in the cluster, applies a dynamic programming algorithm, dynamically adjusts the task allocation mechanism, and ensures that the load balancing of nodes with different performances achieves the best response.
[0026] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without creative work.
[0028] Figure 1 A schematic diagram showing a cluster node task allocation system structure in an embodiment of the present disclosure;
[0029] Figure 2 A flow chart of a cluster node task allocation method according to an embodiment of the present disclosure is shown;
[0030] Figure 3 A flowchart showing a specific example of a cluster node task allocation method in an embodiment of the present disclosure;
[0031] Figure 4 A flowchart showing a specific example of a cluster node task allocation method in an embodiment of the present disclosure;
[0032] Figure 5 A schematic diagram of a cluster node task allocation device in an embodiment of the present disclosure is shown;
[0033] Figure 6 A structural block diagram of an electronic device according to an embodiment of the present disclosure is shown;
[0034] Figure 7 A schematic diagram showing a computer-readable storage medium in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0035] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that the disclosure will be more comprehensive and complete and to fully convey the concepts of the example embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
[0036] In addition, the accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.
[0037] For ease of understanding, several terms involved in the present disclosure are explained below:
[0038] Node: A computer network node. In data communications, a physical network node can be a data circuit termination device, such as a modem, hub, bridge, or switch; or a data terminal device, such as a digital mobile phone, printer, or host (such as a router, workstation, or server). It has the ability to communicate and network and the computing power.
[0039] Consistent hashing: Consistent hashing. The consistent hashing algorithm was proposed by MIT in 1997. It is a special hashing algorithm that aims to solve the problem of distributed caching. When removing or adding a server, the consistent hashing algorithm can change the mapping relationship between existing service requests and the servers that process the requests as little as possible. Consistent hashing solves the problems of dynamic scaling and other issues that simple hashing algorithms have in distributed hash tables (DHT).
[0040] Hash ring: The consistent hashing algorithm maps the entire hash value space into a virtual ring. The value range of the entire hash space is 0 to 2 to the power of 32 - 1. The entire space is organized in a clockwise direction. 0 to 2 to the power of 32 - 1 coincides in the direction of zero. Next, the following algorithm is used to map the service request. The service request is calculated using the hash algorithm to obtain the corresponding hash value, and then the hash value is searched clockwise along the ring according to the position of the hash value. The first server encountered is the corresponding server that processes the request. When a new server is added, the only data affected is the data between the newly added server and the previous server in its ring space (that is, the first server encountered in the counterclockwise direction), and nothing else will be affected.
[0041] Raft algorithm: Raft algorithm. Raft is a consensus algorithm designed to replace Paxos. It is easier to understand than Paxos through logical separation, but it is also formally proven to be safe and provides some additional features. Raft provides a general method for distributing state machines in a cluster of computing systems, ensuring that every node in the cluster agrees on the same series of state transitions.
[0042] Dynamic Programming: Dynamic Programming is a branch of operations research, which is the process of optimizing the decision-making process. Dynamic programming is widely used in engineering technology, economics, industrial production, military and automation control, and has achieved remarkable results in knapsack problems, production and operation problems, capital management problems, resource allocation problems, shortest path problems and complex system reliability problems.
[0043] Iteration: Iteration is the activity of repeating the feedback process, and its purpose is usually to approach the desired goal or result. Each repetition of the process is called an "iteration", and the result of each iteration will be used as the initial value of the next iteration. It is the process of repeatedly executing a series of calculation steps to obtain the subsequent quantities from the previous quantities. Each result of this process is obtained by applying the same calculation steps to the previous result. For a subroutine (a set of instructions) that needs to be executed repeatedly in a specific computer program, it is repeated, that is, the loop in the program is repeatedly executed until a certain condition is met, which is also called an iteration.
[0044] The present exemplary implementation is described in detail below with reference to the accompanying drawings and embodiments.
[0045] Figure 1 A schematic diagram showing an exemplary system architecture that can be applied to a cluster node task allocation method or a cluster node task allocation device according to an embodiment of the present disclosure.
[0046] like Figure 1As shown, the system architecture 100 may include terminal devices 101 , 102 , a network 103 , and nodes 104 , 105 , and 106 .
[0047] The network 103 is a medium for providing a communication link between the terminal devices 101, 102 and the nodes 104, 105, 106, and may be a wired network or a wireless network.
[0048] Optionally, the wireless network or wired network described above uses standard communication technology and / or protocol. The network is usually the Internet, but it can also be any network, including but not limited to a local area network (LAN), a metropolitan area network (MAN), a wide area network (WAN), a mobile, wired or wireless network, a dedicated network or any combination of a virtual private network). In some embodiments, technologies and / or formats including Hyper Text Mark-up Language (HTML), Extensible Markup Language (XML), etc. are used to represent data exchanged through the network. In addition, conventional encryption technologies such as Secure Socket Layer (SSL), Transport Layer Security (TLS), Virtual Private Network (VPN), Internet Protocol Security (IPsec) can also be used to encrypt all or some links. In other embodiments, customized and / or dedicated data communication technologies can also be used to replace or supplement the above data communication technologies.
[0049] The terminal devices 101 and 102 may be various electronic devices, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, wearable devices, augmented reality devices, virtual reality devices, etc.
[0050] Optionally, the client of the application installed in different terminal devices 101 and 102 is the same, or the client of the same type of application based on different operating systems. Based on the different terminal platforms, the specific form of the client of the application can also be different, for example, the application client can be a mobile client, a PC client, etc.
[0051] Nodes 104, 105, and 106 may be servers that provide various services, such as servers that provide support for devices operated by users using terminal devices 101 and 102. The server may analyze and process received request data and feed back the processing results to the terminal device.
[0052] Optionally, the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The terminal can be a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in this application.
[0053] Those skilled in the art will know that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration, and any number of terminal devices, networks and servers may be provided according to actual needs, and the embodiments of the present disclosure do not limit this.
[0054] exist Figure 1 Under the system architecture shown, a cluster node task allocation method is provided in an embodiment of the present disclosure, and the method can be executed by any electronic device with computing and processing capabilities.
[0055] Figure 2 A flow chart of a cluster node task allocation method according to an embodiment of the present disclosure is shown as follows: Figure 2 As shown, the cluster node task allocation method provided in the embodiment of the present disclosure includes the following steps:
[0056] S202, obtaining the response time of each node in the cluster to a single request within a preset statistical time period;
[0057] S204, calculating the average response time of each node to a single request within the preset statistical time period according to the response time of each node to multiple requests within the preset statistical time period;
[0058] S206, determining the number of requests that are expected to be allocated to each node in the cluster according to the average response time of each node to a single request and the total number of requests currently to be allocated in the cluster;
[0059] S208, generating a corresponding number of virtual nodes according to the number of requests expected to be allocated to each node in the cluster, and constructing a hash ring;
[0060] S210, generating a node task allocation scheme of the cluster according to the hash ring, wherein the task allocation scheme is used to allocate a request task to each node in the cluster.
[0061] The present invention applies a dynamic programming algorithm based on the performance of each node in the cluster to dynamically adjust the task allocation mechanism to ensure that the load balancing of nodes with different performances achieves the best response. This avoids the imbalance of machine load caused by data skewness of consistent hashing and the waste of resources caused by the lack of consideration of the performance of different nodes.
[0062] With respect to S202 , in one embodiment, it may be that: a statistical time period is preset, and the response time of each node in the cluster to a single request within the preset statistical time period is obtained.
[0063] For example, a statistical time period is preset as September to October of a certain year. The cluster has two nodes, A and B. It is found that there are two requests to node A from September to October of a certain year, which take 1 second and 3 seconds respectively. There are three requests to node B from September to October of a certain year, which take 3 seconds, 3 seconds and 6 seconds respectively.
[0064] With respect to S204, in one embodiment, it may be that: based on the acquired response time of each node to multiple requests within the statistical time period, the average response time of each node to a single request within the preset statistical time period is calculated.
[0065] For example, based on the fact that node A had two requests from September to October of a certain year, which took 1 second and 3 seconds respectively, and node B had three requests from September to October of a certain year, which took 3 seconds, 3 seconds and 6 seconds respectively, it is calculated that the average response time of node A to a single request from September to October of a certain year is: (1 second + 3 seconds) ÷ 2 = 2 seconds, and the average response time of node B to a single request from September to October of a certain year is (3 seconds + 3 seconds + 6 seconds) ÷ 3 = 4 seconds.
[0066] With respect to S206 , in one embodiment, it may be: according to the average response time of each node to a single request and the total number of requests currently to be allocated in the cluster, the number of requests expected to be allocated to each node in the cluster is determined.
[0067] For example, based on the average response time of node A to a single request of 2 seconds and the average response time of node B to a single request of 4 seconds, the ratio of node A to node B for processing the same task is 2:1, and the total number of requests to be allocated in the cluster is currently 9. It is determined that the estimated number of requests to be allocated to node A is 6 and the estimated number of requests to be allocated to node B is 3.
[0068] In one embodiment, inputting the expected number of requests and obtaining the estimated number of requests to be allocated to each node based on the average response time of each node may include: inputting the expected number of requests and obtaining the estimated number of requests to be allocated to each node based on the average response time of each node using a dynamic programming equation; wherein the dynamic programming equation calculation formula is: distribute[n][m]=distribute[n][m-1]+{local_minmum for(distribute[n][m-1]+1)×cost[n]}, wherein n represents a node, distribute[n][m] represents the number of requests allocated to a node in the mth step, distribute[n][m-1] represents the number of requests allocated to a node in the previous step of the mth step, {local_minmumfor(distribute[n][m-1]+1)×cost[n]} represents taking the node with the lowest response time in the request, cost represents a one-dimensional array, recording the time required for each node to complete a unit request, and cost[n] represents the response time for a node to complete a unit request.
[0069] To further illustrate the specific implementation process of dynamic programming, in one embodiment, a two-dimensional array is initialized to record the cost of a certain node under m tasks (equivalent to the above request) (equivalent to the above average response time); a double loop is performed, traversing m from 1 to M+1 (M is the total number of tasks), and n (n is a node) from 0 to N (N is the total number of nodes); the local minimum cost is initialized to the maximum value of int (integer, data type), and the local minimum index (function) is -1; enter the innermost loop: the current local cost is equal to the previous step cost of the current n nodes plus the cost of assigning a task in this step; find the node with the smallest cost among all nodes, and record localMinValue (local minimum value) and the node pointer localMinIndex; go to the outer loop, add 1 to the number of tasks of the node pointed to by the pointer; complete the loop; initialize an array to record the results; extract the results of the M position of the two-dimensional array from 0 to N into the result array; return the result array. The pseudo code of the final implementation is as follows:
[0070] "distribute = int[N][M+1]
[0071] for m:=1to M+1do
[0072] localMinValue=Integer.MAX_VALUE,localMinIndex=-1
[0073] for n:=0to N do
[0074] localCost=(distribute[n][m-1]+1)*cost[n]
[0075] if localCost<=localMinValue then
[0076] localMinValue=localCost
[0077] localMinIndex=n
[0078] assign distribute[n][m-1]to distribute[n][m]
[0079] end
[0080] assign(distribute[localMinIndex][m-1]+1)todistribute[localMinIndex][m]
[0081] end
[0082] records[] = new int[N]
[0083] for n:=0to N do
[0084] records[n] = distribute[n][M]
[0085] end
[0086] return records".
[0087] For S208, in one embodiment, it can be: according to the number of requests expected to be allocated to each node in the cluster, a corresponding number of virtual nodes are generated, and the consistent hashing algorithm maps the entire hash value space into a virtual ring, and hashes each node and virtual node to this ring.
[0088] For example, if the number of requests expected to be allocated to node A is 6 and the number of requests expected to be allocated to node B is 3, node A can generate 2 virtual nodes, and node B generates 1 virtual node. Node A, node B, the 2 virtual nodes generated by node A, and the 1 virtual node generated by node B are all hashed to the hash ring.
[0089] With respect to S210 , in one embodiment, it may be that: according to the generated hash ring, under the condition of satisfying load balancing, a request task is allocated to each node in the cluster, and a node task allocation scheme of the cluster is generated.
[0090] Figure 3 A flowchart showing a specific example of a cluster node task allocation method according to an embodiment of the present disclosure is shown as follows: Figure 3 As shown, the cluster node task allocation method provided in the embodiment of the present disclosure may also include the following steps:
[0091] S302: According to the node task allocation plan, the data files and memory indexes to be allocated are loaded into each node in the cluster.
[0092] The present disclosure pre-configures data files based on a node task allocation scheme to ensure that load balancing of nodes with different performances achieves optimal response.
[0093] For S302, in one embodiment, it can be: according to the node task allocation plan, the allocation request to be received by each node in the task configuration plan is obtained, and the data file and memory index of the request to be allocated are pre-loaded to the corresponding nodes in the cluster.
[0094] In one embodiment, after the data files and memory indexes of the requests to be allocated are loaded into each node in the cluster according to the node task allocation scheme, the method may further include: distributing the requests to be allocated to the corresponding nodes in the cluster.
[0095] Figure 4 A flowchart showing a specific example of a cluster node task allocation method according to an embodiment of the present disclosure is shown as follows: Figure 4 As shown, the cluster node task allocation method provided in the embodiment of the present disclosure may also include the following steps:
[0096] S402, periodically monitoring the average response time of each node;
[0097] S404, calculating the average response time change of each node between the current cycle and the previous cycle;
[0098] S406, when the change in average response time exceeds a preset threshold, the number of requests expected to be allocated to each node in the cluster is determined according to the average response time of each node in the current cycle and the total number of requests currently to be allocated in the cluster.
[0099] The present disclosure applies a periodic monitoring method to dynamically adapt to the performance changes of nodes, ensuring that when the performance of a node changes, the load balancing of the performance node is adjusted in a timely manner to achieve the best response.
[0100] With respect to S402, in one embodiment, it may be: setting a period, periodically monitoring each node, and detecting the average response time of each node to a single node within the period.
[0101] With respect to S404, in one embodiment, the step may be: calculating a change between an average response time of each node to a single node in the current cycle and an average response time of each node to a single node in the previous cycle.
[0102] For S406, in one embodiment, it can be: a threshold is preset, and when the change in the average response time exceeds the preset threshold, it indicates that the performance of the node has changed, that is, the average response time of a single node has changed, and it is necessary to redetermine the number of requests expected to be allocated to each node in the cluster based on the average response time of each node in the current cycle and the total number of requests currently to be allocated in the cluster.
[0103] Based on the same inventive concept, the present disclosure also provides a cluster node task allocation device, as described in the following embodiments. Since the principle of solving the problem in the device embodiment is similar to that in the above method embodiment, the implementation of the device embodiment can refer to the implementation of the above method embodiment, and the repeated parts will not be repeated.
[0104] Figure 5 A schematic diagram of a cluster node task allocation device in an embodiment of the present disclosure is shown. Figure 5 As shown, the device may include:
[0105] The time-consuming module 501 is used to obtain the time taken by each node in the cluster to respond to a single request within a preset statistical time period;
[0106] The average time consumption calculation module 502 is used to calculate the average response time consumption of each node to a single request within a preset statistical time period according to the response time consumption of each node to multiple requests within a preset statistical time period;
[0107] The estimated request number module 503 is used to determine the estimated number of requests to be allocated to each node in the cluster according to the average response time of each node to a single request and the total number of requests currently to be allocated in the cluster;
[0108] A hash ring construction module 504 is used to generate a corresponding number of virtual nodes according to the number of requests expected to be allocated to each node in the cluster, and to construct a hash ring;
[0109] The task allocation module 505 is used to generate a node task allocation scheme of the cluster according to the hash ring, wherein the task allocation scheme is used to allocate a request task to each node in the cluster.
[0110] In one embodiment, the cluster node task allocation device may further include:
[0111] The loading module is used to load the data files and memory indexes to be allocated to each node in the cluster according to the node task allocation plan.
[0112] In one embodiment, the cluster node task allocation device may further include:
[0113] The distribution module is used to distribute the requests to be allocated to the corresponding nodes in the cluster.
[0114] In one embodiment, the cluster node task allocation device may further include:
[0115] The periodic monitoring module is used to periodically monitor the average response time of each node;
[0116] The module for calculating the time consumption change is used to calculate the average response time change of each node between the current cycle and the previous cycle;
[0117] The estimated request number module is used to determine the estimated number of requests to be allocated to each node in the cluster based on the average response time of each node in the current cycle and the total number of requests currently to be allocated in the cluster when the change in the average response time exceeds a preset threshold.
[0118] Those skilled in the art will appreciate that various aspects of the present disclosure may be implemented as systems, methods or program products. Therefore, various aspects of the present disclosure may be specifically implemented in the following forms, namely: complete hardware implementation, complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to herein as "circuits", "modules" or "systems".
[0119] Refer to the following Figure 6 The electronic device 600 according to this embodiment of the present disclosure is described. Figure 6 The electronic device 600 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0120] like Figure 6 As shown, the electronic device 600 is in the form of a general computing device. The components of the electronic device 800 may include but are not limited to: the at least one processing unit 610, the at least one storage unit 620, and a bus 630 connecting different system components (including the storage unit 620 and the processing unit 610).
[0121] The storage unit stores program codes, which can be executed by the processing unit 610, so that the processing unit 610 executes the steps described in the above “Exemplary Method” section of this specification according to various exemplary embodiments of the present disclosure.
[0122] For example, the processing unit 610 can execute the following steps of the above method embodiment: obtain the response time of each node in the cluster to a single request within a preset statistical time period; calculate the average response time of each node to a single request within the preset statistical time period based on the response time of each node to multiple requests within the preset statistical time period; determine the number of requests expected to be allocated to each node in the cluster based on the average response time of each node to a single request and the total number of requests currently to be allocated in the cluster; generate a corresponding number of virtual nodes based on the number of requests expected to be allocated to each node in the cluster, and construct a hash ring; based on the hash ring, generate a node task allocation plan for the cluster, wherein the task allocation plan is used to allocate request tasks to each node in the cluster.
[0123] In some embodiments, the processing unit 610 in the embodiment of the present disclosure can execute the following steps of the above-mentioned method embodiment: after generating a node task allocation plan for the cluster according to the hash ring, the data files and memory indexes to be allocated are loaded into each node in the cluster according to the node task allocation plan.
[0124] In some embodiments, the processing unit 610 in the embodiment of the present disclosure can execute the following steps of the above-mentioned method embodiment: after loading the data files and memory indexes of the requests to be allocated into each node in the cluster according to the node task allocation plan, the requests to be allocated are distributed to the corresponding nodes in the cluster.
[0125] In some embodiments, the processing unit 610 in the embodiment of the present disclosure can execute the following steps of the above-mentioned method embodiment: periodically monitor the average response time of each node; calculate the change in the average response time of each node between the current cycle and the previous cycle; when the change in the average response time exceeds a preset threshold, determine the number of requests expected to be allocated to each node in the cluster based on the average response time of each node in the current cycle and the total number of requests currently to be allocated in the cluster.
[0126] In some embodiments, the processing unit 610 in the embodiment of the present disclosure may perform the following steps of the above method embodiment: input the expected number of requests, and obtain the expected number of allocated requests for each node using a dynamic programming equation according to the average response time of each node; wherein the calculation formula of the dynamic programming equation is:
[0127] distribute[n][m]=distribute[n][m-1]+{local_minmum for(distribute[n][m-1]+1)×cost[n]}, where n represents a node, distribute[n][m] represents the number of requests distributed to a node in the mth step, distribute[n][m-1] represents the number of requests distributed to a node in the step before the mth step, {local_minmum for(distribute[n][m-1]+1)×cost[n]} means taking the node with the lowest response time in the request, cost represents a one-dimensional array that records the time required for each node to complete a unit request, and cost[n] represents the response time taken by a node to complete a unit request.
[0128] In some embodiments, the processing unit 610 in the embodiment of the present disclosure may execute the following steps of the above method embodiment: applying a heartbeat mechanism to periodically monitor the average response time of each node.
[0129] In some embodiments, the processing unit 610 in the embodiment of the present disclosure may execute the following steps of the above method embodiment: using the Raft algorithm to save the data file and memory index before the request to be allocated.
[0130] The storage unit 620 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 6201 and / or a cache memory unit 6202 , and may further include a read-only memory unit (ROM) 6203 .
[0131] The storage unit 620 may also include a program / utility 6204 having a set (at least one) of program modules 6205, such program modules 6205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0132] Bus 630 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0133] The electronic device 600 may also communicate with one or more external devices 640 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 600, and / or communicate with any device that enables the electronic device 600 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 650. Furthermore, the electronic device 600 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 660. As shown, the network adapter 660 communicates with other modules of the electronic device 600 via a bus 630. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.
[0134] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0135] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is further provided, which may be a readable signal medium or a readable storage medium. Figure 7 A schematic diagram of a computer-readable storage medium in an embodiment of the present disclosure is shown. Figure 7 As shown, a program product capable of implementing the above method of the present disclosure is stored on the computer-readable storage medium 700. In some possible implementations, various aspects of the present disclosure may also be implemented in the form of a program product, which includes a program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps according to various exemplary implementations of the present disclosure described in the above “Exemplary Method” section of this specification.
[0136] For example, when the program product in the embodiment of the present disclosure is executed by a processor, the method implements the following steps: obtaining the response time of each node in the cluster to a single request within a preset statistical time period; calculating the average response time of each node to a single request within the preset statistical time period based on the response time of each node to multiple requests within the preset statistical time period; determining the number of requests expected to be allocated to each node in the cluster based on the average response time of each node to a single request and the total number of requests currently to be allocated in the cluster; generating a corresponding number of virtual nodes based on the number of requests expected to be allocated to each node in the cluster, and constructing a hash ring; generating a node task allocation plan for the cluster based on the hash ring, wherein the task allocation plan is used to allocate request tasks to each node in the cluster.
[0137] In some embodiments, the program product in the embodiments of the present disclosure can also implement the following method steps when executed by a processor: after generating a node task allocation plan for the cluster based on the hash ring, the data files and memory indexes to be allocated are loaded into each node in the cluster according to the node task allocation plan.
[0138] In some embodiments, the program product in the embodiments of the present disclosure can also implement the following method steps when executed by a processor: after loading the data files and memory indexes of the requests to be allocated into each node in the cluster according to the node task allocation plan, the requests to be allocated are distributed to the corresponding nodes in the cluster.
[0139] In some embodiments, the program product in the embodiments of the present disclosure can also implement the following method steps when executed by a processor: periodically monitor the average response time of each node; calculate the change in the average response time of each node between the current cycle and the previous cycle; when the change in the average response time exceeds a preset threshold, determine the number of requests expected to be allocated to each node in the cluster based on the average response time of each node in the current cycle and the total number of requests currently to be allocated in the cluster.
[0140] In some embodiments, when the program product in the embodiments of the present disclosure is executed by a processor, the following method can be implemented: input the expected number of requests, and according to the average response time of each node, use the dynamic programming equation to obtain the expected number of allocated requests for each node; wherein the calculation formula of the dynamic programming equation is:
[0141] distribute[n][m]=distribute[n][m-1]+{local_minmum for(distribute[n][m-1]+1)×cost[n]}, where n represents a node, distribute[n][m] represents the number of requests distributed to a node in the mth step, distribute[n][m-1] represents the number of requests distributed to a node in the step before the mth step, {local_minmum for(distribute[n][m-1]+1)×cost[n]} means taking the node with the lowest response time in the request, cost represents a one-dimensional array that records the time required for each node to complete a unit request, and cost[n] represents the response time taken by a node to complete a unit request.
[0142] In some embodiments, when the program product in the embodiments of the present disclosure is executed by a processor, the following method steps may also be implemented: a heartbeat mechanism is applied to periodically monitor the average response time of each node.
[0143] In some embodiments, when the program product in the embodiments of the present disclosure is executed by a processor, the following method steps may also be implemented: using the Raft algorithm to save the data file and memory index before the request to be allocated.
[0144] As can be seen from the above, the computer-readable storage medium provided by the embodiment of the present disclosure obtains the response time of each node in the cluster to a single request within a preset statistical time period; based on the response time of each node to multiple requests within the preset statistical time period, the average response time of each node to a single request within the preset statistical time period is calculated; based on the average response time of each node to a single request and the total number of requests currently to be allocated in the cluster, the number of requests expected to be allocated to each node in the cluster is determined; based on the number of requests expected to be allocated to each node in the cluster, a corresponding number of virtual nodes are generated to construct a hash ring; based on the hash ring, a node task allocation plan for the cluster is generated, wherein the task allocation plan is used to allocate request tasks to each node in the cluster. Based on the performance of each node in the cluster, a dynamic programming algorithm is applied to dynamically adjust the task allocation mechanism to ensure that the load balancing of nodes with different performances achieves the best response.
[0145] More specific examples of computer-readable storage media in the present disclosure may include, but are not limited to, an electrical connection having one or more conductors, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0146] In the present disclosure, a computer readable storage medium may include a data signal propagated in baseband or as part of a carrier wave, wherein a readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A readable signal medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0147] Alternatively, the program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0148] In a specific implementation, the program code for performing the operations of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).
[0149] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0150] In addition, although the steps of the method in the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0151] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0152] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure, which follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the appended claims.
Claims
1. A cluster node task allocation method, characterized in that: include: Get the response time of each node in the cluster to a single request within the preset statistical time period; According to the response time of each node to multiple requests within the preset statistical time period, calculate the average response time of each node to a single request within the preset statistical time period; Determine the number of requests that are expected to be allocated to each node in the cluster based on the average response time of each node to a single request and the total number of requests currently to be allocated in the cluster; Generate a corresponding number of virtual nodes based on the number of requests expected to be allocated to each node in the cluster and build a hash ring; Generate a node task allocation scheme for the cluster according to the hash ring, wherein the task allocation scheme is used to allocate a request task to each node in the cluster; Among them, the method of determining the number of requests expected to be allocated to each node in the cluster based on the average response time of each node to a single request and the total number of requests currently to be allocated in the cluster includes: initializing a two-dimensional array to record the average response time of the current node under m requests; a double-layer loop, traversing m from 1 to M+1, and n from 0 to N; initializing the local minimum average response time to the maximum integer value, and the local minimum function to -1; entering the innermost loop, the current local average response time is equal to the average response time of the current n nodes in the previous step plus the average response time of assigning a task in this step; finding the node with the smallest average response time among all nodes, and recording the local minimum value and the pointer of the node; going to the outer loop, adding 1 to the number of tasks of the node pointed to by the pointer; completing the loop; initializing an array to record the results; extracting the results of the M position of the two-dimensional array from 0 to N into the result array; returning the result array, wherein M is the total number of tasks, n is a node, and N is the total number of nodes.
2. The cluster node task allocation method according to claim 1, characterized in that: After generating a node task allocation scheme of the cluster according to the hash ring, the method further includes: According to the node task allocation plan, the data files and memory indexes to be allocated are loaded to each node in the cluster.
3. The cluster node task allocation method according to claim 2, characterized in that: After loading the data files and memory indexes of the to-be-allocated requests into each node in the cluster according to the node task allocation scheme, the method further includes: Distribute the requests to be allocated to corresponding nodes in the cluster.
4. The cluster node task allocation method according to claim 1, characterized in that: The method further comprises: Periodically monitor the average response time of each node; Calculate the change in average response time of each node between the current cycle and the previous cycle; When the change in average response time exceeds a preset threshold, the number of requests expected to be allocated to each node in the cluster is determined based on the average response time of each node in the current cycle and the total number of requests currently to be allocated in the cluster.
5. The cluster node task allocation method according to claim 1, characterized in that: When the expected number of requests is input, the estimated number of allocated requests for each node is obtained according to the average response time of each node, including: Input the expected number of requests, and obtain the expected number of requests to be allocated to each node using a dynamic programming equation according to the average response time of each node; Among them, the dynamic programming equation calculation formula is: distribute[n][m]=distribute[n][m-1]+{local_minmum for (distribute[n][m-1]+1)×cost[n]}, Where n represents a node, distribute[n][m] represents the number of requests allocated to a node in the mth step, distribute[n][m-1] represents the number of requests allocated to a node in the previous step of the mth step, {local_minmum for(distribute[n][m-1]+1)×cost[n]} represents taking the node with the lowest response time in the request, cost represents a one-dimensional array that records the time required for each node to complete a unit request, and cost[n] represents the response time required for a node to complete a unit request.
6. The cluster node task allocation method according to claim 4, characterized in that: A heartbeat mechanism is used to periodically monitor the average response time of each node.
7. The cluster node task allocation method according to claim 1, characterized in that: Before loading the data files and memory indexes of the requested allocation requests to each node in the cluster according to the node task allocation plan, the following steps are also included: The Raft algorithm is used to save the data files and memory indexes before the request is allocated.
8. A cluster node task allocation device, characterized in that: include: The time-consuming module is used to obtain the response time of each node in the cluster to a single request within a preset statistical time period; The average time consumption calculation module is used to calculate the average response time consumption of each node to a single request within the preset statistical time period according to the response time consumption of each node to multiple requests within the preset statistical time period; The estimated number of requests module is used to determine the estimated number of requests to be allocated to each node in the cluster based on the average response time of each node to a single request and the total number of requests currently to be allocated in the cluster; A hash ring module is constructed to generate a corresponding number of virtual nodes according to the number of requests expected to be allocated to each node in the cluster, and to construct a hash ring; A task allocation module, used to generate a node task allocation scheme of the cluster according to the hash ring, wherein the task allocation scheme is used to allocate a request task to each node in the cluster; Among them, the estimated request number module is also used to initialize a record of the average response time of the current node under m requests, and record the two-dimensional array; double-layer loop, traverse m from 1 to M+1, n from 0 to N; initialize the local minimum average response time to the maximum integer value, and the local minimum function is -1; enter the innermost loop, the current local average response time is equal to the average response time of the previous step of the current n nodes plus the average response time of a task assigned to this step; find the node with the smallest average response time among all nodes, and record the local minimum value and the pointer of the node; go to the outer loop, add 1 to the number of tasks of the node pointed to by the pointer; complete the loop; initialize an array to record the results; extract the results of the M position of the two-dimensional array from 0 to N into the result array; return the result array, where M is the total number of tasks, n is a node, and N is the total number of nodes.
9. An electronic device, characterized in that: include: processor; as well as A memory, configured to store executable instructions of the processor; The processor is configured to execute the cluster node task allocation method according to any one of claims 1 to 7 by executing the executable instructions.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the cluster node task allocation method described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Distributed request processing method and device, equipment and storage medium
CN113315825A