Coroutine scheduling method, device, system and equipment, storage medium and product

By introducing multi-priority queue groups and storage modules into coroutine scheduling, dynamically divide the scheduling domains, solving the problems of high-priority tasks response delay and low resource utilization in traditional coroutine schedulers, and achieving efficient task scheduling and resource management.

CN120386608AActive Publication Date: 2025-07-29LANGCHAO ELECTRONIC INFORMATION IND CO LTD

Patent Information

Application Number
CN202510866091.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-26
Publication Date
2025-07-29
Estimated Expiration
2045-06-26

AI Technical Summary

Technical Problem

Traditional co-routine schedulers lack priority awareness, resulting in delayed response to high-priority tasks and low resource utilization, especially in hybrid load scenarios, it is difficult to dynamically adjust queue policies.

Method used

Multi-priority queue groups and storage modules are adopted to dynamically divide the scheduling domains, monitor the operating status and load status, and perform task migration to ensure that high-priority tasks prioritize resources.

Benefits of technology

Improve the response speed of high-priority tasks, optimize resource utilization, and improve overall throughput and business robustness in multi-core environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120386608A_ABST
    Figure CN120386608A_ABST
Patent Text Reader

Abstract

The invention discloses a coroutine scheduling method, device, system and equipment, a storage medium and a product, and relates to the technical field of task scheduling, a multi-priority queue group is used for storing a first coroutine task to be executed in a corresponding scheduling domain, and a storage module is used for storing a second coroutine task periodically executed in a corresponding scheduling domain; the execution cycle of the first coroutine task is smaller than that of the second coroutine task. And when the expired second coroutine task exists in the storage module, mounting the expired second coroutine task to the multi-priority queue group. The situation that the first coroutine task with the low priority cannot be executed due to the fact that the second coroutine task does not reach the execution time is effectively avoided. And the coroutine tasks are obtained and executed from the multi-priority queue group according to the priority sequence, so that the tasks with high priorities are ensured to preferentially obtain execution resources. According to the running state and the load state of each scheduling domain, task migration of each scheduling domain is carried out, and the resource utilization rate is optimized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of task scheduling, and particularly to a coroutine scheduling method, device, system, equipment, storage medium and product. Background Art

[0002] A coroutine is a lightweight concurrent execution unit in user space, and its scheduling is directly managed by the application program rather than the operating system kernel. Compared with threads and processes, the context switch of coroutines does not need to enter the kernel state, with lower resource consumption, usually occupying KB-level memory, and faster switching speed, reaching the nanosecond to microsecond level.

[0003] Although coroutines have the advantages of lightweight and high concurrency, their scheduling mechanisms still face some problems. Traditional coroutine schedulers lack the ability to perceive priorities and are difficult to handle mixed loads such as scenarios where real-time tasks and batch processing tasks coexist, resulting in delayed responses for high-priority tasks. When multiple coroutines share the same queue, low-priority or resource-intensive coroutines may preempt the execution resources of high-priority tasks, causing priority inversion or a sharp increase in tail latency. And the current scheduling strategy is based on static resource allocation and is difficult to dynamically adjust the queue strategy according to the system load, affecting resource utilization.

[0004] It can be seen that how to improve resource utilization while ensuring the timely processing of high-priority tasks is a problem that needs to be solved by those skilled in the art. Summary of the Invention

[0005] This application provides a coroutine scheduling method, device, system, equipment, storage medium and product to at least solve the problems of untimely processing of high-priority tasks and low resource utilization in related technologies.

[0006] This application provides a coroutine scheduling method, including: Access the storage module corresponding to the target scheduling domain; wherein, the target scheduling domain is correspondingly provided with a multi-priority queue group; the multi-priority queue group is used to store the first coroutine tasks to be executed in the target scheduling domain; the storage module is used to store the second coroutine tasks that are regularly executed in the scheduling domain; the execution period of the first coroutine tasks is less than the execution period of the second coroutine tasks; In the case where there are expired second coroutine tasks in the storage module, mount the expired second coroutine tasks to the multi-priority queue group; Obtain and execute coroutine tasks from the multi-priority queue group in the order of priority; During the stage of obtaining and executing coroutine tasks, monitor the running state and load state of each scheduling domain; wherein, the target scheduling domain is any one of the scheduling domains; Perform task migration for each scheduling domain according to the running status and load status of each scheduling domain.

[0007] This application also provides a coroutine scheduling device, including an access unit, a mounting unit, an execution unit, a monitoring unit, and a migration unit; The access unit is used to access the storage module corresponding to the target scheduling domain; among them, the target scheduling domain is correspondingly provided with a multi-priority queue group; the multi-priority queue group is used to store the first coroutine tasks to be executed in the target scheduling domain; the storage module is used to store the second coroutine tasks regularly executed in the target scheduling domain; the execution period of the first coroutine task is less than the execution period of the second coroutine task; The mounting unit is used to mount the expired second coroutine task to the multi-priority queue group when there is an expired second coroutine task in the storage module; The execution unit is used to obtain and execute coroutine tasks from the multi-priority queue group in the order of priority; The monitoring unit is used to monitor the running status and load status of each scheduling domain during the stage of obtaining and executing coroutine tasks; among them, the target scheduling domain is any one of the scheduling domains; The migration unit is used to perform task migration for each scheduling domain according to the running status and load status of each scheduling domain.

[0008] This application also provides a coroutine scheduling system, including at least one scheduling domain, there is at least one executor under each scheduling domain, and each executor is bound to at least one processor core; the target scheduling domain is any one of the scheduling domains; the target scheduling domain is correspondingly provided with a multi-priority queue group; The multi-priority queue group is used to store the first coroutine tasks to be executed in the target scheduling domain; The storage module is used to store the second coroutine tasks regularly executed in the target scheduling domain; the execution period of the first coroutine task is less than the execution period of the second coroutine task; The scheduler is used to access the storage module; when there is an expired second coroutine task in the storage module, mount the expired second coroutine task to the multi-priority queue group; obtain and execute coroutine tasks from the multi-priority queue group in the order of priority; monitor the running status and load status of each scheduling domain during the stage of obtaining and executing coroutine tasks; perform task migration for each scheduling domain according to the running status and load status of each scheduling domain.

[0009] An embodiment of this application also provides an electronic device, including: a memory for storing a computer program; a processor for implementing the steps of any of the above coroutine scheduling methods when executing the computer program.

[0010] The present application also provides a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of any one of the above coroutine scheduling methods.

[0011] The present application also provides a computer program product including a computer program, which, when executed by a processor, implements the steps of any one of the above coroutine scheduling methods.

[0012] Access the storage module corresponding to the target scheduling domain through the present application; wherein the target scheduling domain is any one of the scheduling domains; a multi-priority queue group is provided corresponding to the target scheduling domain; the multi-priority queue group is used to store the first coroutine tasks to be executed in the target scheduling domain; the storage module is used to store the second coroutine tasks regularly executed in the target scheduling domain; the execution period of the first coroutine task is less than the execution period of the second coroutine task. In the case where there are due second coroutine tasks in the storage module, the due second coroutine tasks are mounted to the multi-priority queue group. By dividing the multi-priority queue group and the storage module, the first coroutine tasks and the second coroutine tasks can be effectively distinguished, and only when the second coroutine tasks are due are they put into the multi-priority queue group, effectively avoiding the situation where batch tasks have not reached the execution time, resulting in tasks with lower priorities not being able to be executed. By designing the multi-priority queue group, it can be ensured that tasks with higher priorities obtain execution resources first, reducing the tail latency. In the stage of obtaining and executing coroutine tasks, the running status and load status of each scheduling domain can be monitored; according to the running status and load status of each scheduling domain, task migration of each scheduling domain is performed, improving the robustness of the service and optimizing the resource utilization rate. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] To more clearly illustrate the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0014] Figure 1 It is a flowchart of a coroutine scheduling method provided by an embodiment of the present application; Figure 2 It is a schematic diagram of a scheduler for status monitoring provided by an embodiment of the present application; Figure 3 It is a schematic diagram of the link relationship between multiple schedulers and a multi-priority queue group provided by an embodiment of the present application; Figure 4 It is a schematic structural diagram of a coroutine scheduling device provided by an embodiment of the present application; Figure 5Schematic diagram of the structure of a coroutine scheduling system provided by an embodiment of the present application. Detailed implementation manners

