A method, system and device for co-process scheduling based on multi-core working threads

By establishing a coroutine queue for each IO thread and calculating the scheduling priority value, the IO coroutine is allocated to multiple cores, which solves the problem that the coroutine cannot fully utilize the CPU capabilities under the multi-core architecture and improves the IO efficiency of the smart hydropower station.

CN117519931BActive Publication Date: 2024-10-11CHINA THREE GORGES CORPORATION +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311490773.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-09
Publication Date
2024-10-11
Estimated Expiration
2043-11-09

AI Technical Summary

Technical Problem

Under a multi-core architecture, coroutines cannot fully utilize the computing power of multiple CPU cores, resulting in low IO operation efficiency. Especially in IO data-intensive applications such as smart hydropower stations, the performance bottleneck is concentrated at the IO level.

Method used

Establish a coroutine queue for each IO thread and an IO coroutine for each IO task. Calculate the scheduling priority value by obtaining the response ratio, number of coroutines and core load index of each IO coroutine relative to different coroutine queues. , allocate IO coroutines to different coroutine queues to fully utilize multi-core capabilities.

Benefits of technology

It improves the operating efficiency of IO operations, maximizes hardware performance, realizes full utilization of multi-core capabilities, and solves the problem of low IO efficiency in existing technologies.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117519931B_ABST
    Figure CN117519931B_ABST
Patent Text Reader

Abstract

The present invention relates to a coroutine scheduling method, system and device based on a multi-core working thread, which respectively establishes a coroutine queue for each IO thread running on different cores, and simultaneously establishes an IO coroutine for each IO task, and then obtains the response ratio of each IO coroutine relative to different coroutine queues, the number of IO coroutines already existing in each coroutine queue and the load index of each core, and obtains the scheduling priority value of each IO coroutine relative to different coroutine queues, and finally allocates multiple IO coroutines to different coroutine queues according to the scheduling priority value of each IO coroutine relative to different coroutine queues. Compared with the prior art, the present invention solves the problem of how to improve IO efficiency by using multi-core capabilities and coroutine concepts in the prior art, maximizes the hardware performance and makes full use of multi-core capabilities, and improves the IO efficiency of smart hydropower stations.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of intelligent controller system design, and in particular to a coroutine scheduling method, system and device based on multi-core working threads. Background Art

[0002] With the development of computer technology, processes, threads and coroutines have become indispensable concepts in modern computing. A process is an instance of a program running in a computer, a thread is the smallest execution unit scheduled by the operating system, and a coroutine is a more lightweight thread with independent execution flow and context switching capabilities. Coroutines are particularly suitable for handling multiple IO situations, and can avoid the overhead of frequent thread switching.

[0003] However, in the current multi-core architecture, multi-core processors have become a mature technology. Although a thread can contain multiple coroutines and can switch between these coroutines, these coroutines are still executed serially and can only run in one thread, which cannot fully utilize the computing power of the CPU's multi-core.

[0004] In the fields of smart hydropower stations, IO data-intensive applications are very common. For example, monitoring equipment obtains data through sensors, control systems send instructions through actuators, and remote operations require network communication. These IO operations require constant interaction with external devices, resulting in the system's performance bottleneck being mainly concentrated at the IO level. Therefore, how to design a coroutine scheduling method based on multi-core working threads to maximize hardware performance and make full use of multi-core capabilities has become a problem that technicians in this field are eager to solve. Summary of the invention

[0005] In view of this, it is necessary to provide a coroutine scheduling method, system and device based on multi-core working threads to solve the problem of how to use multi-core capabilities and coroutine concepts to improve IO efficiency in the prior art.

[0006] In order to achieve the above technical objectives, the present invention adopts the following technical solutions:

[0007] In a first aspect, the present invention provides a coroutine scheduling method based on a multi-core worker thread, comprising:

[0008] Create a coroutine queue for each IO thread, and each IO thread runs on a different core;

