Task scheduling method and device, electronic equipment and storage medium
By establishing a self-driven and self-managed scheduling loop for each task source entity and dynamically adjusting the task scheduling frequency, the problems of uneven response and resource waste in existing task scheduling methods are solved, and efficient resource utilization and system scalability are achieved.
Patent Information
- Application Number
- CN202511072318.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-01
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2045-08-01
AI Technical Summary
Existing task scheduling methods suffer from uneven response, resource waste, and poor scalability in large-scale distributed systems. In particular, centralized schedulers can easily become performance bottlenecks, and fixed-frequency polling cannot adapt to the busy or idle state of task sources, resulting in resource waste and delays.
A self-driven and self-managed scheduling loop is established for each task source entity. By obtaining the unique identifier of the task source entity, the current number of pending tasks and the task density from the message queue, the delay time of task scheduling is dynamically adjusted to form an adaptive scheduling mechanism.
It improves the response speed of key tasks, enhances resource utilization efficiency and system scalability, reduces the bottleneck risk of centralized management, and realizes decentralized adaptive adjustment.
Smart Images

Figure CN120578478B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer task scheduling, and in particular to a task scheduling method, device, electronic equipment and storage medium. Background Art
[0002] In today's large-scale distributed systems, task scheduling is one of the core links. Existing task scheduling methods mostly rely on a central server to uniformly manage all task sources and use a timer to perform fixed-period polling checks on all task sources. In addition, the device side usually actively reports heartbeats to maintain communication connections. This scheduling method has problems such as uneven response, resource waste, and poor scalability. Summary of the Invention
[0003] The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the present invention provides a task scheduling method, apparatus, electronic device, and storage medium that can establish a self-driven and self-managed scheduling cycle for each independent task source entity, ensuring the response speed of critical tasks, improving overall resource utilization efficiency, and scalability.
[0004] In a first aspect, an embodiment of the present invention provides a task scheduling method, comprising:
[0005] Obtain the unique identifier of the task source entity from the message queue and determine it based on the loop message;
[0006] According to the unique identifier, the number of currently pending tasks of the task source entity is obtained;
[0007] Determining a task density according to the current number of tasks to be processed, wherein the task density is used to characterize a task saturation degree of the task source entity;
[0008] Determining a delay time for the next task scheduling of the task source entity according to the task density;
[0009] A new cyclic message is created and delivered to the message queue, where the new cyclic message includes the unique identifier of the task source entity, the updated state information, and the delay time.
[0010] According to some embodiments of the present invention, determining the task density according to the current number of tasks to be processed includes:
[0011] The task density is determined by performing ratio processing on the current number of tasks to be processed and the maximum number of tasks to be processed in each batch.
[0012] According to some embodiments of the present invention, determining the delay time for the next task scheduling of the task source entity according to the task density includes:
[0013] Determining a delay correction factor according to the task density and a preset delay coefficient;
[0014] The delay time for the next task scheduling of the task source entity is determined according to the product of the delay correction factor and a preset reference delay time.
[0015] According to some embodiments of the present invention, determining the delay correction factor according to the task density and a preset delay coefficient includes:
[0016] Determining a complementary value of the task density according to the task density;
[0017] A delay correction factor is determined according to the product of the complementary value of the task density and a preset delay coefficient.
[0018] According to some embodiments of the present invention, obtaining from the message queue and determining the unique identifier of the task source entity according to the cyclic message further includes:
[0019] The business logic of the task source entity is processed according to the unique identifier.
[0020] According to some embodiments of the present invention, processing the business logic of the task source entity according to the unique identifier further includes:
[0021] The state information of the task source entity is obtained, and when the state information indicates an inactive state, the creation of the loop message is terminated.
[0022] In a second aspect, an embodiment of the present invention provides a task scheduling method, including:
[0023] In response to the activation operation of the task source entity, the server creates a loop message for the task source entity and delivers it to the message queue;
[0024] The message consumer side executes the task scheduling method described in the first aspect.
[0025] In a third aspect, an embodiment of the present invention provides a task scheduling device, including:
[0026] A first acquisition module is used to obtain from the message queue and determine the unique identifier of the task source entity according to the cyclic message;
[0027] A second acquisition module is used to acquire the current number of tasks to be processed of the task source entity according to the unique identifier;
[0028] A first determining module is configured to determine a task density according to the current number of tasks to be processed, wherein the task density is used to characterize a task saturation degree of the task source entity;
[0029] A second determining module is used to determine the delay time of the next task scheduling of the task source entity according to the task density;
[0030] A delivery module is created, which is used to create and deliver a new cyclic message to the message queue, wherein the new cyclic message includes the unique identifier of the task source entity, the updated state information and the delay time.
[0031] In a fourth aspect, an embodiment of the present invention provides an electronic device, including a processor and a memory, wherein the memory stores a computer program, and the processor is used to implement the above-mentioned task scheduling method when running the computer program.
[0032] In a fifth aspect, an embodiment of the present invention provides a storage medium, in which a computer program is stored. When the computer program is executed, the above-mentioned task scheduling method is implemented.
[0033] The embodiments of the present invention have at least the following beneficial effects:
[0034] By obtaining cyclic messages from the message queue, processing them, and then creating and delivering new cyclic messages to the message queue, a self-driven and self-managed scheduling loop can be established, which is conducive to improving scalability. Before creating a new cyclic message, the task density is determined according to the current number of pending tasks of the task source entity, and the delay time of the next task scheduling is determined based on the task density. The task processing frequency can be dynamically adjusted to ensure the response speed of key tasks and improve the overall resource utilization efficiency.
[0035] Additional aspects and advantages of the present invention will be set forth in part in the description which follows and, in part, will be obvious from the description which follows, or may be learned by practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the following description of the embodiments with reference to the accompanying drawings, in which:
[0037] Figure 1 This is one of the step flow charts of the task scheduling method according to an embodiment of the present invention;
[0038] Figure 2 This is the second step flow chart of the task scheduling method according to an embodiment of the present invention;
[0039] Figure 3 is a principle block diagram of a task scheduling device according to an embodiment of the present invention;
[0040] Figure 4 This is a principle block diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0041] The following describes embodiments of the present invention in detail. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended only to explain the present invention and are not to be construed as limiting the present invention.
[0042] In the description of the present invention, "several" means one or more, "multiple" means more than two, "greater than," "less than," and "exceed" are understood to exclude the number itself, and "above," "below," and "within" are understood to include the number itself. The use of terms such as "first" and "second" is solely for the purpose of distinguishing technical features and should not be construed as indicating or implying relative importance, or implicitly specifying the number of the indicated technical features, or implicitly specifying the order of the indicated technical features.
[0043] Existing large-scale distributed systems often require task scheduling. For example, in live streaming platforms, robots need to be scheduled to perform automated tasks for thousands of active live streaming rooms. Another example is the need to perform heartbeat detection and status management on a large number of online devices in the Internet of Things. Existing task scheduling methods have the following drawbacks:
[0044] 1. Fixed-Frequency Polling: This system uses a timer to perform fixed-cycle polling checks on all task sources, making it impossible to distinguish whether a task source is busy or idle. For busy task sources, fixed-cycle polling checks can cause task processing delays and untimely responses. For idle task sources, this can result in a large number of unnecessary polling checks, significantly wasting server computing and network resources.
[0045] 2. Centralized Scheduler: A central scheduling service is used to uniformly manage the scheduling strategies of all task sources. As the number of task sources increases dramatically, for example, from tens of thousands to millions, the central scheduling service itself can easily become a performance bottleneck and a single point of failure, limiting the scalability and robustness of the system.
[0046] 3. Passive trigger mechanism: For example, in the device heartbeat detection scenario, the device actively reports heartbeat data, which can easily trigger a "heartbeat storm" at a specific time point (such as the hour). The instantaneous traffic impact may cause the server to overload or even paralyze.
[0047] To this end, an embodiment of the present invention provides a task scheduling method that can establish a self-driven, self-managed scheduling cycle for each independent task source entity, ensuring the response speed of key tasks, improving overall resource utilization efficiency and scalability.
[0048] Please refer to Figure 1This embodiment discloses a task scheduling method, including steps S110 to S120. It should be noted that the numbering of the steps in this embodiment is only for the convenience of review and understanding, and does not limit the execution order of the steps. The content of each step is detailed below:
[0049] S110. In response to the activation operation of the task source entity, the server creates a loop message for the task source entity and delivers it to the message queue;
[0050] Exemplarily, a task source entity refers to an entity that can generate tasks to be processed, such as a live broadcast room or an IoT device. The state changes of the task source entity, such as the start or end of the live broadcast room, the online or offline of the IoT device, will trigger the scheduling of related tasks. In the initial stage, the task source entity enters the activation state, such as the start of the live broadcast room or the online of the IoT device. The server creates an independent loop message for the task entity and delivers it to the message queue. Among them, the loop message includes the unique identifier of the task source entity, the timestamp of message creation, the loop counter and the status information of the task source entity. The unique identifier of the task source entity is used to mark the task source entity so that the message consumer can identify the task source entity of the task to be processed. The timestamp of message creation is used to record the creation time of the loop message; the loop counter is used to track the number of scheduling times; the status information of the task source entity is used to record the status of the task source, such as active (active) or inactive (inactive), to control the start and stop of the message loop.
[0051] S120. The message consumer executes the following task scheduling method.
[0052] For example, a message queue is a middleware technology that transmits messages between applications. It adopts a producer-consumer model and allows asynchronous communication between different services or processes. Message consumers, also known as subscribers, obtain messages from a message queue and process them. Multiple consumers can process messages in the same queue at the same time. Among them, the state change of the task source entity will trigger the scheduling of related tasks, and the message consumer is responsible for receiving the messages generated by the task source entity and executing specific business logic services or components based on the message content. In order to facilitate understanding of the technical concept of the embodiment of the present invention, the task scheduling method performed by the message consumer is described in detail below:
[0053] Please refer to Figure 2 This embodiment discloses a task scheduling method, including steps S210 to S250. It should be noted that the numbering of the steps in this embodiment is only for the convenience of review and understanding, and does not limit the order of execution of the steps. The content of each step is detailed below:
[0054] S210, obtaining from the message queue and determining the unique identifier of the task source entity according to the cyclic message;
[0055] For example, in the initial state, the server creates a separate loop message for each active task source entity and posts it to the message queue. The message consumer retrieves the loop message from the message queue and parses it to determine the unique identifier of the task source entity.
[0056] S220. Obtain the current number of pending tasks of the task source entity according to the unique identifier;
[0057] For example, based on the unique identifier of the task source entity, all the current pending tasks of the task source entity can be queried, thereby obtaining the current number of pending tasks of the task source entity, and the current task load can be evaluated based on the current number of pending tasks. In theory, the more the current number of pending tasks, the shorter the time interval for task scheduling should be. However, the number of pending tasks changes dynamically. When other factors remain unchanged, the stronger the ability to process tasks, the faster the number of pending tasks decreases; similarly, when other factors remain unchanged, the more frequently the state of the task source entity changes, the faster the number of pending tasks increases. The current number of pending tasks is related to the ability to process tasks and the frequency of state changes of the task source entity.
[0058] S230, determining a task density based on the current number of tasks to be processed, where the task density is used to characterize the task saturation level of the task source entity;
[0059] For example, to achieve adaptive adjustment of task scheduling intervals, this embodiment determines task density based on the current number of pending tasks. Task density is used to characterize the task saturation level of the task source entity. When the task density is high, it indicates that the increment in the number of tasks is large and the number of pending tasks is close to the task processing capacity, that is, the tasks are approaching saturation and should be processed at a higher frequency, that is, the delay time for the next task scheduling is reduced. When the task density is low, it indicates that the increment in the number of tasks is small and there is sufficient task processing capacity. The processing frequency can be reduced, that is, the delay time for the next task scheduling is increased to save resources.
[0060] S240: Determine the delay time for the next task scheduling of the task source entity according to the task density;
[0061] Exemplarily, this embodiment measures the dynamic changes of task load through task density, and determines the delay time of the next task scheduling based on the task density. In this way, the delay time of the next task scheduling can be associated with the task load, thereby dynamically adjusting the delay time of the next task scheduling according to the changes in the task load, thereby achieving adaptive dynamic adjustment of the delay time according to the task load, which is conducive to the rational allocation of resources.
[0062] S250: Create and deliver a new cyclic message to the message queue, where the new cyclic message includes the unique identifier of the task source entity, updated status information, and delay time.
[0063] Exemplarily, the related technology adopts a centralized scheduler, that is, in response to the state change of the task source entity, the server generates a message and delivers it to the message queue. The message consumer obtains the message from the message queue and processes the relevant business logic before terminating. The message consumer of this embodiment can create a new cyclic message and deliver the new cyclic message to the message queue, thereby realizing the self-driving and self-management of the scheduling cycle, ensuring the response speed of key tasks and improving the overall resource utilization efficiency. Moreover, the message consumer can realize self-driven and self-managed cyclic scheduling, realize the decentralization of scheduling, and help improve the scalability of the system. Among them, the new cyclic message includes the unique identifier of the task source entity, the updated status information of the task source entity and the delay time. After a time interval equal to the delay time, the message queue makes the new cyclic message visible to the message consumer, so that the message consumer can obtain the cyclic message from the message queue. Among them, the new cyclic message also includes the timestamp of the message creation and the cycle counter, so that timing can be performed by the timestamp and delay time of the message creation, and the cycle counter is used to track the number of scheduling times.
[0064] Through the above scheme, a cyclic message is obtained from the message queue, processed, and then a new cyclic message is created and delivered to the message queue. A self-driven and self-managed scheduling loop can be established, which is conducive to improving scalability. Before creating a new cyclic message, the task density is determined according to the current number of pending tasks of the task source entity, and the delay time of the next task scheduling is determined according to the task density. The task processing frequency can be dynamically adjusted to ensure the response speed of key tasks and improve the overall resource utilization efficiency.
[0065] In step S230 , the task density is determined based on the current number of tasks to be processed, including: performing ratio processing on the current number of tasks to be processed and the maximum number of tasks to be processed in each batch to determine the task density.
[0066] For example, as described above, the current number of processing tasks is related to the ability to process tasks and the frequency of state changes of the task source entity. Assuming that the hardware conditions remain unchanged and the ability to process tasks remains unchanged, then the maximum number of processing tasks per batch under these hardware conditions can be obtained. Assuming that the speed of task processing remains unchanged, then the greater the number of currently pending tasks, to a certain extent, it reflects that the task source entity generates tasks faster. If the current number of pending tasks is close to the maximum number of processing tasks per batch, then to a certain extent, it reflects that the current task growth rate is relatively fast and the current task processing load is tending to saturation. It is necessary to increase the frequency of obtaining cyclic messages from the message queue and improve task processing efficiency to avoid task accumulation and response delays. Conversely, if the current number of pending tasks is small, or even close to zero, then to a certain extent, it reflects that the current task growth rate is relatively slow and the current task processing load is small, or even the task processing capacity is tending to idle state. In this case, the frequency of obtaining cyclic messages from the message queue can be appropriately reduced to save resources. In order to accurately evaluate the current task processing load, this embodiment evaluates the task density, where the task density is equal to the ratio between the current number of pending tasks and the maximum number of processing tasks per batch. Task density is a value between 0 and 1. Let task density be TaskDensity, then TaskDensity∈[0,1]. When TaskDensity is close to 1, it means that the task processing load tends to be saturated, and when TaskDensity is close to 0, it means that the task processing load tends to be idle.
[0067] Step S240: Determine the delay time for the next task scheduling of the task source entity according to the task density, including:
[0068] Determine the delay correction factor based on the task density and the preset delay coefficient;
[0069] The delay time for the next task scheduling of the task source entity is determined according to the product of the delay correction factor and the preset reference delay time.
[0070] For example, the reference delay time is characterized as the minimum delay time in the case where the task density takes the maximum value, such as 1000 milliseconds. The reference delay time is multiplied by a delay correction factor, and the delay correction factor is related to the task density, so that the reference delay time can be corrected according to the task density. The greater the value of the task density, the closer the delay time of the next task scheduling to the reference delay time. Conversely, the smaller the value of the task density, the greater the delay time of the next task scheduling can be increased by the delay correction factor. The delay factor is a configurable constant for amplifying the delay effect in the case of low task density. For ease of understanding, let the delay time of the next task scheduling be NextLoopDelayMs, the reference delay time be BaseDelay, the delay correction factor be λ, the task density be TaskDensity, and the delay factor be DelayFactor. Then NextLoopDelayMs = BaseDelay * λ, λ = (TaskDensity, DelayFactor), indicating that the delay correction factor is a function of the task density and the delay factor. f
[0071] In a specific application example, the above step of determining the delay correction factor according to the task density and the preset delay factor includes:
[0072] According to the task density, the complement of the task density is determined.
[0073] The delay correction factor is determined according to the product of the complement of the task density and the preset delay factor.
[0074] For example, according to the above, the greater the value of the task density, the closer the delay time of the next task scheduling to the reference delay time, that is, the delay modification factor is close to 1. Therefore, it can be known that the task density and the delay modification factor should be inversely proportional. Let the task density be TaskDensity, then the complement of the task density is equal to 1-TaskDensity, the delay correction factor λ = 1 + (1-TaskDensity) * DelayFactor, and DelayFactor is the delay factor. Therefore, the delay time of the next task scheduling NextLoopDelayMs = BaseDelay * [1 + (1-TaskDensity) * DelayFactor], and BaseDelay is the reference delay time.
[0075] In step S210, the unique identifier of the task source entity is determined according to the loop message obtained from the message queue, and then the business logic of the task source entity is processed according to the unique identifier.
[0076] For example, after the message consumer obtains the loop message from the message queue, it can determine the unique identifier of the task source entity based on the loop message, thereby determining the task source identifier of the task that needs to be processed, and then start processing the business logic of the task source entity. For example, in the live broadcast application scenario, the business logic to be processed may be the dispatching of robot tasks; for example, in the IoT device application scenario, the business logic to be processed may be the detection of device status.
[0077] In some application examples, the above step of processing the business logic of the task source entity according to the unique identifier further includes obtaining status information of the task source entity, and terminating the creation of the loop message when the status information indicates an inactive state.
[0078] For example, after processing the business logic of the task source entity, the state information of the task source entity is queried to obtain the state information of the task source entity. When the task source entity is closed, for example, when the live broadcast room is offline or the IoT device is offline, the state information of the task source entity is characterized as inactive. At this time, no new loop message is created, and the scheduling cycle of the task source entity is naturally terminated. In this way, the task source entity can be self-driven and self-managed, without the need for centralized management on the server side, which facilitates scalability.
[0079] To facilitate understanding of the technical concept of the task scheduling method according to the embodiment of the present invention, a detailed description is given below in conjunction with specific application scenarios.
[0080] Application Scenario 1: Robot Interaction System in Live Broadcast Room
[0081] On a large social platform with tens of millions of potential concurrent live broadcast rooms, during the initialization phase, the baseline delay time is set to 500ms (milliseconds) to cope with sudden interaction peaks. A larger delay coefficient is set, for example 59. When TaskDensity is close to 0, the check cycle for idle live broadcast rooms (the delay time for task scheduling) can be as long as 500ms*[1+(1-TaskDensity)*59]=30 seconds.
[0082] When the live broadcast room starts, the server creates an initial loop message for the live broadcast room and delivers it to the message queue. The initial loop message includes the live broadcast room's unique identifier, the timestamp of message creation, the loop counter, and the live broadcast room's status information.
[0083] In a common live room, the audience interaction is sparse, the robot task queue is empty, and the consumer of the corresponding loop message of the live room is calculated to be close to 0. According to the task density, the delay time of the next task scheduling is determined to be 30 seconds, that is, the message queue of the live room is polled at a low frequency of 30 seconds as a period. Compared with the fixed frequency (such as polling once per second) of the related art, the scheduling method of the embodiment can greatly reduce the consumption of server resources.
[0084] If a gift storm occurs in the live room, for example, a large number of gift interactions occur in the live room, triggering thousands of special effect playing tasks, when the loop message of the live room is consumed, it is detected that the task queue has increased, that is, the task density tends to 1, and the delay time of the next task scheduling gradually tends to 500 milliseconds of the reference delay time. The highest frequency of 2 times per second is used to quickly process tasks to ensure that each gift interaction can get timely robot feedback, thereby ensuring user experience.
[0085] Application scenario 2: Fault perception network of Internet of Things device
[0086] A shared bicycle company needs to monitor the online status of a large number of shared bicycles deployed in different areas in real time. In the initialization stage, the reference delay time is set to 5 seconds for quickly confirming whether the device is lost connection; and a large delay coefficient is set, for example, 119, when the TaskDensity is close to 0, the checking period of the normal device is 5s*[1+ (1-TaskDensity)*119]=600 seconds=10 minutes.
[0087] When the shared bicycle is running normally, the GPS module built in the shared bicycle reports heartbeat data to the server. In the initial stage, the server creates an initial loop message about the reported heartbeat data and delivers it to the message queue. When the message consumer checks the status of the shared bicycle each time, it is found that the reporting time of the heartbeat data is within the preset period, that is, within 10 minutes, in other words, the "lost connection detection" task does not need to be executed. For the "lost connection detection" task, the task density is equal to 0, and the delay time of the next task scheduling is determined to be 10 minutes.
[0088] When the shared bicycle enters a signal-free underground tunnel, it stops reporting heartbeat data. After the detection period of 10 minutes ends, the message consumer finds that the heartbeat timestamp of the shared bicycle has expired, and then executes the "lost connection detection" task with the highest priority. At this time, the task density is equal to 1, and the delay time of the next task scheduling is determined to be 5 seconds, entering a high-frequency detection mode. If the shared bicycle still does not report heartbeat data after 3 consecutive high-frequency detections, it can be confirmed that the shared bicycle is in a lost connection state, and events such as alarm and map marking are triggered.
[0089] From the above application scenarios, it can be seen that the task scheduling method of the embodiment of the present invention has the following beneficial effects compared with the related art:
[0090] 1. Significantly improved resource utilization: Compared with the timed polling method of related technologies, the embodiment of the present invention dynamically adjusts the delay time of the next task scheduling based on the task density. It can schedule tasks at a higher frequency when the task density is high, and at a lower frequency when the task density is low. In actual applications, most task sources are in a low-load state, which can reduce invalid polling overhead and significantly improve resource utilization.
[0091] 2. Decentralized adaptive adjustment: In the embodiment of the present invention, message consumers can create new loop messages. No centralized server intervention is required during the message loop. When the task source experiences a business peak (such as a gift storm), the task scheduling delay time can be adaptively adjusted according to the task density to ensure the response speed of key businesses.
[0092] 3. Significantly Improved Scalability: This embodiment of the present invention encapsulates the scheduling logic and the state of task source entities within cyclic messages, forming a shared-nothing distributed architecture that eliminates performance bottlenecks and single points of failure in the central processing unit and scheduler. In applications, linear or even superlinear scalability can be achieved by adding consumer instances, supporting task sources ranging from thousands to hundreds of millions. A single task source failure will not affect the entire system, improving overall fault tolerance.
[0093] 4. New state management and triggering paradigm: This embodiment of the present invention decouples "state checking" and "action triggering" and delegates control of task scheduling frequency (delay time) to each independent message consumer. This new state management and triggering paradigm can be applied to a variety of application scenarios, such as building large-scale context-aware AI assistants that can perceive the rhythm of conversations, or implementing fault-aware networks for massive IoT terminals.
[0094] Please refer to Figure 3 , an embodiment of the present invention further provides a task scheduling device, comprising:
[0095] A first acquisition module 110 is configured to acquire a unique identifier of a task source entity from a message queue and determine the unique identifier according to a cyclic message;
[0096] The second acquisition module 120 is used to acquire the current number of pending tasks of the task source entity according to the unique identifier;
[0097] A first determining module 130 is configured to determine a task density based on the number of tasks currently to be processed, where the task density is used to characterize the task saturation level of the task source entity;
[0098] The second determining module 140 is used to determine the delay time of the next task scheduling of the task source entity according to the task density;
[0099] The creation and delivery module 150 is used to create and deliver a new cyclic message to the message queue. The new cyclic message includes the unique identifier of the task source entity, the updated state information and the delay time.
[0100] The inventive concept of the present embodiment of the task scheduling device is the same as the inventive concept of the above-mentioned embodiment of the task scheduling method. The contents not covered in the present embodiment of the task scheduling device can be referred to the above-mentioned embodiment of the task scheduling method and will not be described in detail here. By obtaining a cyclic message from a message queue and creating and delivering a new cyclic message to the message queue after processing, a self-driven and self-managed scheduling loop can be established, which is conducive to improving scalability. Before creating a new cyclic message, the task density is determined based on the current number of pending tasks of the task source entity, and the delay time of the next task scheduling is determined based on the task density. The task processing frequency can be dynamically adjusted to ensure the response speed of key tasks and improve the overall resource utilization efficiency.
[0101] Please refer to Figure 4 , an embodiment of the present invention also provides an electronic device, including a processor 210 and a memory 220, wherein a computer program is stored in the memory 220, and the processor 210 is used to implement the above-mentioned task scheduling method when running the computer program. The specific content of the task scheduling method and the corresponding effective effects can be referred to above and will not be repeated here. By obtaining a cyclic message from a message queue and creating and delivering a new cyclic message to the message queue after processing, a self-driven and self-managed scheduling loop can be established, which is conducive to improving scalability. Before creating a new cyclic message, the task density is determined according to the current number of tasks to be processed of the task source entity, and the delay time of the next task scheduling is determined according to the task density. The task processing frequency can be dynamically adjusted to ensure the response speed of key tasks and improve the overall resource utilization efficiency.
[0102] An embodiment of the present invention also provides a storage medium, in which a computer program is stored, and the above-mentioned task scheduling method is implemented when the computer program is run. The specific content of the task scheduling method and the corresponding effective effects can be referred to above and will not be repeated here. By obtaining a cyclic message from a message queue and creating and delivering a new cyclic message to the message queue after processing, a self-driven and self-managed scheduling loop can be established, which is conducive to improving scalability. Before creating a new cyclic message, the task density is determined according to the current number of tasks to be processed of the task source entity, and the delay time of the next task scheduling is determined according to the task density. The task processing frequency can be dynamically adjusted to ensure the response speed of key tasks and improve the overall resource utilization efficiency.
[0103] The embodiments of the present invention are described in detail above with reference to the accompanying drawings. However, the present invention is not limited to the above embodiments. Various changes can be made within the knowledge of ordinary technicians in the relevant technical field without departing from the scope of the present invention.
Claims
1. A task scheduling method, characterized in that: include: Obtain the unique identifier of the task source entity from the message queue and determine it based on the loop message; According to the unique identifier, the number of currently pending tasks of the task source entity is obtained; Determining a task density according to the current number of tasks to be processed, wherein the task density is used to characterize a task saturation degree of the task source entity; Determine, according to the task density, a delay time for the next task scheduling of the task source entity, wherein the delay time for the next task scheduling = a preset reference delay time * [1 + (1-task density) * a preset delay coefficient]; A new cyclic message is created and delivered to the message queue, wherein the new cyclic message includes the unique identifier of the task source entity, the updated state information, and the delay time.
2. The task scheduling method according to claim 1, characterized in that: Determining the task density according to the current number of tasks to be processed includes: The task density is determined by performing ratio processing on the current number of tasks to be processed and the maximum number of tasks to be processed in each batch.
3. The task scheduling method according to claim 1, wherein: The method further includes obtaining the unique identifier of the task source entity from the message queue and determining the unique identifier of the task source entity according to the cyclic message: The business logic of the task source entity is processed according to the unique identifier.
4. The task scheduling method according to claim 1 or 3, characterized in that: The business logic of processing the task source entity according to the unique identifier further includes: The state information of the task source entity is obtained, and when the state information indicates an inactive state, the creation of the loop message is terminated.
5. A task scheduling method, characterized in that: include: In response to the activation operation of the task source entity, the server creates a loop message for the task source entity and delivers it to the message queue; The message consumer executes the task scheduling method according to any one of claims 1 to 4.
6. A task scheduling device, characterized in that: include: A first acquisition module is used to obtain from the message queue and determine the unique identifier of the task source entity according to the cyclic message; A second acquisition module is used to acquire the current number of tasks to be processed of the task source entity according to the unique identifier; A first determining module is configured to determine a task density according to the current number of tasks to be processed, wherein the task density is used to characterize a task saturation degree of the task source entity; A second determining module is configured to determine a delay time for the next task scheduling of the task source entity according to the task density, wherein the delay time for the next task scheduling = a preset reference delay time * [1 + (1-task density) * a preset delay coefficient]; A delivery module is created, which is used to create and deliver a new cyclic message to the message queue, wherein the new cyclic message includes the unique identifier of the task source entity, the updated state information and the delay time.
7. An electronic device comprising a processor and a memory, wherein the memory stores a computer program, wherein: When the processor runs the computer program, it is used to implement the task scheduling method according to any one of claims 1 to 5.
8. A storage medium storing a computer program, wherein: When the computer program is executed, the task scheduling method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Task processing method and device, storage medium and electronic equipment
CN111539780A
Online task dispatching and scheduling system and method thereof
US11206221B1