[go: up one dir, main page]

CN115525402A - Timer task processing method, software timer and storage medium - Google Patents

Timer task processing method, software timer and storage medium Download PDF

Info

Publication number
CN115525402A
CN115525402A CN202110709503.6A CN202110709503A CN115525402A CN 115525402 A CN115525402 A CN 115525402A CN 202110709503 A CN202110709503 A CN 202110709503A CN 115525402 A CN115525402 A CN 115525402A
Authority
CN
China
Prior art keywords
timer
task
queue
earliest
scanning
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110709503.6A
Other languages
Chinese (zh)
Inventor
麦伟鹏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
ZTE Corp
Original Assignee
ZTE Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by ZTE Corp filed Critical ZTE Corp
Priority to CN202110709503.6A priority Critical patent/CN115525402A/en
Priority to PCT/CN2022/096915 priority patent/WO2022267860A1/en
Publication of CN115525402A publication Critical patent/CN115525402A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/485Task life-cycle, e.g. stopping, restarting, resuming execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt

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

The invention discloses a processing method of a timer task, a software timer and a storage medium, wherein a first task is provided with a threaded first timer queue, when the first task sets a timer, the timer is set to the first timer queue, and the earliest time-out timer in the first task is set to a timer scanning task; if the timer scanning task detects that a timer which is the earliest in time in the first task is up, sending a timer up-time notice to the first task; the first task scans the first timer queue according to the timer expiration notification. The main timer scanning work is shared by different tasks to be completed, the problem that the scanning work is concentrated on one task to cause bottleneck under the condition of using the timer in a large scale is avoided, and the problem of software timer lock conflict is avoided by adopting a threading idea, so that the system throughput rate is improved, and the method is suitable for the scene that the system uses a large number of software timers in a multi-core and multi-thread concurrent environment.

Description

定时器任务的处理方法、软件定时器及存储介质Timer task processing method, software timer and storage medium

技术领域technical field

本发明涉及计算机技术领域,尤其涉及一种定时器任务的处理方法、软件定时器及存储介质。The invention relates to the technical field of computers, in particular to a timer task processing method, a software timer and a storage medium.

背景技术Background technique

目前,已有的软件定时器实现思想是,定时器扫描与超时由专门的定时器扫描任务来完成,在多核多线程的并发架构下,由于定时器设置任务和定时器扫描任务需要访问相同的定时器资源,导致设置定时器的多个任务间、设置定时器的任务与定时器扫描任务间存在较多的锁冲突,且扫描工作集中到一个任务来做,在大规模使用定时器情况下易导致瓶颈,特别是在高CAPS(Call Attempts Per Second,每秒建立呼叫数量)场景下,对系统性能的影响十分明显。At present, the existing software timer implementation idea is that the timer scan and timeout are completed by a dedicated timer scan task. Under the multi-core and multi-thread concurrent architecture, since 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. In the case of large-scale use of timers It is easy to cause bottlenecks, especially in high CAPS (Call Attempts Per Second, the number of calls established per second) scenarios, and the impact on system performance is very obvious.

发明内容Contents of the invention

本发明的目的在于至少解决现有技术中存在的技术问题之一,提供一种定时器任务的处理方法、软件定时器及存储介质,能够避免在大规模使用定时器情况下,扫描工作集中到一个任务引起瓶颈。The purpose of the present invention is to at least solve one of the technical problems existing in the prior art, and provide a processing method, a software timer and a storage medium for a timer task, which can avoid the concentration of scanning work in the case of large-scale use of timers. A task causes a bottleneck.

第一方面,本发明实施例提供一种定时器任务的处理方法,包括:In a first aspect, an embodiment of the present invention 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;

若所述定时器扫描任务检测到所述第一任务中最早到时的定时器到时,向所述第一任务发送定时器到时通知;If the 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.

第二方面,本发明实施例提供一种软件定时器,包括定时器设置模块和定时器扫描模块,其中:In a second aspect, an embodiment of the present invention provides a software timer, including a timer setting module and a timer scanning module, wherein:

