CN109684056A - A kind of timer realization method and device, scheduler, storage medium - Google Patents

A kind of timer realization method and device, scheduler, storage medium Download PDF

Info

Publication number
CN109684056A
CN109684056A CN201811497240.1A CN201811497240A CN109684056A CN 109684056 A CN109684056 A CN 109684056A CN 201811497240 A CN201811497240 A CN 201811497240A CN 109684056 A CN109684056 A CN 109684056A
Authority
CN
China
Prior art keywords
timer
automatic machine
event
node
list structure
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.)
Granted
Application number
CN201811497240.1A
Other languages
Chinese (zh)
Other versions
CN109684056B (en
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.)
China Mobile Communications Group Co Ltd
MIGU Culture Technology Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
MIGU Culture Technology Co Ltd
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 China Mobile Communications Group Co Ltd, MIGU Culture Technology Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN201811497240.1A priority Critical patent/CN109684056B/en
Publication of CN109684056A publication Critical patent/CN109684056A/en
Application granted granted Critical
Publication of CN109684056B publication Critical patent/CN109684056B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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/4812Task transfer initiation or dispatching by interrupt, e.g. masked
    • G06F9/4825Interrupt from clock, e.g. time of day
    • 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

Abstract

The embodiment of the invention discloses a kind of timer realization methods, this method comprises: obtaining the attribute value of timer Node according to preset orthogonal list structure;The wherein data store organisation of timer Node described in the preset orthogonal list structural characterization;According to the preset orthogonal list structure, the timer Node that the attribute value is characterized is inserted into position corresponding with the value of row field and column field of the preset orthogonal list structure, generates the timer;Wherein, the row field of the preset orthogonal list structure characterizes automatic machine No. the first, and the column field of the preset orthogonal list structure characterizes time point.The embodiment of the invention also discloses a kind of timer realization device, scheduler and storage mediums.

Description

