Dynamic sharding adaptive task scheduling method and system

Through the dynamic sharding adaptive task scheduling method, the task is broken down into multiple task shards, and the shard size is adjusted according to the number of unsubmitted people, expiration time and priority. The fairness and timeliness in the task scheduling process are solved, and the breakpoint running, failover and load balancing of the task are realized to meet the timeliness and priority requirements of the task.

CN116069461BActive Publication Date: 2025-08-22IND BANK CO +1
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202211556250.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-06
Publication Date
2025-08-22
Estimated Expiration
2042-12-06

AI Technical Summary

Technical Problem

In the prior art, large-scale tasks occupy resources for a long time, resulting in small-scale tasks blocking, and fail to effectively solve the problems of fairness, timeliness and priority of tasks.

Method used

Adaptive task scheduling method of dynamic sharding is adopted to decompose tasks into multiple task shards, each shard is used as the basic unit, and the shard size is dynamically adjusted according to the number of unsubmitted people, expiration time and priority. Through dynamic management of task pools and execution thread pools, task breakpoints continue running, failover and load balancing are supported.

Benefits of technology

It realizes the balance of fairness, timeliness and priority in the task scheduling process, supports task breakpoint continuous running, failover and load balancing, and dynamic expansion, ensuring that tasks of different scales have scheduling opportunities to meet the task timeliness and priority needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116069461B_ABST
    Figure CN116069461B_ABST
Patent Text Reader

Abstract

The present invention provides a method and system for adaptive task scheduling with dynamic slicing, comprising: instructing a scheduling thread to retrieve new tasks from a task table and place them into a task pool; traversing the task pool to obtain task slices for each task and submitting them to a task execution thread pool; and instructing execution threads in the task execution thread pool to execute the task slices. By employing dynamic task slicing, the present invention addresses fairness, timeliness, and priority issues in the task scheduling process, while also supporting task breakpoint resumption, failover, load balancing, and dynamic capacity expansion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of task scheduling, and in particular to a method and system for adaptive task scheduling of dynamic sharding. Background Art

[0002] Patent document CN104899099A provides a task allocation method based on a thread pool, which includes: step one, creating a thread pool and a task pool; step two, predetermining a number value n, initializing n threads and storing the threads sequentially in the thread pool queue; step three, traversing the thread pool after receiving the task, if there is an idle thread in the thread pool, sequentially calling the idle threads from the thread pool and executing the task; if there is no idle thread in the thread pool, storing the tasks sequentially in the queue of the task pool.

[0003] However, patent document CN104899099A does not solve the problem that large-scale tasks may occupy resources for a long time, causing small-scale tasks to be blocked. Summary of the Invention

[0004] In view of the defects in the prior art, the present invention aims to provide a method and system for adaptive task scheduling with dynamic slicing.

[0005] A dynamic sharding adaptive task scheduling method provided by the present invention includes:

[0006] Step S1: Instruct the scheduling thread to take a new task from the task table and put it into the task pool;

[0007] Step S2: traverse the task pool to obtain the task slices of each task and submit them to the task execution thread pool;

[0008] Step S3: Instruct the execution thread in the task execution thread pool to execute the task slice.

[0009] Preferably, in the task pool, the task is decomposed into multiple task slices, each task slice corresponds to an independent subtask, and the task slice is used as the basic unit of task scheduling and execution; the size of the task slice is dynamically adjusted according to the task attributes such as the number of undelivered people, expiration time, and priority; the more people who have undelivered tasks, the shorter the expiration time, and the higher the task priority, the larger the task slice.

[0010] Preferably, step S1 includes the following steps:

[0011] Step S1.1: Obtain a list of tasks to be sent from the database task table;

[0012] Step S1.2: Traverse the task list and update the node number of the current task. If the update fails, traverse the next task. If the update succeeds, trigger step S1.3.

[0013] Step S1.3: If the task pool is full, the new task is sorted together with the tasks in the task pool, and the tasks with the lowest priority, the longest expiration time, or the largest number of remaining people are eliminated; if the task pool is not full, the new task is added to the pool;

[0014] The step S2 comprises the following steps:

[0015] Step S2.1: Traverse the task pool. If the task status is completed, remove the task from the task pool. Otherwise, trigger step S2.2.