[0009] Get multiple IO tasks and create an IO coroutine for each IO task;

[0010] Get the response ratio of each IO coroutine relative to different coroutine queues, the number of existing IO coroutines in each coroutine queue, and the load index of each core, and get the scheduling priority value of each IO coroutine relative to different coroutine queues;

[0011] According to the scheduling priority value of each IO coroutine relative to different coroutine queues, multiple IO coroutines are assigned to different coroutine queues.

[0012] Furthermore, the step of obtaining the response ratio of each IO coroutine relative to different coroutine queues, the number of existing IO coroutines in each coroutine queue, and the load index of each core, and obtaining the scheduling priority value of each IO coroutine relative to different coroutine queues includes:

[0013] Obtaining a response ratio of a target IO coroutine relative to a target coroutine queue, wherein the target IO coroutine is an IO coroutine currently to be analyzed, and the target coroutine queue is a coroutine queue currently to be analyzed;

[0014] Obtain the number of IO coroutines existing in the target coroutine queue as a first value, and the total number of coroutines existing in the core running the IO thread corresponding to the target coroutine queue as a second value, and obtain the IO coroutine ratio according to the ratio of the first value to the second value;

[0015] Obtain the load index of the core running the IO thread corresponding to the target coroutine queue;

[0016] According to the response ratio of the target IO coroutine relative to the target coroutine queue, the IO coroutine proportion, and the load index of the core running the IO thread corresponding to the target coroutine queue, the scheduling priority value of the target IO coroutine relative to the target coroutine queue is obtained.

[0017] Furthermore, the scheduling priority value of the target IO coroutine relative to the target coroutine queue is obtained by the following formula:

[0018]

[0019] in, is the scheduling priority value of the target IO coroutine relative to the target coroutine queue, is the response ratio of the target IO coroutine relative to the target coroutine queue, is the proportion of IO coroutines, is the load index of the core running the IO thread corresponding to the target coroutine queue, , and They are different weight coefficients respectively.

[0020] Further, obtaining the response ratio of the target IO coroutine relative to the target coroutine queue includes:

[0021] Obtain the number of existing IO coroutines in the target coroutine queue and the service time of the target IO coroutine;

[0022] According to the number of IO coroutines existing in the target coroutine queue and the service time of the target IO coroutine, a response ratio of the target IO coroutine relative to the target coroutine queue is obtained.

[0023] Furthermore, the response ratio of the target IO coroutine relative to the target coroutine queue is obtained by the following formula:

[0024]

[0025] in, is the number of IO coroutines that already exist in the target coroutine queue, is the service time of the target IO coroutine, and They are different unit adjustment factors.

[0026] Furthermore, the load index is the CPU usage of the core.

[0027] Furthermore, allocating multiple IO coroutines to different coroutine queues according to the scheduling priority value of each IO coroutine relative to different coroutine queues includes:

[0028] Acquire multiple scheduling priority values ​​of the target IO coroutine relative to multiple coroutine queues as multiple target scheduling priority values, and compare the sizes of the multiple target scheduling priority values;

[0029] If there is a unique maximum target scheduling priority value, the target IO coroutine is assigned to the coroutine queue corresponding to the maximum target scheduling priority value;

[0030] If there are multiple identical maximum target scheduling priority values, the target IO coroutine is assigned to the coroutine queue that was most recently assigned the IO coroutine among the multiple coroutine queues corresponding to the multiple identical maximum target scheduling priority values.

[0031] In a second aspect, the present invention further provides a coroutine scheduling system based on a multi-core working thread, comprising:

[0032] The thread pool creation module is used to create a coroutine queue for each IO thread, and each IO thread runs on a different core;

[0033] The coroutine pool creation module is used to obtain multiple IO tasks and establish an IO coroutine for each IO task;

[0034] The priority value analysis module is used to obtain the response ratio of each IO coroutine relative to different coroutine queues, the number of existing IO coroutines in each coroutine queue, and the load index of each core, and obtain the scheduling priority value of each IO coroutine relative to different coroutine queues;