[0015] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.

[0016] It should be noted that in the description of the present application, the terms "include", "comprise" or any other variation thereof are intended to cover a non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. The terms "first", "second", etc. in the present application are used to distinguish similar objects, rather than to describe a specific order or sequence.

[0017] Modern programming languages and frameworks all provide coroutine support. Modern programming languages include statically strongly typed, compiled languages (Golang, Go), computer programming languages (Python), and modern static programming languages (Kotlin), etc. Frameworks include open source protocol libraries (libco) and c++ libraries (Boost.Coroutine).

[0018] The scheduling algorithm of the lightweight user-mode coroutine (Goroutine, G) implemented by the Go language is based on the M:N model. Through the logical processor (Processor, P), multiple lightweight user-mode coroutines are dynamically bound to a small number of operating system threads (OSThread), and the operating system thread can be regarded as an executor (Machine, M). Load balancing is achieved by using work stealing and local run queues. A combination of cooperative scheduling (function call insertion of preemption points) and signal-based preemptive scheduling (SIGURG forced interruption) is adopted to ensure the response of high-priority tasks. At the same time, the network poller (Netpoller) is integrated to asynchronize blocked input / output (I / O), avoid thread blocking, and finally achieve high-concurrency and low-latency lightweight coroutine scheduling in the user mode.

[0019] However, the current coroutine scheduling method lacks fine-grained priority support: all Gs are by default equal, and it is impossible to distinguish real-time tasks from batch tasks. High-priority tasks may experience response delays due to work stealing or global queue competition. The number of Ps is fixed, and it is impossible to dynamically allocate computing resources. For example, it is difficult to isolate high- and low-priority tasks in scenarios with a mixed load of CPU-intensive and I / O-intensive. Signal preemption depends on SIGURG and a 10ms threshold, and it is impossible to achieve nanosecond-level real-time preemption; moreover, cooperative preemption depends on code-inserted checkpoints and there is a risk of being bypassed, such as in dense loops without function calls.

[0020] Therefore, the embodiments of the present application provide a coroutine scheduling method, device, system, device, storage medium, and product, which realize resource isolation and load balancing by dynamically dividing scheduling domains. Each scheduling domain nests a multi-priority queue group and a storage module, supports task preemption and priority inheritance, and ensures low-latency response for high-priority tasks. By monitoring the running state and load state of each scheduling domain, and dynamically optimizing resource allocation through task migration, the robustness of the service is improved, the resource utilization rate is optimized, and the overall throughput in a multi-core environment is increased.

[0021] In order to enable those skilled in the art of the present technology to better understand the solution of the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0022] The embodiments of the present application provide a coroutine scheduling method. Figure 1 The following is a flowchart of a coroutine scheduling method provided by an embodiment of the present application, including: S101: Access the storage module corresponding to the target scheduling domain; the multi-priority queue group is used to store the first coroutine tasks to be executed in the target scheduling domain; the storage module is used to store the second coroutine tasks that are regularly executed in the target scheduling domain.

[0023] In practical applications, different scheduling domains can be dynamically divided in advance according to physical resources and task characteristics to achieve resource isolation and load balancing. Among them, physical resources can include processor cores, cache levels, etc., and task characteristics can include priorities and resource requirements, etc.

[0024] In the embodiments of the present application, according to the functions to be implemented under each scheduling domain, there can be at least one executor under each scheduling domain.

[0025] The executor can migrate among different scheduling domains. Which scheduling domain the executor executes the service in depends on the requirements and configurations of the service. Each executor is bound to at least one processor core; by binding the executor to the processor core, cross-region cache misses can be reduced, affinity scheduling of tasks and hardware can be achieved, and instruction-level parallelism and cache hit rate can be improved.

[0026] A scheduling domain can contain multiple executors. The functions implemented by each executor are similar. In the embodiments of the present application, the operations of one executor are taken as an example for introduction. The scheduling domain where the executor is located is called the target scheduling domain. The target scheduling domain is any one of the scheduling domains. The target scheduling domain is correspondingly provided with a multi-priority queue group.

[0027] Considering that the second coroutine task often has a specific execution time and the execution time is relatively long. If it is directly placed in the multi-priority queue group according to the priority, when the second coroutine task has not reached its execution time, it will cause the coroutine tasks with lower priorities than it to not be processed for a long time. Therefore, in the embodiments of the present application, in order to better process different types of tasks, a multi-priority queue group and a storage module can be set for each scheduling domain.

[0028] Taking the target scheduling domain as an example, the multi-priority queue group is used to store the first coroutine tasks to be executed in the target scheduling domain. The storage module is used to store the second coroutine tasks that are executed regularly in the target scheduling domain.

[0029] The execution period of the first coroutine task is less than the execution period of the second coroutine task. In practical applications, the first coroutine task can be a real-time coroutine task, and the second coroutine task can be a batch coroutine task.

[0030] S102: In the case that there are expired second coroutine tasks in the storage module, mount the expired second coroutine tasks to the multi-priority queue group.

[0031] S103: Obtain and execute the coroutine tasks from the multi-priority queue group in the order of priority.

[0032] In practical applications, the executor included in the target scheduling domain can be used to obtain and execute the coroutine tasks from the multi-priority queue group in the order of priority.

[0033] S104: During the stage of obtaining and executing the coroutine tasks, monitor the running status and load status of each scheduling domain.

[0034] S105: Perform task migration of each scheduling domain according to the running status and load status of each scheduling domain.

[0035] The actuator in this application is equivalent to a thread, and this thread processes coroutine tasks by calling program code. Among them, the called program code can include coroutine code for executing coroutine tasks, as well as code for obtaining tasks from a multi-priority queue group and monitoring the running status and load status of each scheduling domain.

[0036] For the sake of convenience in description, the coroutine code can be simply referred to as a coroutine, and the code for obtaining tasks from a multi-priority queue group and monitoring the running status and load status of each scheduling domain can be called a scheduler. From the user's perspective, the actuator can implement coroutine scheduling, so the scheduler can be regarded as a module included in the actuator.

[0037] There are multiple actuators in a scheduling domain. When each actuator executes a task, it uses the scheduler to determine whether there are expired coroutine tasks in the storage module. If there are expired coroutine tasks, the coroutine tasks are hung in the multi-priority queue group. The scheduler in the actuator is responsible for obtaining coroutine tasks from the multi-priority queue group.

[0038] Taking the target scheduling domain as an example, in practical applications, the scheduler can access the storage module corresponding to the target scheduling domain; in the case where there are expired second coroutine tasks in the storage module, the expired second coroutine tasks are mounted in the multi-priority queue group; coroutine tasks are obtained from the multi-priority queue group in the order of priority.

[0039] By executing coroutine tasks in the order of priority, it can ensure that coroutine tasks with higher priority are executed first, effectively avoiding the situation where low-priority coroutine tasks preempt resources.

[0040] In the stage of obtaining and executing coroutine tasks, the scheduler can monitor the running status and load status of each scheduling domain; according to the running status and load status of each scheduling domain, task migration of each scheduling domain is performed.

[0041] The coroutine and the scheduler belong to different stacks. The scheduler can obtain coroutine tasks from the multi-priority queue group. When the coroutine returns to the scheduler, the stack is switched, and at this time, the scheduler can automatically perform status monitoring.