[0016] Step S2.2: Get the current task slice. The number of people in the task slice, len, is determined by the expiration time, time, the number of undelivered people, num, the task priority coefficient, p, and the upper and lower limits, cap, and base, of the task slice capacity. The formula is as follows:

[0017]

[0018] Step S2.3: Submit the task slice to the task execution thread pool;

[0019] The step S3 comprises the following steps:

[0020] Step S3.1: Execute the delivery process;

[0021] Step S3.2: Update the number of people who have delivered the task;

[0022] Step S3.3: If the number of people to whom the task has been delivered is equal to the total number of people, then update the task status to Sent.

[0023] Preferably, task scheduling and execution are run on the node, and the node status is updated periodically. If a node finds that the status of other nodes is abnormal, it will pull up the task execution of the abnormal node, thereby realizing failover; after the task sharding is completed, the task execution progress will be saved to ensure that the task can be resumed from the breakpoint; tasks are undertaken through competition. If a node undertakes more tasks, the node's scheduling cycle will be longer, and the competition interval will be longer accordingly, and the fewer new tasks it will undertake.

[0024] A dynamic sharding adaptive task scheduling system provided by the present invention includes:

[0025] Module M1: Instructs the scheduling thread to take a new task from the task table and put it into the task pool;

[0026] Module M2: traverses the task pool to obtain the task slices of each task and submits them to the task execution thread pool;

[0027] Module M3: Instructs the execution threads in the task execution thread pool to execute task slices.

[0028] Preferably, in the task pool, the task is decomposed into multiple task slices, each task slice corresponds to an independent subtask, and the task slice is used as the basic unit of task scheduling and execution; the size of the task slice is dynamically adjusted according to the task attributes such as the number of undelivered people, expiration time, and priority; the more people who have undelivered tasks, the shorter the expiration time, and the higher the task priority, the larger the task slice.

[0029] Preferably, the module M1 includes:

[0030] Module M1.1: Get the task list to be sent from the database task table;

[0031] Module M1.2: traverses the task list and updates the node number of the current task. If the update fails, it traverses the next task. If the update succeeds, it triggers module M1.3.

[0032] Module M1.3: If the task pool is full, the new task is sorted together with the tasks in the task pool, and the tasks with the lowest priority, the longest expiration time, or the largest number of remaining people are eliminated; if the task pool is not full, the new task is added to the pool;

[0033] The module M2 includes:

[0034] Module M2.1: traverse the task pool. If the task status is completed, remove the task from the task pool. Otherwise, trigger module M2.2.

[0035] Module M2.2: Get the current task slice. The number of people in the task slice, len, is determined by the expiration time, time, the number of undelivered people, num, the task priority coefficient, p, and the upper and lower limits, cap, and base, of the task slice capacity. The formula is as follows:

[0036]

[0037] Module M2.3: Submit task slices to the task execution thread pool;

[0038] The module M3 includes:

[0039] Module M3.1: Execute the delivery process;

[0040] Module M3.2: Update the number of people who have delivered the task;

[0041] Module M3.3: If the number of people to whom the task has been delivered is equal to the total number of people, update the task status to sent.

[0042] Preferably, task scheduling and execution are run on the node, and the node status is updated periodically. If a node finds that the status of other nodes is abnormal, it will pull up the task execution of the abnormal node, thereby realizing failover; after the task sharding is completed, the task execution progress will be saved to ensure that the task can be resumed from the breakpoint; tasks are undertaken through competition. If a node undertakes more tasks, the node's scheduling cycle will be longer, and the competition interval will be longer accordingly, and the fewer new tasks it will undertake.

[0043] According to a computer-readable storage medium storing a computer program provided by the present invention, when the computer program is executed by a processor, the steps of the dynamic sharding adaptive task scheduling method are implemented.

[0044] According to an electronic device provided by the present invention, the electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the steps of the dynamic sharding adaptive task scheduling method are implemented.

[0045] Compared with the prior art, the present invention has the following beneficial effects:

[0046] 1. The present invention solves the fairness, timeliness and priority issues in the task scheduling process by adopting the method of dynamic task sharding, and supports task breakpoint resumption, failover, load balancing and dynamic expansion.

[0047] 2. The present invention smoothes out the differences in task scales through task slicing, so that tasks of different scales have the opportunity to be scheduled; the more people who have not delivered a task, the shorter the due time, and the higher the task priority, the larger the task slicing, thereby meeting the timeliness and priority of the task.