[0035] The coroutine scheduling module is used to allocate multiple IO coroutines to different coroutine queues according to the scheduling priority value of each IO coroutine relative to different coroutine queues.

[0036] In a third aspect, the present invention further provides an electronic device, including a memory and a processor, wherein:

[0037] Memory, used to store programs;

[0038] The processor is coupled to the memory and is used to execute the program stored in the memory to implement the steps in the coroutine scheduling method based on multi-core working threads in any of the above implementations.

[0039] In a fourth aspect, the present invention also provides a computer-readable storage medium for storing computer-readable programs or instructions. When the program or instructions are executed by a processor, the steps of the coroutine scheduling method based on multi-core working threads in any of the above-mentioned implementation methods can be implemented.

[0040] The present invention provides a coroutine scheduling method, system and device based on multi-core working threads, which respectively establishes a coroutine queue for each IO thread running on different cores, and establishes an IO coroutine for each IO task, and then obtains the response ratio of each IO coroutine relative to different coroutine queues, the number of existing IO coroutines in each coroutine queue and the load index of each core, and obtains the scheduling priority value of each IO coroutine relative to different coroutine queues, and finally allocates multiple IO coroutines to different coroutine queues according to the scheduling priority value of each IO coroutine relative to different coroutine queues. Compared with the prior art, the present invention equips each IO thread with a coroutine queue, analyzes the response ratio, the number of existing IO coroutines and the load index, and evenly allocates multiple IO coroutines to multiple IO threads through the scheduling priority value. The operating efficiency of IO is improved by means of coroutine scheduling. Most importantly, most of the steps of the present invention can be run in user mode. The allocation of IO coroutines can be completed before the IO thread starts running. At the same time, at least one IO thread is allocated to each core, so that multiple cores can execute IO functions without thread switching. By allocating coroutine queues, cross-core scheduling of IO coroutines is virtualized without the need for actual cross-core thread switching, which solves the problem of how to use multi-core capabilities and coroutine concepts to improve IO efficiency in the prior art, maximizes hardware performance and makes full use of multi-core capabilities, and improves the IO efficiency of smart hydropower stations. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 A method flow chart of an embodiment of a coroutine scheduling method based on a multi-core working thread provided by the present invention;

[0042] Figure 2 for Figure 1 A method flow chart of an embodiment of step S103;

[0043] Figure 3 A system architecture diagram of an embodiment of a coroutine scheduling system based on multi-core working threads provided by the present invention;

[0044] Figure 4 A schematic structural diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0045] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings, wherein the accompanying drawings constitute a part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not used to limit the scope of the present invention.

[0046] It is understandable that the technical terms, English abbreviations, etc. that appear in the following text are all prior art, and those skilled in the art can understand their meanings based on the context, and will not be explained in detail in this article due to space constraints.

[0047] In the description of the present application, “plurality” means two or more than two, unless otherwise clearly and specifically defined.

[0048] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0049] The present invention provides a coroutine scheduling method, system, device and storage medium based on multi-core working threads, which are described below respectively.

[0050] Combination Figure 1 As shown, a specific embodiment of the present invention discloses a coroutine scheduling method based on a multi-core working thread, including:

[0051] S101. Establish a coroutine queue for each IO thread, and each IO thread runs on a different core.

[0052] S102, obtaining multiple IO tasks, and establishing an IO coroutine for each IO task;

[0053] S103, obtaining the response ratio of each IO coroutine relative to different coroutine queues, the number of existing IO coroutines in each coroutine queue, and the load index of each core, and obtaining the scheduling priority value of each IO coroutine relative to different coroutine queues;

[0054] S104. Allocate multiple IO coroutines to different coroutine queues according to the scheduling priority value of each IO coroutine relative to different coroutine queues.