[0042] The scheduler can monitor the running status and load status of the scheduling domain. The running status can include a normal state and an abnormal state. The load status can include a high-load state, a normal-load state, and a low-load state. In practical applications, the respective value ranges corresponding to the high-load state, the normal-load state, and the low-load state can be preset in advance. By comparing the load value of the scheduling domain with the preset value range, the load status can be determined. Among them, the load value of the scheduling domain can be the number of all coroutine tasks included in the scheduling domain.

[0043] Generally, the coroutine tasks executed in different scheduling domains are different. However, due to the particularity of coroutine tasks, the executor in a scheduling domain can also execute coroutine tasks in other scheduling domains. For a scheduling domain in an abnormal state, its corresponding coroutine tasks can be transferred to a scheduling domain in a normal state and with low load.

[0044] The number of scheduling domains and the number of executors in a scheduling domain can be configured according to the requirements of the business. The maximum value can be determined by the number of CPU cores recognizable by the operating system. There is at least one executor in a scheduling domain. An executor is at least bound to one CPU core.

[0045] To ensure high performance, one CPU core is bound to one executor. Therefore, if the maximum value of the number of CPU cores is represented as max_cpus, then the value range of the number of scheduling domains is [1, max_cpus], the value range of the number of executors in a scheduling domain is [1, max_cpus], and the total number of executors in all scheduling domains should be less than max_cpus.

[0046] In a scheduling domain, each executor completes the execution of tasks by obtaining coroutines in the scheduling domain. Coroutines are sorted according to different priorities in the scheduling domain.

[0047] In the specific implementation, the executor obtains coroutine tasks from a multi-priority queue group through a built-in scheduler, and then executes the coroutine tasks.

[0048] It can be seen from the above technical solution that access the storage module corresponding to the target scheduling domain; wherein, the target scheduling domain is correspondingly provided with a multi-priority queue group; the multi-priority queue group is used to store the first coroutine tasks to be executed in its corresponding scheduling domain; the storage module is used to store the second coroutine tasks regularly executed in its corresponding scheduling domain; the execution period of the first coroutine task is less than the execution period of the second coroutine task. In the case where there are expired second coroutine tasks in the storage module, the expired second coroutine tasks are mounted to the multi-priority queue group. By dividing the multi-priority queue group and the storage module, the first coroutine tasks and the second coroutine tasks can be effectively distinguished. Only when the second coroutine tasks expire are they put into the multi-priority queue group, effectively avoiding the situation where batch tasks have not reached the execution time, resulting in tasks with lower priorities unable to be executed. By designing the multi-priority queue group, it can be ensured that tasks with higher priorities obtain execution resources first, reducing the tail latency. In the stage of obtaining and executing coroutine tasks, the running state and load state of the scheduling domain can be monitored; according to the running state and load state of each scheduling domain, task migration of each scheduling domain is performed, improving the robustness of the service and optimizing the resource utilization rate.

[0049] The processing methods of coroutine tasks within each scheduling domain are similar. In the embodiments of this application, a single scheduling domain is used as an example for introduction. A scheduling domain often contains multiple schedulers, and the operations performed by each scheduler are similar. Next, a single scheduler will be used as an example for introduction. For ease of distinction, the scheduling domain to which the current scheduler belongs can be referred to as the target scheduling domain.

[0050] During the stage of obtaining and executing coroutine tasks, the scheduler can monitor the status of the target scheduling domain, the executors included in the target scheduling domain, and the coroutine tasks they execute.

[0051] In the case where the target scheduling domain has an abnormal status, to ensure the smooth execution of coroutine tasks within the target scheduling domain, the coroutine tasks stored in the multi-priority queue group and storage module corresponding to the target scheduling domain can be migrated to a scheduling domain with a normal status and meeting the load requirements. The scheduling domain meeting the load requirements can be the scheduling domain with the lowest load.

[0052] In the case of a target executor with an abnormal status, an executor alarm message can be generated. In the case of a target coroutine task with an abnormal status, a coroutine alarm message is generated.

[0053] Figure 2 This is a schematic diagram of status monitoring for a scheduler provided in the embodiments of this application. Figure 2 In the example, there are two scheduling domains, and each scheduling domain contains two executors. Each executor contains a scheduler. For ease of distinction, the two scheduling domains are respectively called scheduling domain a and scheduling domain b. The scheduler can achieve status monitoring of the scheduling domain where it is located, status monitoring of all executors within the scheduling domain where it is located, and status monitoring of the coroutine tasks it executes. When the operating status of scheduling domain a is abnormal, and the operating status of scheduling domain b is normal and in a low-load state, at this time, the scheduler currently executing coroutine tasks within scheduling domain a can migrate the coroutine tasks in the multi-priority queue group and storage module within scheduling domain a to scheduling domain b.

[0054] In practical applications, the scheduler identifies the operating status of the scheduling domain based on whether the coroutine tasks in the multi-priority queue group and storage module within the scheduling domain where it is located are being executed. For example, if the coroutine tasks in the multi-priority queue group and storage module are being executed normally, it indicates that the scheduling domain is operating normally, and it can be determined that the scheduling domain is in a normal state. When the coroutine tasks in the multi-priority queue group and storage module have not been executed for a long time, it indicates that the scheduling domain is operating abnormally, and it can be determined that the scheduling domain is in an abnormal state.

[0055] The scheduler can evaluate the load status of a scheduling domain based on the number of coroutine tasks contained in the scheduling domain. The scheduler can obtain the number of coroutine tasks stored in the multi-priority queue group and the storage module. For example, when the number of coroutine tasks is greater than the set load upper limit value, it indicates that the load of the scheduling domain is high, and it can be determined that the scheduling domain is in a high-load state; when the number of coroutine tasks is less than the set load lower limit value, it indicates that the load of the scheduling domain is small, and it can be determined that the scheduling domain is in a low-load state; when the number of coroutine tasks is between the load lower limit value and the load upper limit value, it indicates that the load of the scheduling domain is normal, and it can be determined that the scheduling domain is in a normal-load state.

[0056] For the evaluation of the executor status, the scheduler can detect whether the executor does not execute tasks for a long time. If the executor does not execute tasks for a long time, it can be determined that the executor status is abnormal.

[0057] For the situation where the executor status is abnormal, in addition to generating an alarm message, when there is a target executor with an abnormal status, the scheduler can migrate the executor with a normal status from other scheduling domains that meet the load requirements to ensure the smooth execution of coroutine tasks within the current scheduling domain.

[0058] The scheduler can evaluate the status of coroutine tasks according to the execution time of coroutine tasks. For example, when the execution time of a coroutine task exceeds the set time threshold, it can be determined that the status of the coroutine task is abnormal.

[0059] Considering that in practical applications, the number of schedulers contained in a scheduling domain is often large, and different schedulers can execute different coroutine tasks. After the current scheduler completes a coroutine task, the next scheduler will then obtain and execute other coroutine tasks from the multi-priority queue group. At this time, the time interval since the previous scheduler completed the status monitoring is short, and it is not very meaningful to perform status monitoring again.

[0060] Therefore, before each scheduler monitors the status of a target scheduling domain, the executors contained in the target scheduling domain, and the coroutine tasks they execute, it can be judged whether the difference between the current time and the last monitoring time is greater than or equal to the set time threshold.

[0061] When the difference between the current time and the last monitoring time is greater than or equal to the set time threshold, the operation steps of monitoring the status of the target scheduling domain, the executors contained in the target scheduling domain, and the coroutine tasks they execute can be performed. When the difference between the current time and the last monitoring time is less than the set time threshold, there is no need to perform status monitoring at this time, and the coroutine tasks can be directly obtained and executed from the multi-priority queue group in the order of priority.

[0062] By detecting the time interval, it is possible to effectively avoid monitoring the status of the scheduling domain, as well as the actuators and coroutine tasks within the scheduling domain, multiple times within a short period, reducing the workload of the scheduler.