所述定时器设置模块用于将第一任务设置的定时器设置到所述第一任务的线程化的第一定时器队列,并将所述第一任务中最早到时的定时器设置给定时器扫描任务;The timer setting module is used to set the timer set by the first task to the threaded first timer queue of the first task, and set the earliest due timer in the first task to a given time device scan tasks;

所述定时器扫描模块用于检测所述第一任务中最早到时的定时器是否到时,并在所述第一任务中最早到时的定时器到时的情况下向所述第一任务发送定时器到时通知;以及用于在所述第一任务接收到所述定时器到时通知的情况下,扫描所述第一定时器队列。The timer scanning module is used to detect whether the earliest timer in the first task expires, and when the earliest timer in the first task expires, report to the first task sending a timer expiration notification; and scanning the first timer queue when the first task receives the timer expiration notification.

第三方面,本发明实施例提供一种运行控制装置,包括至少一个控制处理器和用于与所述至少一个控制处理器通信连接的存储器;所述存储器存储有可被所述至少一个控制处理器执行的指令,所述指令被所述至少一个控制处理器执行,以使所述至少一个控制处理器能够执行如上第一方面实施例所述的定时器任务的处理方法。In a third aspect, an embodiment of the present invention 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.

第四方面,本发明实施例提供一种计算机可读存储介质,所述计算机可读存储介质存储有计算机可执行指令,所述计算机可执行指令用于使计算机执行如上第一方面实施例所述的定时器任务的处理方法。In a fourth aspect, an embodiment of the present invention 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 perform the above-mentioned first aspect embodiment. The processing method of the timer task.

本发明实施例包括:定时器任务的处理方法、软件定时器、运行控制装置及计算机可读存储介质。根据本发明实施例提供的方案,第一任务通过将定时器设置到线程化的第一定时器队列,第一定时器队列的扫描工作由设置定时器的第一任务自身来做,定时器扫描任务只起到基本的超时作用,主要的定时器扫描工作分摊到不同的任务完成,避免在大规模使用定时器情况下,扫描工作集中到一个任务引起瓶颈,通过采用线程化的思想来避免软件定时器锁冲突的问题,从而提高系统吞吐率,适用于多核多线程并发环境中,系统大量使用软件定时器的场景。The embodiment of the present invention includes: a timer task processing method, a software timer, an operation control device and a computer-readable storage medium. According to the scheme provided by the embodiment of the present invention, 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 which sets the timer, and the timer scans 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.

本发明的其它特征和优点将在随后的说明书中阐述,并且,部分地从说明书中变得显而易见,或者通过实施本发明而了解。本发明的目的和其他优点可通过在说明书、权利要求书以及附图中所特别指出的结构来实现和获得。Additional features and advantages of the invention will be set forth in the description which follows, and in part will be apparent from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention may be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.

附图说明Description of drawings

附图用来提供对本发明技术方案的进一步理解,并且构成说明书的一部分,与本发明的实施例一起用于解释本发明的技术方案,并不构成对本发明技术方案的限制。The accompanying drawings are used to provide a further understanding of the technical solution of the present invention, and constitute a part of the description, and are used together with the embodiments of the present invention to explain the technical solution of the present invention, and do not constitute a limitation to the technical solution of the present invention.

下面结合附图和实施例对本发明进一步地说明;Below in conjunction with accompanying drawing and embodiment the present invention is further described;

图1是本发明实施例提供的一种定时器任务的处理方法的整体框图;FIG. 1 is an overall block diagram of a method for processing a timer task provided by an embodiment of the present invention;

图2是本发明实施例提供的一种定时器任务的处理方法的原理框图;FIG. 2 is a functional block diagram of a method for processing a timer task provided by an embodiment of the present invention;

图3是本发明实施例提供的软件定时器从定时器设置到超时的工作流程图;Fig. 3 is the working flowchart of the software timer that the embodiment of the present invention provides from timer setting to overtime;

图4是本发明实施例提供的软件定时器的结构示意图;FIG. 4 is a schematic structural diagram of a software timer provided by an embodiment of the present invention;

图5是本发明实施例提供的运行控制装置的结构示意图。Fig. 5 is a schematic structural diagram of an operation control device provided by an embodiment of the present invention.

具体实施方式detailed description

