WO2022267860A1 - 定时器任务的处理方法、软件定时器及存储介质 - Google Patents
定时器任务的处理方法、软件定时器及存储介质 Download PDFInfo
- Publication number
- WO2022267860A1 WO2022267860A1 PCT/CN2022/096915 CN2022096915W WO2022267860A1 WO 2022267860 A1 WO2022267860 A1 WO 2022267860A1 CN 2022096915 W CN2022096915 W CN 2022096915W WO 2022267860 A1 WO2022267860 A1 WO 2022267860A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- timer
- task
- earliest
- queue
- scanning
- Prior art date
Links
- 238000000034 method Methods 0.000 title claims abstract description 23
- 238000012545 processing Methods 0.000 title claims abstract description 13
- 238000003672 processing method Methods 0.000 claims description 17
- 238000010586 diagram Methods 0.000 description 8
- 230000008569 process Effects 0.000 description 7
- 238000005516 engineering process Methods 0.000 description 3
- 238000003491 array Methods 0.000 description 2
- 238000004891 communication Methods 0.000 description 2
- 238000013459 approach Methods 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 238000009434 installation Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000007723 transport mechanism Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4843—Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
- G06F9/485—Task life-cycle, e.g. stopping, restarting, resuming execution
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
Definitions
- the present application relates to the field of computer technology, in particular to a timer task processing method, a software timer and a storage medium.
- the existing software timer implementation idea is that the timer scan and timeout are completed by a dedicated timer scan task.
- the timer setting task and the timer scan task need to access the same Timer resources, resulting in more lock conflicts between multiple tasks that set timers, between tasks that set timers and timer scanning tasks, and the scanning work is concentrated in one task.
- CAPS Chip Attempts Per Second, the number of calls established per second
- Embodiments of the present application provide a timer task processing method, a software timer, and a storage medium.
- an embodiment of the present application provides a method for processing a timer task, including: the first task is provided with a threaded first timer queue, and when the first task sets a timer, the timer is set to to the first timer queue, and set the earliest timer in the first task to the timer scan task; if the timer scan task detects the earliest timer in the first task When the timer expires, send a timer expiration notification to the first task; and the first task scans the first timer queue according to the timer expiration notification.
- the embodiment of the present application provides a software timer, including a timer setting module and a timer scanning module, wherein: the timer setting module is configured to set the timer set by the first task to the second A threaded first timer queue of a task, and the earliest timer in the first task is set to the timer scanning task; the timer scanning module is set to detect the earliest timer in the first task Whether the expired timer expires, and when the earliest expired timer in the first task expires, a timer expiration notification is sent to the first task; When the task receives the timer expiry notification, it scans the first timer queue.
- the embodiment of the present application provides an operation control device, including at least one control processor and a memory for communicating with the at least one control processor; the memory stores information that can be processed by the at least one control processor. Instructions executed by the processor, the instructions are executed by the at least one control processor, so that the at least one control processor can execute the timer task processing method described in the embodiment of the first aspect above.
- an embodiment of the present application provides a computer-readable storage medium, the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to make a computer execute the above-mentioned first aspect embodiment.
- the processing method of the timer task is not limited to:
- FIG. 1 is an overall block diagram of a method for processing a timer task provided in an embodiment of the present application
- FIG. 2 is a functional block diagram of a method for processing a timer task provided in an embodiment of the present application
- Fig. 3 is the working flowchart of the software timer provided by the embodiment of the application from timer setting to overtime;
- FIG. 4 is a schematic structural diagram of a software timer provided by an embodiment of the present application.
- Fig. 5 is a schematic structural diagram of an operation control device provided by an embodiment of the present application.
- the embodiment of the present application provides a timer task processing method, a software timer and a storage medium, which can avoid bottlenecks caused by concentrating scanning tasks into one task in the case of large-scale use of timers.
- FIG. 1 is an overall block diagram of a timer task processing method provided by an embodiment of the present application
- FIG. 2 is a functional block diagram of a timer task processing method provided by an embodiment of the present application.
- the embodiment of the first aspect of the present application provides a method for processing a timer task, including:
- the first task is provided with a threaded first timer queue, and when the first task sets a timer, set the timer to the first timer queue, and set the earliest time in the first task The timer setting for the timer scan task;
- timer scanning task detects that the earliest timer in the first task expires, send a timer expiration notification to the first task;
- the first task scans the first timer queue according to the timer expiration notification.
- the first task sets the timer to the threaded first timer queue, and the scanning work of the first timer queue is performed by the first task itself which sets the timer Do
- the timer scan task only plays a basic role of timeout
- the main timer scan work is allocated to different tasks to complete, to avoid the bottleneck caused by the concentration of scan work on one task in the case of large-scale use of timers, by adopting threading
- the idea is to avoid the problem of software timer lock conflicts, thereby improving the system throughput rate, which is suitable for scenarios where the system uses a large number of software timers in a multi-core and multi-threaded concurrent environment.
- the second task is provided with a threaded second timer queue, and when the second task sets a timer, the timer is set to the second timer queue, and The earliest timer in the second task is set to the timer scanning task; the timer scanning task is provided with a timer array, and the timer array stores the earliest timing of the first task timer and the earliest expiry timer of the second task.
- a third task there may also be a third task, a fourth task, and more tasks.
- the method used by these tasks to process the timer task is the same as that of the first task and the second task, and these tasks are all provided with their own timing.
- setting the timer set the timer to its own timer queue, and set the earliest timer in its own timer queue to the timer array of the timer scanning task, and the timer of the timer scanning task
- the array stores the earliest timers for each task.
- the timer scanning task detects that the earliest timer of a certain task expires, it sends a timer expiration notification to the task, so that the task scans its own timer queue according to the received timer expiration notification.
- the timer scanning task polls and detects the earliest expired timers of all the tasks in the timer array.
- the earliest timer for the first task may be stored, and the earliest timer for other tasks may be stored, that is, how many timer arrays may be stored in the timer array?
- the earliest timer of a task by querying and detecting the earliest timers of all tasks in the timer array, it can be detected one by one whether the earliest timers of multiple tasks are due, and if it is time, it will be sent The corresponding task will be notified when the time comes.
- described first task is also provided with and is used for the timer that is set to described first timer queue is checked the heavy checking queue, and described heavy checking queue adopts Red-black tree data structure.
- the duplicate checking queue By setting up the duplicate checking queue, it is used to check the timers that are set repeatedly, and the red-black tree data structure is used to organize the duplicate checking queue, which can balance the two operations of searching and adding and deleting, with fast speed and low resource occupation.
- the first timer queue adopts a red-black tree data structure, a binary tree data structure, a multi-fork data structure, an array data structure or a linked list data structure.
- the second timer queue of the second task and the timer queues of other tasks can also adopt a red-black tree data structure, a binary tree data structure, a multi-fork data structure, an array data structure or a linked list data structure, This application does not limit it.
- FIG. 3 is a working flow chart of the software timer provided by the embodiment of the present application from timer setting to timeout.
- the user of the first task sets the timer, first checks whether the timer is repeatedly set through the check queue, and then sets the timer to the threaded first timer queue of the first task to determine whether the timer is the first
- the earliest timer of the task if so, the earliest timer of the first task is set to the timer array of the timer scanning task; the timer scanning task detects whether the earliest timer of the first task is due, If so, send an arrival notification to the first task; the first task starts to scan its own first timer queue, and sends a timer overtime notification to the user who sets the timer in the first task, so that the user can process the timer overtime message.
- FIG. 4 is a schematic structural diagram of a software timer provided by an embodiment of the present application.
- the embodiment of the second aspect of the present application provides a software timer, including a timer setting module 410 and a timer scanning module 420, wherein:
- the timer setting module 410 configured to set the timer set by the first task to the threaded first timer queue of the first task, and set the timer that expires the earliest in the first task Set to timer scan task.
- the timer queue is organized by the red tree data structure.
- the timer scanning module 420 includes two parts, the first part is set to detect whether the timer that expires the earliest in the first task is due, and when the timer that expires the earliest in the first task expires In the case of sending a timer expiration notification to the first task; the second part is set to scan the first timer queue when the first task receives the timer expiration notification.
- the whole process adopts threading technology without locking, and uses high-efficiency algorithms such as red-black tree/hash, thereby improving performance.
- red-black tree/hash data structure algorithm used in this embodiment is not the only algorithm for implementing this embodiment, and other data structure algorithms such as ordinary binary trees, multi-fork numbers, arrays, linked lists, etc. can be used to achieve This example.
- the user of the first task uses the interface provided by the timer setting module 410 provided by this embodiment to set the timer, sets the timer task into the threaded timer queue of the first task, and simultaneously judges whether the timer is the first task.
- the earliest due timer of a task if yes, set this timer to the timer scan task.
- the timer scanning task detects that the first task’s earliest timer expires, it notifies the first task, the first task starts to scan its own timer queue, and sends a timeout notification to the user who set the timer, and the user processes the timer timeout Notice.
- the entire process accesses threaded data resources without lock overhead, which improves system throughput.
- the use of related timer resources is dynamically scaled to avoid a large occupation of system resources when using a large number of timers.
- timer task processing method and software timer of the embodiment of the present application compared with other software timer implementation methods, in the multi-core multi-thread concurrent architecture, it can achieve lock-free operation throughout the process, avoid lock overhead, and improve system performance. Performance, and the main timer work is shared by multiple tasks, avoiding bottlenecks caused by concentrating on one task, which is conducive to the large-scale use of timers.
- the use of related timer resources is dynamically scaled to avoid a large occupation of system resources when using a large number of timers. It is suitable for scenarios where the system uses a large number of software timers in a multi-core and multi-thread concurrent environment.
- FIG. 5 is a schematic structural diagram of an operation control device 500 provided in an embodiment of the present application.
- the embodiment of the third aspect of the present application provides an operation control device 500, including at least one control processor 510 and a memory 520 for communicating with the at least one control processor 510; Instructions executed by the at least one control processor 510, the instructions are executed by the at least one control processor 510, so that the at least one control processor 510 can perform the timer task as described in the embodiment of the first aspect above Approach.
- the first task sets the timer to the threaded first timer queue, and the scanning work of the first timer queue is done by the first task itself that sets the timer.
- the timer scanning task only plays a basic role of timeout.
- the main timer scanning work is divided into different tasks to complete, so as to avoid the bottleneck caused by the concentration of scanning work on one task in the case of large-scale use of timers.
- the embodiment of the fourth aspect of the present application provides a computer-readable storage medium, the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to make the computer execute the above-mentioned embodiment of the first aspect.
- the processing method of the timer task is not limited to:
- the first task sets the timer to the threaded first timer queue, and the scanning work of the first timer queue is done by the first task itself that sets the timer , the timer scanning task only plays a basic role of timeout.
- the main timer scanning work is allocated to different tasks to complete, avoiding the bottleneck caused by the concentration of scanning work on one task in the case of large-scale use of timers.
- the embodiment of the present application includes: a timer task processing method, a software timer, an operation control device, and a computer-readable storage medium.
- the first task sets the timer to the threaded first timer queue, and the scanning work of the first timer queue is done by the first task which sets the timer itself, and the timer scan
- the task only plays a basic role of timeout.
- the main timer scanning work is allocated to different tasks to complete, avoiding the bottleneck caused by the concentration of scanning work on one task in the case of large-scale use of timers, and avoiding software by using the idea of threading
- the problem of timer lock conflicts, thereby improving the system throughput rate, is suitable for scenarios where the system uses a large number of software timers in a multi-core and multi-threaded concurrent environment.
- Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disk DVD or other optical disk storage, magnetic cartridges, tape, magnetic disk storage or other magnetic storage devices, or can be used in Any other medium that stores desired information and that can be accessed by a computer.
- communication media typically embodies computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media .
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
一种定时器任务的处理方法、软件定时器及存储介质,第一任务设置有线程化的第一定时器队列,第一任务设置定时器时,将定时器设置到第一定时器队列,并将第一任务中最早到时的定时器设置给定时器扫描任务;若定时器扫描任务检测到第一任务中最早到时的定时器到时,向第一任务发送定时器到时通知;第一任务根据定时器到时通知,扫描第一定时器队列。
Description
相关申请的交叉引用
本申请基于申请号为202110709503.6、申请日为2021年06月25日的中国专利申请提出,并要求该中国专利申请的优先权,该中国专利申请的全部内容在此引入本申请作为参考。
本申请涉及计算机技术领域,尤其涉及一种定时器任务的处理方法、软件定时器及存储介质。
目前,已有的软件定时器实现思想是,定时器扫描与超时由专门的定时器扫描任务来完成,在多核多线程的并发架构下,由于定时器设置任务和定时器扫描任务需要访问相同的定时器资源,导致设置定时器的多个任务间、设置定时器的任务与定时器扫描任务间存在较多的锁冲突,且扫描工作集中到一个任务来做,在大规模使用定时器情况下易导致瓶颈,特别是在高CAPS(Call Attempts Per Second,每秒建立呼叫数量)场景下,对系统性能的影响十分明显。
发明内容
本申请实施例提供一种定时器任务的处理方法、软件定时器及存储介质。
第一方面,本申请实施例提供一种定时器任务的处理方法,包括:第一任务设置有线程化的第一定时器队列,所述第一任务设置定时器时,将所述定时器设置到所述第一定时器队列,并将所述第一任务中最早到时的定时器设置给定时器扫描任务;若所述定时器扫描任务检测到所述第一任务中最早到时的定时器到时,向所述第一任务发送定时器到时通知;所述第一任务根据所述定时器到时通知,扫描所述第一定时器队列。
第二方面,本申请实施例提供一种软件定时器,包括定时器设置模块和定时器扫描模块,其中:所述定时器设置模块被设置为将第一任务设置的定时器设置到所述第一任务的线程化的第一定时器队列,并将所述第一任务中最早到时的定时器设置给定时器扫描任务;所述定时器扫描模块被设置为检测所述第一任务中最早到时的定时器是否到时,并在所述第一任务中最早到时的定时器到时的情况下向所述第一任务发送定时器到时通知;以及被设置为在所述第一任务接收到所述定时器到时通知的情况下,扫描所述第一定时器队列。
第三方面,本申请实施例提供一种运行控制装置,包括至少一个控制处理器和用于与所述至少一个控制处理器通信连接的存储器;所述存储器存储有可被所述至少一个控制处理器执行的指令,所述指令被所述至少一个控制处理器执行,以使所述至少一个控制处理器能够执行如上第一方面实施例所述的定时器任务的处理方法。
第四方面,本申请实施例提供一种计算机可读存储介质,所述计算机可读存储介质存储有计算机可执行指令,所述计算机可执行指令用于使计算机执行如上第一方面实施例所述的 定时器任务的处理方法。
本申请的其它特征和优点将在随后的说明书中阐述,并且,部分地从说明书中变得显而易见,或者通过实施本申请而了解。本申请的目的和其他优点可通过在说明书、权利要求书以及附图中所特别指出的结构来实现和获得。
附图用来提供对本申请技术方案的进一步理解,并且构成说明书的一部分,与本申请的实施例一起用于解释本申请的技术方案,并不构成对本申请技术方案的限制。
下面结合附图和实施例对本申请进一步地说明;
图1是本申请实施例提供的一种定时器任务的处理方法的整体框图;
图2是本申请实施例提供的一种定时器任务的处理方法的原理框图;
图3是本申请实施例提供的软件定时器从定时器设置到超时的工作流程图;
图4是本申请实施例提供的软件定时器的结构示意图;
图5是本申请实施例提供的运行控制装置的结构示意图。
本部分将详细描述本申请的具体实施例,本申请之较佳实施例在附图中示出,附图的作用在于用图形补充说明书文字部分的描述,使人能够直观地、形象地理解本申请的每个技术特征和整体技术方案,但其不能理解为对本申请保护范围的限制。
在本申请的描述中,如果有描述到第一、第二只是用于区分技术特征为目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量或者隐含指明所指示的技术特征的先后关系。
本申请的描述中,除非另有明确的限定,设置、安装、连接等词语应做广义理解,所属技术领域技术人员可以结合技术方案的具体内容合理确定上述词语在本申请中的具体含义。
本申请实施例提供一种定时器任务的处理方法、软件定时器及存储介质,能够避免在大规模使用定时器情况下,扫描工作集中到一个任务引起瓶颈。
下面结合附图,对本申请实施例作进一步阐述。
参照图1和图2,图1是本申请实施例提供的一种定时器任务的处理方法的整体框图;图2是本申请实施例提供的一种定时器任务的处理方法的原理框图。
本申请的第一方面实施例提供一种定时器任务的处理方法,包括:
第一任务设置有线程化的第一定时器队列,所述第一任务设置定时器时,将所述定时器设置到所述第一定时器队列,并将所述第一任务中最早到时的定时器设置给定时器扫描任务;
若所述定时器扫描任务检测到所述第一任务中最早到时的定时器到时,向所述第一任务发送定时器到时通知;
所述第一任务根据所述定时器到时通知,扫描所述第一定时器队列。
根据本申请实施例提供的定时器任务的处理方法,第一任务通过将定时器设置到线程化的第一定时器队列,第一定时器队列的扫描工作由设置定时器的第一任务自身来做,定时器扫描任务只起到基本的超时作用,主要的定时器扫描工作分摊到不同的任务完成,避免在大规模使用定时器情况下,扫描工作集中到一个任务引起瓶颈,通过采用线程化的思想来避免 软件定时器锁冲突的问题,从而提高系统吞吐率,适用于多核多线程并发环境中,系统大量使用软件定时器的场景。
在上述定时器任务的处理方法中,第二任务设置有线程化的第二定时器队列,所述第二任务设置定时器时,将所述定时器设置到所述第二定时器队列,并将所述第二任务中最早到时的定时器设置给定时器扫描任务;所述定时器扫描任务设置有定时器数组,所述定时器数组存储有所述第一任务的最早到时的定时器和所述第二任务的最早到时的定时器。
可以理解的是,还可以有第三任务、第四任务以及更多的任务,这些任务处理定时器任务时采用的方法与第一任务和第二任务同理,这些任务均设置有自身的定时器队列,设置定时器时将定时器设置到自身的定时器队列,并将自身的定时器队列中最早到时的定时器设置给定时器扫描任务的定时器数组,定时器扫描任务的定时器数组存储有各个任务的最早到时的定时器。当定时器扫描任务检测到某一个任务的最早到时的定时器到时,则向该任务发送定时器到时通知,使得该任务根据收到的定时器到时通知扫描自身的定时器队列。
在上述定时器任务的处理方法中,所述定时器扫描任务轮询检测所述定时器数组中的所有任务的最早到时的定时器。
定时器扫描任务的定时器数组中,可以存储有第一任务的最早到时的定时器,还有可能存储有其他多个任务的最早到时的定时器,即定时器数组有可能存储有多个任务的最早到时的定时器,通过询检测定时器数组中的所有任务的最早到时的定时器,可以逐一检测多个任务的最早到时的定时器是否到时,若到时则发送到时通知给到相应的任务。
参照图2,在上述定时器任务的处理方法中,所述第一任务还设置有用于对设置到所述第一定时器队列的定时器进行查重的查重队列,所述查重队列采用红黑树数据结构。
通过设置查重队列,用于对重复设置的定时器进行检查,采用红黑树数据结构来组织查重队列,可以兼具查找和增删两种操作的平衡性,速度快,资源占用少。
在上述定时器任务的处理方法中,所述第一定时器队列采用红黑树数据结构、二叉树数据结构、多叉数数据结构、数组数据结构或者链表数据结构。
可以理解的是,第二任务的第二定时器队列以及其他任务的定时器队列也可以同理采用红黑树数据结构、二叉树数据结构、多叉数数据结构、数组数据结构或者链表数据结构,本申请对其不作限制。
下面参照图3对上述的定时器任务的处理方法进行详细介绍,图3是本申请实施例提供的软件定时器从定时器设置到超时的工作流程图。
第一任务的用户设置设置定时器,首先通过查重队列检查定时器是否重复设置,然后将定时器设置到第一任务的线程化的第一定时器队列中,判断该定时器是否是第一任务的最早到时定时器,若是则将第一任务的最早到时的定时器设置给定时器扫描任务的定时器数组;定时器扫描任务检测第一任务最早到时的定时器是否到时,若是则向第一任务发送到时通知;第一任务开始扫描自身的第一定时器队列,发定时器超时通知给第一任务设置定时器的用户,使得用户可以处理定时器超时消息。
参照图4,图4是本申请实施例提供的软件定时器的结构示意图。
本申请的第二方面实施例提供一种软件定时器,包括定时器设置模块410和定时器扫描模块420,其中:
所述定时器设置模块410:被设置为将第一任务设置的定时器设置到所述第一任务的线 程化的第一定时器队列,并将所述第一任务中最早到时的定时器设置给定时器扫描任务。定时器队列采用红给树数据结构来组织。另外,还有一个红黑树数据结构来组织的查重队列,用于对重复设置的定时器进行检查,红黑树数据结构可以兼具查找和增删两种操作的平衡性,速度快,资源占用少。
所述定时器扫描模420:包括两部分,第一部分被设置为检测所述第一任务中最早到时的定时器是否到时,并在所述第一任务中最早到时的定时器到时的情况下向所述第一任务发送定时器到时通知;第二部分被设置为在所述第一任务接收到所述定时器到时通知的情况下,扫描所述第一定时器队列。整个过程采用线程化技术,无需加锁,并采用了红黑树/哈希等高效率算法,从而提高了性能。
需要说明的是,本实施例使用的红黑树/哈希数据结构算法不是唯一的实现本实施例的算法,可采用其他的数据结构算法如普通二叉树、多叉数、数组、链表等来实现本实施例。
第一任务的用户使用本实施例提供的定时器设置模块410提供的接口来设置定时器,将定时器任务设置到第一任务的线程化的定时器队列中,同时判断该定时器是否是第一任务的最早到时的定时器,如果是,将该定时器设置给定时器扫描任务。待定时器扫描任务检测到第一任务的最早到时定时器到时,通知第一任务,第一任务开始扫描自身的定时器队列,发超时通知给设置定时器的用户,用户处理定时器超时通知。整个过程访问的是线程化的数据资源,没有锁开销,提高了系统吞吐率。同时,这一过程中,相关定时器资源的使用是动态弹缩的,避免使用大量定时器时对系统资源的大量占用。
采用本申请实施例的定时器任务的处理方法和软件定时器,与其他软件定时器实现方法相比,在多核多线程并发架构中,能全程做到无锁操作,避免锁开销,提高系能性能,且主要的定时器工作由多个任务分摊完成,避免集中到一个任务引起瓶颈,有利于定时器的大规模使用。同时,相关定时器资源的使用是动态弹缩的,避免使用大量定时器时对系统资源的大量占用。适用于多核多线程并发环境中,系统大量使用软件定时器的场景。
参照图5,图5是本申请实施例提供的运行控制装置500的结构示意图。
本申请的第三方面实施例提供一种运行控制装置500,包括至少一个控制处理器510和用于与所述至少一个控制处理器510通信连接的存储器520;所述存储器520存储有可被所述至少一个控制处理器510执行的指令,所述指令被所述至少一个控制处理器510执行,以使所述至少一个控制处理器510能够执行如上第一方面实施例所述的定时器任务的处理方法。
根据本申请实施例提供的运行控制装置500,第一任务通过将定时器设置到线程化的第一定时器队列,第一定时器队列的扫描工作由设置定时器的第一任务自身来做,定时器扫描任务只起到基本的超时作用,主要的定时器扫描工作分摊到不同的任务完成,避免在大规模使用定时器情况下,扫描工作集中到一个任务引起瓶颈,通过采用线程化的思想来避免软件定时器锁冲突的问题,从而提高系统吞吐率,适用于多核多线程并发环境中,系统大量使用软件定时器的场景。
另外,本申请的第四方面实施例提供一种计算机可读存储介质,所述计算机可读存储介质存储有计算机可执行指令,所述计算机可执行指令用于使计算机执行如上第一方面实施例所述的定时器任务的处理方法。
根据本申请实施例提供的计算机可读存储介质,第一任务通过将定时器设置到线程化的第一定时器队列,第一定时器队列的扫描工作由设置定时器的第一任务自身来做,定时器扫 描任务只起到基本的超时作用,主要的定时器扫描工作分摊到不同的任务完成,避免在大规模使用定时器情况下,扫描工作集中到一个任务引起瓶颈,通过采用线程化的思想来避免软件定时器锁冲突的问题,从而提高系统吞吐率,适用于多核多线程并发环境中,系统大量使用软件定时器的场景。
本申请实施例包括:定时器任务的处理方法、软件定时器、运行控制装置及计算机可读存储介质。根据本申请实施例提供的方案,第一任务通过将定时器设置到线程化的第一定时器队列,第一定时器队列的扫描工作由设置定时器的第一任务自身来做,定时器扫描任务只起到基本的超时作用,主要的定时器扫描工作分摊到不同的任务完成,避免在大规模使用定时器情况下,扫描工作集中到一个任务引起瓶颈,通过采用线程化的思想来避免软件定时器锁冲突的问题,从而提高系统吞吐率,适用于多核多线程并发环境中,系统大量使用软件定时器的场景。
本领域普通技术人员可以理解,上文中所公开方法中的全部或某些步骤、系统可以被实施为软件、固件、硬件及其适当的组合。某些物理组件或所有物理组件可以被实施为由处理器,如中央处理器、数字信号处理器或微处理器执行的软件,或者被实施为硬件,或者被实施为集成电路,如专用集成电路。这样的软件可以分布在计算机可读介质上,计算机可读介质可以包括计算机存储介质或非暂时性介质和通信介质或暂时性介质。如本领域普通技术人员公知的,术语计算机存储介质包括在用于存储信息诸如计算机可读指令、数据结构、程序模块或其他数据的任何方法或技术中实施的易失性和非易失性、可移除和不可移除介质。计算机存储介质包括但不限于RAM、ROM、EEPROM、闪存或其他存储器技术、CD-ROM、数字多功能盘DVD或其他光盘存储、磁盒、磁带、磁盘存储或其他磁存储装置、或者可以用于存储期望的信息并且可以被计算机访问的任何其他的介质。此外,本领域普通技术人员公知的是,通信介质通常包含计算机可读指令、数据结构、程序模块或者诸如载波或其他传输机制之类的调制数据信号中的其他数据,并且可包括任何信息递送介质。
上面结合附图对本申请实施例作了详细说明,但是本申请不限于上述实施例,在所述技术领域普通技术人员所具备的知识范围内,还可以在不脱离本申请宗旨的前提下作出各种变化。
Claims (10)
- 一种定时器任务的处理方法,包括:第一任务设置有线程化的第一定时器队列,所述第一任务设置定时器时,将所述定时器设置到所述第一定时器队列,并将所述第一任务中最早到时的定时器设置给定时器扫描任务;若所述定时器扫描任务检测到所述第一任务中最早到时的定时器到时,向所述第一任务发送定时器到时通知;所述第一任务根据所述定时器到时通知,扫描所述第一定时器队列。
- 根据权利要求1所述的定时器任务的处理方法,其中,第二任务设置有线程化的第二定时器队列,所述第二任务设置定时器时,将所述定时器设置到所述第二定时器队列,并将所述第二任务中最早到时的定时器设置给定时器扫描任务;所述定时器扫描任务设置有定时器数组,所述定时器数组存储有所述第一任务的最早到时的定时器和所述第二任务的最早到时的定时器。
- 根据权利要求2所述的定时器任务的处理方法,其中,所述定时器扫描任务轮询检测所述定时器数组中的所有任务的最早到时的定时器。
- 根据权利要求1所述的定时器任务的处理方法,其中,所述第一任务还设置有用于对设置到所述第一定时器队列的定时器进行查重的查重队列,所述查重队列采用红黑树数据结构。
- 根据权利要求1所述的定时器任务的处理方法,其中,所述第一定时器队列采用红黑树数据结构、二叉树数据结构、多叉数数据结构、数组数据结构或者链表数据结构。
- 一种软件定时器,包括:定时器设置模块,被设置为将第一任务设置的定时器设置到所述第一任务的线程化的第一定时器队列,并将所述第一任务中最早到时的定时器设置给定时器扫描任务;定时器扫描模块,被设置为检测所述第一任务中最早到时的定时器是否到时,并在所述第一任务中最早到时的定时器到时的情况下向所述第一任务发送定时器到时通知;以及被设置为在所述第一任务接收到所述定时器到时通知的情况下,扫描所述第一定时器队列。
- 根据权利要求6所述的软件定时器,其中,所述定时器设置模块还被设置为将第二任务设置的定时器设置到所述第二任务的线程化的第二定时器队列,并将所述第二任务中最早到时的定时器设置给定时器扫描任务;所述定时器扫描任务设置有定时器数组,所述定时器数组存储有所述第一任务的最早到时的定时器和所述第二任务的最早到时的定时器。
- 根据权利要求7所述的软件定时器,其中,所述定时器扫描模块轮询检测所述定时器数组中的存储的所有任务的最早到时的定时器。
- 一种运行控制装置,包括至少一个控制处理器和用于与所述至少一个控制处理器通信连接的存储器;所述存储器存储有可被所述至少一个控制处理器执行的指令,所述指令被所述至少一个控制处理器执行,以使所述至少一个控制处理器能够执行如权利要求1至5任一项所述的定时器任务的处理方法。
- 一种计算机可读存储介质,所述计算机可读存储介质存储有计算机可执行指令,所述计算机可执行指令用于使计算机执行如权利要求1至5任一项所述的定时器任务的处理方法。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110709503.6 | 2021-06-25 | ||
CN202110709503.6A CN115525402A (zh) | 2021-06-25 | 2021-06-25 | 定时器任务的处理方法、软件定时器及存储介质 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2022267860A1 true WO2022267860A1 (zh) | 2022-12-29 |
Family
ID=84544098
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2022/096915 WO2022267860A1 (zh) | 2021-06-25 | 2022-06-02 | 定时器任务的处理方法、软件定时器及存储介质 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN115525402A (zh) |
WO (1) | WO2022267860A1 (zh) |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1474241A (zh) * | 2002-08-07 | 2004-02-11 | 华为技术有限公司 | 海量定时器的调度方法 |
CN101132369A (zh) * | 2007-08-15 | 2008-02-27 | 中兴通讯股份有限公司 | 网络处理器中定时器的实现方法 |
CN101361320A (zh) * | 2005-12-31 | 2009-02-04 | 中兴通讯股份有限公司 | 一种软件系统中定时器的管理系统及管理方法 |
US20090320030A1 (en) * | 2008-06-24 | 2009-12-24 | International Business Machines Corporation | Method for management of timeouts |
CN102455940A (zh) * | 2010-10-29 | 2012-05-16 | 迈普通信技术股份有限公司 | 一种定时器和异步事件的处理方法及系统 |
CN103092682A (zh) * | 2011-10-28 | 2013-05-08 | 浙江大华技术股份有限公司 | 异步网络应用程序处理方法 |
-
2021
- 2021-06-25 CN CN202110709503.6A patent/CN115525402A/zh active Pending
-
2022
- 2022-06-02 WO PCT/CN2022/096915 patent/WO2022267860A1/zh active Application Filing
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1474241A (zh) * | 2002-08-07 | 2004-02-11 | 华为技术有限公司 | 海量定时器的调度方法 |
CN101361320A (zh) * | 2005-12-31 | 2009-02-04 | 中兴通讯股份有限公司 | 一种软件系统中定时器的管理系统及管理方法 |
CN101132369A (zh) * | 2007-08-15 | 2008-02-27 | 中兴通讯股份有限公司 | 网络处理器中定时器的实现方法 |
US20090320030A1 (en) * | 2008-06-24 | 2009-12-24 | International Business Machines Corporation | Method for management of timeouts |
CN102455940A (zh) * | 2010-10-29 | 2012-05-16 | 迈普通信技术股份有限公司 | 一种定时器和异步事件的处理方法及系统 |
CN103092682A (zh) * | 2011-10-28 | 2013-05-08 | 浙江大华技术股份有限公司 | 异步网络应用程序处理方法 |
Also Published As
Publication number | Publication date |
---|---|
CN115525402A (zh) | 2022-12-27 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2019128535A1 (zh) | 消息管理方法、设备及存储介质 | |
US6988268B2 (en) | IO completion architecture for user-mode networking | |
US10268504B2 (en) | Interrupt information processing method, virtual machine monitor, and interrupt controller | |
US11429594B2 (en) | Synchronization between primary database and secondary database | |
US7472214B2 (en) | Real-time embedded simple monitor method and computer product | |
US20200021665A1 (en) | Method and device for timeout monitoring | |
WO2016188282A1 (zh) | 一种消息处理方法、装置及系统 | |
CN109104491A (zh) | 一种微服务调用方法、装置、服务器及存储介质 | |
US20230291696A1 (en) | Method and apparatus for managing buffering of data packet of network card, terminal and storage medium | |
US6256660B1 (en) | Method and program product for allowing application programs to avoid unnecessary packet arrival interrupts | |
US6012121A (en) | Apparatus for flexible control of interrupts in multiprocessor systems | |
CN114928579A (zh) | 数据处理方法、装置、计算机设备及存储介质 | |
CN113535425A (zh) | 一种数据发送方法、装置、电子设备及存储介质 | |
CN110727507B (zh) | 一种消息的处理方法、装置、计算机设备和存储介质 | |
WO2022267860A1 (zh) | 定时器任务的处理方法、软件定时器及存储介质 | |
CN111831408A (zh) | 异步任务处理方法、装置、电子设备及介质 | |
US8051417B2 (en) | Target thread selection in a multi-threaded process | |
CN107819855B (zh) | 一种消息分发方法及装置 | |
CN116501476B (zh) | linux通用字符设备处理方法、装置、设备和介质 | |
US20230353323A1 (en) | Communication method and apparatus | |
CN113704297B (zh) | 业务处理请求的处理方法、模块及计算机可读存储介质 | |
US11582133B2 (en) | Apparatus and method for distributed processing of identical packet in high-speed network security equipment | |
CN114500544B (zh) | 一种节点间负载均衡方法、系统、设备以及介质 | |
US10284501B2 (en) | Technologies for multi-core wireless network data transmission | |
WO2020253378A1 (zh) | 一种数据处理方法、设备、服务器及可读存储介质 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 22827357 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 22827357 Country of ref document: EP Kind code of ref document: A1 |