[0063] The scheduler can execute the coroutine tasks stored in the multi-priority queue group in order of priority. Based on requirements, the multi-priority queue group can be divided into a high-priority queue group, a medium-priority queue group, and a low-priority queue group. The number of queues included in each queue group is dynamically adjustable.

[0064] The total number of low-priority queues included in the low-priority queue group is greater than or equal to the total number of all actuators included in its affiliated scheduling domain. Each actuator is default-linked to a low-priority queue. Each high-priority queue in the high-priority queue group has its own corresponding high priority. Each medium-priority queue in the medium-priority queue group has its own corresponding weight; among them, the weights of the medium-priority queues are set according to the medium-priority weight and the queue weight.

[0065] The number of priority queues included in different priority queue groups can be preset according to resource requirements, and the number of priority queues can also be dynamically adjusted according to changes in requirements during actual operation.

[0066] For each high-priority queue in the high-priority queue group, its own corresponding priority can be set. For each medium-priority queue in the medium-priority queue group, its own corresponding priority can also be set. The priority of each low-priority queue in the low-priority queue group is low priority and can not be further subdivided.

[0067] In practical applications, numbers can be used to represent priorities. The larger the value of the number, the lower the priority. For example, the high-priority queue group contains 3 high-priority queues, and their priorities are 1, 2, and 3 respectively; the medium-priority queue group contains 3 medium-priority queues, and their priorities are 4, 5, and 6 respectively.

[0068] When the scheduler obtains coroutine tasks from the multi-priority queue group, it can determine whether there are high-priority coroutine tasks in the multi-priority queue group.

[0069] In the case of the existence of high-priority coroutine tasks, the coroutine tasks stored in each high-priority queue can be preferentially executed.

[0070] For high-priority queues, the coroutine tasks stored in each high-priority queue can be executed in the order of first-in, first-out.

[0071] In the case of the non-existence of high-priority coroutine tasks, the coroutine tasks in the medium-priority queue group can be executed.

[0072] For each medium-priority queue, there are differences in the priorities of each medium-priority queue. To avoid only executing the coroutine tasks in one medium-priority queue for a long time, resulting in the coroutine tasks in other medium-priority queues waiting for a long time, the number of tasks for each medium-priority queue can be set according to the weights.

[0073] In practical applications, the number of tasks for each medium-priority queue can be determined according to the total number of tasks included in the medium-priority queue group and the weights corresponding to each medium-priority queue. Execute the corresponding number of coroutine tasks for each medium-priority queue in sequence according to the number of tasks for each medium-priority queue.

[0074] The number of tasks for each medium-priority queue can be regarded as the number of coroutine tasks executed from each medium-priority queue in one round of traversal.

[0075] Use W to represent the priority, W(middle) to represent the priority of the medium-priority queue group, and W(low) to represent the priority of the low-priority queue group. The priority of the medium-priority queue group plus the priority of the low-priority queue group is equal to 1, that is, W(middle)+W(low)=1. Assume that w(i) represents the weight of the i-th priority queue. In the multi-priority queue group, the 4th to 6th priority queues are medium-priority queues, and the sum of the weights of all medium-priority queues in the medium-priority queue group is equal to 1, then In the multi-priority queue group, the 7th to nth priority queues are low-priority queues, and the sum of the weights of all low-priority queues in the low-priority queue group is equal to 1, then .

[0076] In a scheduling domain with n schedulers, the weights of each medium-priority queue are as follows: Q(i)=w(i)*W(middle).

[0077] C(sum) represents the total number of tasks in the current medium-priority queue group. Therefore, the number of tasks C(i) for each medium-priority queue in the medium-priority queue group in each round is equal to the total number of tasks multiplied by the weights of each medium-priority queue, that is, C(i)=C(sum)*Q(i).

[0078] In the embodiments of the present application, the higher the priority of a queue, the higher the corresponding weight can be set, so as to ensure that as many coroutine tasks with high priority as possible are processed. The number of tasks in each medium-priority queue is set according to the weight and the total number of tasks. After each time the coroutine tasks corresponding to the number of tasks in the current medium-priority queue are executed, the coroutine tasks in the next medium-priority queue can be executed. Even if there are a large number of coroutine tasks in a certain medium-priority queue, through the limitation of the number of tasks, in each round of loop, only the coroutine tasks corresponding to the number of tasks need to be executed to process the coroutine tasks in the next medium-priority queue, effectively avoiding the situation where the coroutine tasks in the medium-priority queue with low priority are not processed for a long time, and ensuring the timeliness of processing the coroutine tasks in each medium-priority queue.

[0079] The high-priority queue does not participate in the weight calculation. As long as there are coroutine tasks in the high-priority queue, they will be scheduled and executed immediately. The coroutine tasks in each medium-priority queue are executed according to the weight. The coroutine tasks in each low-priority queue can also be executed according to the weight. On this basis, the scheduler preferentially executes the coroutine tasks in the low-priority queue mapped by itself.

[0080] The number of tasks in each medium-priority queue is affected by its weight. The greater the weight, the more the corresponding number of tasks. However, in actual applications, there may be a situation where the actual number of coroutine tasks stored in the medium-priority queue is less than the corresponding number of tasks. For this situation, when the number of tasks in the target medium-priority queue has not been consumed and the coroutine tasks in the target medium-priority queue are empty, the scheduler executes the coroutine tasks in the next medium-priority queue adjacent to the target medium-priority queue. Among them, the target medium-priority queue can be any one of all medium-priority queues.

[0081] For example, assume that there are 8 coroutine tasks stored in a medium-priority queue, and the number of tasks in this medium-priority queue is 10. After the scheduler executes 8 coroutine tasks, the coroutine tasks in this medium-priority queue are empty, but there are still 2 tasks that have not been consumed. At this time, the scheduler can execute the coroutine tasks in the next medium-priority queue adjacent to this medium-priority queue. When all the coroutine tasks in all medium-priority queues are executed, the coroutine tasks in the low-priority queue group can be executed.

[0082] After each round of coroutine tasks in the medium-priority queue group is completed, the total number of coroutine tasks in the medium-priority queue group will change. In order to ensure the rationality of the number of tasks set in each medium-priority queue, after each round of coroutine tasks in the medium-priority queue group is executed, the number of tasks in each medium-priority queue can be adjusted.

[0083] After each round of execution of the coroutine tasks in the medium-priority queue group, the scheduler can count the total number of all remaining coroutine tasks in the medium-priority queue group; determine the latest task numbers of each medium-priority queue according to the total number of all remaining coroutine tasks and the weights corresponding to each medium-priority queue; execute the corresponding number of coroutine tasks in each medium-priority queue in sequence according to the latest task numbers of each medium-priority queue; until all coroutine tasks in the medium-priority queue group are completed.

[0084] In the embodiment of the present application, based on the change in the total number of coroutine tasks in the medium-priority queue group, the task numbers of each medium-priority queue are adjusted, so that the distribution of the task numbers can fit the total number of coroutine tasks in the medium-priority queue group, ensuring the rationality of the task number setting.

[0085] To reduce the conflicts among multiple schedulers when accessing the medium-priority queue, while setting the weight scheduling, the configuration of the concurrency number can be increased for each medium-priority queue. The corresponding concurrency numbers can be preset for different medium-priority queues, and in practical applications, the concurrency numbers corresponding to each medium-priority queue can also be dynamically adjusted.

[0086] The concurrency number refers to the number of schedulers accessing the medium-priority queue at the same time.

[0087] In the embodiment of the present application, when the number of schedulers accessing the target medium-priority queue reaches the concurrency number corresponding to the target medium-priority queue, the scheduler can select the coroutine tasks of the next priority queue to execute; if the number of schedulers of all medium-priority queues reaches their respective corresponding concurrency numbers, the coroutine tasks in the low-priority queue group can be executed.