本部分将详细描述本发明的具体实施例,本发明之较佳实施例在附图中示出,附图的作用在于用图形补充说明书文字部分的描述,使人能够直观地、形象地理解本发明的每个技术特征和整体技术方案,但其不能理解为对本发明保护范围的限制。This part will describe the specific embodiment of the present invention in detail, and the preferred embodiment of the present invention is shown in the accompanying drawings. Each technical feature and overall technical solution of the invention, but it should not be understood as a limitation on the protection scope of the present invention.

在本发明的描述中,如果有描述到第一、第二只是用于区分技术特征为目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量或者隐含指明所指示的技术特征的先后关系。In the description of the present invention, if the first and the second are described only for the purpose of distinguishing technical features, it cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features or implicitly indicating The sequence of the indicated technical features.

本发明的描述中,除非另有明确的限定,设置、安装、连接等词语应做广义理解,所属技术领域技术人员可以结合技术方案的具体内容合理确定上述词语在本发明中的具体含义。In the description of the present invention, unless otherwise clearly defined, words such as setting, installation, and connection should be understood in a broad sense, and those skilled in the art can reasonably determine the specific meanings of the above words in the present invention in combination with the specific content of the technical solution.

本发明实施例提供一种定时器任务的处理方法、软件定时器及存储介质,能够避免在大规模使用定时器情况下,扫描工作集中到一个任务引起瓶颈。Embodiments of the present invention provide 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.

下面结合附图,对本发明实施例作进一步阐述。The embodiments of the present invention will be further described below in conjunction with the accompanying drawings.

参照图1和图2,图1是本发明实施例提供的一种定时器任务的处理方法的整体框图;Referring to FIG. 1 and FIG. 2, FIG. 1 is an overall block diagram of a method for processing a timer task provided by an embodiment of the present invention;

图2是本发明实施例提供的一种定时器任务的处理方法的原理框图。FIG. 2 is a functional block diagram of a timer task processing method provided by an embodiment of the present invention.

本发明的第一方面实施例提供一种定时器任务的处理方法,包括:The embodiment of the first aspect of the present invention 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;

若所述定时器扫描任务检测到所述第一任务中最早到时的定时器到时,向所述第一任务发送定时器到时通知;If the 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.

根据本发明实施例提供的定时器任务的处理方法,第一任务通过将定时器设置到线程化的第一定时器队列,第一定时器队列的扫描工作由设置定时器的第一任务自身来做,定时器扫描任务只起到基本的超时作用,主要的定时器扫描工作分摊到不同的任务完成,避免在大规模使用定时器情况下,扫描工作集中到一个任务引起瓶颈,通过采用线程化的思想来避免软件定时器锁冲突的问题,从而提高系统吞吐率,适用于多核多线程并发环境中,系统大量使用软件定时器的场景。According to the processing method of the timer task provided by the embodiment of the present invention, 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.

在上述定时器任务的处理方法中,第二任务设置有线程化的第二定时器队列,所述第二任务设置定时器时,将所述定时器设置到所述第二定时器队列,并将所述第二任务中最早到时的定时器设置给定时器扫描任务;所述定时器扫描任务设置有定时器数组,所述定时器数组存储有所述第一任务的最早到时的定时器和所述第二任务的最早到时的定时器。In the processing method of the above-mentioned timer task, 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.

可以理解的是,还可以有第三任务、第四任务以及更多的任务,这些任务处理定时器任务时采用的方法与第一任务和第二任务同理,这些任务均设置有自身的定时器队列,设置定时器时将定时器设置到自身的定时器队列,并将自身的定时器队列中最早到时的定时器设置给定时器扫描任务的定时器数组,定时器扫描任务的定时器数组存储有各个任务的最早到时的定时器。当定时器扫描任务检测到某一个任务的最早到时的定时器到时,则向该任务发送定时器到时通知,使得该任务根据收到的定时器到时通知扫描自身的定时器队列。It can be understood that 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. When 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. When 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.

在上述定时器任务的处理方法中,所述定时器扫描任务轮询检测所述定时器数组中的所有任务的最早到时的定时器。In the above method for processing the timer task, the timer scanning task polls and detects the earliest expired timers of all the tasks in the timer array.