[0048] 3. The scheduling method of the present invention undertakes tasks through competition. If a node undertakes more tasks, the scheduling cycle of the node will be longer, and the competition interval will be longer accordingly. The fewer new tasks it undertakes, so that each node can achieve a load balancing effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Other features, objects and advantages of the present invention will become more apparent upon reading the detailed description of non-limiting embodiments with reference to the following drawings:

[0050] Figure 1 It is a schematic diagram of the principle of the present invention. DETAILED DESCRIPTION

[0051] The present invention will be described in detail below with reference to specific embodiments. The following examples will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those skilled in the art, several changes and improvements can be made without departing from the scope of the present invention. These all fall within the scope of protection of the present invention.

[0052] In the messaging system world, batch message delivery can be defined as a delivery task. If the number of people delivering tasks varies significantly, large-scale tasks may occupy resources for a long time, blocking smaller tasks. Tasks are time-sensitive and must be completed before their due date. Tasks are prioritized based on their business type, with higher-priority tasks receiving priority. Furthermore, task execution must ensure breakpoint resumption, failover, load balancing, and dynamic capacity expansion.

[0053] like Figure 1 As shown, the present invention decomposes tasks into multiple task slices, each corresponding to an independent subtask. Task slices serve as the basic unit of task scheduling and execution, and the size of task slices is dynamically adjusted based on the number of undelivered tasks, expiration time, and priority of the task. Task slicing smooths out differences in task scale, allowing tasks of different sizes to have a chance of being scheduled; the more undelivered tasks are, the shorter the expiration time, and the higher the priority of the task, the larger the task slice, thereby meeting the timeliness and priority of the task.

[0054] The task pool is used to store tasks in progress. The task pool has a configured capacity limit and a task entry and exit policy to ensure that the number of tasks stored by a node does not exceed the node's capacity limit. Task statuses are categorized as pending, sending, and completed. Task attributes include task number, task status, total number of people assigned to the task, number of people assigned to the task, expiration time, task priority, and node number.

[0055] Task scheduling and execution are performed on nodes. By regularly updating node status, if a node detects an abnormal state on another node, it will pull up the task execution on the abnormal node, thus achieving failover. After the task shard is executed, the task execution progress is saved to ensure that the task can be resumed after the breakpoint.

[0056] The scheduling method of the present invention uses competition to take on tasks. If a node takes on more tasks, the node's scheduling cycle will be longer, and the competition interval will be longer accordingly. The node will take on fewer new tasks, thus achieving load balancing for each node. The scheduling method of the present invention is stateless and supports dynamic expansion.

[0057] The present invention is described in more detail below. The present invention provides a method for adaptive task scheduling based on dynamic sharding, comprising:

[0058] Step S1: Instruct the scheduling thread to retrieve new tasks from the task table and place them into the task pool in the form of a task list. Specifically, step S1 includes the following steps: Step S1.1: Obtain a list of tasks in the pending state from the database task table. Step S1.2: Traverse the task list and update the node number of the current task. If the update fails, traverse the next task. If the update is successful, proceed to step S1.3. Step S1.3: If the task pool is full, the new task is sorted together with the tasks in the task pool, eliminating tasks with low priority, long expiration time, and a large number of remaining people. If the task pool is not full, the new task is added to the pool.

[0059] Step S2: Traverse the task pool to obtain the task slices of each task and submit them to the task execution thread pool; specifically, step S2 includes the following steps: Step S2.1: Traverse the task pool. If the task status is completed, remove the task from the task pool, otherwise proceed to the next step S2.2; Step S2.2: Obtain the current task slice. The number of people in the task slice, len, is determined by the expiration time, the number of undelivered people, num, the task priority coefficient, p, and the upper and lower limits of the task slice capacity, cap, and base. Step S2.3: Submit the task slice to the thread pool. The calculation formula for the number of people in the task slice, len, is as follows:

[0060]

[0061] Step S3: The execution thread in the task execution thread pool executes the task slice. Specifically, step S3 includes the following steps: step S3.1: executing the delivery process; step S3.2: updating the number of people to whom the task has been delivered; step S3.3: if the number of people to whom the task has been delivered is equal to the total number of people, updating the task status to sent.