[0055] Compared with the prior art, the present invention equips each IO thread with a coroutine queue, analyzes the response ratio, the number of existing IO coroutines and the load index, and evenly distributes multiple IO coroutines to multiple IO threads through the scheduling priority value. The operation efficiency of IO is improved by the coroutine scheduling method. Most importantly, most of the steps of the present invention can be run in user mode, and the allocation of IO coroutines can be completed before the IO thread starts running. At the same time, at least one IO thread is allocated to each core, so that multiple cores can perform IO functions without thread switching. By allocating coroutine queues, cross-core scheduling of IO coroutines is virtualized without the need for actual cross-core thread switching, which solves the problem of how to use multi-core capabilities and coroutine concepts to improve IO efficiency in the prior art, maximizes hardware performance and fully utilizes multi-core capabilities, and improves the IO efficiency of smart hydropower stations.

[0056] In the above steps S101-S102, the IO thread is a thread responsible for processing input and output (IO) operations, and its main function is to read and write data. The above are common IO thread types, and different types of IO threads are created and managed by different system components or applications. The goal of these threads is to improve the performance and response speed of the system and ensure effective IO operations and data transmission.

[0057] On the other hand, in smart hydropower plants, IO tasks include the following:

[0058] 1. Sensor data collection tasks: Smart hydropower stations will install various sensors for real-time data detection and collection, such as water level sensors, flow sensors, temperature sensors, pressure sensors, etc. IO tasks include reading and processing sensor information and transmitting the collected data to the controller or database.

[0059] 2. Real-time monitoring task: The controller of the smart hydropower station will read sensor data to monitor the reservoir water level, flow, water temperature and other operating status information in real time, and make judgments and analyses through built-in algorithms to accurately calculate the power generation to achieve efficient use of water resources.

[0060] 3. Data transmission tasks: Information needs to be exchanged between multiple devices in a smart hydropower station, such as measuring equipment, controllers, dispatch centers, etc. IO tasks include data transmission and processing, transferring data from sensor interfaces to databases, cloud services, or real-time control and alarm systems.

[0061] 4. Control tasks: The dispatching control of the hydropower station should have certain fairness, priority weight and other settings. IO tasks include the controller's control operations on water conservancy projects such as gates, water pumps, generators, and the controller's collection, calculation and dynamic dispatch after real-time judgment of data such as water level, flow, and water temperature.

[0062] 5. Alarm task: The smart hydropower station will make real-time judgments on the monitoring data based on the preset thresholds. Once an abnormal situation occurs (such as the water level exceeds the safe range, the water pressure is too high, or there is a flow change), an alarm will be issued, requiring the operator to handle it in time to ensure the safety and operation of the hydropower station.

[0063] It is understandable that the above steps S101 and S102 are both existing technologies that can be understood and implemented by those skilled in the art, and therefore will not be described in detail herein.

[0064] Further, combined with Figure 2 As shown, in a preferred embodiment, the above step S103, obtaining the response ratio of each IO coroutine relative to different coroutine queues, the number of IO coroutines existing in each coroutine queue and the load index of each core, and obtaining the scheduling priority value of each IO coroutine relative to different coroutine queues, includes:

[0065] S201, obtaining a response ratio of a target IO coroutine relative to a target coroutine queue, wherein the target IO coroutine is an IO coroutine to be analyzed currently, and the target coroutine queue is a coroutine queue to be analyzed currently;

[0066] S202, obtaining the number of IO coroutines existing in the target coroutine queue as a first value, and the total number of coroutines existing in the core running the IO thread corresponding to the target coroutine queue as a second value, and obtaining the IO coroutine ratio according to the ratio of the first value to the second value;

[0067] S203, obtaining a load index of a core running an IO thread corresponding to the target coroutine queue;

[0068] S204. Obtain a scheduling priority value of the target IO coroutine relative to the target coroutine queue according to the response ratio of the target IO coroutine relative to the target coroutine queue, the IO coroutine proportion, and the load index of the core running the IO thread corresponding to the target coroutine queue.