定时器扫描任务的定时器数组中,可以存储有第一任务的最早到时的定时器,还有可能存储有其他多个任务的最早到时的定时器,即定时器数组有可能存储有多个任务的最早到时的定时器,通过询检测定时器数组中的所有任务的最早到时的定时器,可以逐一检测多个任务的最早到时的定时器是否到时,若到时则发送到时通知给到相应的任务。In the timer array of the timer scanning task, 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.

参照图2,在上述定时器任务的处理方法中,所述第一任务还设置有用于对设置到所述第一定时器队列的定时器进行查重的查重队列,所述查重队列采用红黑树数据结构。With reference to Fig. 2, in the processing method of above-mentioned timer task, 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.

通过设置查重队列,用于对重复设置的定时器进行检查,采用红黑树数据结构来组织查重队列,可以兼具查找和增删两种操作的平衡性,速度快,资源占用少。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.

在上述定时器任务的处理方法中,所述第一定时器队列采用红黑树数据结构、二叉树数据结构、多叉数数据结构、数组数据结构或者链表数据结构。In the above timer task processing method, 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.

可以理解的是,第二任务的第二定时器队列以及其他任务的定时器队列也可以同理采用红黑树数据结构、二叉树数据结构、多叉数数据结构、数组数据结构或者链表数据结构,本申请对其不作限制。It can be understood that 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.

下面参照图3对上述的定时器任务的处理方法进行详细介绍,图3是本发明实施例提供的软件定时器从定时器设置到超时的工作流程图。The above-mentioned timer task processing method will be described in detail below with reference to FIG. 3 . FIG. 3 is a working flow chart of the software timer provided by the embodiment of the present invention 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.

参照图4,图4是本发明实施例提供的软件定时器的结构示意图。Referring to FIG. 4 , FIG. 4 is a schematic structural diagram of a software timer provided by an embodiment of the present invention.

本发明的第二方面实施例提供一种软件定时器,包括定时器设置模块410和定时器扫描模块420,其中:The embodiment of the second aspect of the present invention provides a software timer, including a timer setting module 410 and a timer scanning module 420, wherein:

所述定时器设置模块410:用于将第一任务设置的定时器设置到所述第一任务的线程化的第一定时器队列,并将所述第一任务中最早到时的定时器设置给定时器扫描任务。定时器队列采用红给树数据结构来组织。另外,还有一个红黑树数据结构来组织的查重队列,用于对重复设置的定时器进行检查,红黑树数据结构可以兼具查找和增删两种操作的平衡性,速度快,资源占用少。The timer setting module 410: for setting the timer set by the first task to the threaded first timer queue of the first task, and setting the earliest timer in the first task Give the timer scan tasks. The timer queue is organized by the red tree data structure. In addition, there is also a duplicate check queue organized by a red-black tree data structure, which is used to check the timers that are set repeatedly. Occupy less.

所述定时器扫描模420:包括两部分,第一部分是用于检测所述第一任务中最早到时的定时器是否到时,并在所述第一任务中最早到时的定时器到时的情况下向所述第一任务发送定时器到时通知;第二部分是用于在所述第一任务接收到所述定时器到时通知的情况下,扫描所述第一定时器队列。整个过程采用线程化技术,无需加锁,并采用了红黑树/哈希等高效率算法,从而提高了性能。The timer scanning module 420: includes two parts, the first part is used 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 The second part is used 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.

需要说明的是,本实施例使用的红黑树/哈希数据结构算法不是唯一的实现本实施例的算法,可采用其他的数据结构算法如普通二叉树、多叉数、数组、链表等来实现本实施例。It should be noted that the 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.

第一任务的用户使用本实施例提供的定时器设置模块410提供的接口来设置定时器,将定时器任务设置到第一任务的线程化的定时器队列中,同时判断该定时器是否是第一任务的最早到时的定时器,如果是,将该定时器设置给定时器扫描任务。待定时器扫描任务检测到第一任务的最早到时定时器到时,通知第一任务,第一任务开始扫描自身的定时器队列,发超时通知给设置定时器的用户,用户处理定时器超时通知。整个过程访问的是线程化的数据资源,没有锁开销,提高了系统吞吐率。同时,这一过程中,相关定时器资源的使用是动态弹缩的,避免使用大量定时器时对系统资源的大量占用。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. When 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. At the same time, during this process, the use of related timer resources is dynamically scaled to avoid a large occupation of system resources when using a large number of timers.

