Task allocation method and device, computer device and readable storage medium
By using a non-strictly ordered node queue and node sorting that allows deviation values, the problem of large computational workload in task distribution among multiple servers is solved, and fast and efficient load balancing is achieved.
Patent Information
- Application Number
- CN202011614687.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-30
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2040-12-30
AI Technical Summary
When allocating tasks among multiple servers, existing technologies have a large amount of computation and poor load balancing effect. In particular, when a server joins or exits, the hash values of all tasks need to be calculated, resulting in an excessive computational burden.
A node queue with no strict sorting is adopted, and nodes are sorted by allowing deviation values to reduce the computational complexity of node position updates. The target node is determined based on the key value difference and the allowed deviation value to achieve fast task allocation.
The computational complexity in the task allocation process is reduced, the task allocation efficiency is improved, and the load balance is maintained when the server changes, thereby reducing the computational complexity.
Smart Images

Figure CN114691348B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a task allocation method, apparatus, computer equipment, and readable storage medium. Background Art
[0002] With the development of network technology, more and more users are accessing services provided by servers through the network, which in turn increases the number of tasks that need to be processed by servers. To provide services to more users, multiple servers can be deployed on the network to provide services simultaneously. In this scenario, the distribution of tasks among these multiple servers is a hot topic.
[0003] In related technologies, tasks are allocated based on a load balancing strategy. The load balancing strategy refers to evenly distributing all tasks among multiple servers so that the loads on multiple servers are approximately equal. The specific process of the task allocation process is that when there is a task request for a new task, the hash value of each server for the task is determined by the consistent hashing algorithm, and then a server is selected as the target server based on the hash values of each server according to the rules of the consistent hashing algorithm, and the new task is allocated to the target server. The consistent hashing algorithm can ensure that the probability of each server being selected is basically the same. In this technology, when there is a new task, it is necessary to determine the hash value of each server for the task among multiple servers, which requires a large amount of computation. Summary of the Invention
[0004] The embodiments of the present application provide a task allocation method, apparatus, computer device, and readable storage medium, which can quickly find the target node when there is a target task to be assigned, thereby allocating the target task to the target node. The technical solutions provided by the embodiments of the present application are as follows:
[0005] In the first aspect, a task allocation method is provided, and the specific implementation method of the method is as follows: determine a target task to be assigned; obtain a node queue, the node queue includes multiple nodes, each of the multiple nodes corresponds to a key value, and the key value corresponding to each node indicates the load sharing situation on the corresponding node, and multiple nodes in the node queue are sorted according to the corresponding key values. In the node queue, if the difference between the key value of the first node and the key value of the second node exceeds the allowable deviation value, the first node is sorted behind the second node; if the difference between the key value of the first node and the key value of the second node is lower than the allowable deviation value, the first node is sorted in front of the second node or the first node is sorted behind the second node, and the first node and the second node are any two nodes in the node queue; based on at least one node in the node queue located at the front of the queue, determine the target node for executing the target task.
[0006] In an embodiment of the present application, when the difference between the key value of the first node and the key value of the second node exceeds the allowed deviation value, the first node is sorted behind the second node, that is, when the key value difference between the two nodes exceeds the allowed deviation value, the node with the larger key value is sorted behind the node with the smaller key value, and when the difference between the key value of the first node and the key value of the second node is lower than the allowed deviation value, there is no strict requirement for the positions of the first node and the second node, the first node can be sorted in front of the second node, and the first node can also be sorted behind the second node. In other words, within the allowed deviation value, the first node and the second node are not strictly sorted according to the size of the key value. When the key value difference between the two nodes exceeds the allowed deviation value, the first node and the second node are strictly sorted according to the size of the key value, thereby forming a non-strict key value sorting queue from small to large. The non-strict sorting feature of the node queue makes it unnecessary to move the position of the changed node every time when the key value of the node in the node queue changes, thereby greatly reducing the amount of calculation. The node queue's ascending ordering allows for the efficient and rapid identification of nodes with smaller key values within the queue when a target task is waiting to be assigned. This relaxed ascending order allows for the efficient and rapid identification of nodes with smaller key values within the queue, eliminating the need to calculate the key value for each node, significantly reducing computational effort. Furthermore, the target task is assigned to the node with the smaller key value, thus satisfying the load balancing principle. Furthermore, the tolerance value can be flexibly configured to determine the accuracy of load balancing across multiple nodes.
[0007] The task allocation method provided in the embodiment of the present application includes two processes: one is the node queue update process, and the other is the process of allocating tasks based on the node queue.
[0008] Based on the task allocation method provided in the first aspect, in one possible implementation, a node queue is marked with a lightest node and a heaviest node, the lightest node indicating the node with the smallest key value in the node queue, and the heaviest node indicating the node with the largest key value in the node queue. In this case, in this method, for a third node among multiple nodes, upon detecting a change in the key value of the third node, the difference between the key value of the heaviest node and the key value of the lightest node is determined to obtain a target difference, where the third node is any one of the multiple nodes; based on the target difference and the changed key value of the third node, the sorting status of the third node in the node queue is updated.
[0009] Since the node queue provided by the implementation of this application is not strictly sorted, but is loosely sorted based on the allowable deviation value, in order to facilitate the subsequent determination of whether the sorting position of the third node needs to be adjusted, when the key value of the third node changes, it is necessary to determine the difference between the key value of the heaviest node and the key value of the lightest node, so as to facilitate the subsequent determination of whether the sorting position of the third node needs to be adjusted based on the target difference and the allowable deviation value.
[0010] The target difference between the key value of the lightest node and the key value of the heaviest node corresponds to different scenarios when the target difference is in different ranges. Based on the target difference, different scenarios are divided into: scenarios where the target difference is lower than the allowable deviation value, scenarios where the target difference exceeds the allowable deviation value but is lower than 2 times the allowable deviation value, and scenarios where the target difference exceeds 2 times the allowable deviation value. The following details the specific implementation methods for updating the node queue in each of these scenarios.
[0011] Based on the task allocation method provided in the first aspect, in a possible implementation method, the above-mentioned specific implementation method of updating the sorting status of the third node in the node queue based on the target difference and the changed key value of the third node is as follows: when the target difference is lower than the allowable deviation value, if the changed key value of the third node satisfies any of the following conditions, the sorting status of each node in the node queue is kept unchanged: the changed key value of the third node is between the key value of the lightest node and the key value of the heaviest node, or the key value of the third node becomes larger, and the difference between the increased key value of the third node and the key value of the lightest node is lower than the allowable deviation value, or the key value of the third node becomes smaller, and the absolute value of the difference between the decreased key value of the third node and the key value of the heaviest node is lower than the allowable deviation value.
[0012] Through the above sorting state update process, it can be achieved that the sorting between the nodes in the node queue is a non-strict sorting, thereby achieving the technical effect brought about by the aforementioned determination of the target node.
[0013] Based on the task allocation method provided in the first aspect, in a possible implementation method, the above-mentioned specific implementation method of updating the sorting status of the third node in the node queue based on the target difference and the key value after the change of the third node is as follows: when the target difference exceeds the allowable deviation value and is lower than 2 times the allowable deviation value, if the absolute value of the difference between the key value of the third node before the change and the key value of the heaviest node is lower than the allowable deviation value, the key value of the third node becomes smaller, the absolute value of the difference between the key value of the third node after the change and the key value of the heaviest node exceeds the allowable deviation value, and the difference between the key value of the third node after the change and the key value of the lightest node is less than the allowable deviation value, then the third node is transferred to the back of the lightest node in the node queue.
[0014] Through the above sorting state update process, it can be achieved that the sorting between the nodes in the node queue is a non-strict sorting, thereby achieving the technical effect brought about by the aforementioned determination of the target node.
[0015] Based on the task allocation method provided in the first aspect, in a possible implementation method, the above-mentioned specific implementation method of updating the sorting status of the third node in the node queue based on the target difference and the key value after the change of the third node is as follows: when the target difference exceeds the allowable deviation value and is lower than 2 times the allowable deviation value, if the difference between the key value of the third node before the change and the key value of the lightest node is lower than the allowable deviation value, the key value of the third node increases, the difference between the key value of the third node after the increase and the key value of the lightest node exceeds the allowable deviation value, and the absolute value of the difference between the key value of the third node after the increase and the key value of the heaviest node is less than the allowable deviation value, then the third node is transferred to the front of the heaviest node in the node queue.
[0016] Through the above sorting state update process, it can be achieved that the sorting between the nodes in the node queue is a non-strict sorting, thereby achieving the technical effect brought about by the aforementioned determination of the target node.
[0017] Based on the task allocation method provided in the first aspect, in a possible implementation method, the above-mentioned specific implementation method of updating the sorting status of the third node in the node queue based on the target difference and the key value after the change of the third node is as follows: when the target difference exceeds 2 times the allowable deviation value, if the third node before the key value changes belongs to the first range of nodes, and the key value of the third node becomes smaller, and the third node after the key value becomes smaller belongs to the second range of nodes, then the third node is transferred to the end of the nodes in the second range in the node queue. The first range is the node range composed of the key value of the heaviest node in the node queue, and the nodes between the key value of the heaviest node and the difference between the key value of the heaviest node and the allowable deviation value. The second range is the node range composed of the key value of the heaviest node in the node queue and the difference between the key value of the heaviest node and the allowable deviation value, and the sum of the key value of the lightest node and the allowable deviation value.
[0018] Through the above sorting state update process, it can be achieved that the sorting between the nodes in the node queue is a non-strict sorting, thereby achieving the technical effect brought about by the aforementioned determination of the target node.
[0019] Based on the task allocation method provided in the first aspect, in a possible implementation method, the above-mentioned specific implementation method of updating the sorting status of the third node in the node queue based on the target difference and the key value after the change of the third node is as follows: when the target difference exceeds 2 times the allowable deviation value, if the third node before the key value changes belongs to a node in the third range, and the key value of the third node becomes larger, and the third node after the key value becomes larger belongs to a node in the second range, then the third node is transferred to the front of the nodes in the second range in the node queue. The third range is the node range composed of the key value of the lightest node in the node queue, the sum of the key value of the lightest node and the allowable deviation value, and the nodes in between.
[0020] Through the above sorting state update process, it can be achieved that the sorting between the nodes in the node queue is a non-strict sorting, thereby achieving the technical effect brought about by the aforementioned determination of the target node.
[0021] Based on the task allocation method provided in the first aspect, in a possible implementation method, the above-mentioned specific implementation method of updating the sorting status of the third node in the node queue based on the target difference and the key value after the change of the third node is as follows: when the target difference exceeds 2 times the allowable deviation value, if the third node before the key value changes belongs to the node in the second range, and the key value of the third node becomes smaller, and the third node after the key value becomes smaller belongs to the node in the third range, then the third node is transferred to the back of the lightest node in the node queue.
[0022] Through the above sorting state update process, it can be achieved that the sorting between the nodes in the node queue is a non-strict sorting, thereby achieving the technical effect brought about by the aforementioned determination of the target node.
[0023] Based on the task allocation method provided in the first aspect, in a possible implementation method, when multiple nodes are initialized, the key value of each node in the multiple nodes is obtained, and the multiple nodes are sorted according to the key value of each node in the multiple nodes to obtain a node queue at the time of initialization, and the nodes with larger key values in the node queue at the time of initialization are sorted behind the nodes with smaller key values; the node sorted at the front in the node queue at the time of initialization is marked as the lightest node, and the node sorted at the end in the node queue at the time of initialization is marked as the heaviest node.
[0024] In an embodiment of the present application, when the network is initialized, a node queue can be initialized based on the key value of each node, and then when the key value of any node changes, the initialized node queue can be updated. When the key value of a node is detected to have changed again, it is only necessary to continue updating based on the node queue after the last update.
[0025] Based on the task allocation method provided in the first aspect, in one possible implementation, the lightest node is marked in the node queue; based on at least one node at the front of the queue in the node queue, the specific implementation method of determining the target node for executing the target task is as follows: starting from the head of the node queue, traverse the i-th node in sequence, where i is a positive integer greater than or equal to 1, until the first node that meets the reference condition is determined, and the first node that meets the reference condition is used as the target node. The reference condition means that the difference between the key value of the node and the key value of the lightest node is lower than the allowable deviation value.
[0026] In the embodiments of the present application, the head of the node queue is usually a lighter node. However, if an uncontrollable change in the node key value occurs, or in other circumstances, the head of the node queue may not meet the requirements of a lighter node. Therefore, when determining the target node for the task to be assigned, it is necessary to first determine whether the node is a lighter node.
[0027] Based on the task allocation method provided in the first aspect, in a possible implementation, the heaviest node is also marked in the node queue; when traversing to the i-th node, if the difference between the key value of the i-th node and the key value of the lightest node exceeds the allowable deviation value, the i-th node is transferred to the end of the first range in the node queue, and the first range is a node range composed of nodes in the node queue whose key value is between the key value of the heaviest node and the difference between the key value of the heaviest node and the allowable deviation value.
[0028] In an embodiment of the present application, when the key value of the third node changes and the third node is marked as the lightest node, when the difference between the key value of the node within the current lighter node range and the key value of the updated lightest node exceeds the allowable deviation value, that is, the nodes within the lighter node range may no longer belong to the nodes within the lighter node range, but these nodes that do not belong to the lighter node range have not been moved. At this time, these nodes that do not belong to the lighter node range need to be moved.
[0029] Based on the task allocation method provided in the first aspect, in one possible implementation, the target task is the task carried in the task request or the task offloaded from a node whose key value is greater than a threshold, thereby improving the application flexibility of the method provided in the embodiment of the present application.
[0030] Based on the task allocation method provided in the first aspect, in one possible implementation, the key value of each node among multiple nodes indicates the number of tasks on the corresponding node, or indicates the resource occupancy of the tasks on the corresponding node, or indicates the remaining resources of the tasks on the corresponding node.
[0031] That is, in the embodiment of the present application, the key value of the node can be specified in a variety of ways, thereby improving the flexibility of the node queue.
[0032] Based on the task allocation method provided in the first aspect, in one possible implementation, the allowable deviation value is a reference value, or is determined based on a reference percentage of the average value of the key values of each node included in the node queue. That is, in embodiments of the present application, the allowable deviation value can be specified in a variety of ways, thereby increasing the flexibility of the node queue.
[0033] In a second aspect, a task allocation device is provided. The structure of the task allocation device includes a processor and a memory. The memory is used to store a program that supports the task allocation device in executing the task allocation method provided by the first aspect, and to store data involved in implementing the task allocation method provided by the first aspect. The processor is configured to execute the program stored in the memory. The operating device of the storage device may also include a communication bus, which is used to establish a connection between the processor and the memory.
[0034] According to a third aspect, a computer device is provided, comprising:
[0035] processor;
[0036] a memory for storing processor-executable instructions;
[0037] The processor is configured to execute the task allocation method provided in the first aspect above.
[0038] In a fourth aspect, a computer-readable storage medium is provided, in which instructions are stored. When the computer-readable storage medium is run on a computer, the computer executes the task allocation method provided in the first aspect.
[0039] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the task allocation method described in the first aspect.
[0040] The technical effects obtained in the above-mentioned second, third, fourth and fifth aspects are similar to those obtained by the corresponding technical means in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 This is a structural diagram of a task allocation system provided in an embodiment of the present application;
[0042] Figure 2 This is a schematic diagram of a node queue provided in an embodiment of the present application;
[0043] Figure 3 This is a schematic diagram of the structure of a resource pool provided in an embodiment of the present application;
[0044] Figure 4 This is a flow chart of a method for updating a node queue provided in an embodiment of the present application;
[0045] Figure 5 This is a schematic diagram of a node queue provided in an embodiment of the present application;
[0046] Figure 6 This is a schematic diagram of a node queue provided in an embodiment of the present application;
[0047] Figure 7 This is a schematic diagram of a node queue provided in an embodiment of the present application;
[0048] Figure 8 This is a schematic diagram of a node queue provided in an embodiment of the present application;
[0049] Figure 9 This is a schematic diagram of a node queue provided in an embodiment of the present application;
[0050] Figure 10 This is a schematic diagram of a node queue provided in an embodiment of the present application;
[0051] Figure 11 This is a schematic diagram of a node queue provided in an embodiment of the present application;
[0052] Figure 12 This is a schematic diagram of a node queue provided in an embodiment of the present application;
[0053] Figure 13 This is a schematic diagram of a node queue provided in an embodiment of the present application;
[0054] Figure 14 This is a schematic diagram of a node queue provided in an embodiment of the present application;
[0055] Figure 15 This is a schematic diagram of a node queue provided in an embodiment of the present application;
[0056] Figure 16 This is a flow chart of a method for node queue task allocation provided by an embodiment of the present application;
[0057] Figure 17 This is a schematic diagram of a node queue provided in an embodiment of the present application;
[0058] Figure 18 This is a schematic diagram of a node queue provided in an embodiment of the present application;
[0059] Figure 19 This is a schematic diagram of the structure of a task allocation device provided in an embodiment of the present application;
[0060] Figure 20It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0061] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0062] Before explaining the embodiments of the present application in detail, the application scenarios in the embodiments of the present application are first explained.
[0063] When a resource pool with multiple servers services all user task requests, the following general considerations apply: Tasks included in user task requests should be evenly distributed across all servers, ensuring that the load on each server remains similar. If new servers are added, or if a running server crashes or exits, tasks should be redistributed across existing servers to ensure load balancing. Furthermore, when redistributing tasks, the number of tasks moved between servers should be minimized to minimize disruption and impact on user tasks.
[0064] Currently, hashing algorithms are often used to match tasks to different servers. The most commonly used method is consistent hashing. The idea behind consistent hashing is to minimize the instability of the global hash relationship caused by the joining and leaving of individual nodes while ensuring hash balance.
[0065] For example, this approach only affects the neighboring nodes of the node that changes, namely, the node that joins or leaves. When a new node joins, only tasks on neighboring nodes are moved to the new node. When a node leaves, tasks on the exiting node are only assigned to neighboring nodes. While this solution achieves hash consistency, it does not provide good overall load balancing.
[0066] For example, the hash values of all tasks to all nodes are calculated, and the matching relationship is determined according to certain rules. The hash rules must meet consistency requirements. For example, when a new node joins, the hash values of all tasks on the new node are calculated, and then according to the established rules, the tasks that meet the conditions are migrated to the new node. Although this method can achieve a good load balancing effect, when a new node joins, it is necessary to calculate the hash values of all tasks in the system for the new node. When a node exits, the hash values of all tasks in the system for the new node are calculated, and according to the matching rules, the tasks on the exiting node should be migrated to the selected node. In addition, in the above methods, the balancing strategy is based on the number of tasks and does not take into account the actual computing load of the tasks. If there is a significant difference in the computing load of a single task in the application scenario, it may still cause load imbalance between servers.
[0067] The task allocation method provided in the embodiment of the present application is applied to when there is a new task request, and the task carried in the task request is allocated to one of the servers in the plurality of servers with the best efficiency, so that the load is balanced among the plurality of servers. The task allocation method provided in the embodiment of the present application can also be applied to when a server exits or joins, and the minimum number of tasks is moved to achieve load balancing among the plurality of servers. The task allocation method provided in the embodiment of the present application can also be applied to the redistribution of tasks on the server in the case of unbalanced load among the servers, so that the load is balanced among the plurality of servers.
[0068] Figure 1 This is a structural diagram of a task allocation system provided by an embodiment of the present application. Figure 1 The task allocation system 100 includes a management platform 110 and a plurality of nodes 120. The management platform 110 and the nodes 120 are connected to each other via a wired or wireless connection for communication.
[0069] The management platform 110 is used to schedule the allocation of tasks and maintain the dynamic sorting of node queues. The management platform 110 stores node queues. The node queue is formed by sorting multiple nodes according to the size of the node's key value. In one possible implementation, for any node, the key value of the node can indicate the number of tasks undertaken on the node. Optionally, the key value of the node can also indicate the resource occupancy of the task on the node, for example, the size of the central processing unit (CPU) resources occupied by the task. Optionally, the key value of the node can also indicate the remaining resources of the task on the node. Of course, the key value can also be determined by other means, and the embodiments of the present application do not specifically limit this.
[0070] Each node can be a server at the bottom layer, a server cluster, or a server group including multiple server clusters. For example, Figure 2 This is a schematic diagram of the structure of a node provided in an embodiment of the present application. Figure 2 As shown, Figure 2 Each column in the table represents a server. In this case, the nodes involved in the embodiment of the present application can be individual servers or Figure 2 Each server cluster consists of 4 servers, or it can be a server pool composed of various server clusters.
[0071] In one possible implementation, when the node is a server, the key value of the node can indicate the number of all tasks undertaken on the server, or the key value of the node can indicate the resource occupancy of all tasks undertaken on the server. When the node is a server cluster, the key value of the node indicates the number of all tasks undertaken on all servers included in the server cluster, or the key value of the node can indicate the resource occupancy of all tasks undertaken on all servers included in the server cluster. When the node is a server group, the key value of the node indicates the number of all tasks undertaken on all sets of servers included in the server group, or the key value of the node can indicate the number of all tasks undertaken on all sets of servers included in the server group. That is, in an embodiment of the present application, a node is a logically divided module, and an embodiment of the present application does not limit the granularity of the node division.
[0072] In one possible implementation, if the servers in the network form a pyramid structure, and the pyramid has three layers, the bottom layer of the pyramid corresponds to the server, multiple servers constitute a server pool, and multiple server pools constitute a server group. Figure 3 This is a schematic diagram of the distribution of servers provided in an embodiment of the present application. Figure 3 There are a total of 8 servers, with each 4 servers grouped into a server pool, resulting in 2 server pools. Two server pools form a server group. In this scenario, the 4 servers included in the first server pool on the left can be used as nodes in a node queue. In this case, the key values of these 4 servers can be sorted by key value to obtain a node queue. Alternatively, the 2 server pools can be used as nodes in a node queue. In this case, the key values of these 2 server pools can be sorted by key value to obtain a node queue.
[0073] The server pool composed of the above-mentioned multiple servers can also be called a resource pool, and multiple lower-level resource pools are combined to form a higher-level resource pool. This embodiment of the present application does not specifically limit this. In addition, the server is a physical server or a virtual machine within a physical server. This embodiment of the present application does not specifically limit this.
[0074] based on Figure 3In the network shown, when a target task is waiting to be assigned, the management platform assigns the target task to one of the nodes based on the order of the node queues, and ultimately to one of the servers. The specific process for assigning the target task to one of the nodes is as follows: first, a server group with a smaller key value is selected from the node queues consisting of the server groups. Then, a server pool with a smaller key value is iteratively selected from the node queues consisting of the server pools included in the selected server group. Finally, a server with a smaller key value is iteratively selected from the node queues consisting of the servers included in the selected server pool. Finally, the target task is assigned to the server with the smaller key value, thereby meeting the load balancing requirements between servers.
[0075] In addition, in a broadband remote access server (BRAS) system, several physical interfaces (member ports) are aggregated to form a virtual logical interface. This virtual logical interface can schedule tasks on each physical interface, balancing user loads across the physical interfaces to achieve load balancing. Each physical interface is assigned multiple logical nodes, each of which is bound to zero, one, or multiple users.
[0076] In the above BRAS system, Figure 1 The multiple nodes shown may also be multiple physical interfaces. In this case, the management platform 110 is used to maintain a dynamic ordering of multiple physical interfaces under a virtual logical interface, or a dynamic ordering between logical nodes under a physical interface. In other words, the task allocation method provided by the embodiments of the present application is introduced at the layer where each physical interface resides and at the layer where each logical node resides, thereby achieving control over the load balancing accuracy between each physical interface or between each logical node.
[0077] In addition, the number of tasks on the node 120 is constantly changing dynamically, so the key value of the node is also constantly changing dynamically. The scenarios in which the key value of the node changes are mainly divided into two scenarios: controllable and uncontrollable.
[0078] Controllable scenario: When there is a target task to be assigned, the target task can be controllably assigned to one of the nodes in the node queue, causing the key value of the node to change. Alternatively, when a new node is added to the system, some tasks on the overloaded node need to be moved to the new node, and the task can be controllably moved to the new node, causing the key value of the node to change. Uncontrollable scenario: Since the running time of the task is uncontrollable, when a task operation is completed, the corresponding node will delete the task, causing the key value of the node to change. Or when a node is down, all tasks on the node need to be moved to other nodes, causing the key values of other nodes to change.
[0079] When the tasks on different nodes increase or decrease, the node key value will cause a change. The node queue is sorted according to the size of the key value. When the node key value changes, the node queue needs to be updated in real time. In the embodiment of the present application, the sorting of the nodes in the node queue is maintained in a non-strict sorting. The node key value sorting allows a certain deviation value. In this way, when the key value of the node changes, if the difference between the key value of the changed node and the key value of other nodes is within the allowable deviation value range, the position of the node in the node queue does not need to be moved at this time, so there is no need to update the node position every time, reducing the amount of calculation for updating the node queue sorting. If the difference between the key value of the changed node and the key value of other nodes exceeds the allowable deviation range, the changed node can be moved to a suitable position in the node queue, rather than exchanging positions with neighboring nodes every time the key value of the node changes, thereby greatly reducing the amount of calculation for moving the node position.
[0080] In addition, in the embodiment of the present application, the order of the nodes in the node queue is based on the allowed deviation value to maintain a loose order, which can also bring faster search speed when searching for the target node for the task to be assigned. In other words, since the nodes are sorted according to the range of their key values, when searching for new nodes, the required target node can be found at a faster speed, that is, a lighter resource node is assigned to the new task, and when a new node is added or an existing node fails, the more heavily loaded child nodes in the currently heavily loaded node are moved to the currently less loaded node.
[0081] Among them, the key value sorting of the node allows a certain deviation value, which is called the allowed deviation value. In one possible implementation, the allowed deviation value can be a reference value determined by the user, that is, the allowed deviation value is a fixed value, which can be determined by experience and the performance of the server. Optionally, the allowed deviation value can also be dynamically changed. In another possible implementation, the allowed deviation value can be determined based on a reference percentage of the average value of the key values of each node in the node queue. For example, in the case where the key value of the node indicates the remaining resources on the node, the allowed deviation value is equivalent to being determined based on the percentage of the remaining resources of each node in the node queue. For another example, in the case where the key value of the node indicates the used resources on the node, the allowed deviation value is equivalent to being determined based on the percentage of the used resources of each node in the node queue. The embodiments of the present application do not make specific restrictions on this.
[0082] When determining the allowable deviation value based on the remaining resources of a node queue, the allowable deviation value may be determined by summing the remaining resources of each node in the node queue and then averaging the sum to obtain an average value of the remaining resources of the node queue. The allowable deviation value is then calculated as a percentage of the average value of the remaining resources of the node. The percentage may be 10% or other percentages, and is not specifically limited in this embodiment of the present application.
[0083] When the system has a large amount of remaining resources, the allowed deviation is larger. When the system has a small amount of remaining resources, the allowed deviation is smaller. This deviation adjustment strategy more reasonably reflects the relationship between the required accuracy of server load balancing and the system's remaining resources. Specifically, when the system has a large amount of remaining resources, the requirement for load balancing accuracy can be relatively low, while when the system has a small amount of remaining resources, a higher load balancing accuracy is required.
[0084] When determining the allowable deviation value based on the used resources of each node in the node queue, the process for determining the allowable deviation value can be: summing the key values of each node in the node queue and then averaging them to obtain the average value of the node queue key values. The percentage of the average value of the node key value is used as the allowable deviation value. The percentage can be 10% or other percentages, and the embodiments of the present application do not specifically limit this. In addition, by setting the percentage, the size of the allowable deviation value can be controlled, so that the accuracy of load balancing between multiple nodes can be controlled according to user needs and server performance.
[0085] When the allowable deviation value is determined based on the node queue's used resources, the calculated allowable deviation value is also smaller when fewer system resources are occupied. In this case, the node queue sorting is more rigorous and accurate, and the load between servers is correspondingly more balanced. Furthermore, when fewer system resources are occupied, the system has more remaining resources, so the system can fully utilize these remaining resources to strictly sort the node queues. When more system resources are occupied, the calculated allowable deviation value is also larger. In this case, the node queue sorting requirements are lower, and when more system resources are occupied, the system has fewer remaining resources. The system can use fewer resources to sort the node queues, thereby improving server utilization efficiency.
[0086] based on Figure 1 The task allocation system described above will now be described in detail with respect to the task allocation method provided in the embodiments of this application. It should be noted that the task allocation method provided in the embodiments of this application includes two processes: one is the node queue update process, and the other is the task allocation process based on the node queue. The following will describe these two processes in detail using two embodiments.
[0087] Figure 4 This is a flow chart of a method for updating a node queue provided by an embodiment of the present application. Figure 4 As shown, the method includes the following steps.
[0088] Step 401: For a third node among multiple nodes, when it is detected that the key value of the third node changes, the management platform determines the difference between the key value of the heaviest node and the key value of the lightest node to obtain a target difference. The third node is any one of the multiple nodes included in the node queue.
[0089] Since the node queue provided by the implementation of this application is not strictly sorted, but is loosely sorted based on the allowable deviation value, in order to facilitate the subsequent determination of whether the sorting position of the third node needs to be adjusted, when the key value of the third node changes, it is necessary to determine the difference between the key value of the heaviest node and the key value of the lightest node, so as to facilitate the subsequent determination of whether the sorting position of the third node needs to be adjusted based on the target difference and the allowable deviation value.
[0090] Furthermore, to facilitate rapid determination of the target difference, the lightest and heaviest nodes can be pre-labeled in the node queue. The lightest node indicates the node with the smallest key value, and the heaviest node indicates the node with the largest key value. This way, when a change in the key value of the third node is detected, the target deviation can be directly determined based on the labeled lightest and heaviest nodes.
[0091] In the case where the lightest and heaviest nodes are pre-labeled, if a change in the key value of a third node is detected, the management platform determines whether to update the lightest and heaviest nodes based on the changed key value of the third node. This allows the lightest and heaviest nodes to indicate the node with the largest and smallest key values, respectively, in the node queue in real time. Therefore, upon detecting a change in the key value of the third node, the management platform also performs the following operations.
[0092] If the changed key value of the third node is less than the key value of the lightest node, the lightest node is updated to the third node. Correspondingly, if the changed key value of the third node is greater than the key value of the heaviest node, the heaviest node is updated to the third node.
[0093] It should be noted that if the changed key value of the third node is the same as the key value of the lightest node, the label of the lightest node does not need to be updated. Correspondingly, if the changed key value of the third node is the same as the key value of the heaviest node, the label of the heaviest node does not need to be updated.
[0094] Alternatively, instead of marking the lightest and heaviest nodes in advance, each time a change in the key value of the third node is detected, the key values of all nodes in the node queue are temporarily traversed, and then the lightest and heaviest nodes are found. Figure 4 The illustrated embodiment determines whether the sorting position of the third node needs to be adjusted.
[0095] It should be noted that the node queue in the embodiment of the present application is updated in real time. That is, each time a change in the key value of a node is detected, the node queue is updated based on the Figure 4 The illustrated embodiment updates the sorting state of the node queue so that the sorting state in the node queue can represent the latest load condition of each node.
[0096] Among them, when the network is initialized, a node queue can be initialized based on the key value of each node. Then, when the key value of any node changes, the initialized node queue can be updated. When the key value of a node is detected to have changed again, it is only necessary to continue updating based on the node queue after the last update. Figure 4 The embodiment shown is described by taking how to update a node queue once as an example.
[0097] The specific implementation method of the above-mentioned generation of the initialized node queue can be: obtain the key value of each node in the multiple nodes, sort the multiple nodes according to the key value of each node in the multiple nodes, and obtain the node queue at the time of initialization. The nodes with larger key values in the node queue at the time of initialization are sorted behind the nodes with smaller key values, and the node sorted at the front in the node queue at the time of initialization is marked as the lightest node, and the node sorted at the end in the node queue at the time of initialization is marked as the heaviest node.
[0098] In one possible implementation, when sorting multiple nodes, the nodes may be sorted from smallest to largest according to their key values, thereby obtaining an initialized node queue. This embodiment of the present application does not specifically limit this.
[0099] The management node stores this initialized node queue. When a target task is assigned or a task completes, and the node key value changes, the node queue's sorting is updated. A tolerance is set to allow for some variation between node key values. This results in a loosely ordered sequence of small to large key values.
[0100] For ease of explanation, the node queue can also be divided into a heavier node range and a lighter node range based on the size of the key value. The heavier node range is the node range consisting of nodes in the node queue whose key value is the key value of the heaviest node, and the difference between the key value of the heaviest node and the allowed deviation value. The lighter node range is the node range consisting of nodes in the node queue whose key value is the key value of the lightest node, and the sum of the key value of the lightest node and the allowed deviation value.
[0101] The node key values within the lighter node range that meet the conditions can be specifically expressed by the following formula:
[0102] Key(LighterNode)∈(Key(LightestNode),Key(LightestNode)+AllowedDeviation)
[0103] Among them, Key is the key value of the node, Key(LighterNode) is the key value of the lighter node, Key(LightestNode) is the key value of the lightest node, and AllowedDeviation is the allowed deviation value.
[0104] The node key values within the heavier node range that meet the conditions can be specifically expressed by the following formula:
[0105] Key(HeavierNode)∈[Key(HeaviestNode)-AllowedDeviation,Key(HeaviestNode)]
[0106] Among them, Key is the key value of the node, Key(HeavierNode) is the key value of the heavier node, Key(HeaviestNode) is the key value of the heaviest node, and AllowedDeviation is the allowed deviation value.
[0107] Step 402: Based on the target difference and the changed key value of the third node, update the sorting status of the third node in the node queue.
[0108] The difference between the key value of the lightest node and the key value of the heaviest node, or the target difference, corresponds to different scenarios when it is within different ranges. Three scenarios are categorized based on the target difference. The first scenario: The target difference is lower than the allowable deviation value. The second scenario: The target difference exceeds the allowable deviation value but is lower than 2 times the allowable deviation value. The third scenario: The target difference exceeds 2 times the allowable deviation value. The following details the specific implementation methods for updating the node queue in each of these three scenarios.
[0109] The first scenario: The target difference is lower than the allowable deviation value.
[0110] When the difference between the key value of the heaviest node and the key value of the lightest node is lower than the allowed deviation value, all nodes in the node queue are lighter nodes.
[0111] The situation where the target difference is lower than the allowable deviation value can be specifically expressed by the following formula:
[0112] Key(heaviest)<=(Key(lightest)+AllowedDeviation)
[0113] Among them, Key is the key value of the node, Key (heaviest) is the key value of the heaviest node, Key (lightest) is the key value of the lightest node, and AllowedDeviation is the allowed deviation value.
[0114] Figure 5 This is a node queue diagram provided by an embodiment of the present application. Figure 5 , all nodes in the node queue are lighter nodes. Figure 5 In the diagram, the lightest and heaviest nodes are marked.
[0115] exist Figure 5 In the scenario shown, when the key value of the third node changes, the sorting state may or may not be updated. The following explains these two cases separately.
[0116] (1) The sorting status is not updated.
[0117] When it is detected that the key value of the third node has changed, if the changed key value of the third node meets any of the following conditions, the sorting status of each node in the node queue is kept unchanged: the changed key value of the third node is between the key value of the lightest node and the key value of the heaviest node, or the key value of the third node becomes larger, and the difference between the increased key value of the third node and the key value of the lightest node is lower than the allowable deviation value, or the key value of the third node becomes smaller, and the absolute value of the difference between the reduced key value of the third node and the key value of the heaviest node is lower than the allowable deviation value.
[0118] After the system detects a change in the key value of the third node, it compares the changed key value of the third node to see if it is between the key values of the lightest node and the key values of the heaviest node. In one possible implementation, after the task to be assigned is assigned to the third node, if the changed key value of the third node is still between the key values of the lightest node and the key values of the heaviest node, the third node is still within the range of lighter nodes, and in this case, the position of the third node does not need to be updated.
[0119] Alternatively, the task to be assigned is assigned to the third node, which is a lighter node. After the third node's key value changes, it increases. Even if the third node's key value changes to a larger value than the heaviest node's key value, the difference between the third node's key value and the lightest node's key value is less than the allowable deviation, and the third node still falls within the range of lighter nodes. In this case, there is no need to update the third node's position.
[0120] Alternatively, when the task on the third node is completed and deleted from the node, the changed key value of the third node becomes smaller, but since the difference between the changed key value of the third node and the key value of the heaviest node is lower than the allowable deviation value, the third node is still within the range of lighter nodes. In this case, there is no need to update the position of the third node.
[0121] (2) Update the sorting status.
[0122] When it is detected that the key value of the third node changes, and the changed key value of the third node satisfies any of the following conditions, the sorting status of the third node in the node queue is updated.
[0123] Case 1:
[0124] In the case where the key value of the third node increases, if the changed key value of the third node is greater than the key value of the heaviest node, the third node can be directly transferred to the end of the node queue without considering other situations.
[0125] Optionally, when the target difference is lower than the allowable deviation value, if the key value of the third node becomes larger and the difference between the increased key value of the third node and the key value of the lightest node exceeds the allowable deviation value, the third node is transferred to the end of the node queue and marked as the heaviest node.
[0126] In one possible implementation, the third node is within the range of lighter nodes before its key value changes, and the task to be assigned is assigned to the third node. After the task to be assigned to the third node, if its key value after the change does not fall within the range of lighter nodes, that is, the difference between the key value after the change and the key value of the lightest node exceeds the allowable deviation value, the third node is within the range of heavier nodes, and the third node needs to be moved to the end of the node queue and marked as the heaviest node.
[0127] Figure 6 This is a node queue diagram provided by an embodiment of the present application. Figure 6 As shown, the third node is node A, the lightest node in the current node queue is node B, the heaviest node is node D, and the key value of node A increases Figure 6 The black part. Figure 6 As shown, after the key value of node A increases, the difference between the key value of node A and the key value of node B exceeds the allowable deviation value, so node A becomes a heavier node. At this time, node A can be moved to the end of the node queue and marked as the heaviest node. Figure 6 The heaviest node marked by the dotted box is the heaviest node after update.
[0128] Case 2:
[0129] In the case where the key value of the third node becomes smaller, if the changed key value of the third node is smaller than the key value of the lightest node, the third node can be directly transferred to the head of the node queue without considering other situations.
[0130] Optionally, when the target difference is lower than the allowable deviation value, if the key value of the third node becomes smaller and the difference between the key value of the smaller third node and the key value of the heaviest node exceeds the allowable deviation value, the third node is transferred to the head of the node queue and marked as the lightest node.
[0131] In one possible implementation, when a task is completed on the third node and the task is deleted from the third node, the key value of the third node will become smaller, and the difference between the changed key value of the third node and the key value of the heaviest node exceeds the allowable deviation value, that is, the changed key value of the third node is less than the key value of the current lightest node. At this time, the third node needs to be moved to the head of the node queue and marked as the lightest node.
[0132] Figure 7 This is a node queue diagram provided by an embodiment of the present application. Figure 7 As shown, the third node is node C, the lightest node in the current node queue is node B, and the key value of node C is reduced Figure 7 The black part. Figure 7 As shown, after the key value of node C is reduced, the key value of the node is less than the key value of node B, so node C becomes the lightest node. At this time, node C is marked as the lightest node. Figure 7 The lightest node marked by the dotted box is the lightest node after the update. And because the difference between the key value of node C after the reduction and the key value of the heaviest node exceeds the allowable deviation value, node C can be moved to the head of the node queue and the lightest node is updated to node C.
[0133] It should be noted that when the key value of the third node changes and the third node is marked as the lightest node, the difference between the key value of the nodes within the lighter node range and the key value of the updated lightest node may exceed the allowable deviation value. That is, some nodes within the lighter node range may no longer be within the lighter node range. At this time, there is no need to move the nodes that do not belong to the lighter node range. Only the changed third node is moved. When selecting the target node when a task is to be assigned, the validity of the lighter node at the head of the node queue is judged, and then the nodes that do not belong to the lighter node range are moved. The validity judgment of the lighter node at the head of the node queue will be described in detail in the subsequent step 1603, which will not be explained here.
[0134] Optionally, when the third node's key value changes and the third node is marked as the lightest node, some nodes within the lighter node range may no longer be within the lighter node range. In this case, the nodes that do not meet the requirements are moved. When a task is waiting to be assigned, it can be assigned to the node at the head of the node queue.
[0135] For the above cases 1 and 2, in other words, if the changed key value of the third node is less than the key value of the lightest node, and the absolute value of the difference between the changed key value of the third node and the key value of the lightest node exceeds the allowed deviation value, then the third node is transferred to the head of the node queue. Correspondingly, if the changed key value of the third node is greater than the key value of the heaviest node, and the difference between the changed key value of the third node and the key value of the heaviest node exceeds the allowed deviation value, then the third node is transferred to the tail of the node queue.
[0136] It should be noted that, for the first scenario, when the key value of the third node after the change is lower than the lightest node or greater than the heaviest node, the above content is based on the allowable deviation value as a criterion to determine whether to move the third node. Optionally, in the case where the key value of the third node increases, if the key value of the third node after the change is greater than the key value of the heaviest node, even if the difference between the key value of the third node after the change and the key value of the lightest node is lower than the allowable deviation value, the third node can be directly transferred to the end of the node queue. Correspondingly, in the case where the key value of the third node decreases, if the key value of the third node after the change is less than the key value of the lightest node, even if the absolute value of the difference between the key value of the third node after the change and the key value of the heaviest node is lower than the allowable deviation value, the third node can be directly transferred to the head of the node queue.
[0137] That is, in the case where the key value of the third node increases, if the key value of the third node after the change is greater than the key value of the heaviest node, the third node can be directly transferred to the end of the node queue without considering other situations. Correspondingly, if the key value of the third node after the change is less than the key value of the lightest node, the third node can also be directly transferred to the head of the node queue without considering other situations. In the case where the key value of the third node after the change is lower than the lightest node or greater than the heaviest node, the third node is directly transferred to the head or tail of the node queue. This operation can ensure the overall orderliness of the node queue. In the application of the embodiments of the present application, this solution can be preferably adopted.
[0138] Alternatively, if the changed key value of the third node is the same as the key value of the lightest node, the lightest node's flag may not be updated, but the third node may be moved to the head of the node queue. Similarly, if the changed key value of the third node is the same as the key value of the heaviest node, the heaviest node's flag may not be updated, but the third node may be moved to the end of the node queue.
[0139] The second scenario: the target difference exceeds the allowable deviation value and is less than 2 times the allowable deviation value.
[0140] When the difference between the key value of the heaviest node and the key value of the lightest node exceeds the allowable deviation value and is less than 2 times the allowable deviation value, the nodes in the node queue are divided into nodes within the lighter node range and nodes within the heavier node range. Among them, 2 times is 2, and the heavier node range is the node range composed of nodes with a key value of the heaviest node and the difference between the key value of the heaviest node and the allowable deviation value in the node queue. The lighter node range is the node range composed of nodes with a key value of the lightest node and the sum of the key value of the lightest node and the allowable deviation value in the node queue.
[0141] The situation where the target difference exceeds the allowable deviation value but is less than 2 times the allowable deviation value can be specifically expressed by the following formula:
[0142] AllowedDeviation<(Key(heaviest)-Key(lightest))<=2*AllowedDeviation
[0143] Among them, Key is the key value of the node, Key (heaviest) is the key value of the heaviest node, Key (lightest) is the key value of the lightest node, and AllowedDeviation is the allowed deviation value.
[0144] like Figure 8 As shown, Figure 8 This is a node queue diagram provided by an embodiment of the present application. Figure 8 , all nodes in the node queue are divided into heavier nodes and lighter nodes. Figure 8 In the diagram, the lightest and heaviest nodes are marked.
[0145] When the changed key value of the third node satisfies any of the following conditions, it is necessary to move the position of the third node in the node queue and update the sorting status of the third node in the node queue.
[0146] Case 1:
[0147] When it is detected that the key value of the third node has changed, if the absolute value of the difference between the key value of the third node before the change and the key value of the heaviest node is lower than the allowable deviation value, the key value of the third node becomes smaller, the absolute value of the difference between the key value of the third node after the change and the key value of the heaviest node exceeds the allowable deviation value, and the difference between the key value of the third node after the change and the key value of the lightest node is less than the allowable deviation value, then the third node will be transferred to the back of the lightest node in the node queue.
[0148] In one possible implementation, the third node belongs to a node within the range of heavier nodes before the key value changes. When the task on the third node is completed, the key value of the third node becomes smaller, and the third node after becoming smaller does not belong to a node within the range of heavier nodes. The third node now belongs to a node within the range of lighter nodes, and the absolute value of the difference between the key value of the third node after becoming smaller and the key value of the lightest node is less than the allowable deviation value. Considering that the key value of the third node after the change is usually greater than the key value of the lightest node in the node queue, in order to maintain the dynamic sorting of the overall key value of the node queue from small to large, the third node is moved behind the lightest node in the node queue.
[0149] Figure 9 This is a node queue diagram provided by an embodiment of the present application. Figure 9As shown, the third node is node E. The lightest node in the current node queue is node B, the heaviest node is node F, and the key value of node E is reduced by Figure 9 The black part. Figure 9 As shown, after the key value of node E decreases, the difference between the key value of node E and the key value of node F exceeds the allowable deviation value, so node E becomes a lighter node. At this time, node E can be moved behind the lightest node B in the node queue.
[0150] For case one, when it is detected that the key value of the third node has changed, if the difference between the key value of the third node before the change and the key value of the heaviest node is lower than the allowable deviation value, the key value of the third node becomes smaller, but the difference between the key value of the third node after the change and the key value of the heaviest node still does not exceed the allowable deviation value. At this time, there is no need to move the third node.
[0151] Case 2:
[0152] When it is detected that the key value of the third node has changed, if the difference between the key value of the third node before the change and the key value of the lightest node is lower than the allowable deviation value, the key value of the third node increases, the difference between the key value of the third node after the increase and the key value of the lightest node exceeds the allowable deviation value, and the absolute value of the difference between the key value of the third node after the increase and the key value of the heaviest node is less than the allowable deviation value, then the third node is transferred to the front of the heaviest node in the node queue.
[0153] In one possible implementation, the third node belongs to a node within the range of lighter nodes before the key value changes. When the task to be assigned is assigned to the third node, the key value of the third node increases, and the increased key value of the third node does not belong to a node within the range of lighter nodes. The third node now belongs to a node within the range of heavier nodes, and the absolute value of the difference between the increased key value of the third node and the key value of the heaviest node is less than the allowable deviation value. Considering that the key value of the third node is usually less than the key value of the heaviest node in the node queue, in order to maintain the dynamic order of the overall key value of the node queue from small to large, the third node is moved in front of the heaviest node in the node queue.
[0154] Figure 10 This is a node queue diagram provided by an embodiment of the present application. Figure 10 As shown, the third node is node A, the lightest node in the current node queue is node B, the heaviest node is node F, and the key value of node A increases Figure 10 The black part. Figure 10 As shown, after the key value of node A increases, the difference between the key value of node A and the key value of node B exceeds the allowable deviation value, so node A becomes a heavier node. At this time, node A can be moved in front of the heaviest node F in the node queue.
[0155] For case two, when it is detected that the key value of the third node has changed, if the difference between the key value of the third node before the change and the key value of the lightest node is lower than the allowable deviation value, the key value of the third node increases, but the difference between the key value of the third node after the increase and the key value of the lightest node still does not exceed the allowable deviation value. At this time, there is no need to move the third node.
[0156] In the above-mentioned cases 1 and 2, the absolute value of the difference between the key value of the third node after the change and the key value of the lightest node or the heaviest node does not exceed the allowable deviation value. In another possible implementation, if the key value of the third node after the change is less than the key value of the lightest node, and the absolute value of the difference between the key value of the third node after the change and the key value of the lightest node exceeds the allowable deviation value, the third node is transferred to the head of the node queue. Correspondingly, if the key value of the third node after the change is greater than the key value of the heaviest node, and the difference between the key value of the third node after the change and the key value of the heaviest node exceeds the allowable deviation value, the third node is transferred to the tail of the node queue.
[0157] It should also be noted that, for the second scenario, when the key value of the third node after the change is lower than the lightest node or greater than the heaviest node, the above content is based on the allowable deviation value as a criterion to determine whether to move the third node. Optionally, in the case where the key value of the third node increases, if the key value of the third node after the change is greater than the key value of the heaviest node, even if the difference between the key value of the third node after the change and the key value of the lightest node is lower than the allowable deviation value, the third node can be directly transferred to the end of the node queue. Correspondingly, in the case where the key value of the third node decreases, if the key value of the third node after the change is less than the key value of the lightest node, even if the absolute value of the difference between the key value of the third node after the change and the key value of the heaviest node is lower than the allowable deviation value, the third node can be directly transferred to the head of the node queue.
[0158] That is, in the case where the key value of the third node increases, if the key value of the third node after the change is greater than the key value of the heaviest node, the third node can be directly transferred to the end of the node queue without considering other situations. Correspondingly, if the key value of the third node after the change is less than the key value of the lightest node, the third node can also be directly transferred to the head of the node queue without considering other situations. In the case where the key value of the third node after the change is lower than the lightest node or greater than the heaviest node, the third node is directly transferred to the head or tail of the node queue. This operation can ensure the overall orderliness of the node queue. In the application of the embodiments of the present application, this solution can be preferably adopted.
[0159] Alternatively, if the changed key value of the third node is the same as the key value of the lightest node, the lightest node's flag may not be updated, but the third node may be moved to the head of the node queue. Similarly, if the changed key value of the third node is the same as the key value of the heaviest node, the heaviest node's flag may not be updated, but the third node may be moved to the end of the node queue.
[0160] The third scenario: The target difference exceeds 2 times the allowable deviation value.
[0161] When the difference between the key value of the heaviest node and the key value of the lightest node exceeds 2 times the allowed deviation value, the nodes in the node queue are divided into nodes within the lighter node range, nodes within the middle node range, and nodes within the heavier node range.
[0162] The situation where the target difference exceeds 2 times the allowable deviation value can be specifically expressed by the following formula:
[0163] 2*AllowedDeviation<(Key(heaviest)-Key(lightest))
[0164] Among them, Key is the key value of the node, Key (heaviest) is the key value of the heaviest node, Key (lightest) is the key value of the lightest node, and AllowedDeviation is the allowed deviation value.
[0165] like Figure 11 As shown, Figure 11 This is a schematic diagram of a node queue provided by an embodiment of the present application. All nodes in the node queue are divided into heavier nodes, intermediate nodes and lighter nodes. Figure 11 In the diagram, the lightest and heaviest nodes are marked.
[0166] The heavier node range is the node range composed of the nodes whose key value is the key value of the heaviest node in the node queue, and the difference between the key value of the heaviest node and the allowed deviation value. The heavier node range can also be called the first range, and the embodiments of the present application do not specifically limit this. The intermediate node range is the node range composed of the nodes whose key value is the difference between the key value of the heaviest node and the allowed deviation value, and the sum of the key value of the lightest node and the allowed deviation value in the node queue. The intermediate node range can also be called the second range. The lighter node range is the node range composed of the nodes whose key value is the key value of the lightest node in the node queue, and the sum of the key value of the lightest node and the allowed deviation value in the node queue. The lighter node range can also be called the first range.
[0167] When the changed key value of the third node satisfies any of the following conditions, it is necessary to move the position of the third node in the node queue and update the sorting status of the third node in the node queue.
[0168] Case 1:
[0169] If the third node before the key value changes belongs to the first range of nodes, the key value of the third node becomes smaller, and the third node after the key value becomes smaller belongs to the second range of nodes, then the third node will be transferred to the end of the nodes in the second range in the node queue.
[0170] In one possible implementation, the third node is in the heavier range. When a task completes on the third node, the third node's key value decreases. After the decrease, the third node falls within the intermediate range. This indicates that the changed key value of the third node is smaller than the key value of the nodes in the heavier range. Typically, the changed key value of the third node is larger than the key value of the nodes in the intermediate range. Therefore, to maintain the dynamic order of the key values in the node queue from smallest to largest, the third node should be moved to the end of the nodes in the intermediate range in the node queue.
[0171] Figure 12 This is a node queue diagram provided by an embodiment of the present application. Figure 12 As shown, the third node is node I, the heaviest node in the current node queue is node H, and the key value of node I has decreased Figure 12 The black part. Figure 12 As shown, after the key value of the I node is reduced, the difference between the key value of the I node and the key value of the H node exceeds the allowable deviation value, so the I node becomes a node within the range of the intermediate node. At this time, the I node can be moved to the end of the nodes within the range of the intermediate node.
[0172] Case 2:
[0173] If the third node before the key value changes belongs to the third range of nodes, and the key value of the third node increases, and the third node after the key value increases belongs to the second range of nodes, then the third node is transferred to the front of the nodes in the second range in the node queue.
[0174] In one possible implementation, the third node is within the range of lighter nodes. When a task is assigned to the third node, the key value of the third node increases. This increase in the key value of the third node places it within the range of intermediate nodes. This indicates that the key value of the third node after the change is greater than the key value of the nodes within the range of lighter nodes. Typically, the key value of the third node is smaller than the key value of the nodes within the range of intermediate nodes. Therefore, to maintain the dynamic order of the key values of the node queue as a whole, from smallest to largest, the third node should be moved to the front of the nodes within the range of intermediate nodes in the node queue.
[0175] Figure 13 This is a node queue diagram provided by an embodiment of the present application. Figure 13 As shown, the third node is node A, the lightest node in the current node queue is node B, and the key value of node A increases Figure 13 The black part. Figure 13 As shown, after the key value of node A increases, the difference between the key value of node A and the key value of node B exceeds the allowable deviation value, so node A becomes a node in the middle range. At this time, node A can be moved to the front of the nodes in the middle node range.
[0176] Case 3:
[0177] If the third node before the key value changes belongs to the second range of nodes, and the key value of the third node becomes smaller, and the third node after the key value becomes smaller belongs to the third range of nodes, then the third node is transferred to the back of the lightest node in the node queue.
[0178] In one possible implementation, the third node falls within the middle node range. When a task on the third node completes, the third node's key value decreases. This decrease places the third node within the lighter range. This indicates that the changed key value of the third node is smaller than the key values of the nodes within the middle node range. Typically, the key value of the third node is larger than the key value of the lightest node. Therefore, to maintain a dynamic ordering of the node queue's key values from smallest to largest, the third node should be moved behind the lightest node in the queue.
[0179] Figure 14 This is a node queue diagram provided by an embodiment of the present application. Figure 14 As shown, the third node is node F, the lightest node in the current node queue is node B, and the key value of node F is reduced Figure 14 The black part. Figure 14 As shown in the figure, after the key value of node F is reduced, node F becomes a lighter node. At this time, node F can be moved behind the lightest node B.
[0180] In the above cases 1 to 3, the key value of the third node after the change is not less than the lightest node or greater than the heaviest node. In another possible implementation, if the key value of the third node after the change is less than the key value of the lightest node, and the absolute value of the difference between the key value of the third node after the change and the key value of the lightest node exceeds the allowable deviation value, the third node is transferred to the head of the node queue. If the key value of the third node after the change is greater than the key value of the heaviest node, and the difference between the key value of the third node after the change and the key value of the heaviest node exceeds the allowable deviation value, the third node is transferred to the tail of the node queue.
[0181] It should also be noted that, for the third scenario, when the key value of the third node after the change is lower than the lightest node or greater than the heaviest node, the above content is based on the allowable deviation value as a criterion to determine whether to move the third node. Optionally, in the case where the key value of the third node increases, if the key value of the third node after the change is greater than the key value of the heaviest node, even if the difference between the key value of the third node after the change and the key value of the lightest node is lower than the allowable deviation value, the third node can be directly transferred to the end of the node queue. Correspondingly, in the case where the key value of the third node decreases, if the key value of the third node after the change is less than the key value of the lightest node, even if the absolute value of the difference between the key value of the third node after the change and the key value of the heaviest node is lower than the allowable deviation value, the third node can be directly transferred to the head of the node queue.
[0182] That is, in the case where the key value of the third node increases, if the key value of the third node after the change is greater than the key value of the heaviest node, the third node can be directly transferred to the end of the node queue without considering other situations. Correspondingly, if the key value of the third node after the change is less than the key value of the lightest node, the third node can also be directly transferred to the head of the node queue without considering other situations. In the case where the key value of the third node after the change is lower than the lightest node or greater than the heaviest node, the third node is directly transferred to the head or tail of the node queue. This operation can ensure the overall orderliness of the node queue. In the application of the embodiments of the present application, this solution can be preferably adopted.
[0183] Alternatively, if the changed key value of the third node is the same as the key value of the lightest node, the lightest node's flag may not be updated, but the third node may be moved to the head of the node queue. Similarly, if the changed key value of the third node is the same as the key value of the heaviest node, the heaviest node's flag may not be updated, but the third node may be moved to the end of the node queue.
[0184] Case 4:
[0185] If the third node is the lightest node and the key value of the node becomes smaller, the third node is transferred to the head of the node queue.
[0186] In one possible implementation, the third node is the lightest node in the node queue. When a task on the third node completes, the key value of the third node decreases. To maintain the dynamic order of the key values in the node queue from small to large, the third node should be moved to the head of the node queue.
[0187] Figure 15 This is a node queue diagram provided by an embodiment of the present application. Figure 15 As shown, the third node is node B, the lightest node in the current node queue is node B, and the key value of node B is reduced Figure 15The black part. Figure 15 As shown, after the key value of node B is reduced, node B is moved to the head of the node queue.
[0188] It should be noted that if the third node is the lightest node and the key value of the node becomes smaller. The allowable deviation value also changes accordingly. At this time, the difference between the key value of the node within the lighter node range and the key value of the changed third node may exceed the allowable deviation value, that is, some nodes within the lighter node range may belong to the nodes within the intermediate node range. In addition, the nodes within the intermediate node range may not belong to the intermediate node range, but at this time there is no need to move these non-compliant nodes. When the tasks to be assigned are assigned, the validity of the lighter nodes in the node queue is judged, and then these non-compliant nodes are moved. Or when a new node is added, the validity of the heavier nodes in the node queue is judged, and then these non-compliant nodes are moved.
[0189] Similarly, if the third node is the lightest node and the key value of the node increases, the allowed deviation value will also change accordingly. This will cause the range of lighter nodes and the range of intermediate nodes to change. In this case, there is no need to move the nodes that do not meet the requirements.
[0190] It should be noted that in the embodiments of this application, when the words "lower than" and "exceed" appear, "lower than" can mean less than or equal to, and the corresponding "exceed" means greater than. If "lower than" means less than, then the corresponding "exceed" means greater than or equal to. This embodiment of the application does not specifically limit this.
[0191] In the embodiment of the present application, the position of the changed third node is updated in real time, thereby maintaining the key values of the nodes in the node queue in a non-strict ascending order.
[0192] Figure 16 This is a flow chart of a method for allocating tasks based on node queues provided by an embodiment of the present application. Figure 1 As can be seen from the task allocation system shown, the task allocation method is executed by the management platform. Figure 16 ,The task allocation method includes the following steps.
[0193] Step 1601: The management platform determines the target task to be assigned.
[0194] In a possible implementation, the target task is a task carried in a task request. The task request is a task request detected by the task allocation system to be triggered by a user.
[0195] When a node occupies most of its resources and its used resources reach a threshold, the node is considered overloaded. At this point, in order not to affect the efficiency of task execution on the node, tasks on the overloaded node need to be moved to nodes with fewer used resources. Therefore, in another possible implementation, the target task can also be a task offloaded from a node whose key value is greater than the threshold. The threshold can be determined based on experience and the performance of the server included in the node, and this embodiment of the application does not specifically limit this.
[0196] Optionally, the target task may also be a task on a node with an unbalanced load, which is not specifically limited in the embodiments of the present application.
[0197] Step 1602: The management platform obtains a node queue, which includes multiple nodes. Each node in the multiple nodes corresponds to a key value. The key value corresponding to each node indicates the load sharing situation on the corresponding node. The multiple nodes in the node queue are sorted according to the corresponding key values. In the node queue, if the difference between the key value of the first node and the key value of the second node exceeds the allowable deviation value, the first node is sorted behind the second node. If the difference between the key value of the first node and the key value of the second node is lower than the allowable deviation value, the first node is sorted in front of the second node or the first node is sorted behind the second node. The first node and the second node are any two nodes in the node queue.
[0198] based on Figure 4 As can be seen from the illustrated embodiment, each node in the node queue is obtained by performing a non-strict sort based on the allowable deviation value. Therefore, the sorting relationship between any two first nodes and second nodes in the node queue satisfies the following relationship: if the difference between the key value of the first node and the key value of the second node exceeds the allowable deviation value, the first node should be placed after the second node. If the difference between the key value of the first node and the key value of the second node is less than the allowable deviation value, there is no strict requirement for the position of the first node and the second node, and the first node can be sorted before or after the second node.
[0199] Step 1603: The management platform determines a target node for executing the target task based on at least one node at the front of the node queue.
[0200] Assign pending tasks to lighter nodes in the node queue. A lighter node is one whose key value differs from the key value of the lightest node by less than the allowed deviation. Typically, the head of the node queue is the lighter node. However, if uncontrollable changes in the node key value occur, or in other circumstances, the head of the node queue may not meet the lighter node requirement. Therefore, when determining the target node for a pending task, it is necessary to first determine whether the node is a lighter node. This is also known as determining the validity of the lighter nodes in the node queue. The specific determination process is described below.
[0201] Starting from the head of the node queue, traverse the i-th node in sequence, where i is a positive integer greater than or equal to 1, until the first node that meets the reference condition is determined. The first node that meets the reference condition is used as the target node. The reference condition means that the difference between the key value of the node and the key value of the lightest node is lower than the allowable deviation value.
[0202] For the first and second scenarios in step 402, when there is a task to be assigned, after determining the target node for executing the target task, when the key value of the third node changes and the third node is marked as the lightest node, when the difference between the key value of the node within the current lighter node range and the key value of the updated lightest node exceeds the allowable deviation value, that is, the nodes within the lighter node range may not belong to the nodes within the lighter node range, but these nodes that do not belong to the lighter node range have not been moved. At this time, these nodes that do not belong to the lighter node range need to be moved. The specific moving process is described as follows.
[0203] When traversing to the i-th node, if the difference between the key value of the i-th node and the key value of the lightest node exceeds the allowable deviation value, the i-th node is transferred to the end of the node queue.
[0204] For example, Figure 17 As shown, Figure 17 This is a schematic diagram of a node queue provided by an embodiment of the present application. Node C is the lightest node, so the C in the node queue has the lightest node mark. When there are tasks to be assigned, start from the head of the node queue and traverse in sequence, see Figure 17 , the difference between the key value of node A, the head node of the node queue, and the key value of node C exceeds the allowable deviation value, then node A is an invalid lighter node, and node A needs to be moved to the end of the node queue. Then compare the difference between the key value of node B and the key value of node C in the node queue. The difference is lower than the allowable deviation value, so node B is regarded as a valid lighter node, and the task to be assigned is assigned to the lighter node B.
[0205] For the third scenario in step 402, when there is a task to be assigned, the specific process of determining the target node for executing the target task is as follows.
[0206] When traversing to the i-th node, if the difference between the key value of the i-th node and the key value of the lightest node exceeds the allowed deviation value, the i-th node is transferred to the front of the second range in the node queue, for example, Figure 18 As shown, Figure 18 This is a schematic diagram of a node queue provided by an embodiment of the present application. Node D is the lightest node, so D in the node queue has the lightest node mark. When there are tasks to be assigned, start from the head of the node queue and traverse in sequence, see Figure 18 , the difference between the key value of node A, the head node of the node queue, and the key value of node B and the key value of node D exceeds the allowable deviation value, then node A and node B are invalid lighter nodes, and node A and node B need to be moved to the end of the first range in the node queue, and then compare the difference between the key value of node C and the key value of node D in the node queue. The difference is lower than the allowable deviation value, so node C is regarded as a valid lighter node, and the task to be assigned is assigned to the lighter node C.
[0207] For ease of understanding, the method provided in the embodiments of the present application is specifically described in two specific scenarios.
[0208] Application scenario 1: When it is detected that a user triggers a new task request, the task in the task request is assigned. At this time, the task needs to be assigned to a node with less load. Therefore, in the management platform, the node queue and the lightest node marked in the node queue are obtained, and traversal is started from the head of the node queue. That is, the key value of the node at the first position in the node queue is compared with the key value of the lightest node to determine whether it meets the requirements of the lighter node. If not, the key value of the node at the second position in the node queue is compared with the key value of the lightest node, and so on, until a lighter node is found and the task is assigned to the lighter node. Since the node queue is sorted in ascending order according to the key value of the node as a whole, it is possible to find a node that meets the requirements with an efficiency close to the better O(1) (O(1) means that the target element can be directly obtained in one operation). In addition, the task is assigned to the node with the smaller key value, so the load balancing between nodes is also relatively high.
[0209] Application scenario 2: In the task allocation system, when a new node joins, it is necessary to move the tasks on the node with heavier load in the task allocation system to the new node. Therefore, in the management platform, obtain the node queue, the heaviest node marked in the node queue, and start traversing from the end of the node queue. That is, compare the key value of the node in the last position in the node queue with the heaviest node to determine whether it meets the requirements of the heavier node. If not, continue to compare the key value of the node in the second last position in the node queue with the heaviest node, and so on, until the heavier node is found. Move the tasks on the heavier node to the new node. Since the node queue is generally sorted in order of the node key value from small to large, it is possible to find a node that meets the requirements with an efficiency close to the optimal O(1). In addition, the tasks on the node with the larger key value are allocated to the new node, so the load balancing between nodes is also relatively high. In addition, when assigning tasks on a node with a larger key value to a new node, only the tasks on the node with the larger key value are moved, that is, load balancing is re-achieved by relocating as few tasks as possible, so that the load balancing adjustment maintains global task hash consistency.
[0210] It should be noted that when judging the validity of lighter nodes and heavier nodes in the above two scenarios, if the requirements are not met, the position of the node that does not meet the requirements needs to be updated. At this time, the process of updating the node position is described in detail in step 403 and will not be repeated here.
[0211] In an embodiment of the present application, when the difference between the key value of the first node and the key value of the second node exceeds the allowed deviation value, the first node is sorted behind the second node, that is, when the key value difference between the two nodes exceeds the allowed deviation value, the node with the larger key value is sorted behind the node with the smaller key value, and when the difference between the key value of the first node and the key value of the second node is lower than the allowed deviation value, there is no strict requirement for the positions of the first node and the second node, the first node can be sorted in front of the second node, and the first node can also be sorted behind the second node. In other words, within the allowed deviation value, the first node and the second node are not strictly sorted according to the size of the key value. When the key value difference between the two nodes exceeds the allowed deviation value, the first node and the second node are strictly sorted according to the size of the key value, thereby forming a non-strict key value sorting queue from small to large. The non-strict sorting feature of the node queue makes it unnecessary to move the position of the changed node every time when the key value of the node in the node queue changes, thereby greatly reducing the amount of calculation. The node queue's ascending ordering allows for near-optimal efficiency when a target task is waiting to be assigned. This relaxed ascending order allows for the efficient and rapid identification of nodes with smaller key values within the queue. This allows selection from the front of the queue, eliminating the need to calculate the key value for each node, significantly reducing computational effort. This assigns the target task to the node with the smaller key value, thus satisfying the load balancing principle. Furthermore, the tolerance value can be flexibly configured to determine the accuracy of load balancing across multiple nodes.
[0212] See also Figure 19 , an embodiment of the present application provides a structural diagram of a task allocation device, the device 1900 including:
[0213] Determination module 1901, used to determine the target task to be assigned;
[0214] An acquisition module 1902 is configured to acquire a node queue, where the node queue includes multiple nodes, each of the multiple nodes corresponds to a key value, and the key value corresponding to each node indicates the load sharing status of the corresponding node. The multiple nodes in the node queue are sorted according to the corresponding key values. In the node queue, if the difference between the key value of a first node and the key value of a second node exceeds an allowable deviation value, the first node is sorted after the second node. If the difference between the key value of the first node and the key value of the second node is less than the allowable deviation value, the first node is sorted before the second node or after the second node. The first node and the second node are any two nodes in the node queue.
[0215] The determination module 1901 is further configured to determine a target node for executing a target task based on at least one node located at the front of the node queue.
[0216] Optionally, the node queue is marked with a lightest node and a heaviest node, the lightest node indicates the node with the smallest key value in the node queue, and the heaviest node indicates the node with the largest key value in the node queue;
[0217] The device also includes:
[0218] a detection module 1903 configured to, for a third node among the multiple nodes, determine a difference between a key value of the heaviest node and a key value of the lightest node when a change in a key value of the third node is detected, to obtain a target difference value, where the third node is any one of the multiple nodes;
[0219] The updating module 1904 is configured to update the sorting state of the third node in the node queue based on the target difference and the changed key value of the third node.
[0220] Optionally, the update module 1904 is further configured to:
[0221] When the target difference is lower than the allowable deviation, if the changed key value of the third node satisfies any of the following conditions, the sorting state of each node in the node queue remains unchanged:
[0222] The changed key value of the third node is between the key value of the lightest node and the key value of the heaviest node, or the key value of the third node increases, and the difference between the increased key value of the third node and the key value of the lightest node is lower than the allowable deviation value, or the key value of the third node decreases, and the absolute value of the difference between the decreased key value of the third node and the key value of the heaviest node is lower than the allowable deviation value.
[0223] Optionally, the update module 1904 is further configured to:
[0224] When the target difference exceeds the allowable deviation value and is lower than 2 times of the allowable deviation value, if the absolute value of the difference between the key value of the third node before the change and the key value of the heaviest node is lower than the allowable deviation value, the key value of the third node becomes smaller, the absolute value of the difference between the key value of the third node after the change and the key value of the heaviest node exceeds the allowable deviation value, and the difference between the key value of the third node after the change and the key value of the lightest node is less than the allowable deviation value, then the third node is transferred to the back of the lightest node in the node queue.
[0225] Optionally, the update module 1904 is further configured to:
[0226] When the target difference exceeds the allowable deviation value and is lower than 2 times of the allowable deviation value, if the difference between the key value of the third node before the change and the key value of the lightest node is lower than the allowable deviation value, the key value of the third node increases, the difference between the key value of the third node after the increase and the key value of the lightest node exceeds the allowable deviation value, and the absolute value of the difference between the key value of the third node after the increase and the key value of the heaviest node is less than the allowable deviation value, then the third node is transferred to the front of the heaviest node in the node queue.
[0227] Optionally, the update module 1904 is further configured to:
[0228] In the case where the target difference exceeds 2 times the allowable deviation value, if the third node before the key value changes belongs to the first range of nodes, and the key value of the third node becomes smaller and the third node after the key value becomes smaller belongs to the second range of nodes, then the third node is transferred to the end of the nodes in the second range in the node queue. The first range is the node range composed of the nodes in the node queue whose key value is between the key value of the heaviest node and the difference between the key value of the heaviest node and the allowable deviation value. The second range is the node range composed of the nodes in the node queue whose key value is between the difference between the key value of the heaviest node and the allowable deviation value and the sum of the key value of the lightest node and the allowable deviation value.
[0229] Optionally, the update module 1904 is further configured to:
[0230] In the case where the target difference exceeds 2 times the allowable deviation value, if the third node before the key value changes belongs to a node in the third range, and the key value of the third node increases and the third node after the key value increases belongs to a node in the second range, then the third node is transferred to the front of the nodes in the second range in the node queue, and the third range is the node range in the node queue consisting of the key value of the lightest node, the sum of the key value of the lightest node and the allowable deviation value, and the nodes in between.
[0231] Optionally, the update module 1904 is further configured to:
[0232] When the target difference exceeds 2 times the allowable deviation value, if the third node before the key value changes belongs to the node in the second range, and the key value of the third node becomes smaller, and the third node after the key value becomes smaller belongs to the node in the third range, then the third node is transferred to the back of the lightest node in the node queue.
[0233] Optionally, the update module is further configured to:
[0234] If the changed key value of the third node is less than the key value of the lightest node, the lightest node is updated to the third node; if the changed key value of the third node is greater than the key value of the heaviest node, the heaviest node is updated to the third node.
[0235] Optionally, the update module is further configured to:
[0236] If the changed key value of the third node is less than the key value of the lightest node, the third node is transferred to the head of the node queue; if the changed key value of the third node is greater than the key value of the heaviest node, the third node is transferred to the tail of the node queue.
[0237] Optionally, the acquisition module 1902 is further configured to:
[0238] When multiple nodes are initialized, the key value of each node in the multiple nodes is obtained, and the multiple nodes are sorted according to the key value of each node in the multiple nodes to obtain a node queue during initialization. In the node queue during initialization, nodes with larger key values are sorted behind nodes with smaller key values.
[0239] The node at the front of the node queue at the time of initialization is marked as the lightest node, and the node at the end of the node queue at the time of initialization is marked as the heaviest node.
[0240] Optionally, the node queue is marked with the lightest node;
[0241] The determination module 1901 is further configured to:
[0242] Starting from the head of the node queue, traverse the i-th node in sequence, where i is a positive integer greater than or equal to 1, until the first node that meets the reference condition is determined. The first node that meets the reference condition is used as the target node. The reference condition means that the difference between the key value of the node and the key value of the lightest node is lower than the allowable deviation value.
[0243] Optionally, the node queue is also marked with the heaviest node;
[0244] The determination module 1901 is further configured to:
[0245] When traversing to the i-th node, if the difference between the key value of the i-th node and the key value of the lightest node exceeds the allowable deviation value, the i-th node will be transferred to the end of the third range in the node queue, and the third range is the node range composed of the nodes in the node queue whose key values are between the key values of the light and heavy nodes and the sum of the key value of the lightest node and the allowable deviation value.
[0246] Optionally, the target task is a task carried in the task request or a task offloaded from a node whose key value is greater than a threshold.
[0247] Optionally, the key value of each node in the multiple nodes indicates the number of tasks on the corresponding node, or indicates the resource occupancy of the tasks on the corresponding node, or indicates the resource remaining status of the tasks on the corresponding node.
[0248] Optionally, the allowable deviation value is a reference value, or is determined based on a reference percentage of an average value of key values of each node included in the node list.
[0249] In summary, in the embodiment of the present application, when the difference between the key value of the first node and the key value of the second node exceeds the allowed deviation value, the first node is sorted behind the second node, that is, when the key value difference between the two nodes exceeds the allowed deviation value, the node with the larger key value is sorted behind the node with the smaller key value, and when the difference between the key value of the first node and the key value of the second node is lower than the allowed deviation value, there is no strict requirement for the positions of the first node and the second node, the first node can be sorted in front of the second node, and the first node can also be sorted behind the second node. In other words, within the allowed deviation value, the first node and the second node are not strictly sorted according to the size of the key value. When the key value difference between the two nodes exceeds the allowed deviation value, the first node and the second node are strictly sorted according to the size of the key value, thereby forming a non-strict key value sorting queue from small to large. The non-strict sorting feature of the node queue makes it unnecessary to move the position of the changed node every time when the key value of the node in the node queue changes, thereby greatly reducing the amount of calculation. The node queue's ascending ordering allows for the efficient and rapid identification of nodes with smaller key values within the queue when a target task is waiting to be assigned. This relaxed ascending order allows for the efficient and rapid identification of nodes with smaller key values within the queue, eliminating the need to calculate the key value for each node, significantly reducing computational effort. Furthermore, the target task is assigned to the node with the smaller key value, thus satisfying the load balancing principle. Furthermore, the tolerance value can be flexibly configured to determine the accuracy of load balancing across multiple nodes.
[0250] It should be noted that the task allocation device provided in the above embodiment only uses the division of the above functional modules as an example to illustrate task allocation. In actual applications, the above functional allocation can be completed by different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the task allocation device provided in the above embodiment and the task allocation method embodiment are based on the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0251] Figure 20This is a schematic diagram of the structure of a computer device provided by the embodiment of this application. In the above embodiment, the node can be Figure 20 See the computer device shown. Figure 20 The computer device includes at least one processor 2001 , a communication bus 2002 , a memory 2003 and at least one communication interface 2004 .
[0252] The processor 2001 may be a general-purpose central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present application.
[0253] The communication bus 2002 may include a pathway for transmitting information between the aforementioned components.
[0254] The memory 2003 may be a read-only memory (ROM) or other type of static storage device that can store static information and instructions, a random access memory (RAM) or other type of dynamic storage device that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, an optical disc storage (including a compact disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 2003 may exist independently and be connected to the processor 2001 via the communication bus 2002. The memory 2003 may also be integrated with the processor 2001.
[0255] The memory 2003 is used to store program code for executing the solution of the present application, and is controlled by the processor 2001 for execution. The processor 2001 is used to execute the program code stored in the memory 2003. The program code may include one or more software modules. The movement of the node in the above embodiment can be determined by the processor 2001 and one or more software modules in the program code in the memory 2003 to develop data for the application.
[0256] The communication interface 2004 uses any transceiver or other device for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), wireless local area network (WLAN), etc.
[0257] In a specific implementation, as an embodiment, a computer device may include multiple processors, such as Figure 20 2001 and processor 2005 are shown in FIG. Each of these processors can be a single-CPU processor or a multi-CPU processor. A processor herein can refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).
[0258] The aforementioned computer device may be a general-purpose computer device or a dedicated computer device. In a specific implementation, the computer device may be a desktop computer, a portable computer, a network server, a personal digital assistant (PDA), a mobile phone, a tablet computer, a wireless terminal device, a communication device, or an embedded device. The embodiments of the present application do not limit the type of computer device.
[0259] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated therein. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a digital versatile disc (DVD)), or a semiconductor medium (eg, a solid state disk (SSD)).
[0260] Those skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware, or by a program to instruct the relevant hardware, and the program may be stored in a computer-readable storage medium, which may be a read-only memory, a disk, or an optical disk, etc.
[0261] The above description is an embodiment provided for this application and is not intended to limit the embodiments of this application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the embodiments of this application should be included in the scope of protection of the embodiments of this application.
Claims
1. A task allocation method, characterized in that: The method comprises: Determine the target tasks to be assigned; Obtain a node queue, where the node queue includes multiple nodes, each of the multiple nodes corresponds to a key value, the key value corresponding to each node indicates a load sharing situation on the corresponding node, the multiple nodes in the node queue are sorted according to the corresponding key values, and in the node queue, if the difference between the key value of a first node and the key value of a second node exceeds an allowable deviation value, the first node is sorted behind the second node; if the difference between the key value of the first node and the key value of the second node is lower than the allowable deviation value, the first node is sorted before the second node or the first node is sorted behind the second node, and the first node and the second node are any two nodes in the node queue; A target node for executing the target task is determined based on at least one node located at the front of the node queue.
2. The method according to claim 1, wherein The node queue is marked with a lightest node and a heaviest node, the lightest node indicates the node with the smallest key value in the node queue, and the heaviest node indicates the node with the largest key value in the node queue; The method further comprises: For a third node among the plurality of nodes, upon detecting a change in the key value of the third node, determining a difference between the key value of the heaviest node and the key value of the lightest node to obtain a target difference value, the third node being any one of the plurality of nodes; Based on the target difference and the changed key value of the third node, the sorting status of the third node in the node queue is updated.
3. The method according to claim 2, wherein The updating, based on the target difference and the changed key value of the third node, of the sorting state of the third node in the node queue includes: When the target difference is lower than the allowable deviation, if the changed key value of the third node satisfies any of the following conditions, the sorting state of each node in the node queue remains unchanged: The changed key value of the third node is between the key value of the lightest node and the key value of the heaviest node, or the key value of the third node increases, and the difference between the increased key value of the third node and the key value of the lightest node is lower than the allowable deviation value, or the key value of the third node decreases, and the absolute value of the difference between the decreased key value of the third node and the key value of the heaviest node is lower than the allowable deviation value.
4. The method according to claim 2, wherein The updating, based on the target difference and the changed key value of the third node, of the sorting state of the third node in the node queue includes: When the target difference exceeds the allowable deviation value and is lower than 2 times of the allowable deviation value, if the absolute value of the difference between the key value of the third node before the change and the key value of the heaviest node is lower than the allowable deviation value, the key value of the third node becomes smaller, the absolute value of the difference between the key value of the third node after the change and the key value of the heaviest node exceeds the allowable deviation value, and the difference between the key value of the third node after the change and the key value of the lightest node is less than the allowable deviation value, then the third node is transferred to the back of the lightest node in the node queue.
5. The method according to claim 2, wherein The updating, based on the target difference and the changed key value of the third node, of the sorting state of the third node in the node queue includes: When the target difference exceeds the allowable deviation value and is lower than 2 times of the allowable deviation value, if the difference between the key value of the third node before the change and the key value of the lightest node is lower than the allowable deviation value, the key value of the third node increases, the difference between the key value of the third node after the increase and the key value of the lightest node exceeds the allowable deviation value, and the absolute value of the difference between the key value of the third node after the increase and the key value of the heaviest node is less than the allowable deviation value, then the third node is transferred to the front of the heaviest node in the node queue.
6. The method according to claim 2, wherein The updating, based on the target difference and the changed key value of the third node, of the sorting state of the third node in the node queue includes: In the case where the target difference exceeds 2 times the allowable deviation value, if the third node before the key value changes belongs to the first range of nodes, and the key value of the third node becomes smaller and the third node after the key value becomes smaller belongs to the second range of nodes, then the third node is transferred to the end of the nodes in the second range in the node queue. The first range is the node range composed of the nodes in the node queue whose key value is between the key value of the heaviest node and the difference between the key value of the heaviest node and the allowable deviation value. The second range is the node range composed of the nodes in the node queue whose key value is between the difference between the key value of the heaviest node and the allowable deviation value and the sum of the key value of the lightest node and the allowable deviation value.
7. The method according to claim 2, wherein The updating, based on the target difference and the changed key value of the third node, of the sorting state of the third node in the node queue includes: In the case where the target difference exceeds 2 times the allowable deviation value, if the third node before the key value changes belongs to a node in the third range, and the key value of the third node increases and the third node after the key value increases belongs to a node in the second range, then the third node is transferred to the front of the nodes in the second range in the node queue, and the third range is the node range in the node queue consisting of the key value of the lightest node, the sum of the key value of the lightest node and the allowable deviation value, and the nodes in between.
8. The method according to claim 2, wherein The updating, based on the target difference and the changed key value of the third node, of the sorting state of the third node in the node queue includes: When the target difference exceeds 2 times the allowable deviation value, if the third node before the key value changes belongs to the node in the second range, and the key value of the third node becomes smaller, and the third node after the key value becomes smaller belongs to the node in the third range, then the third node is transferred to the back of the lightest node in the node queue.
9. The method according to any one of claims 2 to 8, characterized in that: The method further comprises: If the changed key value of the third node is less than the key value of the lightest node, updating the lightest node to the third node; If the changed key value of the third node is greater than the key value of the heaviest node, the heaviest node is updated to the third node.
10. The method according to claim 9, wherein The method further comprises: If the changed key value of the third node is less than the key value of the lightest node, transferring the third node to the head of the node queue; If the changed key value of the third node is greater than the key value of the heaviest node, the third node is transferred to the end of the node queue.
11. The method according to any one of claims 2 to 8 and 10, characterized in that: The method further comprises: When the multiple nodes are initialized, a key value of each node in the multiple nodes is obtained, and the multiple nodes are sorted according to the key value of each node in the multiple nodes to obtain a node queue during initialization, wherein nodes with larger key values in the node queue during initialization are sorted behind nodes with smaller key values; The node that is ranked first in the node queue during the initialization is marked as the lightest node, and the node that is ranked last in the node queue during the initialization is marked as the heaviest node.
12. The method according to claim 1, wherein The node queue is marked with the lightest node; The determining, based on at least one node located at the front of the node queue, a target node for executing the target task, includes: Starting from the head of the node queue, traverse the i-th node in sequence, where i is a positive integer greater than or equal to 1, until the first node that meets the reference condition is determined, and the first node that meets the reference condition is used as the target node. The reference condition means that the difference between the key value of the node and the key value of the lightest node is lower than the allowable deviation value.
13. The method according to claim 12, wherein: The node queue is also marked with the heaviest node; The method further comprises: When traversing to the i-th node, if the difference between the key value of the i-th node and the key value of the lightest node exceeds the allowable deviation value, the i-th node will be transferred to the end of the third range in the node queue, and the third range is the node range consisting of the nodes in the node queue whose key value is between the key value of the lightest node and the sum of the key value of the lightest node and the allowable deviation value.
14. The method according to any one of claims 1 to 8, 10, 12 to 13, characterized in that: The key value of each node among the multiple nodes indicates the number of tasks on the corresponding node, or indicates the resource occupation status of the tasks on the corresponding node, or indicates the resource remaining status of the tasks on the corresponding node.
15. A task allocation device, characterized in that: The device comprises: A determination module is used to determine the target task to be assigned; an acquisition module, configured to acquire a node queue, the node queue comprising a plurality of nodes, each of the plurality of nodes corresponding to a key value, the key value corresponding to each node indicating a load sharing situation on the corresponding node, the plurality of nodes in the node queue being sorted according to the corresponding key values, and in the node queue, if a difference between a key value of a first node and a key value of a second node exceeds an allowable deviation value, the first node is sorted behind the second node; if a difference between the key value of the first node and the key value of the second node is lower than the allowable deviation value, the first node is sorted in front of the second node or the first node is sorted behind the second node, the first node and the second node being any two nodes in the node queue; The determining module is further configured to determine a target node for executing the target task based on at least one node located at the front of the node queue.
16. The device according to claim 15, characterized in that The node queue is marked with a lightest node and a heaviest node, the lightest node indicates the node with the smallest key value in the node queue, and the heaviest node indicates the node with the largest key value in the node queue; The device further comprises: a detection module configured to, for a third node among the plurality of nodes, determine a difference between the key value of the heaviest node and the key value of the lightest node when a change in the key value of the third node is detected, to obtain a target difference value, wherein the third node is any one of the plurality of nodes; An updating module is used to update the sorting state of the third node in the node queue based on the target difference and the changed key value of the third node.
17. The device according to claim 16, wherein The update module is further configured to: When the target difference is lower than the allowable deviation, if the changed key value of the third node satisfies any of the following conditions, the sorting state of each node in the node queue remains unchanged: The changed key value of the third node is between the key value of the lightest node and the key value of the heaviest node, or the key value of the third node increases, and the absolute value of the difference between the increased key value of the third node and the key value of the lightest node is lower than the allowable deviation value, or the key value of the third node decreases, and the absolute value of the difference between the decreased key value of the third node and the key value of the heaviest node is lower than the allowable deviation value.
18. The apparatus according to claim 16, wherein the updating module is further configured to: When the target difference exceeds the allowable deviation value and is lower than 2 times of the allowable deviation value, if the difference between the key value of the third node before the change and the key value of the heaviest node is lower than the allowable deviation value, the key value of the third node becomes smaller, the difference between the key value of the third node after the change and the key value of the heaviest node exceeds the allowable deviation value, and the absolute value of the difference between the key value of the third node after the change and the key value of the lightest node is less than the allowable deviation value, then the third node is transferred to the back of the lightest node in the node queue.
19. The device according to claim 16, wherein The update module is further configured to: When the target difference exceeds the allowable deviation value and is lower than 2 times of the allowable deviation value, if the difference between the key value of the third node before the change and the key value of the lightest node is lower than the allowable deviation value, the key value of the third node increases, the difference between the key value of the third node after the increase and the key value of the lightest node exceeds the allowable deviation value, and the absolute value of the difference between the key value of the third node after the increase and the key value of the heaviest node is less than the allowable deviation value, then the third node is transferred to the front of the heaviest node in the node queue.
20. The device according to claim 16, wherein The update module is further configured to: In the case where the target difference exceeds 2 times the allowable deviation value, if the third node before the key value changes belongs to the first range of nodes, and the key value of the third node becomes smaller and the third node after the key value becomes smaller belongs to the second range of nodes, then the third node is transferred to the end of the nodes in the second range in the node queue. The first range is the node range composed of the nodes in the node queue whose key value is between the key value of the heaviest node and the difference between the key value of the heaviest node and the allowable deviation value. The second range is the node range composed of the nodes in the node queue whose key value is between the difference between the key value of the heaviest node and the allowable deviation value and the sum of the key value of the lightest node and the allowable deviation value.
21. The device according to claim 16, wherein The update module is further configured to: In the case where the target difference exceeds 2 times the allowable deviation value, if the third node before the key value changes belongs to a node in the third range, and the key value of the third node increases and the third node after the key value increases belongs to a node in the second range, then the third node is transferred to the front of the nodes in the second range in the node queue, and the third range is the node range in the node queue consisting of the key value of the lightest node, the sum of the key value of the lightest node and the allowable deviation value, and the nodes in between.
22. The device according to claim 16, wherein The update module is further configured to: When the target difference exceeds 2 times the allowable deviation value, if the third node before the key value changes belongs to the node in the second range, and the key value of the third node becomes smaller, and the third node after the key value becomes smaller belongs to the node in the third range, then the third node is transferred to the back of the lightest node in the node queue.
23. The device according to any one of claims 16 to 22, characterized in that The update module is further configured to: If the changed key value of the third node is less than the key value of the lightest node, updating the lightest node to the third node; If the changed key value of the third node is greater than the key value of the heaviest node, the heaviest node is updated to the third node.
24. The device according to claim 23, wherein The update module is further configured to: If the changed key value of the third node is less than the key value of the lightest node, transferring the third node to the head of the node queue; If the changed key value of the third node is greater than the key value of the heaviest node, the third node is transferred to the end of the node queue.
25. The device according to any one of claims 16 to 22 and 24, characterized in that The acquisition module is further used for: When the multiple nodes are initialized, a key value of each node in the multiple nodes is obtained, and the multiple nodes are sorted according to the key value of each node in the multiple nodes to obtain a node queue during initialization, wherein nodes with larger key values in the node queue during initialization are sorted behind nodes with smaller key values; The node that is ranked first in the node queue during the initialization is marked as the lightest node, and the node that is ranked last in the node queue during the initialization is marked as the heaviest node.
26. The device according to claim 15, wherein The node queue is marked with the lightest node; The determining module is further configured to: Starting from the head of the node queue, traverse the i-th node in sequence, where i is a positive integer greater than or equal to 1, until the first node that meets the reference condition is determined, and the first node that meets the reference condition is used as the target node. The reference condition means that the difference between the key value of the node and the key value of the lightest node is lower than the allowable deviation value.
27. The device according to claim 26, wherein The node queue is also marked with the heaviest node; The determining module is further configured to: When traversing to the i-th node, if the difference between the key value of the i-th node and the key value of the lightest node exceeds the allowable deviation value, the i-th node will be transferred to the end of the third range in the node queue, and the third range is the node range consisting of the nodes in the node queue whose key value is between the key value of the lightest node and the sum of the key value of the lightest node and the allowable deviation value.
28. The device according to any one of claims 15 to 22, 24, 26 to 27, characterized in that The key value of each node among the multiple nodes indicates the number of tasks on the corresponding node, or indicates the resource occupation status of the tasks on the corresponding node, or indicates the resource remaining status of the tasks on the corresponding node.
29. A computer device, characterized in that: The computer device comprises: processor; a memory for storing processor-executable instructions; The processor is configured to execute the steps of the method according to any one of claims 1 to 14.
30. A computer-readable storage medium, characterized in that The computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the method according to any one of claims 1 to 14.
Citation Information
Patent Citations
Distributed real-time task scheduling method and device, equipment and medium
CN111813513A
Distributed resource allocation in stream processing systems
US20070297332A1