[0062] The present invention is further described in detail below. The present invention also provides a dynamic slicing adaptive task scheduling system, which can be implemented by executing the process steps of the dynamic slicing adaptive task scheduling method, that is, those skilled in the art can understand the dynamic slicing adaptive task scheduling method as a preferred implementation method of the dynamic slicing adaptive task scheduling. Furthermore, a dynamic slicing adaptive task scheduling system provided by the present invention includes: module M1: instructing the scheduling thread to take a new task from the task table and put it into the task pool; module M2: traversing the task pool to obtain the task slice of each task, and submitting it to the task execution thread pool; module M3: instructing the execution thread in the task execution thread pool to execute the task slice.

[0063] In the preferred example, in the task pool, the task is decomposed into multiple task slices, each task slice corresponds to an independent subtask, and the task slice is used as the basic unit of task scheduling and execution; the size of the task slice is dynamically adjusted according to the task attributes such as the number of undelivered people, expiration time, and priority; the more people who have undelivered tasks, the shorter the expiration time, and the higher the task priority, the larger the task slice.

[0064] The module M1 includes: module M1.1: obtaining a list of tasks to be sent from a database task table; module M1.2: traversing the task list, updating the node number of the current task, if the update fails, traversing the next task, and if the update is successful, triggering module M1.3; module M1.3: if the task pool is full, sorting the new task together with the tasks in the task pool, eliminating the task with the lowest priority, the longest expiration time, or the most remaining people; if the task pool is not full, adding the new task to the pool;

[0065] The module M2 includes: module M2.1: traverse the task pool, if the task status is completed, remove the task from the task pool, otherwise trigger module M2.2; module M2.2: obtain the current task slice, the number of people in the task slice len is determined by the expiration time time, the number of undelivered people num, the task priority coefficient p, and the upper and lower limits of the task slice capacity cap and base, and the formula is as follows:

[0066]

[0067] Module M2.3: Submit task slices to the task execution thread pool.

[0068] The module M3 includes: module M3.1: executing the delivery process; module M3.2: updating the number of people to whom the task has been delivered; module M3.3: if the number of people to whom the task has been delivered is equal to the total number of people, updating the task status to sent.

[0069] In a further preferred example, task scheduling and execution are run on the node. By periodically updating the node status, if the node finds that the status of other nodes is abnormal, it will pull up the task execution of the abnormal node, thereby realizing failover; after the task sharding is completed, the task execution progress will be saved to ensure that the task can be resumed from the breakpoint; tasks are undertaken through competition. If a node undertakes more tasks, the node's scheduling cycle will be longer, and the corresponding competition interval will be longer, and the fewer new tasks will be undertaken.

[0070] Those skilled in the art will appreciate that, in addition to implementing the system, device, and various modules provided by the present invention in purely computer-readable program code, it is entirely possible to implement the same program in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, embedded microcontrollers, and the like by logically programming the method steps. Therefore, the system, device, and various modules provided by the present invention can be considered a hardware component, and the modules included therein for implementing various programs can also be considered structures within the hardware component; the modules for implementing various functions can also be considered both software programs for implementing the method and structures within the hardware component.

[0071] According to a computer-readable storage medium storing a computer program provided by the present invention, when the computer program is executed by a processor, the steps of the dynamic sharding adaptive task scheduling method are implemented.

[0072] According to an electronic device provided by the present invention, the electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the steps of the dynamic sharding adaptive task scheduling method are implemented.

[0073] The above describes specific embodiments of the present invention. It should be understood that the present invention is not limited to the specific embodiments described above, and those skilled in the art may make various changes or modifications within the scope of the claims, which do not affect the essence of the present invention. The embodiments of this application and the features in the embodiments may be combined with each other in any manner unless there is a conflict.

Claims

1. A dynamic sharding adaptive task scheduling method, characterized in that: include: Step S1: Instruct the scheduling thread to take a new task from the task table and put it into the task pool; Step S2: traverse the task pool to obtain the task slices of each task and submit them to the task execution thread pool; Step S3: Instruct the execution thread in the task execution thread pool to execute the task slice; In the task pool, tasks are decomposed into multiple task slices. Each task slice corresponds to an independent subtask, and the task slice is used as the basic unit of task scheduling and execution. The size of the task slice is dynamically adjusted according to the number of undelivered tasks, the expiration time, and the priority of the task. The larger the number of undelivered tasks, the shorter the expiration time, and the higher the priority of the task, the larger the task slice. The step S2 comprises the following steps: Step S2.1: Traverse the task pool. If the task status is completed, remove the task from the task pool. Otherwise, trigger step S2.

