Task allocation method and device, electronic equipment, storage medium and program product
By splitting tasks into subtask sets of different business types and determining the target threads according to the arrangement order and priority of thread groups, the problems of load imbalance and overload in multi-threaded systems are solved, and balanced allocation of tasks and efficient utilization of resources are achieved, and system performance is improved.
Patent Information
- Application Number
- CN202510517560.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-23
- Publication Date
- 2025-07-29
AI Technical Summary
The existing task allocation methods have load imbalance and individual thread overload in multi-threaded systems, which affect the overall performance and resource utilization of the system. Especially in distributed storage systems, especially in high concurrency environments, polling allocation and consistent hash allocation cannot effectively solve the problems of thread utilization imbalance and resource competition.
Split the tasks to be allocated into target subtask sets of different business types, and determine the target thread group according to the arrangement order and priority of the target business thread group to achieve balanced allocation of tasks and avoid overloading of individual threads.
Through task splitting and thread group optimization, balanced allocation of tasks is achieved, thread processing load is reduced, thread activity and resource utilization are improved, thread overload and resource competition are avoided, and system performance is improved.
Smart Images

Figure CN120386601A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and in particular, to a task allocation method, apparatus, electronic device, storage medium, and program product. Background Art
[0002] When processing tasks, to ensure multi-task concurrency and improve program efficiency, multi-threading can be used to ensure multi-task concurrent processing, thereby improving the efficiency of task processing.
[0003] The methods of allocating tasks to multiple threads can include round-robin allocation and consistent hashing allocation. Round-robin allocation treats all tasks equally and delivers them in the enqueue order, resulting in unbalanced thread utilization and tasks that cannot be processed in a timely manner; consistent hashing allocation maps the hash values of tasks and threads to a circular hash space, and finds a suitable thread to allocate tasks according to the clockwise direction. However, this method highly depends on the hash algorithm, is complex to process, and even under ideal hash distribution, there is still the phenomenon of local hotspots, and there may be a situation where individual threads are overloaded and the rest of the threads are idle, affecting the overall performance of the multi-threaded system. Summary of the Invention
[0004] This application provides a task allocation method, apparatus, electronic device, storage medium, and program product for evenly allocating tasks.
[0005] In a first aspect, this application provides a task allocation method, including:
[0006] Splitting the task to be allocated into at least one target subtask set, where one target subtask set corresponds to one target business type;
[0007] Determining a target business thread group corresponding to the target business type of the target subtask set. Different business types correspond to different business thread groups, and each business thread group includes at least one business thread;
[0008] Based on the arrangement order of each business thread in the target business thread group, determining the target thread corresponding to the target subtask set, and adding the target subtask set to the target queue corresponding to the target thread.
[0009] In an implementable manner, the splitting the task to be allocated into at least one target subtask set, where one target subtask set corresponds to one target business type, includes:
[0010] Based on the processing steps of the task to be allocated, splitting the task to be allocated into multiple subtasks;
[0011] Determining the subtasks of the same business type among the multiple subtasks as one target subtask set.
[0012] In one implementable manner, determining the target thread corresponding to the target subtask set based on the arrangement order of each service thread in the target service thread group includes:
[0013] According to the arrangement order of each service thread in the target thread group, determining the service thread in the queue corresponding to the service thread in the target thread group where the number of subtask sets is less than a preset first threshold as the target thread;
[0014] If there is no service thread in the target thread group where the number of subtask sets in the queue is less than the preset first threshold, then determining the target thread from the target thread group and the non-target thread groups corresponding to other service types except the target service type.
[0015] In one implementable manner, determining the target thread from the target thread group and the non-target thread groups corresponding to other service types except the target service type includes:
[0016] Based on the priority order of the non-target thread group and the target thread group, determining whether there is a calibrated thread group in the non-target thread group, where there is a service thread in the calibrated thread group where the number of subtask sets is less than the preset first threshold;
[0017] If there is the calibrated thread group, then determining the target thread in the calibrated thread group;
[0018] If there is no such calibrated thread group, then determining the target thread from the non-target thread group and the target thread group.
[0019] In one implementable manner, determining whether there is a calibrated thread group in the non-target thread group includes:
[0020] If there is a service thread group in the non-target thread group whose priority is after the target thread group, then determining whether there is such a calibrated thread group in the service thread group whose priority is after the target thread group;
[0021] If it is determined that there is no such calibrated thread group in the service thread group whose priority is after the target thread group, then determining whether there is a service thread group in the non-target thread group whose priority is before the target thread group;
[0022] If there is no service thread group in the non-target thread group whose priority is before the target thread group, then determining that there is no such calibrated thread group in the non-target thread group;
[0023] If there is a thread group with a priority before the target thread group in the non-target thread group, determine whether the calibration thread group exists in the business thread group with a priority before the target thread group;
[0024] If the calibration thread group does not exist in the business thread group with a priority before the target thread group, determine that the calibration thread group does not exist in the non-target thread group.
[0025] In one implementable manner, determining whether the calibration thread group exists in the business thread group with a priority after the target thread group includes:
[0026] Based on the priority order in the business thread group with a priority after the target thread group, if there is an initial thread group in which the number of subtask sets in the queue corresponding to the business threads in the business thread group is less than a preset first threshold, determine the initial thread group as the calibration thread group;
[0027] If there is no initial thread group in which the number of subtask sets in the queue corresponding to the business threads in the business thread group with a priority after the target thread group is less than the preset first threshold, determine that the calibration thread group does not exist in the business thread group with a priority after the target thread group.
[0028] In one implementable manner, determining the target thread in the calibration thread group includes:
[0029] Based on the arrangement order of the business threads in the calibration thread group, determine the business thread in which the number of subtask sets in the queue corresponding to the business thread in the calibration thread group is less than the preset first threshold as the target thread.
[0030] In one implementable manner, determining the target thread in the non-target thread group and the target thread group includes:
[0031] Determine the business thread in which the number of subtask sets in the queue corresponding to the business thread in the non-target thread group and the target thread group is less than a preset second threshold as the target thread.
[0032] In a second aspect, the present application provides a task allocation device, including: a task splitting module, configured to split a task to be allocated into at least one target subtask set, and one target subtask set corresponds to one target service type;
[0033] A thread group determination module, configured to determine a target business thread group corresponding to the target service type of the target subtask set, different service types correspond to different business thread groups, and each business thread group includes at least one business thread;
[0034] A thread determination module, configured to determine a target thread corresponding to the target subtask set based on the arrangement order of service threads in the target service thread group, and add the target subtask set to a target queue corresponding to the target thread.
[0035] In a third aspect, the present application provides an electronic device, including: a processor, and a memory communicatively connected to the processor;
[0036] The memory stores computer-executable instructions;
[0037] The processor executes the computer-executable instructions stored in the memory to implement the method described in the first aspect.
[0038] In a fourth aspect, the present application provides a computer-readable storage medium, in which computer-executable instructions are stored, and when the computer-executable instructions are executed by a processor, they are used to implement the method described in the first aspect.
[0039] In a fifth aspect, the present application provides a computer program product, including a computer program, and when the computer program is executed by a processor, it implements the method described in the first aspect.
[0040] The task allocation method, device, electronic device, storage medium, and program product provided by the present application split the task to be allocated into target subtask sets corresponding to different service types, and perform thread allocation for different target subtask sets respectively. The processing load of the subtasks in the target subtask set will be lower than the processing load of the task to be allocated, so as to reduce the load amount processed by each thread; at the same time, the target service thread group corresponding to the target subtask set of different target service types can be determined, and the subtask set is preferentially allocated to the thread where the corresponding target service thread group is located. At the same time, according to the arrangement order of the service threads in the target service thread group, the target thread of each subtask set is determined. This process can achieve the balanced allocation of the task to be allocated and avoid the problem of individual thread overload. Description of the Drawings
[0041] The accompanying drawings here are incorporated into the specification and constitute a part of this specification, showing the embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.
[0042] Figure 1 is an implementation scenario diagram shown in an exemplary embodiment;
[0043] Figure 2 is a flowchart of a task allocation method shown in an exemplary embodiment;
[0044] Figure 3 is a flowchart of a task allocation method shown in another exemplary embodiment;
[0045] Figure 4 is a flowchart of a task allocation method shown in another exemplary embodiment;
[0046] Figure 5 This is a schematic diagram of a thread pool structure shown in an exemplary embodiment;
[0047] Figure 6 is a structural diagram of a task allocation device shown in an exemplary embodiment;
[0048] Figure 7 It is a block diagram of an electronic device shown in an exemplary embodiment.
[0049] The above drawings illustrate specific embodiments of the present application, which will be described in more detail below. These drawings and the textual description are not intended to limit the scope of the present application in any way, but rather to illustrate the concepts of the present application to those skilled in the art by reference to specific embodiments. DETAILED DESCRIPTION
[0050] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
[0051] In order to ensure multi-task concurrency and improve program efficiency when delivering user tasks, distributed cloud storage systems usually use thread pools to manage and reuse thread resources in multi-threaded programming. By creating a group of pre-initialized threads and storing these threads in a pool, the overhead caused by frequent thread creation and destruction can be reduced, thereby improving program performance and responsiveness.
[0052] However, some task allocation methods fail to consider the actual thread load, which can lead to load imbalance. This can easily cause a single thread to be assigned multiple, time-consuming tasks, resulting in delayed task processing and a failure to control task priority and load adjustment. Distributed storage services operate concurrently in multiple business scenarios, each with varying processing complexity and timeliness requirements. Therefore, a task allocation method is needed that achieves load balancing across threads in the thread pool.
[0053] Some task allocation methods to achieve thread pool load balancing include polling allocation and consistent hashing allocation, which can achieve balanced task allocation while balancing the load and prevent some threads from being overloaded.
[0054] Polling allocation treats all front-end tasks equally without distinguishing the priorities of tasks. In a distributed cloud storage system, there will be high-priority user tasks and some low-priority background tasks in the environment at the same time. The tasks in the waiting queue of the thread pool do not distinguish the differences in priorities and execution times, and are delivered in the enqueue order, resulting in unbalanced resource utilization and the situation where user tasks cannot be processed in time.
[0055] In a high-concurrency environment, the polling allocation method may lead to resource competition among threads. Especially when multiple threads access common resources simultaneously, it may cause thread blocking or even deadlock phenomena, further reducing the system's response speed and efficiency, thus affecting the performance of the storage software.
[0056] The consistent hashing allocation method maps the hash values of user tasks and threads to a circular hash space, and finds a suitable node to process the tasks according to the clockwise direction. This method highly depends on the hash algorithm, but even under the ideal hash distribution, there is still the phenomenon of local hotspots, and there may be a situation where individual threads are overloaded and the rest of the threads are idle, affecting the overall performance of the system.
[0057] It can be seen that most of the above methods for allocating tasks to the thread pool can only provide basic task allocation. In scenarios with uneven task loads, heterogeneous system resources, and the need for dynamic adjustment, it will significantly affect the performance of task allocation and resource utilization rate, which is a bottleneck for distributed storage systems that pursue high performance and high concurrency.
[0058] The task allocation method, device, electronic device, storage medium, and program product provided by this application aim to solve the above technical problems in the prior art.
[0059] The following uses specific embodiments to elaborate in detail on the technical solutions of this application and how the technical solutions of this application solve the above technical problems. These several specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of this application will be described below in conjunction with the accompanying drawings.
[0060] The service deployment method provided by this application can be implemented on any electronic device with data processing capabilities, or it can also be a service deployment system. It should be noted that the service deployment system can be deployed alone on an electronic device in any environment (for example: alone on an edge server in the edge environment), or it can be fully deployed in the cloud environment, or it can be distributedly deployed in different environments.
[0061] For example, a service deployment system can be logically divided into multiple parts, each with different functions. Each part in the service deployment system can be deployed in any two or three of an electronic device (located on the user side, such as a client), an edge environment, and a cloud environment. The edge environment is an environment including a set of edge electronic devices relatively close to the electronic device, and the edge electronic devices include: edge servers, edge small stations with computing power, etc. Each part of the container startup system deployed in different environments or devices collaborates to implement the functions of the data processing platform.
[0062] It should be understood that this application does not restrictively divide which parts of the service deployment system are specifically deployed in what environment. In actual applications, adaptive deployment can be carried out according to the computing power of the electronic device, the resource occupancy of the edge environment and the cloud environment, or specific application requirements.
[0063] Such as Figure 1 is an implementation scenario diagram shown in an exemplary embodiment. The task allocation system corresponding to this implementation scenario includes a client 10 and a server 11, and the client 10 and the server 11 are connected through network communication.
[0064] The execution subject of the method in the embodiment of this application is the server 11. The client 10 can receive a task to be allocated, and the client 10 sends the task to be allocated to the server 11 through the network. The server 11 performs task allocation and can feedback the allocation task result to the client 10 through the network. The client 10 has a graphical user interface, and the task allocation result can be displayed on this graphical user interface.
[0065] In some embodiments, after receiving the task to be allocated, the server 11 splits the task to be allocated into at least one target sub-task set, and one target sub-task set corresponds to one target business type; determines the target business thread group corresponding to the target business type of the target sub-task set. Different business types correspond to different business thread groups, and each business thread group includes at least one business thread; based on the arrangement order of each business thread in the target business thread group, determines the target thread corresponding to the target sub-task set, and adds the target sub-task set to the target queue corresponding to the target thread.
[0066] It can be understood that the task allocation device can be set in Figure 1 the server 11 in, but the implementation environment shown in this embodiment such as Figure 1 shown is only exemplary. In other embodiments, the task allocation method can also be applied to other implementation environments, and the task allocation device can also be set in other structures in other implementation environments, which are not specifically limited here.
[0067] In this embodiment, the client 10 is an electronic device on the user side, which can be a wired terminal with a visual structure or a wireless terminal. In some other embodiments, the terminal can be an electronic device with a visual structure such as a mobile phone, a computer, a tablet, and a vehicle-mounted device, etc.
[0068] The server 11 can be an edge environment and a cloud environment, such as a physical server, a server cluster, and a cloud server, etc., which is not specifically limited here.
[0069] Figure 2 It is a flowchart of a task allocation method shown in an exemplary embodiment, which is applied to Figure 1 the server 11 in Figure 2 As shown, this method includes steps S201 to S203, which are introduced in detail as follows:
[0070] S201. Split the task to be allocated into at least one target subtask set, and one target subtask set corresponds to one target business type.
[0071] In some embodiments, the task to be allocated may include multiple actions. For example, there is a task to be allocated to write A data into B location. At this time, it may include steps of opening B location and writing A data into B location. In this way, the task to be allocated can be split into multiple subtasks.
[0072] In some embodiments, each processing step may correspond to one action or business type. For example, the action corresponding to opening B location is "read", and the action corresponding to writing A data into B location is write.
[0073] In some embodiments, the task to be allocated is a task in a storage scenario, such as in the field of distributed cloud storage. This task allocation method can be applied to the field of cloud storage.
[0074] In some embodiments, the subtasks can be divided into different business types. For example, in the field of distributed cloud storage, the business types may include user read business type, user write business type, metadata business type, and background business type. The user read business type represents the operation steps for a user to read data, the user write business type identifies the operation steps for a user to submit or modify data, the metadata business type identifies the operation steps for processing metadata, and the background business type identifies the operation steps for asynchronous tasks such as batch processing tasks, data backup, and log analysis.
[0075] Classify the multiple subtasks obtained by splitting the task to be allocated respectively to obtain the business types of each subtask, and divide the subtasks with the same business type into one subtask set, so as to obtain the target subtask set of the task to be allocated.
[0076] It can be understood that based on the processing steps of the task to be assigned, the task to be assigned is split into multiple subtasks, each processing step can be divided into a subtask, and the subtasks with the same business type among the multiple subtasks are determined as a target subtask set. The number of target subtask sets of a task to be assigned can be one or more, and the number of subtasks in a target subtask set can be one or more. The business types of the subtasks in a target subtask set correspond to a target business type, and different target subtask sets of a task to be assigned correspond to different target business types.
[0077] S202. Determine the target business thread group corresponding to the target business type of the target subtask set. Different business types correspond to different business thread groups, and each business thread group includes at least one business thread.
[0078] In some embodiments, for different business types, there are corresponding business thread groups, and each business thread group includes at least one business thread.
[0079] In some embodiments, there is a thread pool, and the business threads in the thread pool can be allocated to obtain multiple business thread groups, and the business threads corresponding to different business thread groups are different.
[0080] In some embodiments, in the thread pool, the business thread groups are allocated according to the sorting of the business threads. Each business thread group has a corresponding arrangement order, and the arrangement order set of the business thread groups is the priority order of the business thread groups. For the thread group b whose arrangement order in the thread pool is between the thread groups a, the priority order of the thread group b is also between the thread groups a. That is, the arrangement order between each business thread group corresponds to the priority order between each business thread group. The higher the priority, the earlier the serial number in the thread pool.
[0081] For different target subtask sets, there are corresponding target business thread groups.
[0082] S203. Based on the arrangement order of the business threads in the target business thread group, determine the target thread corresponding to the target subtask set, and add the target subtask set to the target queue corresponding to the target thread.
[0083] In some embodiments, the target business thread group includes at least one business thread, and there is an arrangement order between the business threads. Therefore, the target thread of the target subtask set can be determined according to the arrangement order of the business threads in the target business thread group.
[0084] In some embodiments, according to the arrangement order of the service threads in the target thread group, the service threads in the queues corresponding to the service threads in the target thread group with the number of subtask sets less than a preset first threshold are determined as target threads; if there are no service threads in the target thread group with the number of subtask sets less than the preset first threshold in the queue, the target threads are determined based on the target thread group and the non-target thread groups corresponding to other service types except the target service type.
[0085] After determining the target threads, the target subtask set can be added to the target queue corresponding to the target thread. Subsequently, the target thread can execute the subtasks in the subtask set in sequence according to the arrangement order of the subtask sets in the target queue.
[0086] In the embodiments of the present application, the task to be allocated is split into target subtask sets corresponding to different service types, and thread allocation is performed for different target subtask sets respectively. The processing load of the subtasks in the target subtask set will be lower than the processing load of the task to be allocated, thereby reducing the load amount processed by each thread; at the same time, the target service thread groups corresponding to the target subtask sets of different target service types can be determined, and the subtask set is preferentially allocated to the threads where the corresponding target service thread groups are located. At the same time, according to the arrangement order among the service threads in the target service thread group, the target threads of each subtask set are determined. This process can achieve the balanced allocation of the task to be allocated and avoid the problem of individual threads being overloaded.
[0087] Figure 3 is a flowchart of a task allocation method shown in another exemplary embodiment, which is applied to Figure 1 the server 11 in Figure 3 as shown in
[0088] S301. Based on the processing steps of the task to be allocated, the task to be allocated is split into multiple subtasks.
[0089] In some embodiments, after obtaining the task to be allocated, the task to be allocated can be split. For the field of distributed cloud storage, according to different storage modes corresponding to the task to be allocated, the corresponding splitting methods may be different.
[0090] For example, in some embodiments, through the replica mode for splitting, the task to be allocated can be split into multiple subtasks, and then each subtask is copied into multiple replicas, and different replicas are stored on different nodes. At this time, the number of subtasks will increase exponentially, but the fault tolerance of the task to be allocated can be improved. At this time, if subtask A on one node fails, subtask A on another node may succeed.
[0091] For another example, in some other embodiments, splitting is performed in the erasure code (EC) mode. The task to be allocated is split into multiple subtasks, and parity blocks are generated. The relationship between the multiple subtasks is captured through the parity blocks. In this way, when a subtask fails, the subtask can be restored through the parity block and other subtasks, thereby reducing the amount of data stored and being applicable to sensitive task implementation scenarios.
[0092] S302. Determine the subtasks of the same service type among the multiple subtasks as a target subtask set.
[0093] In some embodiments, after obtaining multiple subtasks, the service type of each subtask can be determined. The service type of the subtask can be predicted through a pre-trained classification model, which can be a neural network model. Input the historical training subtask data into the classification model and train the classification model with the labels of the historical training subtask data, so as to obtain the pre-trained classification model. Then, input the data of the subtask into the pre-trained classification model to obtain the corresponding service type.
[0094] In the embodiments of the present application, the subtasks of the same service type are determined as a target subtask set, so as to divide the task to be allocated into target subtask sets. The subsequent tasks can be allocated for the target subtask sets of the same target service type. At the same time, different service types are set to have corresponding thread groups in the follow-up. Through the target subtask sets of the target service type and the target thread groups, the efficiency of task classification is improved.
[0095] Figure 4 It is a flowchart of a task allocation method shown in another exemplary embodiment, applied to Figure 1 the server 11 in Figure 4 as shown. This method includes step S401 to step S402. This method proposes a way to determine the target subtask set, which is introduced in detail as follows:
[0096] S401. According to the arrangement order of each service thread in the target thread group, determine the service threads in the queues corresponding to the service threads in the target thread group whose subtask set quantity is less than a preset first threshold as target threads.
[0097] In some embodiments, such as Figure 5As shown, there are multiple business threads in the thread pool, and there is an arrangement order between different business threads. The business thread group can be determined according to the arrangement order of the business threads. The business threads in different business thread groups are different. There is at least one business thread in a business thread group. When there are multiple business threads in a business thread group, there is an arrangement order between the business threads in a business thread group, and there is an arrangement order between each business thread group. The arrangement order between the business thread groups is the priority order of each business thread group. The corresponding business thread groups can be prioritized according to the importance of the business type corresponding to the business thread group. The business type with high importance has a high priority corresponding to the business thread group, and its arrangement order in the thread pool is higher.
[0098] In some embodiments, there are four business types: user read business type, user write business type, metadata business type, and background business type, and the priority order among the four business types is user read business type, user write business type, metadata business type, and background business type. Then the priority order of the business thread groups corresponding to the four business types is the business thread group corresponding to the user read business type, the business thread group corresponding to the user write business type, the business thread group corresponding to the metadata business type, and the business thread group corresponding to the background business type. In the thread group, the arrangement order of the business thread groups corresponding to the four business types is the business thread group corresponding to the user read business type, the business thread group corresponding to the user write business type, the business thread group corresponding to the metadata business type, and the business thread group corresponding to the background business type.
[0099] In some embodiments, for a certain target subtask set, after determining the corresponding target business thread group, the first business thread in the queue corresponding to the business thread in the target thread group whose number of subtask sets is less than a preset first threshold is determined as the target thread according to the arrangement order of the business threads in the target thread group.
[0100] According to the arrangement order of each business thread in the target thread group, the number of subtask sets in the queue corresponding to the business thread is detected in turn. If it is detected that the number of subtask sets in the queue corresponding to a business thread is less than the preset first threshold, the business thread is determined as the target thread.
[0101] The preset first threshold can be set by empirical parameters, such as 10, 20, 25, etc., and can be set according to the load of the business thread in the thread pool. No specific restrictions are made here.
[0102] S402: If there is no business thread in the target thread group whose number of subtask sets in the queue is less than a preset first threshold, determine a target thread based on the target thread group and non-target thread groups corresponding to business types other than the target business type.
[0103] In some embodiments, if there is no business thread in the target thread group whose number of sub-task sets in the queue is less than a preset first threshold, that is, the number of sub-task sets in the queue of each business thread in the target thread group is greater than the preset first threshold, and the business load of each business thread in the target thread group is relatively large. At this time, for the balance of thread classification, the target thread can be determined through the target thread group and the non-target thread group, so as to ensure the balance of task allocation.
[0104] For example, in one embodiment, there are 3 business threads in the target thread group, and the number of sub-task sets in the queues corresponding to each business thread is 10, 8, and 12 respectively. The preset first threshold is 15. At this time, the number of sub-task sets in the queues of the 3 business threads in the target thread group is less than the preset first threshold, that is, there is no business thread in the target thread group whose number of sub-task sets in the queue is less than the preset first threshold, and the target thread can be determined in the target thread group and the non-target thread.
[0105] In some embodiments, if there is no business thread in the target thread group whose number of sub-task sets in the queue is less than the preset first threshold, then the number of sub-task sets in the queues of all business threads in the target thread group and the non-target thread group is balanced to determine the target thread. For example, in one embodiment, the load of each business thread in the non-target thread group is more than that in the target thread group. At this time, the finally determined target thread may still be in the target thread group.
[0106] In some embodiments, a method for determining the target thread after there is no business thread in the target thread group whose number of sub-task sets in the queue is less than the preset first threshold is also proposed. Based on the priority order of the non-target thread group and the target thread group, it is determined whether there is a calibration thread group in the non-target thread group, and there is a business thread in the calibration thread group whose number of sub-task sets in the queue is less than the preset first threshold; if there is a calibration thread group, the target thread is determined in the calibration thread group; if there is no calibration thread group, the target thread is determined in the non-target thread group and the target thread group.
[0107] In some embodiments, if there is no business thread in the target thread group whose number of sub-task sets in the queue is less than the preset first threshold, the calibration thread group can be determined according to the priority order of the non-target thread group, and the target thread is preferably determined in the calibration thread group. If there is no calibration thread group, the target thread is determined by integrating all business thread groups.
[0108] In some embodiments, a method for determining whether there is a calibration thread group is also proposed: if there is a business thread group with a priority after the target thread group in the non-target thread group, then determine whether there is a calibration thread group in the business thread groups with priorities after the target thread group; if it is determined that there is no calibration thread group in the business thread groups with priorities after the target thread group, then determine whether there is a business thread group with a priority before the target thread group in the non-target thread group; if there is no thread group with a priority before the target thread group in the non-target thread group, then determine that there is no calibration thread group in the non-target thread group; if there is a business thread group with a priority before the target thread group in the non-target thread group, then determine whether there is a calibration thread group in the business thread groups with priorities before the target thread group; if there is no calibration thread group in the business thread groups with priorities before the target thread group, then determine that there is no calibration thread group in the non-target thread group.
[0109] In some embodiments, first determine whether there is a calibration thread group in the business thread groups with priorities after the target thread group. If there are multiple business thread groups that can be used as the calibration thread group, then according to the priority order of each business thread group in the business thread groups with priorities after the target thread group, determine the business thread group with the highest priority as the calibration thread group, and there is at least one sub-task set in the queue of the business threads in this calibration thread group whose quantity is less than a preset first threshold. That is, if there are multiple business thread groups that can be used as the calibration thread group, determine the business thread group with the highest priority and with at least one sub-task set in the queue of the business threads whose quantity is less than the preset first threshold in the business thread groups with priorities after the target thread group as the calibration thread group.
[0110] If there is no sub-task set in the queue of the business threads in the business thread groups with priorities after the target thread group whose quantity is less than the preset first threshold, then determine whether there is a calibration thread group in the business thread groups with priorities before the target thread group. If there are multiple business thread groups that can be used as the calibration thread group, then according to the priority order of each business thread group in the business thread groups with priorities before the target thread group, determine the business thread group with the highest priority as the calibration thread group.
[0111] If there is no sub-task set in the queue of the business threads in the business thread groups with priorities after the target thread group whose quantity is less than the preset first threshold, and there is no sub-task set in the queue of the business threads in the business thread groups with priorities before the target thread group whose quantity is less than the preset first threshold, then determine that there is no calibration thread group.
[0112] In some embodiments, a method for determining whether there is a calibration thread group in a service thread group whose priority is after the target thread group is also proposed: based on the priority order in the thread groups whose priority is after the target thread group, if there is an initial thread group in which the number of subtask sets in the queue corresponding to the service threads in the service thread group is less than a preset first threshold, the initial thread group is determined as the calibration thread group; if there is no initial thread group in which the number of subtask sets in the queue corresponding to the service threads in the thread groups whose priority is after the target thread group is less than the preset first threshold, it is determined that there is no calibration thread group in the thread groups whose priority is after the target thread group.
[0113] In some embodiments, when determining whether there is a calibration thread group in a service thread group whose priority is after the target thread group, in accordance with the priority order, it is determined in turn whether the number of subtask sets in the queue corresponding to the service threads in the service thread groups whose priority is after the target thread group is less than the preset first threshold. If it is less than the preset first threshold, the service thread group is determined as the initial thread group, and the initial thread group is determined as the calibration thread group. If after traversing in turn all the service thread groups whose priority is after the target thread group, there is no service thread group in which the number of subtask sets in the queue corresponding to the service threads is less than the preset first threshold, it is determined that there is no calibration thread group in the service thread groups whose priority is after the target thread group.
[0114] At this time, if it is determined that there is no calibration thread group in the service thread groups whose priority is after the target thread group, it can be determined whether there is a thread group whose priority is before the target thread group in the non-target thread group. If there is a thread group whose priority is before the target thread group in the non-target thread group, it can be determined whether there is a calibration thread group in the thread groups whose priority is before the target thread group in the non-target thread group.
[0115] Similarly, when determining whether there is a calibration thread group in a service thread group whose priority is before the target thread group, in accordance with the priority order, it is determined in turn whether the number of subtask sets in the queue corresponding to the service threads in the service thread groups whose priority is before the target thread group is less than the preset first threshold. If it is less than the preset first threshold, the service thread group is determined as the calibration thread group. If after traversing in turn all the service thread groups whose priority is before the target thread group, there is no service thread group in which the number of subtask sets in the queue corresponding to the service threads is less than the preset first threshold, it is determined that there is no calibration thread group in the non-target thread group.
[0116] In some embodiments, if there is a calibration thread group, a target thread is determined in the calibration thread group. Specifically, based on the arrangement order of the service threads in the calibration thread group, the service thread in the calibration thread group whose number of subtask sets in the corresponding queue is less than the preset first threshold is determined as the target thread.
[0117] In some embodiments, after determining that there is a calibration thread group, a target thread can be determined in the calibration thread group. For example, according to the arrangement order of each business thread in the target thread group, it is judged whether the number of subtask sets in the queue corresponding to the business thread is less than a preset first threshold, and the first business thread in the corresponding queue whose number of subtask sets is less than the preset first threshold is determined as the target thread.
[0118] If there are multiple business threads in the calibration thread group whose corresponding queue subtask set numbers are less than the preset first threshold, the first business thread among the multiple business threads with queue subtask set numbers less than the preset first threshold in the arrangement order of each business thread in the calibration thread group is determined as the target thread.
[0119] In some embodiments, if there is no calibration thread group, a target thread is determined in the non-target thread group and the target thread group. Specifically, the business threads in the non-target thread group and the target thread group whose corresponding queue subtask set numbers are less than a preset second threshold are determined as the target threads.
[0120] In some embodiments, if there is no target first thread, the number of subtask sets in the queues of each business thread in all business thread groups (non-target thread groups and target thread groups) is comprehensively considered, and the business thread with the smallest number of subtask sets is determined as the target thread.
[0121] In some embodiments, the preset second threshold can be set through empirical parameters. For example, the preset second threshold can be the value with the smallest number of subtask sets in the queue, or a value greater than the value with the smallest number of subtask sets in the queue of the business thread, and the preset second threshold is greater than the preset first threshold.
[0122] As Figure 5 shown, there are 4 business thread groups in the thread pool, and their priority orders in the thread pool are a, b, c, d respectively. There are 3 business threads in business thread groups a and b, and 2 business threads in business thread groups c and d.
[0123] For the target subtask set A of the task to be allocated, the corresponding target business thread group is b. Then, it is sequentially determined whether there is a business thread in the 3 business threads in the target business thread group b whose corresponding queue subtask set number is less than the preset first threshold. If so, the first business thread in the 3 business threads in the target business thread group b whose queue subtask set number is less than the preset first threshold is determined as the target thread. If not, a, c, and d are determined as non-target thread groups.
[0124] There are business thread groups with priorities after the target thread group in the non-target thread group, that is, business thread groups c and d. Therefore, it is determined whether there is a calibration thread group in the business thread groups with priorities after the target thread group (business thread groups c and d). AsFigure 5 As shown by the arrow directions, first determine whether the c service thread group is a calibrated thread group. If the number of subtask sets in the queues corresponding to the service threads in the c service thread group is not less than a preset first threshold, then determine whether the d service thread group is a calibrated thread group. If the number of subtask sets in the queues corresponding to the service threads in the c service thread group is not less than the preset first threshold, then determine whether there is a calibrated thread group in the service thread group (a service thread group) with a priority higher than that of the target thread group. If none of a, c, and d are calibrated thread groups, determine the service threads with the number of subtask sets in the queues corresponding to the service threads in the non-target thread group and the target thread groups (c, d, a, and b service thread groups) less than a preset second threshold as target threads.
[0125] The task allocation method provided by the embodiments of the present application can wake up fewer threads for processing tasks, improve the activity of the threads, reduce the resource consumption caused by frequently waking up idle threads, reduce the competition for global locks, improve the efficiency and utilization rate of the threads. At the same time, by setting service thread groups of different service types and setting the priorities between the service thread groups, the priorities of subtask sets of different service types can be ensured, and the tasks of all threads in the thread pool can be reasonably allocated and executed.
[0126] In distributed storage, the thread pool is divided into multiple service thread groups. The target subtask sets delivered to the thread pool can identify and distinguish service types, priorities, and target locations, and can manage and schedule the target subtask sets delivered to the queue and the threads in the thread pool. Through the number of subtask sets in the queues of each service thread in the service thread group, it is possible to efficiently utilize the threads, balance the complexity of different threads as much as possible, improve the activity of the threads, reduce the resource consumption caused by waking up threads, and reduce the generation of local hot spot threads.
[0127] When the target thread group is relatively busy, load balancing is performed through the service thread group with a priority lower than that of the target thread group and the service thread group with a priority higher than that of the target thread group. The service thread group with a priority lower than that of the target thread group ensures that high-priority target subtask sets can be efficiently and concurrently completed. The service thread group with a priority higher than that of the target thread group ensures that when the thread pool is under high pressure, low-priority target subtask sets can also be timely delivered to idle threads for execution, reducing the generation of local hot spots in a certain thread group. When all threads in the thread pool are in a busy state, a relatively idle thread can be dynamically selected for delivery, improving the performance of the threads.
[0128] Figure 6 It is a structural diagram of a task allocation device shown in an exemplary embodiment. The task allocation device 600 is applied to the server of the task allocation system and may include:
[0129] A task splitting module 610, configured to split a task to be assigned into at least one target subtask set, where one target subtask set corresponds to one target service type;
[0130] A thread group determination module 630, configured to determine a target service thread group corresponding to the target service type of the target subtask set. Different service types correspond to different service thread groups, and each service thread group includes at least one service thread;
[0131] A thread determination module 650, configured to determine a target thread corresponding to the target subtask set based on the arrangement order of each service thread in the target service thread group, and add the target subtask set to a target queue corresponding to the target thread.
[0132] In an implementable manner, the task splitting module includes:
[0133] A splitting unit, configured to split the task to be assigned into multiple subtasks based on the processing steps of the task to be assigned;
[0134] An aggregating unit, configured to determine subtasks of the same service type among the multiple subtasks as one target subtask set.
[0135] In an implementable manner, the thread determination module includes:
[0136] A first target thread determination unit, configured to determine, according to the arrangement order of each service thread in the target thread group, a service thread in the queue corresponding to the service thread in the target thread group, where the number of subtask sets in the queue is less than a preset first threshold, as the target thread;
[0137] A second target thread determination unit, configured to, if there is no service thread in the target thread group whose number of subtask sets in the queue is less than the preset first threshold, determine the target thread based on the target thread group and non-target thread groups corresponding to other service types except the target service type.
[0138] In an implementable manner, the second target thread determination unit includes:
[0139] A calibrated thread group determination subunit, configured to determine whether there is a calibrated thread group in the non-target thread group based on the priority order of the non-target thread group and the target thread group, where there is a service thread in the calibrated thread group whose number of subtask sets in the queue is less than the preset first threshold;
[0140] A first target thread determination subunit, configured to, if there is a calibrated thread group, determine the target thread in the calibrated thread group;
[0141] A second target thread determination subunit, configured to, if there is no calibrated thread group, determine the target thread in the non-target thread group and the target thread group.
[0142] In one implementable manner, the calibration thread group determination subunit includes:
[0143] The first calibration thread group determination section is used to, if there is a service thread group in the non-target thread group whose priority is after the target thread group, determine whether there is a calibration thread group in the service thread groups whose priority is after the target thread group;
[0144] The first processing section is used to, if it is determined that there is no calibration thread group in the service thread groups whose priority is after the target thread group, determine whether there is a service thread group in the non-target thread group whose priority is before the target thread group;
[0145] The second processing section is used to, if there is no service thread group in the non-target thread group whose priority is before the target thread group, determine that there is no calibration thread group in the non-target thread group;
[0146] The second calibration thread group determination section is used to, if there is a thread group in the non-target thread group whose priority is before the target thread group, determine whether there is a calibration thread group in the service thread groups whose priority is before the target thread group;
[0147] The third processing section is used to, if there is no calibration thread group in the service thread groups whose priority is before the target thread group, determine that there is no calibration thread group in the non-target thread group.
[0148] In one implementable manner, the first calibration thread group determination includes:
[0149] The first processing sub-section is used to, based on the priority order in the service thread groups whose priority is after the target thread group, if there is an initial thread group in which the number of subtask sets in the queue corresponding to the service threads in the service thread group is less than a preset first threshold, determine the initial thread group as the calibration thread group;
[0150] The second processing sub-section is used to, if there is no initial thread group in which the number of subtask sets in the queue corresponding to the service threads in the service thread groups whose priority is after the target thread group is less than a preset first threshold, determine that there is no calibration thread group in the service thread groups whose priority is after the target thread group.
[0151] In one implementable manner, the first target thread determination subunit includes:
[0152] The first target thread determination section is used to, based on the arrangement order of the service threads in the calibration thread group, determine the service threads in the calibration thread group whose number of subtask sets in the queue corresponding to the service threads is less than a preset first threshold as the target threads.
[0153] In one implementable manner, the first target thread determination subunit includes:
[0154] The first target thread determination section is configured to determine, as target threads, business threads in the non-target thread group and the business thread corresponding queues in the target thread group where the number of subtask sets is less than a preset second threshold. The task allocation device provided in this embodiment can be used to execute the above task allocation method, and its implementation principle and technical effects are similar, which will not be elaborated here in this embodiment.
[0155] Figure 7 is a block diagram of an electronic device shown in an exemplary embodiment. Please refer to Figure 7 , the electronic device 700 may include: a processor 71 and a memory 72. Among them, the processor 71 and the memory 72 can communicate. Exemplarily, the processor 71 and the memory 72 communicate through a communication bus 73. The memory 72 is used to store computer execution instructions, and the processor 71 is used to call the computer execution instructions in the memory to execute the task allocation method shown in any of the above method embodiments.
[0156] The above processor may be a Central Processing Unit (CPU), or may also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the present application can be directly embodied as being executed by a hardware processor, or can be executed by a combination of hardware and software modules in the processor.
[0157] The present application provides a computer-readable storage medium, on which computer execution instructions are stored; when the computer execution instructions are executed by a processor, they are used to implement the task allocation method in any of the above embodiments.
[0158] The embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the above task allocation method is implemented.
[0159] It should be noted that for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the present application is not limited by the described action sequence, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to the present application.
[0160] It should be further noted that although the steps in the flowchart are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear description in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowchart may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential either, but can be executed alternately or in turn with at least a part of other steps or sub-steps or stages of other steps.
[0161] It should be understood that the above device embodiments are illustrative only, and the devices of the present application can also be implemented in other ways. For example, the division of units / modules in the above embodiments is only a logical function division, and there can be other division methods in actual implementation. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.
[0162] In addition, without special instructions, in each embodiment of the present application, each functional unit / module can be integrated into one unit / module, or each unit / module can exist physically alone, or two or more units / modules can be integrated together. The above integrated unit / module can be implemented in the form of hardware or in the form of a software program module.
[0163] When the integrated unit / module is implemented in the form of hardware, the hardware can be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to transistors, memristors, etc. Without special instructions, the processor can be any suitable hardware processor, such as CPU, GPU, FPGA, DSP, and ASIC, etc. Without special instructions, the storage unit can be any suitable magnetic storage medium or magneto-optical storage medium, such as resistive random access memory RRAM (Resistive Random Access Memory), dynamic random access memory DRAM (Dynamic Random Access Memory), static random access memory SRAM (Static Random-Access Memory), enhanced dynamic random access memory EDRAM (Enhanced Dynamic Random Access Memory), high-bandwidth memory HBM (High-Bandwidth Memory), hybrid memory cube HMC (Hybrid Memory Cube), etc.
[0164] When the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present application. The aforementioned memory includes various media that can store program codes, such as USB flash drives, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), mobile hard disks, magnetic disks, or optical discs.
[0165] In the above embodiments, the descriptions of the various embodiments have their own emphases. For the parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments. The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as within the scope described in this specification.
[0166] Those skilled in the art will readily think of other implementation manners of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any variations, uses, or adaptations of the present application, which follow the general principles of the present application and include the common general knowledge or conventional technical means in the technical field not disclosed in the present application. The specification and the embodiments are only regarded as exemplary, and the true scope and spirit of the present application are pointed out by the following claims.
[0167] It should be understood that the present application is not limited to the exact structure already described and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present application is only limited by the appended claims.
Claims
1. A task allocation method, characterized in that, Including: Splitting the task to be assigned into at least one target subtask set, where one target subtask set corresponds to one target business type; Determining a target business thread group corresponding to the target business type of the target subtask set. Different business types correspond to different business thread groups, and each business thread group includes at least one business thread; Based on the arrangement order of each business thread in the target business thread group, determining the target thread corresponding to the target subtask set, and adding the target subtask set to the target queue corresponding to the target thread.
2. The method according to claim 1, wherein The splitting the task to be assigned into at least one target subtask set includes: Based on the processing steps of the task to be assigned, splitting the task to be assigned into multiple subtasks; Determining the subtasks of the same business type among the multiple subtasks as one target subtask set.
3. The method according to claim 1, wherein The determining the target thread corresponding to the target subtask set based on the arrangement order of each business thread in the target business thread group includes: According to the arrangement order of each business thread in the target thread group, determining the business thread whose number of subtask sets in the queue corresponding to the business thread in the target thread group is less than a preset first threshold as the target thread; If there is no business thread in the target thread group whose number of subtask sets in the queue is less than the preset first threshold, then determining the target thread based on the target thread group and non-target thread groups corresponding to other business types except the target business type.
4. The method according to claim 3, wherein The determining the target thread based on the target thread group and non-target thread groups corresponding to other business types except the target business type includes: Based on the priority order of the non-target thread group and the target thread group, determining whether there is a calibrated thread group in the non-target thread group, where there is a business thread in the calibrated thread group whose number of subtask sets in the queue is less than the preset first threshold; If there is the calibrated thread group, then determining the target thread in the calibrated thread group; If there is no the calibrated thread group, then determining the target thread in the non-target thread group and the target thread group.
5. The method according to claim 4, wherein The determining whether there is a calibrated thread group in the non-target thread group includes: If there is a business thread group in the non-target thread group whose priority is after the target thread group, then determining whether there is the calibrated thread group in the business thread group whose priority is after the target thread group; If it is determined that there is no the calibrated thread group in the business thread group whose priority is after the target thread group, then determining whether there is a business thread group in the non-target thread group whose priority is before the target thread group; If there is no business thread group in the non-target thread group whose priority is before the target thread group, then determining that there is no the calibrated thread group in the non-target thread group; If there is a thread group in the non-target thread group whose priority is before the target thread group, then determining whether there is the calibrated thread group in the business thread group whose priority is before the target thread group; If the calibration thread group does not exist in the service thread group whose priority is before the target thread group, it is determined that the calibration thread group does not exist in the non-target thread group.
6. The method according to claim 5, characterized in that, Determining whether the calibration thread group exists in the service thread group whose priority is after the target thread group includes: Based on the priority order in the service thread group whose priority is after the target thread group, if there is an initial thread group in which the number of subtask sets in the queue corresponding to the service threads in the service thread group is less than a preset first threshold, the initial thread group is determined as the calibration thread group; If there is no initial thread group in which the number of subtask sets in the queue corresponding to the service threads in the service thread group whose priority is after the target thread group is less than the preset first threshold, it is determined that the calibration thread group does not exist in the service thread group whose priority is after the target thread group.
7. The method according to claim 4, wherein Determining the target thread in the calibration thread group includes: Based on the arrangement order of the service threads in the calibration thread group, the service thread in the calibration thread group whose queue corresponding subtask set number is less than the preset first threshold is determined as the target thread.
8. The method according to claim 4, characterized in that, Determining the target thread in the non-target thread group and the target thread group includes: The service threads in the non-target thread group and the target thread group whose queue corresponding subtask set number is less than a preset second threshold are determined as the target threads.
9. A task allocation device, characterized in that, Includes: A task splitting module, configured to split the task to be assigned into at least one target subtask set, and one target subtask set corresponds to one target service type; A thread group determining module, configured to determine the target service thread group corresponding to the target service type of the target subtask set, different service types correspond to different service thread groups, and each service thread group includes at least one service thread; A thread determining module, configured to determine the target thread corresponding to the target subtask set based on the arrangement order of the service threads in the target service thread group, and add the target subtask set to the target queue corresponding to the target thread.
10. An electronic device, characterized in that, Includes: A processor and a memory communicatively connected to the processor; The memory stores computer execution instructions; The processor executes the computer execution instructions stored in the memory to implement the method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that, Computer execution instructions are stored in the computer-readable storage medium, and when the computer execution instructions are executed by a processor, they are used to implement the method according to any one of claims 1 to 8.
12. A computer program product, characterized in that, Includes a computer program, and when the computer program is executed by a processor, it implements the method according to any one of claims 1-8.
Citation Information
Cited By
Data fragmentation processing method and device and electronic equipment
CN122195689A