[0088] Taking the medium-priority queue group including three medium-priority queues as an example, namely medium-priority queue (4), medium-priority queue (5) and medium-priority queue (6), assuming the concurrency number of medium-priority queue (4) is 3, it means that 3 schedulers are allowed to access medium-priority queue (4) at the same time. If there are already 3 schedulers accessing medium-priority queue (4), when the 4th scheduler accesses medium-priority queue (4), since the number of schedulers accessing medium-priority queue (4) is 3 and has reached the concurrency number corresponding to medium-priority queue (4), the 4th scheduler can access medium-priority queue (5), so as to execute the coroutine tasks in medium-priority queue (5).

[0089] Assume that the concurrency number of the medium-priority queue (4) is 3, the concurrency number of the medium-priority queue (5) is 2, and the concurrency number of the medium-priority queue (6) is 1. If there are already 3 schedulers accessing the medium-priority queue (4), 2 schedulers accessing the medium-priority queue (5), and 1 scheduler accessing the medium-priority queue (6). When the 7th scheduler accesses the medium-priority queue, since the number of schedulers accessing each medium-priority queue has reached the corresponding concurrency number of each medium-priority queue, the 7th scheduler can access the low-priority queue.

[0090] The concurrency number of each medium-priority queue can be configured and dynamically adjusted according to the actual business situation. The dynamic adjustment method can be dynamically adjusted according to the load situation, weight, and performance of the business.

[0091] In practical applications, the concurrency number of each medium-priority queue is first set according to the weight ratio of the medium-priority queue, and then this value can be enlarged or reduced proportionally according to the load, weight, and performance during the actual task execution stage.

[0092] In the embodiment of this application, two conditions, namely weight and concurrency number, are used to jointly determine which coroutine task on the medium-priority queue to execute. When the scheduler selects the coroutine task of the medium-priority queue, if the number of schedulers accessing this medium-priority queue reaches the concurrency number limit, then select the coroutine task of the next medium-priority queue to execute. If all the medium-priority queues have reached the concurrency number limit, then execute the coroutine task of the low-priority queue. This can not only ensure the priority execution of high-priority coroutine tasks, but also avoid the long-term unprocessed coroutine tasks on other priority queues, and improve the resource utilization rate.

[0093] To ensure the efficient operation of the medium priority, a monitoring module can be set. The background tasks included in the monitoring module can be controlled through configuration development. By using the method of interval sampling, monitor the conflict problems of each priority queue when multiple schedulers obtain coroutine tasks. During the interval sampling period, collect the average time-consuming for each scheduler to obtain the coroutine tasks on each priority queue, and perform statistics by classifying according to the priority queue. Determine whether it is necessary to adjust the concurrency number of each medium-priority queue according to the number of tasks processed during the sampling period and the acquisition time-consuming of the coroutine tasks in each medium-priority queue. If the ratio of the number of tasks processed by each medium-priority queue to the average time-consuming is relatively low, the monitoring module can reduce the concurrency number to achieve the goal of improving performance and helping developers debug the program.

[0094] Each scheduler has a default-linked low-priority queue. Therefore, when the scheduler obtains the execution permission of the coroutine tasks in the low-priority queue group, it can preferentially execute the coroutine tasks in the low-priority queue it is default-linked to.

[0095] Figure 3 A schematic diagram of the link relationship between multiple schedulers and a multi - priority queue group provided by an embodiment of the present application. Figure 3 Taking 3 schedulers as an example, the default queue of each scheduler is a low - priority queue in a multi - priority queue group. The multi - priority queue group is divided into a high - priority queue group, a medium - priority queue group, and a low - priority queue group. Figure 3 Taking each priority queue group as an example of containing 3 priority queues, there are a total of 9 priority queues, numbered from (1) to (9). For the high - priority queue group and the medium - priority queue group, the smaller the value of the corresponding label, the higher the priority level. And the priority levels of the low - priority queues in the low - priority queue group are the same.

[0096] Figure 3 In it, the default queue of the first scheduler is the low - priority queue (7), the default queue of the second scheduler is the low - priority queue (8), and the default queue of the third scheduler is the low - priority queue (9). When the first scheduler obtains the execution permission of the coroutine tasks in the low - priority queue group, it preferentially executes the coroutine tasks stored in the low - priority queue (7). When the second scheduler obtains the execution permission of the coroutine tasks in the low - priority queue group, it preferentially executes the coroutine tasks stored in the low - priority queue (8). When the third scheduler obtains the execution permission of the coroutine tasks in the low - priority queue group, it preferentially executes the coroutine tasks stored in the low - priority queue (9).

[0097] In the low - priority queue group, each low - priority queue has the same priority level. By setting the default queues of each scheduler to different low - priority queues, it ensures the balanced execution of the coroutine tasks on each low - priority queue in the low - priority queue group, avoiding the situation that all schedulers concentrate on executing the coroutine tasks on a certain low - priority queue, resulting in the coroutine tasks in other low - priority queues not being processed for a long time.

[0098] The high - priority queue group often contains multiple high - priority queues. To reduce the conflict situation caused by multiple schedulers accessing a high - priority queue simultaneously, a concurrency upper limit can be set for the high - priority queue. The concurrency upper limit refers to the upper limit value of the number of schedulers accessing the high - priority queue simultaneously.

[0099] In the embodiment of the present application, when the number of schedulers accessing the target high - priority queue reaches the concurrency upper limit corresponding to the target high - priority queue, the scheduler can select the coroutine tasks of the next - priority queue for execution.

[0100] For example, assume that the upper limit of the concurrency number of the high-priority queue is 3. Currently, 3 schedulers are already accessing this high-priority queue. If a 4th scheduler also comes to access this high-priority queue, since the number of schedulers accessing this high-priority queue has reached its corresponding upper limit of the concurrency number, the 4th scheduler can access the next priority queue adjacent to this high-priority queue.

[0101] When multiple schedulers access the same high-priority queue simultaneously, they often need to obtain coroutine tasks from the high-priority queue in sequence, which will cause multiple schedulers to queue and wait, and the coroutine tasks of other priority queues cannot be processed in a timely manner. By setting the upper limit of the concurrency number for the high-priority queue, it can effectively avoid conflicts caused by multiple schedulers accessing the same high-priority queue simultaneously, resulting in waste of resources.

[0102] After setting the upper limit of the concurrency number of the high-priority queue, the upper limit of the concurrency number of the high-priority queue can also be dynamically adjusted according to the changes in the actual situation.

[0103] In the embodiment of the present application, when the number of schedulers accessing the target high-priority queue is greater than the number of queues containing tasks, the current scheduler can calculate the difference between the number of schedulers accessing the target high-priority queue and the number of queues containing tasks. When the difference is less than or equal to the predefined value, the difference is used as the upper limit of the concurrency number; when the difference is greater than the predefined value, the predefined value is used as the upper limit of the concurrency number.

[0104] The value range of the upper limit of the concurrency number of each high-priority queue is [1, the number of executors in the scheduling domain].

[0105] In specific implementation, if the total number of schedulers accessing the high-priority queue is 1, the upper limit of the concurrency number of each high-priority queue is 1, and the scheduler obtains the coroutine tasks in each high-priority queue according to the priority. Only when the high-priority queue is empty can it obtain the coroutine tasks in the lower-level queue.

[0106] If the number of schedulers accessing the high-priority queue is less than or equal to the number of queues containing tasks, the upper limit of the concurrency number of each high-priority queue is 1, and the scheduler selects the coroutine tasks in the high-priority queue that has not reached the upper limit of the concurrency number according to the priority for execution.

[0107] The number of queues containing tasks refers to the number of high-priority queues containing coroutine tasks among all high-priority queues. For example, the high-priority queue group contains 5 high-priority queues, and 3 of them contain coroutine tasks, then the number of queues containing tasks is 3.