2. Step S2.2: Get the current task slice. The number of people in the task slice, len, is determined by the expiration time, the number of undelivered people, num, the task priority coefficient, p, and the upper and lower limits of the task slice capacity, cap, and base. The formula is as follows: Step S2.3: Submit the task slice to the task execution thread pool; Task scheduling and execution run on the node, by regularly updating the node status. If a node finds that the status of other nodes is abnormal, it will pull up the task execution of the abnormal node, thereby realizing failover. After the task sharding is completed, the task execution progress will be saved to ensure that the task can be resumed at the breakpoint. Tasks are undertaken through competition. If a node undertakes more tasks, the node scheduling cycle will be longer, and the competition interval will be longer accordingly, and the fewer new tasks it will undertake.

2. The adaptive task scheduling method for dynamic sharding according to claim 1, characterized in that: The step S1 comprises the following steps: Step S1.1: Obtain a list of tasks to be sent from the database task table; Step S1.2: Traverse the task list and update the node number of the current task. If the update fails, traverse the next task. If the update succeeds, trigger step S1.

3. Step S1.3: If the task pool is full, the new task is sorted together with the tasks in the task pool, and the tasks with the lowest priority, the longest expiration time, or the largest number of remaining people are eliminated; if the task pool is not full, the new task is added to the pool; The step S3 comprises the following steps: Step S3.1: Execute the delivery process; Step S3.2: Update the number of people who have delivered the task; Step S3.3: If the number of people to whom the task has been delivered is equal to the total number of people, then update the task status to Sent.

3. A dynamic sharding adaptive task scheduling system, characterized in that: include: Module M1: Instructs the scheduling thread to take a new task from the task table and put it into the task pool; Module M2: traverses the task pool to obtain the task slices of each task and submits them to the task execution thread pool; Module M3: Instructs the execution threads in the task execution thread pool to execute task slices; In the task pool, tasks are decomposed into multiple task slices. Each task slice corresponds to an independent subtask, and the task slice is used as the basic unit of task scheduling and execution. The size of the task slice is dynamically adjusted according to the number of undelivered items, expiration time, and priority of the task attributes. The more people who have not delivered the task, the shorter the due time, and the higher the task priority, the larger the task shard; The module M2 includes: Module M2.1: traverse the task pool. If the task status is completed, remove the task from the task pool. Otherwise, trigger module M2.

2. Module M2.2: Get the current task slice. The number of people in the task slice, len, is determined by the expiration time, the number of undelivered people, num, the task priority coefficient, p, and the upper and lower limits of the task slice capacity, cap, and base. The formula is as follows: Module M2.3: Submit task slices to the task execution thread pool; Task scheduling and execution run on the node, by regularly updating the node status. If a node finds that the status of other nodes is abnormal, it will pull up the task execution of the abnormal node, thereby realizing failover. After the task sharding is completed, the task execution progress will be saved to ensure that the task can be resumed at the breakpoint. Tasks are undertaken through competition. If a node undertakes more tasks, the node scheduling cycle will be longer, and the competition interval will be longer accordingly, and the fewer new tasks it will undertake.

4. The adaptive task scheduling system for dynamic sharding according to claim 3, characterized in that: The module M1 includes: Module M1.1: Get the task list to be sent from the database task table; Module M1.2: traverses the task list and updates the node number of the current task. If the update fails, it traverses the next task. If the update succeeds, it triggers module M1.

3. Module M1.3: If the task pool is full, the new task is sorted together with the tasks in the task pool, and the tasks with the lowest priority, the longest expiration time, or the largest number of remaining people are eliminated; if the task pool is not full, the new task is added to the pool; The module M3 includes: Module M3.1: Execute the delivery process; Module M3.2: Update the number of people who have delivered the task; Module M3.3: If the number of people to whom the task has been delivered is equal to the total number of people, update the task status to sent.

5. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the dynamic sharding adaptive task scheduling method according to any one of claims 1 to 2 are implemented.

6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the computer program is executed by a processor, the steps of the dynamic sharding adaptive task scheduling method according to any one of claims 1 to 2 are implemented.

Citation Information

Patent Citations

  • Task allocation method based on thread pool

    CN104899099A

  • Big data real-time scheduling method

    CN107172149A

  • Self-feedback task scheduling method for DevOps platform

    CN113900781A