A kind of timer realization method and device, scheduler, storage medium
Technical field
The present invention relates to network communication technology field more particularly to a kind of timer realization method and device, scheduler, deposit Storage media.
Background technique
Event-based model is the single thread concurrent processing model based on NIO (Non-Blocking I/O), relative to based on multithreading Concurrent processing model, event-based model have higher reliability, handling capacity will not be caused to reduce because of load increase.Event Driving model is mainly made of scheduler, event queue, automatic machine queue and event loop, to adapt to practical application scene, Timer is needed, also to complete overtime relevant treatment.However efficient design is not related to how in existing event-based model Timer, scheduler is to the management of timer than relatively time-consuming.
Summary of the invention
In view of this, an embodiment of the present invention is intended to provide a kind of timer realization method and device, scheduler, storage Jie Matter can effectively promote scheduler to the efficiency of management of timer.
The technical solution of the embodiment of the present invention is achieved in that
In a first aspect, the embodiment of the present invention provides a kind of timer realization method, it is applied in event-based model, it is described Method includes:
According to preset orthogonal list structure, the attribute value of timer Node is obtained;The wherein preset orthogonal list The data store organisation of timer Node described in structural characterization;
According to the preset orthogonal list structure, the timer Node that the attribute value is characterized is inserted into and institute The corresponding position of value for stating the row field and column field of preset orthogonal list structure, generates the timer;Wherein, described pre- If orthogonal list structure row field characterize automatic machine No. the first, the preset orthogonal list structure column field characterization when Between point.
In the above scheme, after the generation timer, the method also includes:
Calculate first time interval of the current time apart from previous scan;The current time refers to opposite morning zero point Offset;
In the first time interval, obtain in the timer it is corresponding with the current time at least one first Timer Node;
Update at least one first timer node first belongs to overtime number of days, described first to overtime number of days The attribute value of timer Node in the timer;
When at least one updated first timer node first when overtime number of days be 0 when, trigger timing thing Part.
In the above scheme, after the generation timer, the method also includes:
According to preset automatic machine number to be destroyed, at least one second timer node in the timer is deleted.
In the above scheme, after the generation timer, the method also includes:
The timer Node in the timer is retrieved, the corresponding time out event of the timer Node is put into event team Column;
Obtain the first event in the event queue;
Obtain automatic machine queue;
When the purpose of the first event corresponds to the automatic machine queue, the first event is given to corresponding automatic machine Processing;
The request for receiving the automatic machine creates new timer Node according to the request.
Second aspect, the embodiment of the present invention provide a kind of timer realization device, in application affairs driving model, the dress It sets and includes:
Attribute acquiring unit, for obtaining the attribute value of timer Node according to preset orthogonal list structure;Wherein institute State the data store organisation of timer Node described in preset orthogonal list structural characterization;
It is inserted into unit, according to the preset orthogonal list structure, the timer Node that the attribute value is characterized It is inserted into position corresponding with the value of row field and column field of the preset orthogonal list structure, generates the timer; Wherein, the row field of the preset orthogonal list structure characterizes automatic machine No. the first, the preset orthogonal list structure Column field characterizes time point.
The third aspect, the embodiment of the present invention provide a kind of scheduler, are applied in event-based model, the scheduler is extremely It less include: processor, memory, communication interface, and for connecting the processor, memory and the bus of communication interface; The processor is used to execute the timer stored in the memory and realizes program, to realize as described in above-mentioned first aspect Method.
Fourth aspect, the embodiment of the present invention provide a kind of computer readable storage medium, are applied in event-based model, It is stored thereon with timer and realizes program, be applied in event-based model, the timer realizes that program is executed by processor Method of the Shi Shixian as described in above-mentioned first aspect.
The embodiment of the invention provides a kind of timer realization method and device, scheduler, storage mediums, are applied to event In driving model, this method comprises: obtaining the attribute value of timer Node according to preset orthogonal list structure;It is wherein described The data store organisation of timer Node described in preset orthogonal list structural characterization;According to the preset orthogonal list knot Structure, the timer Node that the attribute value is characterized are inserted into row field and column with the preset orthogonal list structure The corresponding position of the value of field, generates the timer;Wherein, the row field characterization first of the preset orthogonal list structure The column field of automatic machine number, the preset orthogonal list structure characterizes time point.That is, what the embodiment of the present invention proposed A kind of timer realization method stores timer Node by default orthogonal list structure, improves scheduler to timer The efficiency of management.
Detailed description of the invention
Fig. 1 is the structure chart of event-based model;
Fig. 2 is a kind of structure chart of the event-based model with timer proposed in the embodiment of the present invention;
Fig. 3 is a kind of flow chart one for timer realization method that the embodiment of the present invention proposes;
Fig. 4 is a kind of illustratively preset cross link structure figure of timer provided in an embodiment of the present invention;
Fig. 5 is a kind of flow diagram for timer realization method that the embodiment of the present invention proposes;
Fig. 6 is a kind of flowchart 2 for timer realization method that the embodiment of the present invention proposes;
Fig. 7 is the timer scanning algorithm flow diagram based on double Mapping data structures;
Fig. 8 is a kind of flow diagram for timer queue scan method that the embodiment of the present invention proposes;
Fig. 9 is a kind of flow chart 3 for timer realization method that the embodiment of the present invention proposes;
Figure 10 is a kind of all calculations for having not timed out timer Node for deleting specified automatic machine provided in an embodiment of the present invention Method flow diagram;
Figure 11 is a kind of timer realization method flow chart four provided in an embodiment of the present invention;
Figure 12 is the flow diagram of event loop in event-based model of embodiment of the present invention structure;
Figure 13 is the flow diagram without event loop in the event-based model structure of timer module;
Figure 14 is a kind of timer realization device figure that the embodiment of the present invention proposes;
Figure 15 is a kind of timer queue scanning means figure that the embodiment of the present invention proposes;
Figure 16 is that a kind of timer Node that the embodiment of the present invention proposes deletes device figure;
Figure 17 is a kind of event loop device figure that the embodiment of the present invention proposes;
Figure 18 is a kind of composed structure schematic diagram for scheduler that the embodiment of the present invention proposes.
Specific embodiment
Event-based model is mainly made of scheduler, event queue, automatic machine queue and event loop.Fig. 1 is thing The structure chart of part driving model, by constantly executing event loop, drives entire as shown in Figure 1, scheduler is the core of system Each module operation of frame, while scheduler acts also as tertium quid role, the phase between scheduling events queue, network, automatic machine queue Mutually call.
However, in practical application, especially in communication protocol processes, automatic machine in addition to needs processing come automatic network or its Outside the event of his automatic machine on schedule, it is also necessary to which timer is set to handle the time out event not executed.Typical scene is such as: caller hair It send a message to network, waits called returning response message, at this time timer need to set, so that scheduler can be according to quilt Cry within the time of timer setting whether response message and execute corresponding operating, comprising: be called the non-response message within the time When, corresponding time out event is constructed to notify caller.
Fig. 2 is a kind of structure chart of the event-based model with timer proposed in the embodiment of the present invention, such as Fig. 2 institute Showing, it further includes timer queue that event-based model structure chart, which not only includes scheduler, event queue, automatic machine queue, wherein Timer queue is orthogonal list structure, and the horizontal axis of orthogonal list structure is time shaft, represents the timing length of time trigger;It is vertical Axis is automatic arbor, the automatic machine number of representative office's director's part.
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete Site preparation description.
Embodiment one
The embodiment of the invention provides a kind of timer realization method, Fig. 3 is a kind of timing that the embodiment of the present invention proposes The flow chart one of device implementation method, as shown in figure 3, in an embodiment of the present invention, timer realization method may include following Step:
S101, according to preset orthogonal list structure, obtain the attribute value of timer Node;Wherein preset orthogonal list The data store organisation of structural characterization timer Node.
In an embodiment of the present invention, scheduler constructs timer Node, the reality of timer according to the request of automatic machine Existing device, that is, scheduler.Scheduler can obtain timer according to preset orthogonal list structure after constructing timer Node The attribute value of node, wherein the data store organisation of preset orthogonal list structural characterization timer Node.
It should be noted that automatic machine is commonly known as finite state machine in field of software development, with the side of automatic machine Formula handles problem and (only transmits money through explicit state between the step of formula of execution is divided into automatic machine and each step News) it is necessary some in the design of event-driven formula.
Illustratively, in network communication field, automatic machine can be understood as different communication protocol, and network session event Execution, completed based on communication protocol.
In an embodiment of the present invention, scheduler can receive the request of automatic machine and construct timer Node.Including certainly Motivation requests next event after having handled an event, and manages for one timer of next event request.Accordingly Ground, scheduler can receive the request of automatic machine and construct corresponding timer Node.Automatic machine request scheduling device creates timer The case where node further includes that current event is untreated, needs to create corresponding time out event, at this point, scheduler can also receive automatically The request of machine and construct corresponding timer Node.
Illustratively, automatic machine can then generate connection message after the message related to calls for completing a caller, at this point, adjusting It is the request that connection message creates timer that degree device, which can receive automatic machine,.Either automatic machine after issuing message related to calls, Caller does not receive feedback in predetermined time, and automatic machine may need to create corresponding time out event at this time, to prompt caller to exhale Message is made not to be successfully executed, it is the request that time out event creates timer that scheduler, which can also receive automatic machine, at this time.
It should be noted that in an embodiment of the present invention, scheduler is after constructing timer Node, according to preset Orthogonal list structure obtains the attribute of timer Node.It is wrapped in the data store organisation that preset orthogonal list structure is characterized Include automatic machine No. the first, to overtime number of days and time point.Scheduler obtains timer Node according to preset orthogonal list structure Attribute value be include the automatic machine No. the first for obtaining timer Node, first to overtime number of days and first time point.
Further, in an embodiment of the present invention, in the data store organisation that preset orthogonal list structure is characterized It further include the automatic machine number of each automatic machine in automatic machine queue, it is in an embodiment of the present invention, each automatic machine is corresponding Automatic machine be known as automatic machine No. the second.The attribute value of timer Node further includes automatic machine No. the second, so as to subsequent basis Automatic machine No. first automatic machine No. the second of corresponding taking-up.
Moreover, in an embodiment of the present invention, in the data store organisation that preset orthogonal list structure is characterized It further include four bidirectional pointers.Four bidirectional pointers safeguard orthogonal list when mainly timer being facilitated to delete.
Illustratively, when the timing that scheduler needs one to be had on orthogonal list up and down direction adjacent timing When device knot removal, following modification mode can be taken: the bottom pointer of the adjacent timer Node in modification top be currently to Delete the identical timer Node in lower section that timer Node bottom is directed toward;The top pointer of the adjacent timer Node in modification lower section The adjacent timer Node in top being directed toward for current timer Node top to be deleted;Modify the adjacent timer Node in the left side Right pointer is the adjacent timer Node in the right that current timer Node right to be deleted is directed toward;The adjacent timing in modification the right The left pointer of device node is the adjacent timer Node in the left side that current timer Node left to be deleted is directed toward.
In this way, the doubly linked list structure of horizontal remains unchanged, subsequently through water after deleting timer Node The doubly linked list gauge outfit of flat/vertical direction, still can normally traverse entire chained list.And by modifying timer section to be deleted The timer Node that point four direction pointer is directed toward is the next node of timer Node to be deleted, Algorithms T-cbmplexity It is very low, only o (1).
Further, in an embodiment of the present invention, the method that scheduler obtains automatic machine No. the first of timer Node Are as follows: the corresponding automatic machine number of automatic machine and first threshold modulus are obtained timer Node and correspond to preset cross chain by scheduler Automatic machine No. first of the row field of table structure;Wherein, the longitudinal length of first threshold characterization orthogonal list structure.
It should be noted that in an embodiment of the present invention, first threshold is a parameter, hash in orthogonal list structure Function (i.e. modulo operation) is automatic machine number (automatic machine No. the second) mod first threshold, for different automatic machines number, hash Functional value may be identical, and it is corresponding to be all placed on hash functional value for the corresponding timer Node of the identical automatic machine of each hash functional value In the conflict chained list that the corresponding conflict chained list gauge outfit of the orthogonal list longitudinal axis is directed toward, corresponding is automatic machine No. the first.In addition, such as Described in preceding, first threshold is a parameter, and the parameter value is adjustable, but in an embodiment of the present invention, and first Threshold value is preferably 2 power side, and such hash function can be obtained by displacement mode operation.It is understood that the first threshold Value is bigger, and conflict chained list is shorter, and search efficiency is higher, certainly bigger for the memory of memory contention chained list gauge outfit.
Illustratively, first threshold can be 8192, automatic for different automatic machine number (automatic machine No. the second), second Machine mod 8192 may identical (when such as the second automatic machine number=8293 and automatic machine No. the second=1, be by 8192 modulus 1).Automatic machine No. second be 8293 and second automatic machine number be 1 the corresponding timer Node of automatic machine be all placed on orthogonal list In the same conflict chained list that the corresponding conflict chained list gauge outfit of the longitudinal axis is directed toward.
Further, in an embodiment of the present invention, scheduler obtains the first side to overtime number of days of timer Node Method are as follows: timing length and second threshold are rounded by timer, obtain timer Node in data store organisation first to super When number of days;Wherein, timing length is the time to be triggered that automatic machine handles event, and second threshold characterizes the cross of orthogonal list structure To length.The method that scheduler obtains the first time point of timer Node are as follows: scheduler asks timing length and current time With rear and second threshold modulus, obtains timer Node and correspond to the first time point in the column field of orthogonal list structure;Wherein Current time refers to the offset of opposite morning zero point.
It should be noted that in an embodiment of the present invention, it is not absolute time that timing length, which is a relative time,.
Illustratively, second threshold 86400 represent one day duration, when scheduler is arranged according to the request of automatic machine One timing length is the timer Node of 49 hours 10 minutes durations, and timer Node days initial value is 2, the i.e. timer The first of node is 2 to overtime number of days.And at the time of in the horizontal axis characterization of orthogonal list one day, it can be understood as every on horizontal axis One lattice scale, which represents, shares 86400 lattice for 1 second one.When current time curSecond is 0 with respect to the offset of morning zero point, The corresponding current time curSecond of timing length is that curSecond pointer deviates 1 backward again in the horizontal axis coordinate of orthogonal list 10 minutes hours, i.e. curSecond pointer will deviate 4200 lattice backward;And when current time curSecond is with respect to morning zero point Offset when being 84000, the corresponding current time curSecond of timing length needs deviate 4200 lattice backward again, practical horizontal seat Target value be just 1800 (84000+4200 divided by 86400 after remainder).
In addition, it should be noted that, scheduler is during scanning timer Node, the every multiple scanning of scheduler to one The value of secondary current time, the first overtime day digital section in the data store organisation of timer Node just subtracts 1, when scheduler is found When the overtime number of days of the first of some timer Node is 0, indicates that time is up for the timer Node, need to trigger overtime thing Part.
S102, according to preset orthogonal list structure, the timer Node that attribute value characterizes is inserted into and preset ten The corresponding position of value of the row field and column field of word list structure generates timer;Wherein, preset orthogonal list structure Row field characterizes automatic machine No. the first, and the column field of preset orthogonal list structure characterizes time point.
In an embodiment of the present invention, scheduler, can be according to preset cross after the attribute value for obtaining timer Node The timer Node that attribute value characterizes is inserted into corresponding with the value of the row field of orthogonal list structure and column field by list structure Position, i.e., generation timer.
It include: first automatic as described in step S101, in the data store organisation of the timer Node in timer Machine number, first are to overtime number of days, first time point and automatic machine No. the second.
Illustratively, Fig. 4 is a kind of illustratively preset cross link structure of timer provided in an embodiment of the present invention Figure, as shown in figure 4, the horizontal axis of timer is 86400, unit is the second;The longitudinal axis is 8192, corresponding automatic machine No. first.The timing There are 5 timer Nodes in device, wherein timer Node 1 and the timing length having the same of timer Node 2, first are automatically Machine number and automatic machine No. the second;And timer Node 3 and the automatic machine No. first having the same of timer Node 1, but it is different Automatic machine No. second and first is to overtime number of days and first time point;Timer Node 4 and timer Node 1 are having the same Automatic machine No. first and automatic machine No. the second, but different first is to overtime number of days and first time point;Timer Node 5 and fixed When device node 1 have identical first time point, but different the first overtime number of days, the first autonumber and automatic machines No. the second.
It is understood that in an embodiment of the present invention, scheduler creation has the timing of orthogonal list storage organization Device, so that scheduler searches timer Node, and the time complexity for the operations such as deleting to timer Node reduces, convenient Management of the scheduler to timer.
Illustratively, Fig. 5 is a kind of flow diagram for timer realization method that the embodiment of the present invention proposes, such as Fig. 5 It is shown, this method comprises:
S201, scheduler construct timer Node according to the request of automatic machine.
FsmHash=fsmNo%8192 is arranged in S202, scheduler, and timeHash=is arranged (when curSecond+ timing It is long) %86400, timing length/86400 days=are set.
It should be noted that fsmHash is longitudinal first of orthogonal list in illustratively embodiment of the invention Automatic machine number, fsmNo are the automatic machine number (automatic machine No. the second) of automatic machine, and days is first to overtime number of days, and 8192 be the One threshold value, 86400 be second threshold.
The timer Node of construction is inserted into the corresponding Hash chained list gauge outfit of timeHash by S203, scheduler.
It should be noted that timeHash corresponds to the water of orthogonal list structure in illustratively embodiment of the invention Square to.
The timer Node of construction is inserted into the corresponding Hash chained list gauge outfit of fsmHash by S204, scheduler.
It should be noted that fsmHash corresponds to the vertical of orthogonal list structure in illustratively embodiment of the invention Direction.
By the process of the timer realization method of Fig. 5 it is found that scheduler is under the request of automatic machine, according to timing length With automatic machine number, calculate separately horizontally and vertically coordinate, then by timer Node be inserted into it is corresponding horizontal and Vertical direction chained list, Algorithms T-cbmplexity are o (1).
Embodiment two
Same inventive concept based on embodiment one, Fig. 6 are a kind of timer realization method that the embodiment of the present invention proposes Flowchart 2, as shown in fig. 6, in an embodiment of the present invention, after generating timer, i.e. after step S102, the present invention Embodiment provide a kind of timer realization method can with the following steps are included:
S103A, first time interval of the current time apart from previous scan is calculated, current time refers to opposite morning zero point Offset.
In an embodiment of the present invention, scheduler, can be based on pre- after the internet message for receiving the return of select system If the corresponding timer Node of orthogonal list structural scan.Before the scan, before scheduler can calculate current time distance The first time interval of secondary scanning.Wherein, current time refers to the offset of opposite morning zero point.
Scheduler can be swept after the creation for realizing the timer with orthogonal list structure based on orthogonal list structure Corresponding timer Node is retouched, scheduler can be referred to as timer queue scanning algorithm to the scan method of timer Node. Scheduler calls (such as 20 milliseconds) timer queue scanning algorithm at regular intervals, and the time interval called every time can not Together, in event-based model, timing time delay can be called by select system and be realized, in this way if stopped in select system There is internet message arrival during dormancy, select system can return to scheduler immediately and execute, rather than latency period always, To improve system response time and handling capacity.
Further, in an embodiment of the present invention, when current time is apart from the first time interval of previous scan time When no more than 0, illustrate that scheduler is terminated also without scanning timer, scanning process at this time.
S104A, in first time interval, obtain timer at least one first timer corresponding with current time Node.
In an embodiment of the present invention, when first time interval is greater than 0, scheduler obtains in first time interval At least one first timer node corresponding with current time in timer.
It should be noted that in an embodiment of the present invention, scheduler in first time interval, obtain in timer with At least one corresponding first timer node of current time refers to: obtaining each current time within the scope of first time interval On first timer node, wherein each current time is likely present multiple first timer nodes in vertical direction.
Illustratively, it is assumed that first timer node, second timer node and the 5th timer Node pair shown in Fig. 4 The first time point answered is 8631, then scheduler can obtain 3 timer Nodes under 8631 current time, wherein the The automatic machine No. the first and first timer node of five timer Nodes and the first automatic machine difference of second timer node.
Specifically, the method that scheduler obtains at least one first timer node are as follows: scheduler is in first time interval It is interior, update current time;When updated current time be less than second threshold when, obtain timer in it is updated current when Between at least one corresponding first timer node;Wherein, the lateral length of second threshold characterization orthogonal list structure.
It should be noted that in an embodiment of the present invention, current time is in corresponding orthogonal list structure on horizontal axis Time point, first time interval characterize scheduler and are based on the scannable range of current time.Scheduler is in first time interval model Interior traversal is enclosed, updated current time is based on, obtains at least one first timer node.
Illustratively, when second threshold is 86400, current time is the value between 0~86399, such as 8630.And first When time interval is 10 seconds, the scannable range of scheduler is 8631~8640.When any moment in the scanning range when Between o'clock less than 86400 when, scheduler just since 8631, obtains at least one corresponding timer section in timer by time point Point.Wherein, 8631~8640 any moment is updated current time.
Further, in an embodiment of the present invention, it includes: scheduler according to current time that scheduler, which updates current time, With the first prefixed time interval, obtained for the second time point;When being not less than second threshold at the second time point, current time is updated It is 0.
Illustratively, if current time be 86399, the first prefixed time interval be 1, then its second time point be When 86400, current time is reset to 0 at this time.In an embodiment of the present invention, the horizontal direction of orthogonal list can be interpreted as One annular, current time move in ring.
Further, in an embodiment of the present invention, scheduler update current time further include: scheduler according to it is current when Between and the second prefixed time interval, obtain the second time point;When being less than second threshold at the second time point, and work as in timer not When in the presence of at least one first timer node corresponding with the second time point, according between the second time point and the second preset time Every, obtain third time point, current time is updated to third time point.
Illustratively, when current time is 8630, the second prefixed time interval is 1, then the second time point was 8631, this Two time points, there is no the timer sections that first time point is 8631 less than 86400, and in the timer of orthogonal list structure When point, obtaining the third time at this time is 8632, and updating current time is 8632.
S105A, update the first of at least one first timer node to overtime number of days, first belong to overtime number of days it is fixed When device in timer Node attribute value.
In an embodiment of the present invention, it is fixed to will be updated at least one after obtaining at least one timer Node for scheduler When device node first to overtime number of days, wherein first is the attribute value of timer Node to overtime number of days.
It should be noted that in an embodiment of the present invention, the first of at least one first timer node is updated to super When number of days refer to when scheduler scans are at least one first timer node, by the of at least one timer Node One subtracts 1 to the value of overtime number of days.
Illustratively, the first of the corresponding first timer node of current time is when overtime number of days is 1, scheduler When scanning the first timer node, updating first to overtime number of days is 0.
S106A, when at least one updated first timer node first when overtime number of days be 0 when, triggering timing Everything part.
In an embodiment of the present invention, scheduler is when at least one updated first timer node is first to super When number of days be 0 when, trigger timed events.
It should be noted that in an embodiment of the present invention, when first day of scheduler scans to first timer node Number is 0, shows that timing has arrived, need to trigger timed events.
Further, in an embodiment of the present invention, after triggering timed events, scheduler may also need to construct time-out Event, and it is put into event queue.
Illustratively, automatic machine executes message related to calls at corresponding time point, i.e. scheduler triggers timed events, then Automatic machine can also request scheduling device generate connection message, which is put into event queue, as scheduler construction is super When event, which is put into event queue by scheduler.
Further, in an embodiment of the present invention, scheduler need to also be deleted after triggering timed events in timer Except at least one first timer node.
In an embodiment of the present invention, scheduler deletes at least one first timer node after triggering timer event Purpose be to prevent the subsequent repeated trigger timed events.
It is understood that the timer in the embodiment of the present invention is the data store organisation of orthogonal list.However, in order to Take into account timer timing scan scene and timer and destroy scene, common processing mode be can define two Map:Map < from Motivation number, List<timer>>and Map<time, List<timer>>.Fig. 7 is the timer based on double Mapping data structures Scanning algorithm flow diagram, as shown in fig. 7, the timer scanning algorithm based on double Mapping data structures includes the following steps:
S401, scheduler calculate interval number of seconds gap of the present scan apart from last scan.
S402, scheduler judge whether gap is greater than 0, if more than 0, execute step S403;It is no to then follow the steps S414.
S403, scheduler update current time curSecond, update mode curSecond=curSecond+1.
S404, scheduler judge whether current time curSecond is more than or equal to 86400, when curSecond is less than Step S405A is executed when 86400, it is no to then follow the steps S405B.
S405A, scheduler are based on time Map, timer Node are traversed in the List1 that curSecond is directed toward, when finding Step S406A is executed when corresponding timer Node;Otherwise, step S406B is executed.
It should be noted that time Map refers to Map<time, List<timer>>.
It is 0 that S405B, scheduler, which update current time curSecond, continues to execute step S405A.
S406A, scheduler take out corresponding timer Node timer1 in List1.
Gap value is subtracted 1 by S406B, scheduler, and returns to step S402.
The days value of timer1 is subtracted 1 by S407, scheduler.
It should be noted that the days of timer1 represents the overtime number of days of timer Node.
S408, scheduler judge whether the days value of timer1 is equal to 0, when being equal to 0, execute step S409A, no Then follow the steps S409B.
S409A, scheduler delete timer1 from List1, continue to execute step S410.
S409B, step S405A is continued to execute.
S410, scheduler are based on automatic machine Map, traverse timing in the List2 that corresponding set automatic machine number is directed toward Device node executes step S411A when finding corresponding timer Node;It is no to then follow the steps S405A.
It should be noted that automatic machine Map refers to Map<automatic machine number, List<timer>>.
S411A, scheduler take out corresponding timer Node timer2 in List2.
S412, scheduler judge whether timer2.timeHash is equal to timer.timeHash and curSecond, and Whether timer2.days is 0, if meeting condition thens follow the steps S413;It is no to then follow the steps S410.
S413, scheduler delete timer2 from List2.
S414, scheduler scans terminate.
Relatively, in an embodiment of the present invention, illustratively, Fig. 8 is a kind of timer that the embodiment of the present invention proposes The flow diagram of queued scans method, as shown in figure 8, this method comprises:
S501, scheduler calculate interval number of seconds gap of the present scan apart from last scan.
S502, scheduler judge whether gap is greater than 0, when being greater than 0, execute step S503, no to then follow the steps S510.
S503, scheduler are by current time curSecond, update mode curSecond=curSecond+1.
S504, scheduler judge whether current time curSecond is more than or equal to 86400, when curSecond is less than Step S505A is executed when 86400, it is no to then follow the steps S505B.
S505A, scheduler traversal curSecond are directed toward on chained list whether have the timer Node not traversed, if so, holding Row step S506A;It is no to then follow the steps S506B.
S506A, scheduler take out timer Node timer, continue to execute step S507.
Gap value is subtracted 1 by S506B, scheduler, returns to step S502.
S507, scheduler update timer Node, update mode are as follows: timer.days=time.days-1.
It should be noted that in an embodiment of the present invention, time.days represents the first overtime day of timer Node Number.
S508, scheduler judge whether timer.days is equal to 0, if so, executing step S509;Step is executed if it is not, returning Rapid S505A.
S509, scheduler delete timer Node timer from orthogonal list structure, and construct corresponding overtime thing Part is put into event queue, and continues to execute step S505A.
S510, scheduler scans terminate.
It is understood that in scanning algorithm shown in Fig. 7, more Map need to safeguard, algorithm complexity will be big Width is promoted.Such as in timer queue scanning algorithm, it is assumed that Map<time, List<timer>>in List average length For M, Map<automatic machine number, List<timer>>in the average length of List be N, each sweep spacing is T, then algorithm is complicated Degree is O (T*M*N).And in the embodiment of the present invention, using orthogonal list timer scanning algorithm when, pass through orthogonal list Horizontal direction pointer, so that it may find adjacent node before and after timer to be deleted, they are connected, does not need to lead to again Cross the similar Map<automatic machine number of traversal, List<timer>>data structure, so its algorithm complexity is only O (T*M).
Embodiment three
Same inventive concept based on embodiment one, Fig. 9 are a kind of timer realization method that the embodiment of the present invention proposes Flow chart 3, as shown in figure 9, in an embodiment of the present invention, after generating timer, i.e. after step S102, the present invention Embodiment provide a kind of timer realization method can with the following steps are included:
S103B, by preset automatic machine number to be destroyed and first threshold modulus, generate automatic machine No. the first;Wherein, first Threshold value characterizes the longitudinal length of preset orthogonal list structure.
In an embodiment of the present invention, scheduler receive automatic machine request after, will preset automatic machine number to be destroyed and First threshold modulus, generates automatic machine No. the first, and first threshold characterizes the longitudinal length of preset orthogonal list structure.
Illustratively, automatic machine number to be destroyed is 8293, first threshold 8192, then by preset automatic machine to be destroyed Number with first threshold modulus generate automatic machine No. the first be 1.
In embodiments of the present invention, scheduler may be used also after the creation for realizing the timer with orthogonal list structure Specified all of automatic machine are deleted according to the request of automatic machine and have not timed out timer Node, and specifically, scheduler is according to preset Automatic machine number to be destroyed deletes at least one second timer node in timer.
S104B, according to automatic machine No. the first, obtain at least one third timer Node in timer, at least one It further include automatic machine No. the second in third timer Node.
In an embodiment of the present invention, scheduler can obtain at least one of timer according to automatic machine No. the first Three timer Nodes further include automatic machine No. the second at least one third timer Node.
It should be noted that further include in an embodiment of the present invention, at least one third timer Node second from Motivation number, automatic machine No. the second also belong to the attribute value of timer Node in preset orthogonal list structure, automatic machine No. the second Be it is corresponding with automatic machine No. the first, automatic machine No. the first is obtained after automatic machine No. the second and first threshold modulus.The Automatic machines No. two are the corresponding automatic machine number of automatic machine, and automatic machine No. the first characterizes automatic machine No. the second in preset orthogonal list The value of the row field of structure.
Illustratively, the second automatic automatic machine number is 8293, first threshold 8192, and automatic machine No. the first is 1 (8293%8192), the first automatic machine number 1 is value of second automatic machine number 8293 in the row field of preset orthogonal list structure.
S105B, automatic machine No. the second and preset automatic machine phase to be destroyed when at least one third timer Node Meanwhile obtaining at least one second timer node.
In real-time example of the invention, scheduler can further judge after obtaining at least one third timer Node At least one identical second timer node with preset automatic machine number to be destroyed.
It should be noted that because automatic machine No. the first is obtained by automatic machine No. the second and first threshold modulus, it is right It may be identical in automatic machine No. first of the second different automatic machines number in preset orthogonal list structure.
Illustratively, in timer Node shown in Fig. 4, as described in step S602, has same first automatic machine Number at least one corresponding third timer Node includes four, and such as timer Node 1-4, automatic machine No. the first is all fsmHash1.And in 4 timer Nodes, timer Node 1, timer Node 2, timer Node 4 automatic machine No. the second For fsmNo1, automatic machine No. the second of timer Node 3 is fsmNo3.When automatic machine number to be destroyed is fsmNo1, then obtain At least one the second timer node taken includes timer Node 1, timer Node 2, timer Node 4.
S106B, at least one second timer node is deleted.
In an embodiment of the present invention, scheduler is after obtaining at least one second timer node, can will at least One second timer node is deleted from timer, is deleted with completing the timer Nodes that have not timed out all to specified automatic machine It removes.
It is understood that in an embodiment of the present invention, the automatic machine number that scheduler passes through calculating automatic machine to be destroyed Automatic machine No. the first, then clear up in timer Node belonging to automatic machine No. the first automatic machine No. the second and to be destroyed automatic The identical timer Node of machine number.If the length of horizontal direction list is M, the time complexity of algorithm is O (M).
Illustratively, Figure 10 is that a kind of delete provided in an embodiment of the present invention specifies all of automatic machine to have not timed out timer The algorithm flow schematic diagram of node, as shown in Figure 10, timer Node delet method includes:
S701, scheduler obtain the first automatic machine fsmHash.
It should be noted that in an embodiment of the present invention, the first automatic machine fsmHash=automatic machine % to be deleted 8192。
S702, scheduler search in the corresponding timer of fsmHash whether have the node not traversed, if so, executing step S703, it is no to then follow the steps S706.
S703, scheduler take out a timer Node timer from the corresponding timer of fsmHash.
S704, scheduler judge whether timer.fsmNo and automatic machine number to be deleted are equal, if so, step S705 is executed, It is no to then follow the steps S702.
It should be noted that in an embodiment of the present invention, timer.fsmNo is the second automatic machine of timer Node Number.
S705, scheduler delete timer Node timer from timer, continue to execute step S702.
S706, end.
Example IV
Same inventive concept based on embodiment one, Figure 11 are a kind of timer realization method provided in an embodiment of the present invention Flow chart four, as shown in figure 11, in an embodiment of the present invention, after generating timer, i.e. after step S102, timer is real Existing method can also include the following steps:
Timer Node in S103C, retrieval timer, is put into event team for the corresponding time out event of timer Node Column.
In an embodiment of the present invention, scheduler is after the creation for realizing the timer with orthogonal list structure, i.e., Execution event can be recycled based on the event-based model with orthogonal list structure timer.
In an embodiment of the present invention, scheduler can retrieve timing after the timer for generating orthogonal list structure Corresponding time out event is put into event queue by the timer Node in device.
It should be noted that in an embodiment of the present invention, the time out event that scheduler not only generates in dispatch timer, It also needs processing to carry out the request of automatic network, network request decoding is converted into event deposit event queue.Wherein, network request refers to Request based on http protocol, to request to service to WEB server.And in the embodiment China of this law invention, time out event It can be understood as having executed the event that may be needed to be implemented in next step after timed events.Time out event is also scheduler according to automatic The request of machine and create, and corresponding timer Node is created in timer for the time out event.
Illustratively, automatic machine can then generate connection message, scheduler exists after the message related to calls for completing a caller After the request for receiving automatic machine, time out event can be created for the connection message, and corresponding timer section is created in timer Point.
First event in S104C, acquisition event queue.
In an embodiment of the present invention, scheduler can take after time out event is put into event queue from event queue Outgoing event, to be handled to corresponding automatic machine.
It should be noted that the core of event-based model is, there are multiple events in event queue, if there is event standard It gets ready, scheduler will dispatch corresponding automatic machine place to go director's part.
Illustratively, there are call event, connection event etc. in event queue, when call event triggers, scheduler will be adjusted The automatic machine of degree processing calling goes execution event.
S105C, automatic machine queue is obtained.
In an embodiment of the present invention, scheduler can obtain automatic machine queue after obtaining pending first event, with Just first event corresponding automatic machine is scheduled to handle.
S106C, when the purpose of first event corresponds to automatic machine queue, by first event give corresponding automatic machine handle.
In an embodiment of the present invention, scheduler can do different processing according to the purpose of first event, when the first thing When the purpose of part corresponds to automatic machine queue, i.e., first event is delivered to corresponding automatic machine and handled.
It should be noted that in an embodiment of the present invention, the first event that scheduler takes out from event queue, this The purpose of one event is also possible to corresponding be network module.When it is network module that first event is corresponding, scheduler can be incited somebody to action To the event code, binary code stream is converted to, issues external progress processing.
Further, in an embodiment of the present invention, when the purpose of first event corresponds to automatic machine queue, scheduler is also It need to judge automatic machine number whether effectively.Specifically, when scheduler judges that the purpose of first event corresponds to automatic machine queue, scheduling Device searches automatic machine corresponding with the automatic machine number of first event in automatic machine queue, when there are corresponding automatic machine, Scheduler gives first event to automatic machine processing;And when corresponding automatic machine is not present, scheduler will create and first event Corresponding automatic machine, and give first event to automatic machine processing.
S107C, the request for receiving automatic machine, new timer Node is created according to request.
In an embodiment of the present invention, first event is being handled it to corresponding automatic machine in automatic machine queue by scheduler Afterwards, also new timer Node can be created according to the request of automatic machine.
It should be noted that in an embodiment of the present invention, automatic machine, can request scheduling device after having handled first event The automatic machine is deleted, in case event repeats.Moreover, automatic machine is also possible to that new event and request scheduling device can be generated New event is put into event queue so as to subsequent triggers execution, and simultaneously, automatic machine can also be that this is new with request scheduling device Event creates new timer Node.After scheduler receives the request that automatic machine creates new timer Node, it is also desirable to according to Preset orthogonal list structure creates, and the new timer Node of creation is put into the row field of preset orthogonal list structure Position corresponding with the value of column field.
Illustratively, an intelligent call, when calling automatic machine sends request connection called message, if in timing It is interior, receive the EDP message for identifying called off-hook, it is necessary to this timer Node for representing connection message be removed, it is prevented It is triggered below;It is all answered without off-hook if being called in timing, one section of prompt tone at this moment can be put to caller, is then released Put calling.Give calling party one section of prompt tone, i.e. the new events of scheduler creation, scheduler can also be determined for new events creation is new When device node, and new timer Node is put into row field and the corresponding position of column field of preset orthogonal list structure.
Based on above-mentioned steps S103C-S107C, illustratively, Figure 12 is in event-based model of embodiment of the present invention structure The flow diagram of event loop, as shown in figure 12, event loop includes the following steps:
S901, scheduler read the request for carrying out automatic network, and decoding is converted to event deposit event queue.
S902, scheduler retrieve timer queue, find out each overtime timer node, generate time out event and are put into event team Column.
S903, scheduler take out event from event queue.
S904, scheduler do different processing according to different event purposes, execute step S905A, S905B or S905C.
S905A, scheduler judge event purpose for automatic machine queue, and when automatic machine number is invalid, and scheduler creation is automatic Machine, and be put into automatic machine queue, while event is delivered to the automatic machine and handled by scheduler, and further executes step S906。
S905B, scheduler judge event purpose for automatic machine queue, and when automatic machine number is effective, scheduler is from automatic machine Corresponding automatic machine is found in queue, is delivered to it and is handled, and further executes step S906.
S905C, scheduler judge that event purpose is for network module, and event code is converted to binary code by scheduler Stream, issues external progress.
S906, scheduler receive the request of corresponding automatic machine, execute operation, comprising: destroy automatic machine/generation new events simultaneously It is put into the new timer Node of event queue/creation.
Relatively, Figure 13 is the flow diagram without event loop in the event-based model structure of timer module, As shown in figure 13, event loop includes the following steps:
S1001, scheduler read the request for carrying out automatic network, and decoding is converted to event deposit event queue.
S1002, scheduler take out event from event queue.
S1003, scheduler do different processing according to different event purposes, execute step S1004A, S1004B or S1004C。
S1004A, scheduler judge event purpose for automatic machine queue, and when automatic machine number is invalid, and scheduler creation is automatic Machine, and be put into automatic machine queue, while event is delivered to the automatic machine and handled by scheduler, and further executes step S1005。
S1004B, scheduler judge event purpose for automatic machine queue, and when automatic machine number is effective, scheduler is from automatic machine Corresponding automatic machine is found in queue, is delivered to it and is handled, and further executes step S1005.
S1004C, scheduler judge that event purpose is for network module, and event code is converted to binary code by scheduler Stream, issues external progress.
S1005, scheduler receive the request of corresponding automatic machine, execute operation, comprising: destroy automatic machine/generation new events And it is put into event queue.
Comparison is without in the method and the embodiment of the present invention of event loop in the event-based model structure of timer module Event loop method, it is to be understood that in an embodiment of the present invention, scheduler, which can constantly be read, carrys out disappearing for automatic network Breath, and network request decoding is converted into event deposit event queue, moreover, in the embodiment of the present invention, scheduler can also The timed node in timer is retrieved, generates time out event to be put into event queue, and scheduler can also receive asking for automatic machine It asks, creates new timer Node for new events, i.e. the embodiment of the present invention passes through timer of the creation based on orthogonal list structure, Scheduler is also enabled to dispatch the processing for completing time out event.
Embodiment five
Same inventive concept based on embodiment one to example IV, the embodiment of the invention provides a kind of realizations of timer Device, Figure 14 is a kind of timer realization device figure that the embodiment of the present invention proposes, as shown in figure 14, in the embodiment of the present invention In, timer realization device 1000 includes:
Attribute acquiring unit 1001, for obtaining the attribute value of timer Node according to preset orthogonal list structure;Its Described in timer Node described in preset orthogonal list structural characterization data store organisation;
It is inserted into unit 1002, according to the preset orthogonal list structure, the timer that the attribute value is characterized Node is inserted into position corresponding with the value of row field and column field of the preset orthogonal list structure, generates the timing Device;Wherein, the row field of the preset orthogonal list structure characterizes automatic machine No. the first, the preset orthogonal list structure Column field characterize time point.
It in other examples, include automatic machine No. the first in the data store organisation, to overtime number of days and time Point, the attribute acquiring unit 1001 are also used to obtain the timer Node according to the preset orthogonal list structure Automatic machine No. first, first are to overtime number of days and first time point.
It in other examples, include automatic machine No. the first in the data store organisation, to overtime number of days and time Point, the attribute acquiring unit 1001 are also used to the corresponding automatic machine number of the automatic machine and first threshold modulus obtaining institute State the automatic machine No. first that timer Node corresponds to the row field of the preset orthogonal list structure;Wherein, described One threshold value characterizes the longitudinal length of the preset orthogonal list structure;
Timing length and second threshold are rounded, obtain the timer Node in the data store organisation described in First to overtime number of days;Wherein, the timing length is the time to be triggered that the automatic machine handles event, the second threshold Characterize the lateral length of the preset orthogonal list structure;
After the timing length and current time summation, with second threshold modulus, the timer Node will be obtained and correspond to institute State the first time point in the column field of preset orthogonal list structure;Wherein the current time refers to opposite morning zero The offset of point.
In other examples, after generating timer, the timer realization device 1000 further include:
Timing unit 1003A, for calculating first time interval of the current time apart from previous scan;The current time Refer to the offset of opposite morning zero point.
Acquiring unit 1004A, in the first time interval, obtain in the timer with the current time At least one corresponding first timer node.
Updating unit 1005A, it is described for updating the first of at least one first timer node to overtime number of days First belongs to the attribute value of the timer Node in the timer to overtime number of days.
Trigger unit 1006A, for when at least one updated first timer node is first to overtime day When number is 0, timed events are triggered.
In other examples, the updating unit 1005A, is also used in the first time interval, updates institute State current time;
When updated current time be less than second threshold when, obtain in the timer with updated current time pair At least one the first timer node answered;Wherein, the second threshold characterizes the transverse direction of the preset orthogonal list structure Length.
In other examples, the updating unit 1005A, when being also used to default according to the current time and first Between be spaced, obtain the second time point;
When being not less than second threshold at second time point, the current time is updated to 0.
In other examples, the updating unit 1005A, when being also used to default according to the current time and second Between be spaced, obtain the second time point;
When being less than second threshold at second time point, and it is not present in the timer and second time point When at least one corresponding first timer node, according to second time point and second prefixed time interval, obtain Third time point;
The current time is updated to the third time point.
In other examples, the timer realization device 1000 further include:
Unit 1003B is deleted, for deleting at least one described first timer node from the timer.
In other examples, after generating timer, the timer realization device 1000 further include: computing unit 1004B, for generating automatic machine No. the first for the preset automatic machine number to be destroyed and first threshold modulus;Wherein, described First threshold characterizes the longitudinal length of the preset orthogonal list structure;
Acquiring unit 1005B, for obtaining at least one third in the timer according to the automatic machine No. first Timer Node further includes automatic machine No. the second at least one described third timer Node;
Comparing unit 1006B, the automatic machine No. second and institute at least one third timer Node described in State preset automatic machine number to be destroyed it is identical when, obtain at least one described second timer node;
Unit 1007B is deleted, for deleting at least one described second timer node.
In other examples, after generating timer, the timer realization device 1000 further include:
Retrieval unit 1003C, it is for retrieving the timer Node in the timer, the timer Node is corresponding Time out event is put into event queue;
First acquisition unit 1004C, for obtaining the first event in the event queue;
Second acquisition unit 1005C, for obtaining automatic machine queue;
Judging unit 1006C, for when the purpose of the first event corresponds to the automatic machine queue, by described first Event gives the processing of corresponding automatic machine;
Creating unit 1007C creates new timer section according to the request for receiving the request of the automatic machine Point.
In other embodiments, judging unit 1006C is also used to correspond to the automatic machine when the purpose of the first event When queue, the corresponding automatic machine of automatic machine number of the first event is searched in the automatic machine queue;
When there are the automatic machine, the first event is given to automatic machine processing.
In other embodiments, judging unit 1006C is also used to correspond to the automatic machine when the purpose of the first event When queue, automatic machine corresponding with the automatic machine number of the first event is searched in the automatic machine queue;
When the automatic machine is not present, the automatic machine corresponding with the first event is created;
Give the first event to automatic machine processing.
The description of apparatus of the present invention embodiment, into example IV, the description of embodiment of the method is class with above-described embodiment one As, there is with embodiment of the method similar beneficial effect.For undisclosed technical detail in apparatus of the present invention embodiment, ask Referring to embodiment of the present invention method description and understand.
Embodiment six
Corresponding, the same inventive concept based on embodiment one to example IV, Figure 18 is what the embodiment of the present invention proposed A kind of composed structure schematic diagram of scheduler is applied in event-based model, as shown in figure 18, scheduler proposed by the present invention It may include processor 01, the memory 02 for being stored with 01 executable instruction of processor, communication interface 03, and handled for connection The bus 04 of device 01, memory 02 and communication interface 03.Wherein, processor 01 is for executing the timer stored in memory Program is realized, to perform the steps of
According to preset orthogonal list structure, the attribute value of timer Node is obtained;The wherein preset orthogonal list The data store organisation of timer Node described in structural characterization;
According to the preset orthogonal list structure, the timer Node that the attribute value is characterized is inserted into and institute The corresponding position of value for stating the row field and column field of preset orthogonal list structure, generates the timer;Wherein, described pre- If orthogonal list structure row field characterize automatic machine No. the first, the preset orthogonal list structure column field characterization when Between point.
In an embodiment of the present invention, above-mentioned processor 01 can be application-specific IC (Application Specific Integrated Circuit, ASIC), digital signal processor (Digital Signal Processor, DSP), digital signal processing device (Digital Signal Processing Device, DSPD), programmable logic device (ProgRAMmable Logic Device, PLD), field programmable gate array (Field ProgRAMmable Gate Array, FPGA), CPU, controller, at least one of microcontroller, microprocessor.It is to be appreciated that being set for different It is standby, can also be to be other for realizing the electronic device of above-mentioned processor function, the embodiment of the present invention is not especially limited.The tune Spending device can also include memory 02, which can connect with processor 01, wherein memory 02 is for storing timing Device realizes that program code, the program code include computer operation instruction, and memory 02 may include high speed RAM memory, It may further include nonvolatile memory, for example, at least two magnetic disk storages.
In practical applications, above-mentioned memory 02 can be volatile memory (volatile memory), such as at random It accesses memory (Random-Access Memory, RAM);Or nonvolatile memory (non-volatile memory), Such as read-only memory (Read-Only Memory, ROM), flash memory (flash memory), hard disk (Hard Disk Drive, HDD) or solid state hard disk (Solid-State Drive, SSD);Or the combination of the memory of mentioned kind, and to place It manages device 01 and instruction and data is provided.
In addition, each functional module in the present embodiment can integrate in one processing unit, it is also possible to each list Member physically exists alone, and can also be integrated in one unit with two or more units.Above-mentioned integrated unit both can be with Using formal implementation of hardware, can also be realized in the form of software function module.
If integrated unit realizes that being not intended as independent product is sold or made in the form of software function module Used time can store in a computer readable storage medium, based on this understanding, the technical solution sheet of the present embodiment The all or part of the part that contributes to existing technology or the technical solution can be with software product in other words in matter Form embodies, which is stored in a storage medium, including some instructions are used so that a meter It calculates machine equipment (can be personal computer, server or the network equipment etc.) or processor (processor) executes this implementation The all or part of the steps of example method.And storage medium above-mentioned includes: USB flash disk, mobile hard disk, read-only memory (Read Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic or disk etc. is various to deposit Store up the medium of program code.
It is understood that in an embodiment of the present invention, scheduler creation has the timing of orthogonal list storage organization Device facilitates management of the scheduler to timer.
The embodiment of the present invention provides a kind of computer readable storage medium, is stored thereon with timer and realizes program, application In scheduler, such as any one or more embodiments into example IV of embodiment one are realized when which is executed by processor In method.
It should be understood by those skilled in the art that, the embodiment of the present invention can provide as method, system or computer program Product.Therefore, the shape of hardware embodiment, software implementation or embodiment combining software and hardware aspects can be used in the present invention Formula.Moreover, the present invention, which can be used, can use storage in the computer that one or more wherein includes computer usable program code The form for the computer program product implemented on medium (including but not limited to magnetic disk storage and optical memory etc.).
The present invention be referring to according to the method for the embodiment of the present invention, the realization of equipment (system) and computer program product Flow diagram and/or block diagram describe.It should be understood that flow diagram and/or box can be realized by computer program instructions The combination of each flow and/or block in figure and the process in implementation process schematic diagram and/or block diagram and/or box. These computer program instructions be can provide to general purpose computer, special purpose computer, Embedded Processor or other programmable datas The processor of processing equipment is to generate a machine, so that passing through computer or the processor of other programmable data processing devices The instruction of execution generate for realizing in one box of implementation process schematic diagram one process or multiple processes and/or block diagrams or The device for the function of being specified in multiple boxes.
These computer program instructions, which may also be stored in, is able to guide computer or other programmable data processing devices with spy Determine in the computer-readable memory that mode works, so that it includes referring to that instruction stored in the computer readable memory, which generates, The manufacture of device is enabled, which realizes in implementation process schematic diagram one process or multiple processes and/or block diagrams one The function of being specified in a box or multiple boxes.
These computer program instructions also can be loaded onto a computer or other programmable data processing device, so that counting Series of operation steps are executed on calculation machine or other programmable devices to generate computer implemented processing, thus in computer or The instruction that is executed on other programmable devices provide for realizing in one process of implementation process schematic diagram or multiple processes and/or The step of function of being specified in one or more blocks of the block diagram.
The foregoing is only a preferred embodiment of the present invention, is not intended to limit the scope of the present invention.

Claims (16)

1. a kind of timer realization method is applied in event-based model, which is characterized in that the described method includes:
According to preset orthogonal list structure, the attribute value of timer Node is obtained;The wherein preset orthogonal list structure Characterize the data store organisation of the timer Node;
According to the preset orthogonal list structure, the timer Node that the attribute value is characterized be inserted into it is described pre- If orthogonal list structure row field and column field the corresponding position of value, generate the timer;Wherein, described preset The row field of orthogonal list structure characterizes automatic machine No. the first, and the column field of the preset orthogonal list structure characterizes the time Point.
2. the method according to claim 1, wherein in the data store organisation include automatic machine No. the first, It is described that the attribute value of the timer Node is obtained according to preset orthogonal list structure to overtime number of days and time point, packet It includes:
According to the preset orthogonal list structure, automatic machine No. the first of the timer Node is obtained, first to overtime day Several and first time point.
3. according to the method described in claim 2, it is characterized in that, described according to the preset orthogonal list structure, acquisition Automatic machine No. first of the timer Node, first are to overtime number of days and first time point, comprising:
By the corresponding automatic machine number of the automatic machine and first threshold modulus, obtain the timer Node correspond to it is described preset The automatic machine No. first of the row field of orthogonal list structure;Wherein, the first threshold characterizes the preset cross chain The longitudinal length of table structure;
Timing length and second threshold are rounded, described first of the timer Node in the data store organisation is obtained To overtime number of days;Wherein, the timing length is the time to be triggered that the automatic machine handles event, the second threshold characterization The lateral length of the preset orthogonal list structure;
By the timing length and current time summation after with second threshold modulus, obtain the timer Node correspond to it is described pre- If orthogonal list structure column field in the first time point;Wherein the current time refers to opposite morning zero point Offset.
4. the method according to claim 1, wherein the method is also wrapped after the generation timer It includes:
Calculate first time interval of the current time apart from previous scan;The current time refers to the offset relative to morning zero point Amount;
In the first time interval, at least one first timing corresponding with the current time in the timer is obtained Device node;
Update the first of at least one first timer node to overtime number of days, described first belong to overtime number of days it is described The attribute value of timer Node in timer;
When at least one updated first timer node first when overtime number of days be 0 when, trigger timed events.
5. according to the method described in claim 4, it is described fixed to obtain it is characterized in that, described in the first time interval When device at least one first timer node corresponding with the current time, comprising:
In the first time interval, the current time is updated;
When updated current time is less than second threshold, obtain corresponding with updated current time in the timer At least one first timer node;Wherein, the second threshold characterizes the lateral length of the preset orthogonal list structure.
6. according to the method described in claim 5, working as described in update it is characterized in that, described in the first time interval The preceding time, comprising:
According to the current time and the first prefixed time interval, obtained for the second time point;
When being not less than second threshold at second time point, the current time is updated to 0.
7. according to the method described in claim 5, working as described in update it is characterized in that, described in the first time interval The preceding time, comprising:
According to the current time and the second prefixed time interval, obtained for the second time point;
When being less than second threshold at second time point, and when there is no corresponding with second time point in the timer At least one first timer node when, according to second time point and second prefixed time interval, obtain third Time point;
The current time is updated to the third time point.
8. according to the method described in claim 4, it is characterized in that, after the triggering timed events, the method also includes:
At least one described first timer node is deleted from the timer.
9. the method according to claim 1, wherein the method is also wrapped after the generation timer It includes:
According to preset automatic machine number to be destroyed, at least one second timer node in the timer is deleted.
10. according to the method described in claim 9, it is characterized in that, described according to preset automatic machine number to be destroyed, deletion institute State at least one second timer node in timer, comprising:
By the preset automatic machine number to be destroyed and first threshold modulus, automatic machine No. the first is generated;Wherein, first threshold Value characterizes the longitudinal length of the preset orthogonal list structure;
According to the automatic machine No. first, at least one third timer Node in the timer is obtained, described at least one It further include automatic machine No. the second in a third timer Node;
When the automatic machine No. second and the preset automatic machine number to be destroyed of at least one third timer Node When identical, at least one described second timer node is obtained;
Delete at least one described second timer node.
11. the method according to claim 1, wherein the method is also wrapped after the generation timer It includes:
The timer Node in the timer is retrieved, the corresponding time out event of the timer Node is put into event queue;
Obtain the first event in the event queue;
Obtain automatic machine queue;
When the purpose of the first event corresponds to the automatic machine queue, by the first event at corresponding automatic machine Reason;
The request for receiving the automatic machine creates new timer Node according to the request.
12. according to the method for claim 11, which is characterized in that described when the purpose correspondence of the first event is described certainly When motivation queue, the first event is given to the processing of corresponding automatic machine, comprising:
When the purpose of the first event corresponds to the automatic machine queue, first thing is searched in the automatic machine queue The corresponding automatic machine of the automatic machine number of part;
When there are the automatic machine, the first event is given to automatic machine processing.
13. according to the method for claim 12, which is characterized in that described when the purpose correspondence of the first event is described certainly When motivation queue, the first event is given to the processing of corresponding automatic machine, comprising:
When the purpose of the first event corresponds to the automatic machine queue, searched and described first in the automatic machine queue The corresponding automatic machine of the automatic machine number of event;
When the automatic machine is not present, the automatic machine corresponding with the first event is created;
Give the first event to automatic machine processing.
14. a kind of timer realization device, which is characterized in that in application affairs driving model, described device includes:
Attribute acquiring unit, for obtaining the attribute value of timer Node according to preset orthogonal list structure;It is wherein described pre- If orthogonal list structural characterization described in timer Node data store organisation;
It is inserted into unit, according to the preset orthogonal list structure, the timer Node that the attribute value is characterized is inserted into To position corresponding with the value of row field and column field of the preset orthogonal list structure, the timer is generated;Wherein, The row field of the preset orthogonal list structure characterizes automatic machine No. the first, the column field of the preset orthogonal list structure Characterize time point.
15. a kind of scheduler, which is characterized in that be applied in event-based model, the scheduler includes at least: processor, Memory, communication interface, and for connecting the processor, memory and the bus of communication interface;The processor is used for It executes the timer stored in the memory and realizes program, to realize such as method of any of claims 1-13.
16. a kind of computer readable storage medium is stored thereon with timer and realizes program, is applied in event-based model, The timer, which is realized, realizes such as method of any of claims 1-13 when program is executed by processor.
CN201811497240.1A 2018-12-07 2018-12-07 Timer implementation method and device, scheduler and storage medium Active CN109684056B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811497240.1A CN109684056B (en) 2018-12-07 2018-12-07 Timer implementation method and device, scheduler and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811497240.1A CN109684056B (en) 2018-12-07 2018-12-07 Timer implementation method and device, scheduler and storage medium

Publications (2)

Publication Number Publication Date
CN109684056A true CN109684056A (en) 2019-04-26
CN109684056B CN109684056B (en) 2021-04-13

Family

ID=66187251

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811497240.1A Active CN109684056B (en) 2018-12-07 2018-12-07 Timer implementation method and device, scheduler and storage medium

Country Status (1)

Country Link
CN (1) CN109684056B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107870812A (en) * 2017-11-17 2018-04-03 南京国电南自轨道交通工程有限公司 One kind is based on single thread concurrently more timer application management methods
CN111245935A (en) * 2020-01-10 2020-06-05 深圳前海环融联易信息科技服务有限公司 Timeout request processing method and device, computer equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7203767B2 (en) * 1999-08-31 2007-04-10 Intel Corporation System processing data packets received from remote host to control system operation according to adjustable timer interrupts based on data flow rate
CN1963766A (en) * 2006-12-11 2007-05-16 宁波市科技园区菊风系统软件有限公司 A scheduling method for timer
US20090320030A1 (en) * 2008-06-24 2009-12-24 International Business Machines Corporation Method for management of timeouts
CN102122273A (en) * 2010-01-08 2011-07-13 洛克威尔自动控制技术股份有限公司 Hardware based connection state machine with built in timers
CN104991823A (en) * 2015-07-02 2015-10-21 北京京东尚科信息技术有限公司 Method and device for realizing Javascript multitask mechanism

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7203767B2 (en) * 1999-08-31 2007-04-10 Intel Corporation System processing data packets received from remote host to control system operation according to adjustable timer interrupts based on data flow rate
CN1963766A (en) * 2006-12-11 2007-05-16 宁波市科技园区菊风系统软件有限公司 A scheduling method for timer
US20090320030A1 (en) * 2008-06-24 2009-12-24 International Business Machines Corporation Method for management of timeouts
CN102122273A (en) * 2010-01-08 2011-07-13 洛克威尔自动控制技术股份有限公司 Hardware based connection state machine with built in timers
CN104991823A (en) * 2015-07-02 2015-10-21 北京京东尚科信息技术有限公司 Method and device for realizing Javascript multitask mechanism

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107870812A (en) * 2017-11-17 2018-04-03 南京国电南自轨道交通工程有限公司 One kind is based on single thread concurrently more timer application management methods
CN107870812B (en) * 2017-11-17 2021-06-15 南京国电南自轨道交通工程有限公司 Application management method based on single thread concurrent multi-timer
CN111245935A (en) * 2020-01-10 2020-06-05 深圳前海环融联易信息科技服务有限公司 Timeout request processing method and device, computer equipment and storage medium

Also Published As

Publication number Publication date
CN109684056B (en) 2021-04-13

Similar Documents

Publication Publication Date Title
CN109684056A (en) A kind of timer realization method and device, scheduler, storage medium
TWI269220B (en) System and method for granular control of message logging
CN107395659A (en) A kind of method and device of service handling and common recognition
CN104346345B (en) The storage method and device of data
CN106993153B (en) A kind of video amended record method and apparatus
TW201025334A (en) Non-volatile memory with extended operating temperature range
CN106326013A (en) Disk quota management system and method for distributed file system
CN106331148A (en) Cache management method and cache management device for data reading by clients
CN103535014B (en) A kind of network store system, data processing method and client
CN107844402A (en) A kind of resource monitoring method, device and terminal based on super fusion storage system
CN108121511A (en) Data processing method, device and equipment in a kind of distributed edge storage system
CN106528851A (en) Intelligent recommendation method and device
CN110430255A (en) The processing method of service request, system and electronic equipment in distributed type assemblies
CN112448883B (en) Message pushing method, device, computer equipment and storage medium
CN109241021A (en) A kind of file polling method, apparatus, equipment and computer readable storage medium
CN110019870B (en) Image retrieval method and system based on memory image cluster
CN109726591A (en) One kind being based on the self-destructed cloud storage data system of data
CN110569291A (en) Key data query and acquisition method and device for digital currency wallet
CN110083602A (en) A kind of method and device of data storage and data processing based on hive table
CN110046131A (en) The Stream Processing method, apparatus and distributed file system HDFS of data
CN109101197A (en) A kind of file stores and accesses method, apparatus, file memory and system
CN109255001A (en) Maintaining method and device, the electronic equipment in interface instance library
Du et al. Out‐of‐Core Simplification and Crack‐Free LOD Volume Rendering for Irregular Grids
CN106649359A (en) Spatial point data processing method and apparatus
CN110096518A (en) Knowledge base metadata sending method and device, readable storage medium storing program for executing

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
GR01 Patent grant
GR01 Patent grant