[0069] The above process is actually an improvement of the highest response ratio priority (HRRN) scheduling algorithm. Based on the response ratio of the IO coroutine, it combines the core's IO coroutine ratio and the core's load index to obtain a skip priority value that characterizes the appropriateness of allocating the target IO coroutine to the target coroutine queue (that is, to the corresponding IO thread) to achieve load balancing of multiple cores, minimize the waiting time of each IO coroutine, and maximize the use of the advantages of hardware multi-cores to achieve IO parallel processing.

[0070] Specifically, in a preferred embodiment, the above step S201, obtaining the response ratio of the target IO coroutine relative to the target coroutine queue, specifically includes:

[0071] Obtain the number of existing IO coroutines in the target coroutine queue and the service time of the target IO coroutine;

[0072] According to the number of IO coroutines existing in the target coroutine queue and the service time of the target IO coroutine, a response ratio of the target IO coroutine relative to the target coroutine queue is obtained.

[0073] Specifically, in a preferred embodiment, the response ratio of the target IO coroutine relative to the target coroutine queue is obtained by the following formula:

[0074]

[0075] in, is the number of IO coroutines that already exist in the target coroutine queue, is the service time of the target IO coroutine, and They are different unit adjustment factors.

[0076] The above process uses the number of existing IO coroutines in the target coroutine queue to represent the waiting time. The service time of the target IO coroutine can be represented by the amount of data it transmits. The two units are unified through two different unit adjustment coefficients, and an improved response ratio is finally obtained. The response ratio is used to represent the ratio of the waiting time to the service time of the target IO coroutine. Shorter service time usually has a higher response ratio. The above formula can take into account the waiting time and service time of the IO coroutine and has a higher response rate. IO coroutines with shorter service time have the opportunity to execute earlier, and IO coroutines with longer waiting time will also be allocated to the queue first.

[0077] Further, in a preferred embodiment, the load index is the CPU usage of the core. By monitoring the CPU usage of each core, its current load can be evaluated. A higher CPU usage indicates that the core is performing more computing tasks and is under a heavier load. At this time, it is obviously inappropriate to assign the target IO coroutine to the IO thread of the core.

[0078] It is understandable that in practice, depending on the specific situation, other standards may be selected as the load index for measuring the core load, such as the number of processes, the number of threads, the process waiting time, the memory usage, etc. A combination of multiple factors may also be used, and the existing average load indicator (Load Average) may be used as the load index in the present invention.

[0079] Further, in a preferred embodiment, the scheduling priority value of the target IO coroutine relative to the target coroutine queue is obtained by the following formula:

[0080]

[0081] in, is the scheduling priority value of the target IO coroutine relative to the target coroutine queue, is the response ratio of the target IO coroutine relative to the target coroutine queue, is the proportion of IO coroutines, is the load index of the core running the IO thread corresponding to the target coroutine queue, , and They are different weight coefficients respectively.

[0082] In the above formula, the first and last items represent the response ratio and core load respectively. Obviously, the higher the response ratio value is, the lower the core load value is, which means that it is more appropriate to assign the target IO coroutine to the target coroutine queue. The second item describes the IO coroutine ratio of the core. The higher the IO coroutine ratio is, the higher the frequency of the core executing IO tasks is, and the lower the frequency of switching different types of coroutines or threads is, so the overhead of switching coroutines or threads is less. At this time, more IO coroutines can be appropriately assigned to the core to improve IO efficiency from the perspective of system overhead. In addition, the present invention uses three different weight coefficients to weigh the proportion of the above three factors to the final scheduling priority value to achieve a scientific and reasonable scheduling result.

[0083] Further, in a preferred embodiment, the above step S104, allocating multiple IO coroutines to different coroutine queues according to the scheduling priority value of each IO coroutine relative to different coroutine queues, specifically includes:

