A simulation scheduling method and device based on a multi-layer time wheel
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-20
- Publication Date
- 2026-08-11
AI Technical Summary
[0005]本发明针对传统多层时间轮存在的相对时间重计算开销大、级联风暴、延迟毛刺、并发支持不足、缓存访问效率低等问题,提供一种基于多层时间轮的仿真调度方法及装置,通过绝对时间戳计算槽位、零拷贝直接级联、动态层级分配、优先级感知多队列调度,实现插入删除、免重计算级联、高缓存命中率、千万级并发支撑、微秒级精度与10ms至1.36年全时间范围覆盖的高性能调度
Smart Images

Figure CN122547486A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of time event scheduling technology at the underlying level of computer systems, specifically to a simulation scheduling method and system based on a multi-layer time wheel. Background Technology
[0002] Event scheduling is a core foundational service for systems such as operating system kernels, network protocol stacks, simulation platforms, and game engines. Current mainstream event scheduling algorithms include min-heaps, red-black trees, single-level time wheels, classic multi-level time wheels, and hash time wheels.
[0003] The time complexity of insertion and deletion operations in min-heap and red-black tree is O(n). When the number of tasks reaches tens of thousands or more, the scheduling overhead increases significantly, making it unsuitable for high-concurrency scenarios; although a single-layer time wheel can achieve this... While complex operations are possible, time precision and time coverage are mutually constrained, making it difficult to support long-duration tasks. Classic multi-level time wheels use relative time calculation slots, with typical implementations such as the Linux kernel's hrtimer and Netty-HashedWheelTimer. As the time wheel pointer advances, higher-level tasks need to frequently retrieve, recalculate, and re-insert relative times into lower-level tasks, which can easily lead to cascading storms and latency spikes under high concurrency. Hash time wheels suffer from hash collisions and uncontrollable cascading overhead, making it impossible to simultaneously meet the scheduling requirements of high precision, wide time span, and tens of millions of concurrent tasks.
[0004] Existing technologies cannot solve technical defects such as cascading overhead, latency spikes, low cache hit rate, and unpredictable scheduling under ultra-large-scale concurrency, which seriously restrict the system performance in key areas such as military simulation, industrial control, and financial transactions. Summary of the Invention
[0005] This invention addresses the problems of high relative time recalculation overhead, cascading storms, latency spikes, insufficient concurrency support, and low cache access efficiency inherent in traditional multi-layer time wheels. It provides a simulation scheduling method and apparatus based on multi-layer time wheels, achieving [the following is a description of the method and apparatus:] slot calculation using absolute timestamps, zero-copy direct cascading, dynamic hierarchical allocation, and priority-aware multi-queue scheduling. Insertion and deletion, deduplication cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level precision and high-performance scheduling covering the entire time range from 10ms to 1.36 years.
[0006] To address the aforementioned technical problems, a first aspect of this invention discloses a simulation scheduling method based on a multi-layer time wheel, the method comprising: S1: Obtain the scheduled task and time parameters, and initialize the multi-layer time wheel; The time parameters include the task wake-up time (wake_time) and the current system time (current_time). S2, process the scheduling task and time parameters to obtain task node information; S3, Based on the multi-layer time wheel, process the task node information to obtain a task priority queue; S4, the task priority queue is processed using the multi-layer time wheel to execute the due tasks.
[0007] As an optional implementation, in the first aspect of the present invention, the multi-layer time wheel adopts a three-dimensional array structure wheels_[4]
[256] [7], and each element stores the ID of the head node of the linked list of the corresponding priority queue; the multi-layer time wheel supports full time range coverage from 10ms to 1.36 years; The multi-layer time wheel includes a first time wheel, a second time wheel, a third time wheel, and a fourth time wheel; The first, second, third, and fourth time wheels are all base-256 time wheels. The hierarchical time relationship between the first time wheel, the second time wheel, the third time wheel, and the fourth time wheel is as follows: The first layer of the time wheel covers an area of 256 ticks; The second layer of the time wheel covers an area of = ×tick; The coverage area of the third time wheel = ×tick; and the coverage area of the fourth time wheel = ×tick; The first, second, third, and fourth time wheels are each configured with 256 slots; each slot includes a first priority P0, a second priority P1, a third priority P2, a fourth priority P3, a fifth priority P4, a sixth priority P5, and a seventh priority, with the priority levels decreasing sequentially from first priority P0, second priority P1, third priority P2, fourth priority P3, fifth priority P4, sixth priority P5, to seventh priority. The fourth, third, second, and first time wheels are arranged in a descending cascade manner; when a high-level task expires, it is rescheduled to a lower-level time wheel through the cascaded demotion of the fourth, third, second, and first time wheels in sequence. The first time wheel, the second time wheel, the third time wheel, and the fourth time wheel are connected in sequence.
[0008] As an optional implementation, in a first aspect of the present invention, the initialization of the multi-layer time wheel includes: S11, use bitwise AND operation to locate the slot and obtain the initial position of the target slot; The slot positioning expression is: , , in, The initial position of the target slot; A virtual time scale for converting the absolute wake-up time of a task; S12, based on the time wheel base time, determines the time coverage range of each level; The expressions for the time coverage range of each level are as follows: in, This represents a time coverage area. This is the second-level time coverage area; It covers a three-layer time range; It covers four time layers; The base time for the time wheel. The default value is ; S13, using the time reset cycle configuration model, process the base time of the time wheel to obtain the timestamp automatic reset cycle and the absolute wake-up time of the task after reset; The expression for the time reset cycle configuration model is: , , in, The time stamp is automatically reset periodically; The absolute wake-up time for tasks not yet performed; This refers to the absolute wake-up time of the task after the reset; S14, determine a periodic reset mechanism based on the timestamp automatic reset cycle and the absolute wake-up time of the task after the reset.
[0009] As an optional implementation, in the first aspect of the present invention, processing the scheduling task and time parameters to obtain task node information includes: S21, Based on the scheduled task, obtain the absolute wake-up time of the task. Get the current absolute time of the system. ; S22, Absolute wake-up time of the task and the current absolute time of the system Process the data to obtain the task delay time. ; The expression for the task delay time is: , S23, based on the task delay time Absolute wake-up time for the task and the current absolute time of the system The process is performed to obtain task node information.
[0010] As an optional implementation, in a first aspect of the present invention, the step of basing the task delay time... Absolute wake-up time for the task and the current absolute time of the system The process yields task node information, including: S231, based on the dynamic hierarchical priority allocation model, the task delay time... Processing is performed to obtain the task allocation target level. ; The expression for the dynamic hierarchical priority allocation model is: , in Based on the time scale; This represents the current traversal level. S232, Assign target level based on the task The absolute wake-up time is calculated using an absolute time slot calculation model. Processing is performed to obtain the target slots corresponding to the target level. ; S233, based on the target slot Determine the target hierarchy priority; S234, Assign target levels to the task. The target slot The target level priority and the coroutine handle are combined to obtain task node information.
[0011] As an optional implementation, in the first aspect of the present invention, the absolute time slot calculation model expression is: , , , , in, A virtual time scale for converting the absolute wake-up time of a task; The unit time span for the target level.
[0012] As an optional implementation, in the first aspect of the present invention, the step of processing the task node information based on the multi-layer time wheel to obtain a task priority queue includes: S31, based on the basic time scale Advance the multi-layered time wheel, utilizing the basic time scale. Update the system's current absolute time; The current absolute time expression of the system is: , in, This refers to the current absolute time of the system. This is the system's current absolute time before the update; S32, insert the task node information into the slot priority sequence of the corresponding level; S33, Based on the current absolute time of the system, obtain the target task; S34, Based on the task node information, determine the current slot; S35, Based on the current slot, obtain the expiration task sequence corresponding to the current slot and the slot priority sequence corresponding to the current slot; S36. Based on the slot priority sequence, process the due task sequence to obtain a task priority queue.
[0013] The second aspect of the present invention discloses a simulation scheduling device based on a multi-layer time wheel, the device comprising: a time wheel initialization module, a first processing module, a second processing module and a third processing module; The time wheel initialization module is used to obtain the scheduling task and time parameters, and initialize the multi-layer time wheel; The time parameters include the task wake-up time (wake_time) and the current system time (current_time). The first processing module is used to process the scheduling task and time parameters to obtain task node information; The second processing module is used to process the task node information based on the multi-layer time wheel to obtain a task priority queue; The third processing module is used by the multi-layer time wheel to process the task priority queue and execute the due tasks; The time wheel initialization module, the first processing module, the second processing module, and the third processing module are connected in sequence.
[0014] A third aspect of the present invention discloses another simulation scheduling device based on a multi-layer time wheel, the device comprising: Memory containing executable program code; A processor coupled to the memory; The processor calls the executable program code stored in the memory to execute some or all of the steps in the simulation scheduling method based on a multi-layer time wheel disclosed in the first aspect of the present invention.
[0015] The fourth aspect of the present invention discloses a computer-readable storage medium storing computer instructions, which, when invoked, execute some or all of the steps in the simulation scheduling method based on a multi-layer time wheel disclosed in the first aspect of the present invention.
[0016] Compared with the prior art, the embodiments of the present invention have the following beneficial effects: 1. Extremely optimized scheduling performance: Task insertion and deletion are all optimized. Time complexity, no recalculation of cascading processes, and complete elimination of cascading storms; 2. Balanced time coverage and accuracy: Supports full-span coverage from 10ms to 1.36 years, with microsecond-level scheduling accuracy at the underlying level; 3. High concurrency and high memory efficiency: Supports concurrent scheduling of tens of millions of tasks, with a cache hit rate of [missing information]. The memory layout is fixed and free of fragmentation; 4. Fair and reliable scheduling: Built-in 7-level priority queue and anti-starvation mechanism, high-priority tasks are responded to first, and low-priority tasks are not blocked; 5. Strong engineering adaptability: Supports deep integration with C++20 coroutines, and can be directly connected to platforms such as military simulation, real-time systems, and game engines. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 This is a schematic diagram illustrating an application scenario of the simulation scheduling device based on a multi-layer time wheel disclosed in an embodiment of the present invention. Figure 2 This is a schematic diagram of the simulation scheduling method based on a multi-layer time wheel disclosed in an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of a simulation scheduling device based on a multi-layer time wheel disclosed in an embodiment of the present invention; Figure 4 This is a schematic diagram of another simulation scheduling device based on a multi-layer time wheel disclosed in an embodiment of the present invention. Detailed Implementation
[0019] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0020] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this invention are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, apparatus, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices.
[0021] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0022] In this application, the term "exemplary" is used to mean "used as an example, illustration, or description." Any embodiment described as "exemplary" in this application is not necessarily to be construed as being more preferred or advantageous than other embodiments. The following description is provided to enable any person skilled in the art to make and use this application. Details are set forth in the following description for purposes of explanation. It should be understood that those skilled in the art will recognize that this application can be made without using these specific details. In other instances, well-known structures and processes are not described in detail to avoid obscuring the description of this application with unnecessary detail. Therefore, this application is not intended to be limited to the embodiments shown, but is consistent with the broadest scope of the principles and features disclosed in this application.
[0023] It should be noted that since the method in this application embodiment is executed in a computer device, the processing objects of each computer device exist in the form of data or information, such as time, which is essentially time information. It is understood that if size, quantity, position, etc. are mentioned in subsequent embodiments, they are all corresponding data that exist so that the computer device can process them. Specific details will not be elaborated here.
[0024] It should be noted that the artificial intelligence-related technologies that may be involved in this application will be briefly described. Artificial intelligence (AI) is the theory, method, technology, and application system that uses digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new kind of intelligent machine that can react in a way similar to human intelligence. Artificial intelligence is the study of the design principles and implementation methods of various intelligent machines, enabling machines to have the functions of perception, reasoning, and decision-making.
[0025] Artificial intelligence (AI) is a comprehensive discipline encompassing a wide range of fields, including both hardware and software technologies. Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies primarily include computer vision, speech processing, natural language processing, and machine learning / deep learning.
[0026] This application provides a simulation scheduling method, apparatus, computer device, and computer-readable storage medium based on a multi-layer time wheel, which will be described in detail below.
[0027] Please see Figure 1 , Figure 1This is a schematic diagram illustrating the application scenario of the simulation scheduling device based on a multi-layer time wheel provided in this application within a model simulation system. The model simulation system may include a computer device 100, which integrates a simulation scheduling device based on a multi-layer time wheel. Figure 1 Computer equipment in the country.
[0028] In this embodiment, the computer device 100 can be a standalone server, a server network, or a server cluster. For example, the computer device 100 described in this embodiment includes, but is not limited to, a computer, a network host, a single network server, a set of multiple network servers, or a cloud server composed of multiple servers. The cloud server is composed of a large number of computers or network servers based on cloud computing.
[0029] Those skilled in the art will understand Figure 1 The application environment given is merely one application scenario for the solution in this application and does not constitute a limitation on the application scenario of this application. Other application environments may include those that are more complex than those described above. Figure 1 The number of computer devices shown is more or less, for example Figure 1 Only one computer device is shown in the diagram. It is understood that the system may also include one or more other services, which are not limited here.
[0030] In addition, such as Figure 1 As shown, the model simulation system may also include a memory 200 for storing model data, model parameter data, model simulation result data, and model simulation process data.
[0031] It should be noted that, Figure 1 The schematic diagram of the simulation scheduling device based on multi-layer time wheels shown is merely an example. The model simulation system and scenario described in this application embodiment are for the purpose of more clearly illustrating the technical solutions of this application embodiment and do not constitute a limitation on the technical solutions provided in this application embodiment. As those skilled in the art will know, with the evolution of model simulation systems and the emergence of new business scenarios, the technical solutions provided in this application embodiment are also applicable to similar technical problems.
[0032] This invention addresses the problems of high relative time recalculation overhead, cascading storms, latency spikes, insufficient concurrency support, and low cache access efficiency inherent in traditional multi-layer time wheels. It provides a simulation scheduling method and apparatus based on multi-layer time wheels, achieving [the following is a description of the method and apparatus:] slot calculation using absolute timestamps, zero-copy direct cascading, dynamic hierarchical allocation, and priority-aware multi-queue scheduling. Insertion and deletion, deduplication cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level accuracy and high-performance scheduling covering the entire time range from 10ms to 1.36 years, improve the performance, time coverage and accuracy of simulation scheduling, the performance of task concurrency scheduling and memory, the fairness and reliability of scheduling, and enhance engineering adaptability.
[0033] Example 1 Please see Figure 2 , Figure 2 This is a flowchart illustrating a simulation scheduling method based on a multi-layer time wheel disclosed in an embodiment of the present invention. Figure 2 The described simulation scheduling method based on multi-layer time wheels is applied to model simulation systems, such as local servers or cloud servers used in model simulation systems; however, this embodiment of the invention is not limited to these applications. Figure 2 As shown, this simulation scheduling method based on multi-layer time wheels includes: S1: Obtain the scheduled task and time parameters, and initialize the multi-layer time wheel; The time parameters include the task wake-up time (wake_time) and the current system time (current_time). S2, process the scheduling task and time parameters to obtain task node information; S3, Based on the multi-layer time wheel, process the task node information to obtain a task priority queue; S4, use the multi-layer time wheel to process the task priority queue and execute the due tasks; It should be noted that the process of using the multi-layer time wheel to process the task priority queue and execute due tasks includes: using the multi-layer time wheel to execute due tasks according to task priority and enabling the anti-starvation mechanism. It should be noted that the aforementioned anti-starvation mechanism refers to preventing low-priority tasks from starving through priority decay. As can be seen, the simulation scheduling method based on multi-layer time wheels described in the embodiments of the present invention, by employing the multi-layer time wheels to process the scheduling tasks and time parameters, achieves... Insertion and deletion, deduplication cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level accuracy and high-performance scheduling covering the entire time range from 10ms to 1.36 years, improve the performance, time coverage and accuracy of simulation scheduling, the performance of task concurrency scheduling and memory, the fairness and reliability of scheduling, and enhance engineering adaptability.
[0034] Optionally, the multi-layer time wheel adopts a three-dimensional array structure. wheels_[4]
[256] [7]Each element stores the ID of the head node of the corresponding priority queue; the multi-level time wheel supports full time range coverage from 10ms to 1.36 years. The multi-layer time wheel includes a first time wheel, a second time wheel, a third time wheel, and a fourth time wheel; The first, second, third, and fourth time wheels are all base-256 time wheels. The hierarchical time relationship between the first time wheel, the second time wheel, the third time wheel, and the fourth time wheel is as follows: The first layer of the time wheel covers an area of 256 ticks; The second layer of the time wheel covers an area of = ×tick; The coverage area of the third time wheel = ×tick; and the coverage area of the fourth time wheel = ×tick; The first, second, third, and fourth time wheels are each configured with 256 slots; each slot includes a first priority P0, a second priority P1, a third priority P2, a fourth priority P3, a fifth priority P4, a sixth priority P5, and a seventh priority, with the priority levels decreasing sequentially from first priority P0, second priority P1, third priority P2, fourth priority P3, fifth priority P4, sixth priority P5, to seventh priority. The fourth, third, second, and first time wheels are arranged in a descending cascade manner; when a high-level task expires, it is rescheduled to a lower-level time wheel through the cascaded demotion of the fourth, third, second, and first time wheels in sequence. The first time wheel, the second time wheel, the third time wheel, and the fourth time wheel are connected in sequence. As can be seen, implementing the simulation scheduling method based on multi-layer time wheels described in the embodiments of the present invention utilizes the multi-layer time wheels to process scheduling tasks and time parameters, thereby achieving... Insertion and deletion, deduplication cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level accuracy and high-performance scheduling covering the entire time range from 10ms to 1.36 years, improve the performance, time coverage and accuracy of simulation scheduling, the performance of task concurrency scheduling and memory, the fairness and reliability of scheduling, and enhance engineering adaptability.
[0035] Optionally, the initialization of the multi-layer time wheel includes: S11, use bitwise AND operation to locate the slot and obtain the initial position of the target slot; The slot positioning expression is: , , in, The initial position of the target slot; A virtual time scale for converting the absolute wake-up time of a task; S12, based on the time wheel base time, determines the time coverage range of each level; The expressions for the time coverage range of each level are as follows: in, This represents a time coverage area. This is the second-level time coverage area; It covers a three-layer time range; It covers four time layers; The base time for the time wheel. The default value is ; S13, using the time reset cycle configuration model, process the base time of the time wheel to obtain the timestamp automatic reset cycle and the absolute wake-up time of the task after reset; The expression for the time reset cycle configuration model is: , , in, The time stamp is automatically reset periodically; The absolute wake-up time for tasks not yet performed; This refers to the absolute wake-up time of the task after the reset; S14, determine a periodic reset mechanism based on the timestamp automatic reset cycle and the absolute wake-up time of the task after the reset; As can be seen, implementing the simulation scheduling method based on multi-layer time wheels described in this embodiment of the invention involves initialization, which prepares the subsequent processing of scheduling tasks and time parameters using the multi-layer time wheels to achieve [the desired result]. It provides a technical foundation for high-performance scheduling with insertion and deletion, deduplication-free cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level accuracy, and full time range coverage from 10ms to 1.36 years, thereby improving the performance, time coverage and accuracy of simulation scheduling, the performance of task concurrency scheduling and memory, and the fairness and reliability of scheduling.
[0036] Optionally, the process of processing the scheduling task and time parameters to obtain task node information includes: S21, Based on the scheduled task, obtain the absolute wake-up time of the task. Get the current absolute time of the system. ; S22, Absolute wake-up time of the task and the current absolute time of the system Process the data to obtain the task delay time. ; The expression for the task delay time is: , S23, based on the task delay time Absolute wake-up time for the task and the current absolute time of the system Process the data to obtain task node information; As can be seen, implementing the simulation scheduling method based on a multi-layer time wheel described in this embodiment of the invention processes the scheduling task and time parameters to obtain task node information, thus enabling... It provides a data foundation for high-performance scheduling with insertion and deletion, deduplication-free cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level accuracy, and full time range coverage from 10ms to 1.36 years, thereby improving the performance, time coverage and accuracy of simulation scheduling, the performance of task concurrency scheduling and memory, and the fairness and reliability of scheduling.
[0037] Optionally, the step based on the task delay time Absolute wake-up time for the task and the current absolute time of the system The process yields task node information, including: S231, based on the dynamic hierarchical priority allocation model, the task delay time... Processing is performed to obtain the task allocation target level. ; The expression for the dynamic hierarchical priority allocation model is: , in Based on the time scale; This represents the current traversal level. S232, Assign target level based on the task The absolute wake-up time is calculated using an absolute time slot calculation model. Processing is performed to obtain the target slots corresponding to the target level. ; S233, based on the target slot Determine the target hierarchy priority; S234, Assign target levels to the task. The target slot The target level priority and coroutine handle are combined to obtain task node information and store it in the node pool; It should be noted that the task node information includes: coroutine handle. Expiry date Priority Level Slot Predecessor node Successor nodes and scheduling status ; It should be noted that the expiration time... Absolute wake-up time of the task Consistent; the priority Consistent with the target level priority, the priority The range of values is , The highest level; the level in question. With task allocation target level Consistent; the slot in question With the target slot Consistent; the scheduling state for Indicates that it has been scheduled. Indicates no scheduling; It should be noted that the dynamic hierarchical priority allocation model uses closed expressions to replace traversal judgments, thus achieving... Hierarchical selection; ensures tasks fall into the minimum feasible level, significantly reducing cascading frequency; As can be seen, the simulation scheduling method based on a multi-layer time wheel described in the embodiments of the present invention is based on the task delay time. Absolute wake-up time for the task and the current absolute time of the system Processing is performed to obtain task node information, in order to achieve... It provides a data foundation for high-performance scheduling with insertion and deletion, deduplication-free cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level accuracy, and full time range coverage from 10ms to 1.36 years, thereby improving the performance, time coverage and accuracy of simulation scheduling, the performance of task concurrency scheduling and memory, and the fairness and reliability of scheduling.
[0038] Optionally, the node pool is managed using a memory pool, and the size expression of the memory pool is: , in, This represents the total size of the memory pool. The maximum number of concurrent tasks supported by the system. The number of bytes occupied by the coroutine handle. Number of bytes used for a 64-bit timestamp (fixed) ), Number of bytes occupied by integer variables (fixed) ), Number of bytes occupied by a pointer (fixed) ), Number of bytes occupied by a Boolean variable (fixed) ); As can be seen, implementing the simulation scheduling method based on multi-layer time wheels described in the embodiments of the present invention, using a memory pool to manage the node pool, supports fast allocation and reclamation, reduces memory fragmentation, ensures that memory allocation matches the task volume, and improves high cache hit rate, support for tens of millions of concurrent requests, and the fairness and reliability of scheduling.
[0039] Optionally, the absolute time slot calculation model expression is: , , , , in, A virtual time scale for converting the absolute wake-up time of a task; For the target level, the unit time span; It should be noted that the absolute time slot calculation model uses absolute time throughout the simulation scheduling process, without recalculating relative time; it directly calculates the target slot during cascading, achieving zero-copy cascading; at the same time, it eliminates traditional cascading storms, reducing the single-task cascading overhead to 1~2 instructions. As can be seen, the simulation scheduling method based on a multi-layer time wheel described in the embodiments of the present invention is based on the task delay time. Absolute wake-up time for the task and the current absolute time of the system Processing is performed to obtain task node information, in order to achieve... It provides a data foundation for high-performance scheduling with insertion and deletion, deduplication-free cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level accuracy, and full time range coverage from 10ms to 1.36 years, thereby improving the performance, time coverage and accuracy of simulation scheduling, the performance of task concurrency scheduling and memory, and the fairness and reliability of scheduling.
[0040] Optionally, the step of processing the task node information based on the multi-layer time wheel to obtain a task priority queue includes: S31, based on the basic time scale Advance the multi-layered time wheel, utilizing the basic time scale. Update the system's current absolute time; The current absolute time expression of the system is: , in, This refers to the current absolute time of the system. This is the system's current absolute time before the update; It should be noted that by using the current absolute time of the system, the time wheel is advanced in fixed steps, and the time accuracy is controllable, ensuring a stable scheduling rhythm. S32, insert the task node information into the slot priority sequence of the corresponding level; S33, Based on the current absolute time of the system, obtain the target task; S34, Based on the task node information, determine the current slot; S35, Based on the current slot, obtain the expiration task sequence corresponding to the current slot and the slot priority sequence corresponding to the current slot; S36, Based on the slot priority sequence, process the due task sequence to obtain a task priority queue; It should be noted that the aforementioned processing refers to arranging the sequence of due tasks in descending order of slot priority; As can be seen, implementing the simulation scheduling method based on a multi-layer time wheel described in this embodiment of the invention, processing the task node information based on the multi-layer time wheel to obtain a task priority queue, is for the purpose of achieving... It provides a data foundation for high-performance scheduling with insertion and deletion, deduplication-free cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level accuracy, and full time range coverage from 10ms to 1.36 years, thereby improving the performance, time coverage and accuracy of simulation scheduling, the performance of task concurrency scheduling and memory, and the fairness and reliability of scheduling.
[0041] Optionally, obtaining the due task sequence and the slot priority sequence corresponding to the current slot based on the current slot includes: S351, Obtain the slot index of the current slot; Determine whether the slot index is equal to 0 to obtain the target slot determination result; S352, when the target slot determination result is yes, increment the current traversal level by 1 and execute S231; If the target slot determination result is negative, execute S353; S353, Obtain the slot task set for the current slot; The slot task set includes several slot tasks; S354, for any of the slot tasks, determine whether the absolute wake-up time of the corresponding task is less than or equal to the current absolute time of the system, and obtain the task expiration judgment result; S355, when the task expiration determination result is yes, the slot task is an expired task, the expired task is merged into the slot expired task sequence, and S356 is executed; If the task expiration determination result is negative, execute S354; S356, Obtain the task priority corresponding to the due task and add it to the slot task priority sequence; S357, Arrange the slot task priority sequence in descending order of priority to obtain the slot priority sequence; The slot expiration task sequence is arranged according to the slot priority sequence to obtain the slot priority sequence; As can be seen, implementing the simulation scheduling method based on a multi-layer time wheel described in this embodiment of the invention, based on the current slot, yields the due task sequence and the slot priority sequence corresponding to the current slot, in order to achieve... It provides a data foundation for high-performance scheduling with insertion and deletion, deduplication-free cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level accuracy, and full time range coverage from 10ms to 1.36 years, thereby improving the performance, time coverage and accuracy of simulation scheduling, the performance of task concurrency scheduling and memory, and the fairness and reliability of scheduling.
[0042] Optionally, the slot priority sequence adopts a doubly linked list structure with 7 priorities per slot per layer, and higher priority tasks are scheduled first within the same slot. Low-priority tasks are prevented from starving through priority decay or time-slice rotation mechanisms. The expression for the waiting threshold of the low-priority task is: , in, Priority Task waiting threshold; Based on the waiting threshold; For task priority ( ); It should be noted that the basic waiting threshold is set to [default value]. ; It should be noted that the value range of the task priority is as follows: The lower the task priority, the higher the waiting threshold, to ensure that low-priority tasks are not starved for a long time. The priority decay expression is: , in, The priority of the task after attenuation; Priority of tasks before decay; It should be noted that the aforementioned prevention of starvation for low-priority tasks through priority decay means that when the task waiting time exceeds [a certain threshold], [the situation will change]. At time, every interval The priority of a task decays over time until it is raised to the highest priority. Low-priority tasks that time out are gradually promoted to higher priority, eventually reaching the highest priority, thus completely avoiding starvation. As can be seen, by implementing the simulation scheduling method based on a multi-layer time wheel described in the embodiments of the present invention, the slot priority sequence is utilized to achieve... Insertion and deletion, deduplication cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level accuracy and high-performance scheduling covering a full time range from 10ms to 1.36 years, thereby improving the performance, time coverage and accuracy of simulation scheduling, the performance of concurrent task scheduling and memory, and the fairness and reliability of scheduling.
[0043] Optionally, the simulation scheduling method based on multi-layer time wheels further includes: Based on the task node information, cancel the target task; The step of canceling the target task based on the task node information includes: S51, retrieve user task cancellation command; S52, based on the user task cancellation instruction, locate the target task node using the task node information; S52, Remove the target task node from the doubly linked list to obtain and update the target task pointer; The target task pointer expression is: , , in, Pointer to the preceding task; Pointer to the successor task; S53, mark the target task node as unscheduled and reclaim the node resources; It should be noted that the unscheduled state refers to... ; As can be seen, implementing the simulation scheduling method based on a multi-layer time wheel described in this embodiment of the invention, based on the task node information, cancels the target task and reclaims the task node to the memory pool, avoiding resource leaks, and thus enabling the task to be completed. It provides a foundation for high-performance scheduling with insertion and deletion, deduplication-free cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level precision, and full time range coverage from 10ms to 1.36 years.
[0044] Optionally, the simulation scheduling method based on multi-layer time wheels further includes: Integrating the aforementioned simulation scheduling method with the C++20 coroutine framework provides , , , The coroutine interface enables asynchronous, non-blocking scheduling. Among them, the The coroutine interface is a coroutine task submission interface, used to submit a C++20 coroutine handle to the scheduler, which automatically schedules the execution based on priority and time wheel slots; Wherein, the The coroutine interface is the coroutine sleep interface, and the coroutine wake-up time expression is: , Among them, the For the duration of coroutine sleep; To awaken absolute time for coroutines; To retrieve the system's current time during hibernation; It should be noted that the coroutine sleep duration and the absolute time of coroutine wake-up ensure accurate coroutine wake-up; using absolute time wake-up eliminates accumulated errors, and the coroutine sleep accuracy reaches the microsecond level. The The coroutine interface is a timeout-protected scheduling interface that supports safe asynchronous tasks, avoids deadlock and dead waiting, and improves the reliability of simulation scheduling. The The coroutine interface is a periodic coroutine scheduling interface, and the periodic wake-up time expression is: , in, For the first Absolute time of the second wake-up; For the first Absolute time of the second wake-up; For fixed execution intervals; It should be noted that the fixed execution interval For periodic execution intervals, For the first The wake-up time ensures accurate execution of periodic tasks; the absolute time of periodic tasks increases progressively without drift, ensuring accurate long-term operation. As can be seen, implementing the simulation scheduling method based on a multi-layer time wheel described in the embodiments of the present invention, and integrating the simulation scheduling method with the C++20 coroutine framework, provides... , , , The coroutine interface enables asynchronous non-blocking scheduling. Insertion and deletion, deduplication cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level accuracy and high-performance scheduling covering the entire time range from 10ms to 1.36 years, improve the engineering adaptability of simulation scheduling.
[0045] Optionally, the simulation scheduling method based on multi-layer time wheels further includes: Real-time collection of performance metrics; these performance metrics include scheduling latency, task throughput, cascading frequency, queue length, and cache hit rate. The scheduling delay expression is as follows: , in Due to task scheduling delay, The actual execution time of the task. For task wake-up time, when ( This is the scheduling delay threshold, the default value. When this happens, adjust automatically. Interval optimization scheduling performance; The cache hit rate is expressed as: , in To cache the hit count, The total number of cached accesses; It should be noted that the cache hit rate mentioned above ensures that the cache hit rate is maintained at a certain level. ; Based on the aforementioned performance metrics, the basic time scale interval, hierarchical selection strategy, or priority resource allocation are adaptively adjusted. The expression for the basic time scale interval is: , in, This is the adjusted base time scale interval; This is the baseline time interval before adjustment; It should be noted that the units of the basic time scale interval, the adjusted basic time scale interval, and the basic time scale interval before adjustment are all milliseconds (ms). As can be seen, implementing the simulation scheduling method based on a multi-layer time wheel described in the embodiments of the present invention, and collecting performance indicators in real time, is essential for achieving asynchronous non-blocking scheduling. Data support is provided for insertion and deletion, deduplication cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level accuracy and high-performance scheduling covering the entire time range from 10ms to 1.36 years.
[0046] Example 2 Please see Figure 3 , Figure 3 This is a diagram illustrating the composition of a simulation scheduling device based on a multi-layer time wheel, as disclosed in an embodiment of the present invention. Figure 3 The described simulation scheduling device based on multi-layer time wheels is applied to model simulation systems, such as local servers or cloud servers used in model simulation systems; however, this embodiment of the invention is not limited to these applications. Figure 3 As shown, the simulation scheduling device based on a multi-layer time wheel includes: a time wheel initialization module 101, a first processing module 102, a second processing module 103, and a third processing module 104. The time wheel initialization module 101 is used to obtain the scheduling task and time parameters, and initialize the multi-layer time wheel; The first processing module 102 is used to process the scheduling task and time parameters to obtain task node information; The second processing module 103 is used to process the task node information based on the multi-layer time wheel to obtain a task priority queue; The third processing module 104 is used by the multi-layer time wheel to process the task priority queue and execute the due tasks; The time wheel initialization module 101, the first processing module 102, the second processing module 103, and the third processing module 104 are connected in sequence. As can be seen, the simulation scheduling device based on multi-layer time wheels described in this embodiment, using the simulation scheduling method based on multi-layer time wheels described in Embodiment 1, realizes the task... Insertion and deletion, deduplication cascading, high cache hit rate, support for tens of millions of concurrent requests, microsecond-level accuracy and high-performance scheduling covering a full time range from 10ms to 1.36 years, thereby improving the performance, time coverage and accuracy of simulation scheduling, the performance of concurrent task scheduling and memory, and the fairness and reliability of scheduling.
[0047] Example 3 Please see Figure 4 , Figure 4 This is a schematic diagram of another simulation scheduling device based on a multi-layer time wheel disclosed in an embodiment of the present invention. Figure 4 The described apparatus can be applied to model simulation systems, such as local servers or cloud servers used in model simulation systems, and the embodiments of the present invention are not limited thereto. Figure 4 As shown, the device may include: Memory 201 storing executable program code; Processor 202 coupled to memory 201; The processor 202 calls the executable program code stored in the memory 201 to execute the steps in the simulation scheduling method based on multi-level time wheels described in Embodiment 1.
[0048] Example 4 This invention discloses a computer-readable storage medium that stores a computer program for electronic data interchange, wherein the computer program causes a computer to execute the steps in the simulation scheduling method based on a multi-level time wheel described in Embodiment 1.
[0049] Example 5 This invention discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to perform the steps in the simulation scheduling method based on a multi-level time wheel described in Embodiment 1.
[0050] The device embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0051] It should be noted that all calculation expressions or mathematical functions in the embodiments of the present invention have undergone dimensionless processing of the variables involved before calculation.
[0052] It should be noted that in all the calculation expressions or mathematical functions in the embodiments of the present invention, the values of the input independent variables all meet the reasonable requirements of the input value range of the calculation expression or mathematical function, and can ensure that the calculation expression or mathematical function can be calculated smoothly without violating physical laws or mathematical rules.
[0053] Through the detailed description of the above embodiments, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, including read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), once programmable read-only memory (OTPROM), electronically erasable rewritable read-only memory (EEPROM), read-only optical disc (CD-ROM) or other optical disc storage, disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0054] Finally, it should be noted that the simulation scheduling method and apparatus based on multi-layer time wheels disclosed in the embodiments of the present invention are merely preferred embodiments of the present invention and are only used to illustrate the technical solutions of the present invention, not to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A simulation scheduling method based on a multi-layer time wheel, characterized in that, The method includes: S1: Obtain the scheduled task and time parameters, and initialize the multi-layer time wheel; The time parameters include the task wake-up time (wake_time) and the current system time (current_time). S2, process the scheduling task and time parameters to obtain task node information; S3, Based on the multi-layer time wheel, process the task node information to obtain a task priority queue; S4, the task priority queue is processed using the multi-layer time wheel to execute the due tasks.
2. The simulation scheduling method based on multi-layer time wheel according to claim 1, characterized in that, The multi-layer time wheel adopts a three-dimensional array structure wheels_[4][256][7], and each element stores the ID of the head node of the linked list of the corresponding priority queue; the multi-layer time wheel supports full time range coverage from 10ms to 1.36 years; The multi-layer time wheel includes a first time wheel, a second time wheel, a third time wheel, and a fourth time wheel; The first, second, third, and fourth time wheels are all base-256 time wheels. The hierarchical time relationship between the first time wheel, the second time wheel, the third time wheel, and the fourth time wheel is as follows: The first layer of the time wheel covers an area of 256 ticks; The second layer time wheel coverage range xtick; The third layer time wheel coverage range xtick; and the fourth layer time wheel coverage range xtick; The first, second, third, and fourth time wheels are each configured with 256 slots; each slot includes a first priority P0, a second priority P1, a third priority P2, a fourth priority P3, a fifth priority P4, a sixth priority P5, and a seventh priority, with the priority levels decreasing sequentially from first priority P0, second priority P1, third priority P2, fourth priority P3, fifth priority P4, sixth priority P5, to seventh priority. The fourth, third, second, and first time wheels are arranged in a descending cascade manner; when a high-level task expires, it is rescheduled to a lower-level time wheel through the cascaded demotion of the fourth, third, second, and first time wheels in sequence. The first time wheel, the second time wheel, the third time wheel, and the fourth time wheel are connected in sequence.
3. The simulation scheduling method based on multi-layer time wheels according to claim 1, characterized in that, The initialization of the multi-layer time wheel includes: S11, use bitwise AND operation to locate the slot and obtain the initial position of the target slot; The slot positioning expression is: , , wherein, is the initial position of the target slot; is the virtual time scale converted from the absolute wake-up time of the task. S12, based on the time wheel base time, determines the time coverage range of each level; The expressions for the time coverage range of each level are as follows: in, This represents a time coverage area. This is the second-level time coverage area; It covers a three-layer time range; It covers four time zones; The base time for the time wheel. The default value is ; S13, using the time reset cycle configuration model, process the base time of the time wheel to obtain the timestamp automatic reset cycle and the absolute wake-up time of the task after reset; The expression for the time reset cycle configuration model is: , , wherein, is the timestamp auto-reset period; is the absolute wake-up time for the task not executed; is the absolute wake-up time for the task after reset; S14, determine a periodic reset mechanism based on the timestamp automatic reset cycle and the absolute wake-up time of the task after the reset.
4. The simulation scheduling method based on multi-layer time wheel according to claim 1, wherein, The process of processing the scheduling task and time parameters to obtain task node information includes: S21, based on the scheduling task, obtaining a task absolute wake-up time ; obtaining a current absolute time of the system ; S22, Absolute wake-up time of the task and the current absolute time of the system Process the data to obtain the task delay time. ; The expression for the task delay time is: , S23, based on the task delay time Absolute wake-up time for the task and the current absolute time of the system The process is performed to obtain task node information.
5. The simulation scheduling method based on multi-layer time wheel according to claim 2, characterized in that, the task delay time the task absolute wake-up time and the system current absolute time processing to obtain task node information, including: S231, based on the dynamic hierarchical priority allocation model, delaying the task time processing to obtain a task allocation target level ; The expression for the dynamic hierarchical priority allocation model is: , wherein is a base time scale; is a current traversal level; S232, based on the task allocation target level , calculate the absolute wake-up time using the absolute time slot calculation model processing to obtain the target slot corresponding to the target level ; S233, determining a target level priority based on the target slot , determining out the target level priority; S234, Assign target levels to the task. The target slot The target level priority and the coroutine handle are combined to obtain task node information.
6. The simulation scheduling method based on multi-layer time wheel according to claim 3, characterized in that, The expression for the absolute time slot calculation model is: , , , , in, A virtual time scale for converting the absolute wake-up time of a task; The unit time span for the target level.
7. The simulation scheduling method based on multi-layer time wheel according to claim 1, wherein, The process of processing the task node information based on the multi-layer time wheel to obtain a task priority queue includes: S31, in base time scale advancing said multi-layered time wheel, using said base time scale updating the current absolute time of the system; The current absolute time expression of the system is: , wherein, is the current absolute time of the system; is the current absolute time of the system before the update; S32, insert the task node information into the slot priority sequence of the corresponding level; S33, Based on the current absolute time of the system, obtain the target task; S34, Based on the task node information, determine the current slot; S35, Based on the current slot, obtain the expiration task sequence corresponding to the current slot and the slot priority sequence corresponding to the current slot; S36. Based on the slot priority sequence, process the due task sequence to obtain a task priority queue.
8. A simulation scheduling apparatus based on a multi-layer time wheel, characterized by comprising: The apparatus for implementing the simulation scheduling method based on a multi-layer time wheel as described in any one of claims 1-7 includes: a time wheel initialization module, a first processing module, a second processing module, and a third processing module; The time wheel initialization module is used to obtain the scheduling task and time parameters, and initialize the multi-layer time wheel; The time parameters include the task wake-up time (wake_time) and the current system time (current_time). The first processing module is used to process the scheduling task and time parameters to obtain task node information; The second processing module is used to process the task node information based on the multi-layer time wheel to obtain a task priority queue; The third processing module is used by the multi-layer time wheel to process the task priority queue and execute the due tasks; The time wheel initialization module, the first processing module, the second processing module, and the third processing module are connected in sequence.
9. A simulation scheduling apparatus based on a multi-layer time wheel, characterized by, The device includes: Memory containing executable program code; A processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the simulation scheduling method based on a multi-level time wheel as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions, which, when invoked, are used to execute the simulation scheduling method based on a multi-layer time wheel as described in any one of claims 1-7.