[0108] If the number of schedulers C(p) accessing the high-priority queue is greater than the number of queues C(q) containing tasks, the difference is denoted as C(n), and C(n) = C(p) - C(q). The upper limit of concurrency for each high-priority queue can be calculated dynamically. When 1 < C(n) <= the predefined value, the upper limit of concurrency takes the value of C(n); when C(n) > the predefined value, the upper limit of concurrency is the predefined value.

[0109] The value of the predefined value can be obtained through testing according to the actual business situation. The predefined value belongs to a configurable value. For example, in the initial state, the predefined value can be set to 3.

[0110] In the embodiment of the present application, by comparing the number of schedulers accessing the high-priority queue and the number of queues containing tasks, the adjustment of the upper limit of concurrency for the high-priority queue is realized, so that the upper limit of concurrency for each high-priority queue is set more reasonably, effectively reducing the situation of conflicts caused by multiple schedulers accessing the same high-priority queue simultaneously.

[0111] When the average value of the number of schedulers accessing all high-priority queues currently is greater than the predefined value, it means that each high-priority queue has its corresponding upper limit of concurrency schedulers executing. For the extra current schedulers, they can execute the coroutine tasks of the medium-priority queue group.

[0112] When a new coroutine task is received, the new coroutine task can be added to the matching position in the multi-priority queue group according to the priority of the new coroutine task.

[0113] When the new coroutine task is a high-priority coroutine task, the new coroutine task can be added to the high-priority queue in the high-priority queue group with the same priority as the new coroutine task.

[0114] When the new coroutine task is a medium-priority coroutine task, the new coroutine task can be added to the medium-priority queue in the medium-priority queue group with the same priority as the new coroutine task.

[0115] When the new coroutine task is a low-priority coroutine task, according to the preset low-priority task allocation strategy, the new coroutine task can be added to the low-priority queue in the low-priority queue group.

[0116] For low-priority coroutine tasks, to ensure the balance of coroutine tasks in the low-priority queue, the preset low-priority task allocation strategy can adopt methods such as polling or load balancing to add the new coroutine task to the corresponding low-priority queue.

[0117] In a specific implementation, when the new coroutine task is a low-priority coroutine task, the new coroutine task can be added to the low-priority queue polled this time in a polling manner. Or, the loads of each low-priority queue can be counted; the new coroutine task can be added to the low-priority queue with the smallest load.

[0118] The polling method is to add coroutine tasks to all low-priority queues in turn. The load method is to select a low-load priority queue from all low-priority queues and add the coroutine task to it.

[0119] In practical applications, there may be a situation where the new coroutine task does not have a priority. For the situation where the new coroutine task does not have a priority, the new coroutine task can be set to the default priority, so that the new coroutine task can be added to the appropriate position in the multi-priority queue group.

[0120] To ensure the correctness of the execution of coroutine tasks, status query and statistics functions can be added to the scheduling domain, executor, and scheduler.

[0121] The status query and statistics functions added to the scheduling domain can query the configuration of the scheduling domain, the number of executors under the current scheduling domain, the number of queues included in the multi-priority queue group in the scheduling domain, the number of coroutine tasks existing in the multi-priority queue group, the number of coroutine tasks existing in the storage module, the status of the current scheduler, etc. The status of the current scheduler can include whether there is an executor in an abnormal state, whether there have been coroutine tasks migrated from other scheduling domains, etc.

[0122] The status query and statistics functions added to the executor can query the status of the executor, the number of coroutine tasks executed by the current scheduler, whether there has been a switch of the executor to a different scheduling domain, the creation time of the executor, etc.

[0123] The status query and statistics functions added to the scheduler can query the status, creation time, execution times, etc. of the coroutine tasks in each priority queue; it can query the number of coroutine tasks and the task status in the storage module.

[0124] Figure 4 FIG. is a schematic structural diagram of a coroutine scheduling device provided for an embodiment of the present application, which is applicable to a scheduler. The device includes an access unit 41, a mounting unit 42, an execution unit 43, a monitoring unit 44, and a migration unit 45; The access unit 41 is used to access the storage module corresponding to the target scheduling domain; wherein, the target scheduling domain is correspondingly provided with a multi-priority queue group; the multi-priority queue group is used to store the first coroutine tasks to be executed in the target scheduling domain; the storage module is used to store the second coroutine tasks regularly executed in the scheduling domain corresponding to it; the execution period of the first coroutine task is less than the execution period of the second coroutine task; A mounting unit 42, configured to mount an expired second coroutine task to a multi-priority queue group when there is an expired second coroutine task in the storage module; wherein, the multi-priority queue group is used to store first coroutine tasks to be executed in its corresponding scheduling domain; An execution unit 43, configured to obtain and execute coroutine tasks from the multi-priority queue group in the order of priority; A monitoring unit 44, configured to monitor the running state and load state of each scheduling domain during the stage of obtaining and executing coroutine tasks; A migration unit 45, configured to perform task migration of each scheduling domain according to the running state and load state of each scheduling domain.

[0125] For the omitted content of the virtual device claim, it should be described in detail in the specification and corresponding to the method claim one by one.

[0126] For the description of the features in the embodiments corresponding to the coroutine scheduling device, reference can be made to the relevant description of the embodiments corresponding to the coroutine scheduling method, which will not be elaborated here one by one.

[0127] It can be seen from the above technical solutions that the scheduler accesses the storage module corresponding to the target scheduling domain; wherein, the target scheduling domain is correspondingly provided with a multi-priority queue group; the multi-priority queue group is used to store first coroutine tasks to be executed in the target scheduling domain; the storage module is used to store second coroutine tasks that are regularly executed in the target scheduling domain; the execution period of the first coroutine task is less than the execution period of the second coroutine task. There is at least one executor under each scheduling domain, and each executor is bound to at least one processor core. By binding the required processor cores for each scheduling domain, the purpose of dividing the processor core resources is achieved, effectively improving the utilization rate of processor resources and enhancing the service efficiency. Each executor is built-in with a scheduler. When there is an expired second coroutine task in the storage module, the scheduler mounts the expired second coroutine task to the multi-priority queue group. Wherein, the multi-priority queue group is used to store first coroutine tasks to be executed in its corresponding scheduling domain. By dividing the multi-priority queue group and the storage module, the first coroutine task and the second coroutine task can be effectively distinguished, and the second coroutine task is only put into the multi-priority queue group when it expires, effectively avoiding the situation where batch tasks have not reached the execution time and tasks with lower priorities cannot be executed. By designing the multi-priority queue group, it can be ensured that tasks with higher priorities obtain execution resources first, reducing the tail latency. During the stage of obtaining and executing coroutine tasks, the scheduler can monitor the running state and load state of each scheduling domain; according to the running state and load state of each scheduling domain, perform task migration of each scheduling domain, enhancing the robustness of the service and optimizing the resource utilization rate.

[0128] Figure 5A structural schematic diagram of a coroutine scheduling system provided by an embodiment of the present application, including at least one scheduling domain 1, and there is at least one executor 2 under each scheduling domain 1. The executor 2 can migrate among different scheduling domains 1.

[0129] Considering that the second coroutine task often has a specific execution time and a relatively long execution time. If it is directly placed in the multi-priority queue group 3 according to the priority, it will cause the coroutine tasks with lower priority than it to not be processed for a long time when the second coroutine task has not reached its execution time. Therefore, in the embodiment of the present application, in order to better process different types of tasks, a multi-priority queue group 3 and a storage module 4 can be set for each scheduling domain 1. Figure 5 Taking two scheduling domains as an example.

[0130] Taking any scheduling domain in each scheduling domain, that is, the target scheduling domain as an example, the multi-priority queue group 3 is used to store the first coroutine tasks to be executed in the target scheduling domain; the storage module 4 is used to store the second coroutine tasks that are regularly executed in the target scheduling domain; the execution period of the first coroutine task is less than the execution period of the second coroutine task.