[0084] Acquire multiple scheduling priority values ​​of the target IO coroutine relative to multiple coroutine queues as multiple target scheduling priority values, and compare the sizes of the multiple target scheduling priority values;

[0085] If there is a unique maximum target scheduling priority value, the target IO coroutine is assigned to the coroutine queue corresponding to the maximum target scheduling priority value;

[0086] If there are multiple identical maximum target scheduling priority values, the target IO coroutine is assigned to the coroutine queue that was most recently assigned the IO coroutine among the multiple coroutine queues corresponding to the multiple identical maximum target scheduling priority values.

[0087] In the above process, if there are multiple identical maximum target scheduling priority values, it is theoretically possible to assign the target IO coroutine to any of the coroutine queues corresponding to these maximum target scheduling priority values. In this embodiment, it is considered that the IO thread of the coroutine queue that was most recently assigned an IO coroutine is a thread that is more suitable for processing IO tasks. Therefore, this embodiment chooses to assign the target IO coroutine to the coroutine queue that was most recently assigned an IO coroutine among multiple coroutine queues corresponding to multiple identical maximum target scheduling priority values, so as to further rationalize and balance the scheduling of coroutines.

[0088] In order to better implement the coroutine scheduling method based on the multi-core working thread in the embodiment of the present invention, based on the coroutine scheduling method based on the multi-core working thread, correspondingly, please refer to Figure 3 , Figure 3 This is a structural diagram of an embodiment of a coroutine scheduling system based on a multi-core working thread provided by the present invention. A coroutine scheduling system 300 based on a multi-core working thread provided by an embodiment of the present invention includes:

[0089] The thread pool creation module 310 is used to establish a coroutine queue for each IO thread, and each IO thread runs on a different core;

[0090] A coroutine pool creation module 320 is used to obtain multiple IO tasks and establish an IO coroutine for each IO task;

[0091] The priority value analysis module 330 is used to obtain the response ratio of each IO coroutine relative to different coroutine queues, the number of existing IO coroutines in each coroutine queue, and the load index of each core, and obtain the scheduling priority value of each IO coroutine relative to different coroutine queues;

[0092] The coroutine scheduling module 340 is used to allocate multiple IO coroutines to different coroutine queues according to the scheduling priority value of each IO coroutine relative to different coroutine queues.

[0093] It should be noted here that the corresponding system 300 provided in the above embodiment can implement the technical solutions described in the above method embodiments. The specific implementation principles of the above modules or units can refer to the corresponding contents in the above method embodiments, which will not be repeated here.

[0094] See also Figure 4 , Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. Based on the above-mentioned method for scheduling a coroutine based on a multi-core working thread, the present invention also provides a corresponding device 400 for scheduling a coroutine based on a multi-core working thread, that is, the above-mentioned electronic device, the device 400 for scheduling a coroutine based on a multi-core working thread can be a computing device such as a mobile terminal, a desktop computer, a notebook, a PDA, and a server. The device 400 for scheduling a coroutine based on a multi-core working thread includes a processor 410, a memory 420, and a display 430. Figure 4 Only some components of the coroutine scheduling device based on multi-core working threads are shown, but it should be understood that it is not required to implement all the components shown, and more or fewer components may be implemented instead.

[0095] In some embodiments, the memory 420 may be an internal storage unit of the coroutine scheduling device 400 based on the multi-core working thread, such as a hard disk or memory of the coroutine scheduling device 400 based on the multi-core working thread. In other embodiments, the memory 420 may also be an external storage device based on the coroutine scheduling device 400 based on the multi-core working thread, such as a plug-in hard disk, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the coroutine scheduling device 400 based on the multi-core working thread. Further, the memory 420 may also include both the internal storage unit of the coroutine scheduling device 400 based on the multi-core working thread and an external storage device. The memory 420 is used to store application software and various types of data installed on the coroutine scheduling device 400 based on the multi-core working thread, such as the program code of the coroutine scheduling device 400 installed on the multi-core working thread. The memory 420 can also be used to temporarily store data that has been output or is to be output. In one embodiment, a coroutine scheduler 440 based on a multi-core working thread is stored in the memory 420, and the coroutine scheduler 440 based on a multi-core working thread can be executed by the processor 410, thereby realizing the coroutine scheduling method based on a multi-core working thread of each embodiment of the present application.