采用本发明实施例的定时器任务的处理方法和软件定时器,与其他软件定时器实现方法相比,在多核多线程并发架构中,能全程做到无锁操作,避免锁开销,提高系能性能,且主要的定时器工作由多个任务分摊完成,避免集中到一个任务引起瓶颈,有利于定时器的大规模使用。同时,相关定时器资源的使用是动态弹缩的,避免使用大量定时器时对系统资源的大量占用。适用于多核多线程并发环境中,系统大量使用软件定时器的场景。Using the timer task processing method and software timer in the embodiment of the present invention, compared with other software timer implementation methods, in the multi-core and 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. At the same time, 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.

参照图5,图5是本发明实施例提供的运行控制装置500的结构示意图。Referring to FIG. 5 , FIG. 5 is a schematic structural diagram of an operation control device 500 provided by an embodiment of the present invention.

本发明的第三方面实施例提供一种运行控制装置500,包括至少一个控制处理器510和用于与所述至少一个控制处理器510通信连接的存储器520;所述存储器520存储有可被所述至少一个控制处理器510执行的指令,所述指令被所述至少一个控制处理器510执行,以使所述至少一个控制处理器510能够执行如上第一方面实施例所述的定时器任务的处理方法。The embodiment of the third aspect of the present invention 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.

根据本发明实施例提供的运行控制装置500,第一任务通过将定时器设置到线程化的第一定时器队列,第一定时器队列的扫描工作由设置定时器的第一任务自身来做,定时器扫描任务只起到基本的超时作用,主要的定时器扫描工作分摊到不同的任务完成,避免在大规模使用定时器情况下,扫描工作集中到一个任务引起瓶颈,通过采用线程化的思想来避免软件定时器锁冲突的问题,从而提高系统吞吐率,适用于多核多线程并发环境中,系统大量使用软件定时器的场景。According to the operation control device 500 provided in the embodiment of the present invention, 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. By adopting the idea of threading To avoid the problem of software timer lock conflicts, thereby improving the system throughput rate, it is suitable for scenarios where the system uses a large number of software timers in a multi-core and multi-threaded concurrent environment.

另外,本发明的第四方面实施例提供一种计算机可读存储介质,所述计算机可读存储介质存储有计算机可执行指令,所述计算机可执行指令用于使计算机执行如上第一方面实施例所述的定时器任务的处理方法。In addition, the embodiment of the fourth aspect of the present invention 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.

根据本发明实施例提供的计算机可读存储介质,第一任务通过将定时器设置到线程化的第一定时器队列,第一定时器队列的扫描工作由设置定时器的第一任务自身来做,定时器扫描任务只起到基本的超时作用,主要的定时器扫描工作分摊到不同的任务完成,避免在大规模使用定时器情况下,扫描工作集中到一个任务引起瓶颈,通过采用线程化的思想来避免软件定时器锁冲突的问题,从而提高系统吞吐率,适用于多核多线程并发环境中,系统大量使用软件定时器的场景。According to the computer-readable storage medium provided by the embodiment of the present invention, 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. By adopting threaded 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.