[0131] The executor 2 is used to access the storage module 4; in the case where there is an expired second coroutine task in the storage module 4, the expired second coroutine task is mounted to the multi-priority queue group 3; the coroutine tasks are obtained and executed from the multi-priority queue group 3 in the order of priority; during the stage of obtaining and executing the coroutine tasks, the running state and load state of each scheduling domain 1 are monitored; according to the running state and load state of each scheduling domain 1, task migration of each scheduling domain 1 is performed.

[0132] Each executor 2 is built-in with a scheduler 21. There are multiple executors 2 in the scheduling domain 1. When each executor 2 executes a task, it judges whether there is an expired coroutine task in the storage module 4 through the scheduler 21. If there is an expired coroutine task, the coroutine task is hung in the multi-priority queue group 3. The scheduler 21 in the executor 2 is responsible for obtaining and executing the coroutine tasks from the multi-priority queue group.

[0133] In practical applications, the scheduler 21 can access the storage module 4 corresponding to the target scheduling domain; in the case where there is an expired second coroutine task in the storage module 4, the expired second coroutine task is mounted to the multi-priority queue group 3; the coroutine tasks are obtained and executed from the multi-priority queue group 3 in the order of priority.

[0134] By executing the coroutine tasks in the order of priority, it can ensure that the coroutine tasks with higher priority are executed first, effectively avoiding the situation where the coroutine tasks with lower priority preempt resources.

[0135] In the stage of obtaining and executing coroutine tasks, the scheduler 21 can monitor the running status and load status of each scheduling domain 1; according to the running status and load status of each scheduling domain 1, task migration of each scheduling domain 1 can be performed.

[0136] The coroutine and the scheduler 21 belong to different stacks. The scheduler 21 can obtain coroutine tasks from the multi-priority queue group. When the coroutine returns to the scheduler 21, the stack will be switched, and at this time, the scheduler 21 can automatically perform status monitoring.

[0137] The scheduler 21 can monitor the running status and load status of the scheduling domain 1. The running status can include a normal state and an abnormal state. The load status can include a high-load state, a normal-load state, and a low-load state. In practical applications, the respective value ranges corresponding to the high-load state, the normal-load state, and the low-load state can be preset in advance. By comparing the load value of the scheduling domain 1 with the preset value range, the load status can be determined. Among them, the load value of the scheduling domain 1 can be the number of all coroutine tasks included in the scheduling domain 1.

[0138] Generally, the coroutine tasks executed in different scheduling domains 1 are different. However, due to the particularity of the coroutine tasks, the executor 2 in the scheduling domain 1 can also execute the coroutine tasks in other scheduling domains 1. For the scheduling domain in the abnormal state, its corresponding coroutine tasks can be transferred to the scheduling domain in the normal state and the low-load state.

[0139] As can be seen from the above technical solution, the coroutine scheduling system divides different scheduling domains. There is at least one executor under each scheduling domain, and each executor is bound to at least one processor core. The target scheduling domain is correspondingly provided with a multi-priority queue group. The multi-priority queue group is used to store the first coroutine tasks to be executed in its corresponding scheduling domain. The storage module is used to store the second coroutine tasks that are regularly executed in its corresponding scheduling domain. By dividing multiple scheduling domains, the coroutine tasks are divided into different scheduling domains for execution, achieving the purpose of dividing the processor core resources, effectively improving the utilization rate of the processor resources, and improving the service efficiency. By dividing the multi-priority queue group and the storage module, the first coroutine tasks and the second coroutine tasks can be effectively distinguished. Only when the second coroutine task expires, it is put into the multi-priority queue group, effectively avoiding the situation that batch tasks have not reached the execution time, resulting in tasks with lower priorities not being able to be executed. Each executor is built-in with a scheduler; the scheduler is used to access the storage module corresponding to the target scheduling domain; in the case where there are expired second coroutine tasks in the storage module, the expired second coroutine tasks are mounted to the multi-priority queue group; the coroutine tasks are obtained and executed from the multi-priority queue group in the order of priority. By designing the multi-priority queue group, it can be ensured that tasks with higher priorities obtain execution resources first, reducing the tail latency. During the stage of obtaining and executing the coroutine tasks, the scheduler can monitor the running state and load state of the scheduling domain; according to the running state and load state of each scheduling domain, the task migration of each scheduling domain is performed, improving the robustness of the service and optimizing the resource utilization rate.

[0140] An embodiment of the present application further provides an electronic device, including a memory and a processor. A computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any of the above embodiments of the coroutine scheduling method.

[0141] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps in any of the above embodiments of the coroutine scheduling method when running.

[0142] In an exemplary embodiment, the above computer-readable storage medium may include, but is not limited to: USB flash drive, read-only memory (abbreviated as ROM), random access memory (abbreviated as RAM), mobile hard disk, magnetic disk or optical disc and other various media that can store computer programs.

[0143] An embodiment of the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, it implements the steps in any of the above embodiments of the coroutine scheduling method.

[0144] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium storing a computer program, and when the computer program is executed by a processor, the steps in any of the above-described embodiments of the coroutine scheduling method are implemented.

[0145] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.

[0146] The above has introduced in detail a coroutine scheduling method, device, system, equipment, storage medium, and product provided by the present application. Specific examples are used herein to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application. It should be noted that for those of ordinary skill in the art in the technical field, without departing from the principle of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the protection scope of the claims of the present application.

Claims

1. A coroutine scheduling method, characterized in that, Including: Accessing a storage module corresponding to a target scheduling domain; wherein, the target scheduling domain is correspondingly provided with a multi-priority queue group; the multi-priority queue group is used to store first coroutine tasks to be executed in the target scheduling domain; the storage module is used to store second coroutine tasks regularly executed in the target scheduling domain; the execution period of the first coroutine task is less than the execution period of the second coroutine task; When there is an expired second coroutine task in the storage module, mounting the expired second coroutine task to the multi-priority queue group; Obtaining and executing coroutine tasks from the multi-priority queue group in the order of priority; During the stage of obtaining and executing the coroutine tasks, monitoring the running status and load status of each scheduling domain; wherein, the target scheduling domain is any one of the scheduling domains; Performing task migration for each of the scheduling domains according to the running status and load status of each of the scheduling domains.

2. The coroutine scheduling method according to claim 1, wherein, The obtaining and executing coroutine tasks from the multi-priority queue group in the order of priority includes: Using an executor included in the target scheduling domain to obtain and execute coroutine tasks from the multi-priority queue group in the order of priority.

3. The coroutine scheduling method according to claim 2, wherein Monitoring the running status and load status of each scheduling domain; Performing task migration for each of the scheduling domains according to the running status and load status of each of the scheduling domains includes: Monitoring the status of the target scheduling domain, the executor included in the target scheduling domain, and the coroutine tasks executed by it, and recording the monitoring time; When the target scheduling domain has an abnormal status, migrating the coroutine tasks stored in the multi-priority queue group and the storage module corresponding to the target scheduling domain to a scheduling domain with a normal status and meeting the load requirements; When there is an abnormal target executor, invoking a normal-status executor from other scheduling domains that meet the load requirements; When there is an abnormal target coroutine task, generating a coroutine alarm message.

4. The coroutine scheduling method according to claim 3, wherein, Before monitoring the status of the target scheduling domain, the executor included in the target scheduling domain, and the coroutine tasks executed by it, it further includes: Judging whether the difference between the current time and the last monitoring time is greater than or equal to a set time threshold; When the difference between the current time and the last monitoring time is greater than or equal to the set time threshold, performing the operation steps of monitoring the status of the target scheduling domain, the executor included in the target scheduling domain, and the coroutine tasks executed by it.