[0096] In some embodiments, the processor 410 may be a central processing unit (CPU), a microprocessor or other data processing chip, used to run program codes or process data stored in the memory 420, such as executing a coroutine scheduling method based on a multi-core working thread.

[0097] In some embodiments, the display 430 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, etc. The display 430 is used to display information of the coroutine scheduling device 400 based on a multi-core working thread and to display a visual user interface. The components 410-430 of the coroutine scheduling device 400 based on a multi-core working thread communicate with each other through a system bus.

[0098] In one embodiment, when the processor 410 executes the coroutine scheduling program 440 based on the multi-core working thread in the memory 420, the steps in the coroutine scheduling method based on the multi-core working thread are implemented.

[0099] This embodiment also provides a computer-readable storage medium on which a coroutine scheduler based on a multi-core working thread is stored. When the coroutine scheduler based on the multi-core working thread is executed by a processor, the steps in the above embodiment can be implemented.

[0100] The present invention provides a coroutine scheduling method, system and device based on multi-core working threads, which respectively establishes a coroutine queue for each IO thread running on different cores, and establishes an IO coroutine for each IO task, and then obtains the response ratio of each IO coroutine relative to different coroutine queues, the number of existing IO coroutines in each coroutine queue and the load index of each core, and obtains the scheduling priority value of each IO coroutine relative to different coroutine queues, and finally allocates multiple IO coroutines to different coroutine queues according to the scheduling priority value of each IO coroutine relative to different coroutine queues. Compared with the prior art, the present invention equips each IO thread with a coroutine queue, analyzes the response ratio, the number of existing IO coroutines and the load index, and evenly allocates multiple IO coroutines to multiple IO threads through the scheduling priority value. The operating efficiency of IO is improved by means of coroutine scheduling. Most importantly, most of the steps of the present invention can be run in user mode. The allocation of IO coroutines can be completed before the IO thread starts running. At the same time, at least one IO thread is allocated to each core, so that multiple cores can execute IO functions without thread switching. By allocating coroutine queues, cross-core scheduling of IO coroutines is virtualized without the need for actual cross-core thread switching, which solves the problem of how to use multi-core capabilities and coroutine concepts to improve IO efficiency in the prior art, maximizes hardware performance and makes full use of multi-core capabilities, and improves the IO efficiency of smart hydropower stations.

[0101] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by any technician familiar with the technical field within the technical scope disclosed by the present invention should be covered within the protection scope of the present invention.

Claims

1. A coroutine scheduling method based on multi-core working threads, characterized in that: include: Create a coroutine queue for each IO thread, and each IO thread runs on a different core; Get multiple IO tasks and create an IO coroutine for each IO task; Obtaining a response ratio of a target IO coroutine relative to a target coroutine queue, wherein the target IO coroutine is an IO coroutine to be analyzed currently, and the target coroutine queue is a coroutine queue to be analyzed currently; Obtain the number of IO coroutines existing in the target coroutine queue as a first value, and the total number of coroutines existing in the core running the IO thread corresponding to the target coroutine queue as a second value, and obtain the IO coroutine ratio according to the ratio of the first value to the second value; Obtain the load index of the core running the IO thread corresponding to the target coroutine queue; Obtaining a scheduling priority value of the target IO coroutine relative to the target coroutine queue according to a response ratio of the target IO coroutine relative to the target coroutine queue, an IO coroutine proportion, and a load index of a core running an IO thread corresponding to the target coroutine queue; According to the scheduling priority value of each IO coroutine relative to different coroutine queues, multiple IO coroutines are assigned to different coroutine queues.