本领域普通技术人员可以理解,上文中所公开方法中的全部或某些步骤、系统可以被实施为软件、固件、硬件及其适当的组合。某些物理组件或所有物理组件可以被实施为由处理器,如中央处理器、数字信号处理器或微处理器执行的软件,或者被实施为硬件,或者被实施为集成电路,如专用集成电路。这样的软件可以分布在计算机可读介质上,计算机可读介质可以包括计算机存储介质或非暂时性介质和通信介质或暂时性介质。如本领域普通技术人员公知的,术语计算机存储介质包括在用于存储信息诸如计算机可读指令、数据结构、程序模块或其他数据的任何方法或技术中实施的易失性和非易失性、可移除和不可移除介质。计算机存储介质包括但不限于RAM、ROM、EEPROM、闪存或其他存储器技术、CD-ROM、数字多功能盘DVD或其他光盘存储、磁盒、磁带、磁盘存储或其他磁存储装置、或者可以用于存储期望的信息并且可以被计算机访问的任何其他的介质。此外,本领域普通技术人员公知的是,通信介质通常包含计算机可读指令、数据结构、程序模块或者诸如载波或其他传输机制之类的调制数据信号中的其他数据,并且可包括任何信息递送介质。Those skilled in the art can understand that all or some of the steps and systems in the methods disclosed above can be implemented as software, firmware, hardware and an appropriate combination thereof. Some or all of the physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit . Such software may be distributed on computer readable media, which may include computer storage media or non-transitory media and communication media or transitory media. As is well known to those of ordinary skill in the art, the term computer storage media includes both volatile and nonvolatile, Removable and non-removable media. 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. In addition, as is well known to those of ordinary skill in the art, 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 .

上面结合附图对本发明实施例作了详细说明,但是本发明不限于上述实施例,在所述技术领域普通技术人员所具备的知识范围内,还可以在不脱离本发明宗旨的前提下作出各种变化。The embodiments of the present invention have been described in detail above in conjunction with the accompanying drawings, but the present invention is not limited to the above embodiments. Within the scope of knowledge possessed by those of ordinary skill in the technical field, various modifications can be made without departing from the gist of the present invention. kind of change.

Claims (10)

1. A method for processing a timer task, comprising:
setting a first timer queue of threading in a first task, setting the timer to the first timer queue when the first task sets the timer, and setting the timer which is the earliest to be reached in the first task to a timer scanning task;
if the timer scanning task detects that a timer which is the earliest to be expired in the first task is expired, sending a timer expiration notice to the first task;
and the first task scans the first timer queue according to the timer expiration notice.
2. The method for processing the timer task according to claim 1, wherein a second task is provided with a 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 a timer scanning task; the timer scanning task is provided with a timer array, and the timer array stores a timer of the earliest time-out of the first task and a timer of the earliest time-out of the second task.
3. The method for processing the timer task according to claim 2, wherein the timer scanning task polling detects a timer that is the earliest expiration of all tasks in the timer array.
4. The method for processing the timer task according to claim 1, wherein the first task is further provided with a duplicate checking queue for checking duplicate timers set to the first timer queue, and the duplicate checking queue adopts a red-black tree data structure.
5. The method for processing the timer task according to claim 1, wherein 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.
6. A software timer, comprising:
a timer setting module, configured to set a timer set by a first task to a threaded first timer queue of the first task, and set a timer that expires earliest in the first task to a timer scanning task;
a timer scanning module, configured to detect whether an earliest expired timer in the first task expires, and send a timer expiration notification to the first task when the earliest expired timer in the first task expires; and means for scanning the first timer queue if the first task receives the timer expiry notification.
7. The software timer of claim 6, wherein the timer setting module is further configured to set a timer set by a second task to a second timer queue of the second task for threading, and set an earliest expired timer in the second task to a timer scanning task; the timer scanning task is provided with a timer array, and the timer array stores a timer of the earliest time-out of the first task and a timer of the earliest time-out of the second task.
8. The software timer of claim 7, wherein the timer scanning module polls a timer that detects the earliest expiration of all tasks stored in the timer array.
9. An operation control device comprising at least one control processor and a memory for communicative connection with the at least one control processor; the memory stores instructions executable by the at least one control processor to enable the at least one control processor to perform a method of processing a timer task as claimed in any one of claims 1 to 5.
10. A computer-readable storage medium storing computer-executable instructions for causing a computer to perform a method of processing a timer task according to any one of claims 1 to 5.
CN202110709503.6A 2021-06-25 2021-06-25 Timer task processing method, software timer and storage medium Pending CN115525402A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202110709503.6A CN115525402A (en) 2021-06-25 2021-06-25 Timer task processing method, software timer and storage medium
PCT/CN2022/096915 WO2022267860A1 (en) 2021-06-25 2022-06-02 Method for processing timer tasks, software timer and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110709503.6A CN115525402A (en) 2021-06-25 2021-06-25 Timer task processing method, software timer and storage medium