5. The coroutine scheduling method according to claim 1, wherein The multi-priority queue group includes a high-priority queue group, a medium-priority queue group, and a low-priority queue group; The obtaining and executing coroutine tasks from the multi-priority queue group in the order of priority includes: Judging whether there are high-priority coroutine tasks in the high-priority queue group; When there are high-priority coroutine tasks, preferentially executing the coroutine tasks stored in each high-priority queue; When there are no high-priority coroutine tasks, determining the number of tasks in each medium-priority queue according to the total number of tasks included in the medium-priority queue group and the weights corresponding to each medium-priority queue; Executing the corresponding number of coroutine tasks in each medium-priority queue according to the number of tasks in each medium-priority queue; When obtaining the execution permission of the coroutine tasks in the low-priority queue group, preferentially execute the coroutine tasks in the low-priority queue with which it is default-linked.

6. The coroutine scheduling method according to claim 5, wherein The step of executing the corresponding number of coroutine tasks for each medium-priority queue according to the number of tasks in each medium-priority queue includes: When the number of tasks in the target medium-priority queue has not been exhausted and the coroutine tasks in the target medium-priority queue are empty, then execute the coroutine tasks in the next medium-priority queue adjacent to the target medium-priority queue; wherein, the target medium-priority queue is any one of the medium-priority queues.

7. The coroutine scheduling method according to claim 6, wherein It further includes: Every time a round of coroutine tasks in the medium-priority queue group is executed, count the total number of remaining coroutine tasks in the medium-priority queue group; According to the total number of remaining coroutine tasks and the respective weights corresponding to each medium-priority queue, determine the latest number of tasks for each medium-priority queue; Execute the corresponding number of coroutine tasks for each medium-priority queue according to the latest number of tasks for each medium-priority queue until all coroutine tasks in the medium-priority queue group are completed.

8. The coroutine scheduling method according to claim 7, wherein Before successively executing the corresponding number of coroutine tasks for each medium-priority queue according to the latest number of tasks for each medium-priority queue, it further includes: When the number of schedulers accessing the target medium-priority queue reaches the concurrency number corresponding to the target medium-priority queue, select the coroutine tasks of the next medium-priority queue to execute; if the number of schedulers accessing all medium-priority queues reaches their respective corresponding concurrency numbers, then execute the coroutine tasks in the low-priority queue group; wherein, the scheduler is a module included in the executor in the target scheduling domain and is used to obtain coroutine tasks from the multi-priority queue group.

9. The coroutine scheduling method according to claim 5, wherein It further includes: When the number of schedulers accessing the target high-priority queue reaches the upper limit of the concurrency number corresponding to the target high-priority queue, select the coroutine tasks of the next high-priority queue to execute; wherein, the target high-priority queue is any one of the high-priority queues; the scheduler is a module included in the executor in the target scheduling domain and is used to obtain coroutine tasks from the multi-priority queue group.

10. The coroutine scheduling method according to claim 9, wherein, Regarding the determination of the upper limit of the concurrency number, the method further includes: When the number of schedulers accessing the target high-priority queue is greater than the number of queues with tasks, calculate the difference between the number of schedulers accessing the target high-priority queue and the number of queues with tasks; When the difference is less than or equal to the predefined value, use the difference as the upper limit of the concurrency number; When the difference is greater than the predefined value, use the predefined value as the upper limit of the concurrency number.

11. The coroutine scheduling method according to claim 10, wherein It further includes: When the average value of the number of schedulers accessing all high-priority queues currently is greater than the predefined value, execute the coroutine tasks of the medium-priority queue group.

12. The coroutine scheduling method according to claim 1, wherein It further includes: When receiving new coroutine tasks, according to the priorities of the new coroutine tasks, add the new coroutine tasks to the matching positions in the multi-priority queue group.

13. The coroutine scheduling method according to claim 12, wherein, The multi-priority queue group includes a high-priority queue group, a medium-priority queue group, and a low-priority queue group; Adding the new coroutine task to a corresponding position in the multi-priority queue group according to the priority of the new coroutine task includes: When the new coroutine task is a high-priority coroutine task, adding the new coroutine task to a high-priority queue in the high-priority queue group with the same priority as the new coroutine task; When the new coroutine task is a medium-priority coroutine task, adding the new coroutine task to a medium-priority queue in the medium-priority queue group with the same priority as the new coroutine task; When the new coroutine task is a low-priority coroutine task, adding the new coroutine task to a low-priority queue in the low-priority queue group according to a preset low-priority task allocation strategy.

14. The coroutine scheduling method according to claim 13, wherein The step of adding the new coroutine task to a low-priority queue in the low-priority queue group according to a preset low-priority task allocation strategy includes: Adding the new coroutine task to the low-priority queue polled this time in a polling manner.

15. The coroutine scheduling method according to claim 13, wherein, The step of adding the new coroutine task to a low-priority queue in the low-priority queue group according to a preset low-priority task allocation strategy includes: Counting the loads of each low-priority queue; Adding the new coroutine task to the low-priority queue with the smallest load.

16. A coroutine scheduling device, characterized in that, Including an access unit, a mounting unit, an execution unit, a monitoring unit, and a migration unit; The access unit is used to access a storage module corresponding to a target scheduling domain; wherein, the target scheduling domain is correspondingly provided with a multi-priority queue group; the multi-priority queue group is used to store first coroutine tasks to be executed in the target scheduling domain; the storage module is used to store second coroutine tasks regularly executed in the target scheduling domain; the execution period of the first coroutine task is less than the execution period of the second coroutine task; The mounting unit is used to mount the expired second coroutine task to the multi-priority queue group when there is an expired second coroutine task in the storage module; The execution unit is used to obtain and execute coroutine tasks from the multi-priority queue group in the order of priority; The monitoring unit is used to monitor the running state and load state of each scheduling domain during the stage of obtaining and executing the coroutine task; wherein, the target scheduling domain is any one of the scheduling domains; The migration unit is used to perform task migration of each scheduling domain according to the running state and load state of each scheduling domain.

17. A coroutine scheduling system, characterized in that, Including at least one scheduling domain, there is at least one executor under each scheduling domain, and each executor is bound to at least one processor core; The target scheduling domain is any one of the scheduling domains; The target scheduling domain is correspondingly provided with a multi-priority queue group; The multi-priority queue group is used to store first coroutine tasks to be executed in the target scheduling domain; The storage module is used to store second coroutine tasks regularly executed in the target scheduling domain; wherein, the execution period of the first coroutine task is less than the execution period of the second coroutine task; The actuator is used to access the storage module; when there is an expired second coroutine task in the storage module, mount the expired second coroutine task to the multi-priority queue group; Obtain and execute coroutine tasks from the multi-priority queue group in the order of priority; during the stage of obtaining and executing the coroutine tasks, monitor the running status and load status of each scheduling domain; according to the running status and load status of each scheduling domain, perform task migration of each scheduling domain.

18. An electronic device, characterized in that, It includes: A memory for storing computer programs; A processor for implementing the steps of the coroutine scheduling method according to any one of claims 1 to 15 when executing the computer program.

19. A computer-readable storage medium, characterized in that, A computer program is stored in the computer-readable storage medium, wherein the computer program implements the steps of the coroutine scheduling method according to any one of claims 1 to 15 when executed by a processor.

20. A computer program product, comprising a computer program, characterized in that, The computer program implements the steps of the coroutine scheduling method according to any one of claims 1 to 15 when executed by a processor.

Citation Information

Patent Citations

  • High-availability task processing control model in parallel computing environment

    CN107621978A

  • Task scheduling method and device

    CN110955503A

  • Task scheduling method and device, storage medium and terminal

    CN112286661A

  • Timed task scheduling method and device, equipment and storage medium

    CN116820697A

  • Task scheduling method and device

    CN117234691A

Cited By

  • Timer event processing method and device, medium, program and server system

    CN120849067A

  • Shared resource access method and device, equipment, medium and product

    CN121029442A