2. The method for co-routine scheduling based on multi-core working threads according to claim 1, characterized in that: The scheduling priority value of the target IO coroutine relative to the target coroutine queue is obtained by the following formula: in, is the scheduling priority value of the target IO coroutine relative to the target coroutine queue, is the response ratio of the target IO coroutine relative to the target coroutine queue, is the proportion of IO coroutines, is the load index of the core running the IO thread corresponding to the target coroutine queue, , and They are different weight coefficients respectively.

3. The method for co-routine scheduling based on multi-core working threads according to claim 2, characterized in that: The obtaining of the response ratio of the target IO coroutine relative to the target coroutine queue includes: Obtain the number of existing IO coroutines in the target coroutine queue and the service time of the target IO coroutine; According to the number of IO coroutines existing in the target coroutine queue and the service time of the target IO coroutine, a response ratio of the target IO coroutine relative to the target coroutine queue is obtained.

4. The method for co-routine scheduling based on multi-core working threads according to claim 3 is characterized in that: The response ratio of the target IO coroutine to the target coroutine queue is obtained by the following formula: , in, is the number of IO coroutines that already exist in the target coroutine queue, is the service time of the target IO coroutine, and They are adjustment factors for different units.

5. The method for co-routine scheduling based on multi-core working threads according to claim 4, characterized in that: The load index is the CPU usage of the core.

6. The method for co-routine scheduling based on multi-core working threads according to claim 5, characterized in that: The method of allocating multiple IO coroutines to different coroutine queues according to the scheduling priority value of each IO coroutine relative to different coroutine queues includes: Acquire multiple scheduling priority values ​​of the target IO coroutine relative to multiple coroutine queues as multiple target scheduling priority values, and compare the sizes of the multiple target scheduling priority values; If there is a unique maximum target scheduling priority value, the target IO coroutine is assigned to the coroutine queue corresponding to the maximum target scheduling priority value; If there are multiple identical maximum target scheduling priority values, the target IO coroutine is assigned to the coroutine queue that was most recently assigned the IO coroutine among the multiple coroutine queues corresponding to the multiple identical maximum target scheduling priority values.

7. A coroutine scheduling system based on multi-core working threads, characterized in that: include: The thread pool creation module is used to create a coroutine queue for each IO thread, and each IO thread runs on a different core; The coroutine pool creation module is used to obtain multiple IO tasks and establish an IO coroutine for each IO task; A priority value analysis module, used to obtain a response ratio of a target IO coroutine relative to a target coroutine queue, wherein the target IO coroutine is an IO coroutine to be analyzed currently, and the target coroutine queue is a coroutine queue to be analyzed currently; obtain the number of IO coroutines existing in the target coroutine queue as a first value, and the total number of coroutines existing in the core running the IO thread corresponding to the target coroutine queue as a second value, and obtain the IO coroutine ratio according to the ratio of the first value to the second value; obtain the load index of the core running the IO thread corresponding to the target coroutine queue; obtain the scheduling priority value of the target IO coroutine relative to the target coroutine queue according to the response ratio of the target IO coroutine relative to the target coroutine queue, the IO coroutine ratio and the load index of the core running the IO thread corresponding to the target coroutine queue; The coroutine scheduling module is used to allocate multiple IO coroutines to different coroutine queues according to the scheduling priority value of each IO coroutine relative to different coroutine queues.

8. An electronic device, characterized in that: comprising a memory and a processor, wherein: The memory is used to store programs; The processor is coupled to the memory and is used to execute the program stored in the memory to implement the steps in the coroutine scheduling method based on multi-core working threads as described in any one of claims 1 to 6 above.

9. A computer-readable storage medium, characterized in that: Used to store computer-readable programs or instructions, which, when executed by a processor, can implement the steps in the coroutine scheduling method based on multi-core working threads as described in any one of claims 1 to 6 above.