Publications (1)

Publication Number Publication Date
CN115525402A true CN115525402A (en) 2022-12-27

Family

ID=84544098

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110709503.6A Pending CN115525402A (en) 2021-06-25 2021-06-25 Timer task processing method, software timer and storage medium

Country Status (2)

Country Link
CN (1) CN115525402A (en)
WO (1) WO2022267860A1 (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102455940A (en) * 2010-10-29 2012-05-16 迈普通信技术股份有限公司 Processing method and system of timers and asynchronous events
CN102622426A (en) * 2012-02-27 2012-08-01 杭州闪亮科技有限公司 Database writing system and database writing method
CN103092682A (en) * 2011-10-28 2013-05-08 浙江大华技术股份有限公司 Asynchronous network application program processing method
US9424075B1 (en) * 2015-01-30 2016-08-23 Amazon Technologies, Inc. Dynamic virtual partitioning for delayed queues
CN111813552A (en) * 2020-07-16 2020-10-23 济南浪潮数据技术有限公司 Scheduling execution method, device and medium based on multi-thread task

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1332548C (en) * 2002-08-07 2007-08-15 华为技术有限公司 Dispatching method for massive timer
WO2007076636A1 (en) * 2005-12-31 2007-07-12 Zte Corporation A management system and management method of the timer in the software system
CN100589449C (en) * 2007-08-15 2010-02-10 中兴通讯股份有限公司 Method for implementing timing device of network processor
US8239871B2 (en) * 2008-06-24 2012-08-07 International Business Machines Corporation Managing timeout in a multithreaded system by instantiating a timer object having scheduled expiration time and set of timeout handling information

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102455940A (en) * 2010-10-29 2012-05-16 迈普通信技术股份有限公司 Processing method and system of timers and asynchronous events
CN103092682A (en) * 2011-10-28 2013-05-08 浙江大华技术股份有限公司 Asynchronous network application program processing method
CN102622426A (en) * 2012-02-27 2012-08-01 杭州闪亮科技有限公司 Database writing system and database writing method
US9424075B1 (en) * 2015-01-30 2016-08-23 Amazon Technologies, Inc. Dynamic virtual partitioning for delayed queues
CN111813552A (en) * 2020-07-16 2020-10-23 济南浪潮数据技术有限公司 Scheduling execution method, device and medium based on multi-thread task

Also Published As

Publication number Publication date
WO2022267860A1 (en) 2022-12-29

Similar Documents

Publication Publication Date Title
US7702796B2 (en) Recovering a pool of connections
CN111078436B (en) Data processing method, device, equipment and storage medium
US11611634B2 (en) Method and device for timeout monitoring
CN107241281B (en) Data processing method and device
EP3680787B1 (en) Method for synchronization between primary database and standby database, database system and device
US6988268B2 (en) IO completion architecture for user-mode networking
CN111585867A (en) Message processing method and device, electronic equipment and readable storage medium
CN111190854B (en) Communication data processing method, device, equipment, system and storage medium
US20230291696A1 (en) Method and apparatus for managing buffering of data packet of network card, terminal and storage medium
CN107589990B (en) Data communication method and system based on thread pool
US11748164B2 (en) FAAS distributed computing method and apparatus
US20230030856A1 (en) Distributed table storage processing method, device and system
CN111831408A (en) Asynchronous task processing method and device, electronic equipment and medium
US20230353323A1 (en) Communication method and apparatus
CN109831394B (en) Data processing method, terminal and computer storage medium
CN110995817B (en) Request callback method and device and client equipment
CN110928887A (en) Data processing method and device
WO2022267860A1 (en) Method for processing timer tasks, software timer and storage medium
CN107819855B (en) Message distribution method and device
CN108241616B (en) Message pushing method and device
CN113704297B (en) Processing method, module and computer readable storage medium for business processing request
CN108121580B (en) Method and device for realizing application program notification service
US20230393782A1 (en) Io request pipeline processing device, method and system, and storage medium
US11582133B2 (en) Apparatus and method for distributed processing of identical packet in high-speed network security equipment
US10284501B2 (en) Technologies for multi-core wireless network data transmission

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination