CN109426554B - Timing implementation method and device for server - Google Patents

Timing implementation method and device for server Download PDF

Info

Publication number
CN109426554B
CN109426554B CN201710724288.0A CN201710724288A CN109426554B CN 109426554 B CN109426554 B CN 109426554B CN 201710724288 A CN201710724288 A CN 201710724288A CN 109426554 B CN109426554 B CN 109426554B
Authority
CN
China
Prior art keywords
timing
subscript
array
task
idle
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.)
Active
Application number
CN201710724288.0A
Other languages
Chinese (zh)
Other versions
CN109426554A (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
China Mobile Hangzhou Information Technology Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
China Mobile Hangzhou Information 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, China Mobile Hangzhou Information Technology Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN201710724288.0A priority Critical patent/CN109426554B/en
Publication of CN109426554A publication Critical patent/CN109426554A/en
Application granted granted Critical
Publication of CN109426554B publication Critical patent/CN109426554B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • 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

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 embodiment of the application discloses a timing implementation method and a timing implementation device of a server, wherein the method comprises the steps of selecting an idle task from a set idle task set to be set as a timing task; taking the array subscript currently pointed by the pointer of the set time index array as a timing start subscript; calculating a first ratio of the timing duration to the duration of the time interval, and taking an array subscript determined based on the sum of the first ratio and the timing start subscript as a timing end subscript; adding the timing tasks to array elements corresponding to the timing termination subscript, determining that a pointer of a time index array points to the timing termination subscript, and adding each timing task contained in the array elements corresponding to the timing termination subscript to a set execution queue; and executing all the timing tasks in the execution queue in parallel, and recycling the timing tasks after execution into an idle task set. Therefore, the system performance is improved, the calculation complexity is simplified, and the timing precision is ensured.

Description

Timing implementation method and device for server
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for implementing timing of a server.
Background
With the development of computer technology, high-capacity and high-concurrency servers are developed to meet the increasing network service requirements of people. The high-capacity high-concurrency server generally maintains long TCP connection between the high-capacity high-concurrency server and the client through a heartbeat mechanism, and pushes messages between the high-capacity high-concurrency server and the client.
Taking an Always-On server as an example, referring to fig. 1a, a schematic diagram of an Always-On system is shown, the Always-On system includes an Always-On server (AOG) and an Always-On client (AOE). And the AOG is based on a TCP/IP long connection technology and carries out TCP long connection and message pushing with the AOE. In order to maintain TCP long connection and message push between the AOG and the AOE, the AOG needs to maintain two timing tasks, namely, an AOE heartbeat timing task and a message push response timing task, for each AOE through a timer.
Wherein, the AOE heartbeat timing task is as follows: and the AOE sends a heartbeat packet to the AOG every 5 minutes, the AOG establishes a timing task of 6 minutes through a timer and judges whether the heartbeat packet sent by the AOE is received within 6 minutes, if so, the previous timing task is stopped and a new timing task is restarted, and otherwise, the TCP long connection between the AOG and the AOE is released.
The message push response timing task comprises the following steps: when the AOG pushes the message to the AOE, the AOG maintains a timing task of 30s through a timer, and judges whether a push response message returned by the AOE is received in 30s, if so, the pushing is judged to be normal, the timing task of 30s is stopped, otherwise, the pushing is judged to be abnormal, and the long connection of the TCP between the AOG and the AOE is released.
In the prior art, a high-capacity high-concurrency server adopts a timer to time, and mainly adopts the following modes to realize timing:
taking java.util.timer as an example, referring to fig. 1b, the java.util.timer includes three parts, namely a timing task, a task queue and a timing thread. All timed tasks added to the java. The task queue performs priority sequencing on each timing task by adopting a minimum binary heap; and the timing thread takes out the first task from the task queue every time, and executes the corresponding task when the timing task reaches the specified time length.
However, there are many disadvantages to using this timing approach. Firstly, the timing task needs to be frequently started and stopped, which can cause frequent allocation and release of the timing task object, thereby generating a large amount of memory fragments and reducing the system performance; secondly, the timing tasks are sequenced by adopting the binary heap, when the number of the timing tasks reaches the million orders, the calculation complexity is extremely high, the timing efficiency is reduced, and the performance requirements of the system cannot be met.
Disclosure of Invention
The embodiment of the application provides a timing implementation method and device for a server, which are used for parallelly processing timing tasks when a high-capacity high-concurrency server implements timing through a timer, so that the timing processing efficiency is improved, and the timing precision is ensured.
The embodiment of the application provides the following specific technical scheme:
in a first aspect, a method for implementing timing of a server includes:
determining that a timing instruction containing timing duration is received, selecting an idle task from idle tasks contained in a set idle task set, and setting the idle task as a timing task;
taking the array subscript currently pointed by the set pointer of the time index array as the timing start subscript of the timing task, wherein the pointer of the time index array always points to the array subscript set corresponding to the current time interval, and the timing start subscript of the timing task indicates that: the timing task is set in the time interval corresponding to the timing subscript;
calculating a first ratio of the timing duration to the duration of the time interval, and taking an array subscript determined based on the sum of the first ratio and the timing start subscript as a timing end subscript of the timing task, wherein the timing end subscript of the timing task indicates: the timing task is timed to end in a time interval corresponding to the timing ending subscript;
adding the timing tasks to array elements corresponding to the timing termination subscript, determining that a pointer of a time index array points to the timing termination subscript, and adding each timing task contained in the array elements corresponding to the timing termination subscript to a set execution queue;
and executing all the timing tasks in the execution queue in parallel, setting the timing tasks after execution as idle tasks and recycling the idle tasks into an idle task set.
Preferably, the array subscript determined based on the sum of the first ratio and the timing start subscript is used as the timing end subscript of the timing task, and specifically includes:
calculating the sum of the first ratio and a timing start subscript;
calculating a second ratio of the sum to a preset array length;
rounding the second ratio to obtain the array cycle times of the timing task;
and (4) taking the second ratio and obtaining the array subscript corresponding to the timing task as the timing termination subscript of the timing task.
Preferably, when determining that the pointer of the time index array points to the timing termination subscript, adding each timing task included in the array element corresponding to the timing termination subscript to the set execution queue, specifically includes:
acquiring an array subscript currently pointed by a pointer of a time index array;
determining that the array subscript currently pointed by the pointer is the timing termination subscript, judging whether the array cycle number of the timing tasks is 0, if so, adding each timing task contained in the array elements corresponding to the timing termination subscript to an execution queue;
and if the timing task is determined to be finished in timing, adding each timing task contained in the array elements corresponding to the timing ending subscript into the execution queue.
Preferably, when the timing task is determined to end based on the adjusted array cycle number, adding each timing task included in the array element corresponding to the timing end subscript to the execution queue, including:
the following steps are executed until the number of array cycles is 0: determining that the array subscript currently pointed by the pointer is a timing termination subscript, and when the adjusted array cycle number is not 0, reducing the adjusted array cycle number by one;
and when the array subscript currently pointed by the pointer is determined to be the timing termination subscript and the adjusted array cycle number is 0, adding each timing task contained in the array element corresponding to the timing termination subscript into the execution queue.
Preferably, further comprising:
in the timing process of the timing task, when the execution stopping instruction is determined to represent that the execution of the timing task is stopped based on the received execution stopping instruction, the timing task is set as an idle task and is recycled to an idle task set.
In a second aspect, an apparatus for implementing timing of a server includes:
the setting unit is used for determining that a timing instruction containing timing duration is received, selecting an idle task from idle tasks contained in the set idle task set, and setting the idle task as a timing task;
the acquisition unit is used for taking the array subscript currently pointed by the set pointer of the time index array as the timing start subscript of the timing task, wherein the pointer of the time index array always points to the array subscript set corresponding to the current time interval, and the timing start subscript of the timing task indicates that: the timing task is set in the time interval corresponding to the timing subscript;
the calculating unit is used for calculating a first ratio of the timing duration to the duration of the time interval, and taking an array subscript determined based on the sum of the first ratio and the timing start subscript as a timing end subscript of the timing task, wherein the timing end subscript of the timing task indicates that: the timing task is timed to end in a time interval corresponding to the timing ending subscript;
the adding unit is used for adding the timing tasks to the array elements corresponding to the timing ending subscript, determining that the pointer of the time index array points to the timing ending subscript, and adding each timing task contained in the array elements corresponding to the timing ending subscript to a set execution queue;
and the execution unit is used for executing all the timing tasks in the execution queue in parallel, setting the timing tasks after execution as idle tasks and recycling the idle tasks into an idle task set.
Preferably, when the array subscript determined based on the sum of the first ratio and the timing start subscript is used as the timing end subscript of the timing task, the calculation unit is specifically configured to:
calculating the sum of the first ratio and a timing start subscript;
calculating a second ratio of the sum to a preset array length;
rounding the second ratio to obtain the array cycle times of the timing task;
and (4) taking the second ratio and obtaining the array subscript corresponding to the timing task as the timing termination subscript of the timing task.
Preferably, when the pointer of the time index array is determined to point to the timing termination index, and each timing task included in the array element corresponding to the timing termination index is added to the set execution queue, the adding unit is specifically configured to:
acquiring an array subscript currently pointed by a pointer of a time index array;
determining that the array subscript currently pointed by the pointer is the timing termination subscript, judging whether the array cycle number of the timing tasks is 0, if so, adding each timing task contained in the array elements corresponding to the timing termination subscript to an execution queue;
and if the timing task is determined to be finished in timing, adding each timing task contained in the array elements corresponding to the timing ending subscript into the execution queue.
Preferably, when determining that the timing task ends in timing based on the adjusted number of array cycles and adding each timing task included in the array element corresponding to the timing end subscript to the execution queue, the adding unit is further configured to:
the following steps are executed until the number of array cycles is 0: determining that the array subscript currently pointed by the pointer is a timing termination subscript, and when the adjusted array cycle number is not 0, reducing the adjusted array cycle number by one;
and when the array subscript currently pointed by the pointer is determined to be the timing termination subscript and the adjusted array cycle number is 0, adding each timing task contained in the array element corresponding to the timing termination subscript into the execution queue.
Preferably, the execution unit is further configured to:
in the timing process of the timing task, when the execution stopping instruction is determined to represent that the execution of the timing task is stopped based on the received execution stopping instruction, the timing task is set as an idle task and is recycled to an idle task set.
In a third aspect, an electronic device includes: one or more processors; and
one or more computer readable media having stored thereon a time-implemented program for a server, wherein the program, when executed by one or more processors, performs the steps of the method of any of the above first aspects.
In a fourth aspect, one or more computer readable media having stored thereon a time-implemented program for a server, wherein the program, when executed by one or more processors, causes a communication device to perform the method of any of the first aspects described above.
In the embodiment of the application, an idle task is selected from an idle task set to be a timing task, a timing end subscript of a time index array corresponding to the timing task is calculated based on the timing duration of the timing task, the timing task is added to an array element corresponding to the timing end subscript of the time index array, the timing end of the timing task is judged when a pointer of the time index array points to the timing end subscript, the timing task is transferred to an execution queue, all the timing tasks in the execution queue are processed in parallel, further, the timing task after execution is reset to be the idle task and is recycled to the idle task set, therefore, when the high-capacity high-concurrency server executes the timing task, the idle task is directly selected from the idle task set to be the timing task, and when the timing task is executed, the method has the advantages that the idle tasks are reset and recovered into the idle task set, the creation and the deletion of the timing tasks are avoided, the generation of memory fragments is reduced, the system performance is improved, secondly, the multiple timing tasks contained in the array element of a time index array do not need to be sequenced, the timing tasks are added into the corresponding array elements according to the timing duration of the timing tasks, the calculation complexity is simplified, the timing efficiency is improved, furthermore, the timing tasks finished at the timing can be processed simultaneously in parallel, and the timing precision is guaranteed.
Drawings
FIG. 1a is a schematic diagram of an always-on system according to the prior art;
FIG. 1b is a prior art timing flow diagram;
FIG. 1c is a schematic diagram of a timing implementation architecture of a server in an embodiment of the present application;
FIG. 1d is a flowchart of a method for implementing timing of a server in an embodiment of the present application;
fig. 2 is a schematic structural diagram of a timing implementation apparatus of a server in an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present application without any creative effort belong to the protection scope of the present application.
In order to reduce generated memory fragments, improve system performance, simplify computation complexity, improve timing efficiency, process timing tasks in parallel and ensure timing precision when a high-capacity high-concurrency server executes the timing tasks, in the embodiment of the application, a timing implementation method of the server is designed.
The preferred embodiments of the present application will be described below with reference to the accompanying drawings of the specification, it being understood that the preferred embodiments described herein are merely for illustrating and explaining the present invention and are not intended to limit the present invention, and that the embodiments and features of the embodiments in the present application may be combined with each other without conflict.
Fig. 1c is a schematic diagram of a timing implementation architecture of the server. In the embodiment of the application, the timer adopted by the server comprises an idle task set, a time index array and an execution queue.
The idle task set comprises a plurality of idle tasks which are pre-allocated by the server according to self resources. Alternatively, the set of idle tasks may be an idle queue.
The time index array is an array established based on time, namely, an array subscript of each time index array corresponds to a time interval, and array elements of each time index array comprise a plurality of timing tasks which end in a timing mode in the corresponding time interval. And the pointer of the time index array always points to the array subscript corresponding to the current time interval.
For example, referring to fig. 1c, when the pointer of the time index array currently points to T1, the server adds each timed task corresponding to T1 in the time index array to the execution queue, and determines that the pointer of the time index array points to T200, the server sequentially adds 4 timed tasks corresponding to T200 to the execution queue.
The execution queue includes timed tasks that end at respective timings.
In the embodiment of the application, firstly, the server selects an idle task from an idle task set based on a timing instruction, and sets the idle task as the timing task.
Then, the server determines an array subscript of a time index array corresponding to the timing task based on the timing duration corresponding to the timing task, and adds the timing task to corresponding elements of the time index array according to the acquired array subscript.
Further, when the server determines that the timing task timing is finished, the timing task is added into the execution queue.
And finally, the server performs parallel processing on each timing task in the execution queue through multithreading, sets the processed timing task as an idle task, and then recycles the idle task to an idle task set.
Referring to fig. 1d, which is a flowchart for implementing timing of a server, in the embodiment of the present application, a specific process for implementing timing of the server is as follows:
step 100: and when the server determines that the timing instruction is received, selecting an idle task from the idle task set and setting the idle task as the timing task.
Specifically, when step 100 is executed, the idle task set may be an idle queue including a plurality of idle tasks.
When the timer is initialized, the server estimates the number of online users supported by the server according to the resources of the server to obtain an estimation result, determines the number of required idle tasks according to the estimation result, and then allocates the idle tasks corresponding to the number to the idle task set at one time.
Therefore, the number of the required idle tasks can be estimated, the estimated number of the idle tasks is allocated to the idle task set at one time, when the timing task is required, one idle task is directly selected from the idle task set and set as the timing task, further, the timing task which is finished is set as the idle task and is recycled into the idle task set, cyclic utilization is achieved, a large amount of memory fragments caused by frequent establishment and deletion of the timing task are avoided, and the timing processing efficiency and the system performance are improved.
Step 101: and the server acquires the timing duration of the timing task contained in the timing instruction.
For example, the server determines the timing duration of the timing task to be 1min based on the timing instruction.
Step 102: and the server takes the array subscript currently pointed by the pointer of the set time index array as the timing start subscript of the timing task.
Specifically, when the timer is initialized, the server establishes a time index array in advance, wherein array subscripts of the time index array have a corresponding relationship with time intervals, each array subscript corresponds to one time interval, and pointers of the time index array always point to the array subscripts set corresponding to the current time interval.
For example, the server sets the duration of a time interval to be 5min, and the time interval is 5: and when the index of the corresponding array is 0 in the range of 00-5:05, the time interval is 5:06-5:10, and the index of the corresponding array is 1.
Thus, the time index can be established by a one-dimensional array, i.e. a time index array. Each array index corresponds to a time interval, and each array element also corresponds to a time interval.
Further, when step 102 is executed, the server determines the array index currently pointed to by the pointer of the time index array, and takes the array index as the timing start index of the timing task. Wherein the timing start subscript of the timing task indicates: the timing task is set in the time interval corresponding to the timing subscript.
Thus, the time interval for starting the timing task can be determined according to the array subscript currently pointed by the pointer of the time index array.
Step 103: and the server calculates a first ratio of the timing duration to the duration of the time interval, and takes an array subscript determined based on the sum of the first ratio and the timing start subscript as a timing end subscript of the timing task.
Specifically, first, the server calculates a first ratio between the timing duration and the duration of the time interval.
For example, the timer start index is 5, the timer duration is 1h, and the duration of a time interval is 10min, then the server calculates 60/10-6 as the first ratio between the timer duration and the duration of the time interval.
Then, the server calculates the sum of the first ratio and the timing start subscript, and calculates a second ratio of the sum to a preset array length.
And then, the server rounds the second ratio to obtain the array cycle times corresponding to the timing task.
Optionally, when the number of array cycles corresponding to the timing task is calculated, the following formula may be adopted:
C=(curID+T/T0)/N;
wherein curID is a timing start subscript, C is an array cycle number, T is a timing duration, T0 is a duration of a time interval, and N is an array length.
And finally, the server performs remainder on the second ratio to obtain an array subscript corresponding to the timing task, and the array subscript is used as a timing termination subscript of the timing task.
Optionally, when calculating the array subscript of the timing task, the following formula may be adopted:
timerID=(curID+T/T0)%N;
wherein, timerID is the array subscript corresponding to the timing task, curID is the timing start subscript, T is the timing duration, T0 is the duration of the time interval, and N is the array length.
For example, if the timing duration of the timing task is 1h, the timing start index is 2, the duration of the time interval is 5min, and the array length is 6, the server determines that the array cycle number of the timing task is (2+60min/5min)/6 ═ 2, and the array index is (2+ 60/5)% 6 ═ 2.
This is because the length of the time index array is always limited, and the time is infinite, so in practical applications, the time index array is set as a circular array, that is, the array subscript is circularly used, and if the array length of the time index array is set to N, the array subscript ranges from 0 to N-1.
The larger the array length is, the higher the space complexity is, so that the array length can be reduced, the space complexity is reduced and the system performance is improved through the cyclic use of the array.
Step 104: and the server adds the timing task to the array element corresponding to the timing termination subscript.
Specifically, the server adds the timing task to the array element of the time index array corresponding to the array subscript.
Furthermore, when the array subscripts corresponding to the plurality of timing tasks are the same, one array element comprises the plurality of timing tasks, and the plurality of timing tasks comprised in one array element do not need to be sequenced, so that the calculation complexity is reduced, the operation steps are simplified, and the timing efficiency is improved.
Step 105: and when the server determines that the pointer of the time index array points to the timing termination lower limit, judging whether the cycle number corresponding to the timing task is 0, if so, executing step 106, otherwise, executing step 109.
Specifically, when the server determines that the pointer of the time index array points to the timing termination subscript, it determines that each timing task included in the array element corresponding to the timing termination subscript is timed to end, acquires each timing task included in the array element corresponding to the timing termination subscript, and performs the following steps for each acquired timing task:
and judging whether the array cycle number corresponding to one timing task is 0, if so, executing the step 106, and otherwise, executing the step 109.
Therefore, the timing task with timing ending can be determined according to the pointer of the time index array and the cycle number of the timing task.
Step 106: the server adds the timed task to the execution queue.
Specifically, when step 106 is executed, the server sequentially adds the timed tasks that end at the fixed time to the tail of the execution queue.
Therefore, only the timing task finished by timing is sequentially added to the tail of the execution queue through the single thread without other operations, the operation is simple, the operation steps are simplified, the next timing task is transferred after the execution of one timing task such as a large amount of time is not needed, and the timing precision is ensured.
Step 107: and the server performs parallel processing on all the timing tasks in the execution queue.
Specifically, when the execution queue includes a plurality of timing tasks, the server performs parallel execution on each timing task included in the execution queue by using a multithreading technology.
Therefore, by processing all timing tasks finished at fixed time in parallel, the efficiency of executing the timing tasks and the precision of the timing tasks are ensured.
Step 108: and when the server determines that the execution of the timing task is finished, setting the timing task as an idle task and recycling the idle task into an idle task set.
Further, in the timing process of one timing task, the server determines that the stop execution instruction represents stopping the execution of the one timing task based on the received stop execution instruction, stops executing the one timing task, sets the one timing task as an idle task, and recycles the idle task into the idle task set.
Therefore, the timing task can be circularly used in the idle task set, the queue set and the execution queue, the creation and deletion of the timing task are avoided, namely frequent allocation and release of the memory are not needed, the generation of memory fragments is reduced, and the system performance is improved.
Step 109: the server subtracts one from the array cycle number corresponding to the timing task to obtain the adjusted array cycle number, and executes step 105.
Therefore, the length of the time index array can be reduced through the number of array circulation times, the time complexity is reduced, and the timing processing efficiency is improved.
In an embodiment of the present application, an electronic device includes: one or more processors; and
one or more computer readable media having stored thereon a program for a timed implementation of a server, wherein the program, when executed by one or more processors, performs the steps in the above embodiments.
In an embodiment of the present application, one or more computer readable media having stored thereon a program for a timing implementation of a server, where the program, when executed by one or more processors, causes a communication device to perform the steps in the above embodiments.
Based on the foregoing embodiment, referring to fig. 2, a schematic structural diagram of a timing implementation apparatus of a server is shown, in the embodiment of the present application, the timing implementation apparatus of the server specifically includes:
the setting unit 20 is configured to determine that a timing instruction including a timing duration is received, select an idle task from idle tasks included in the set idle task set, and set the idle task as a timing task;
the obtaining unit 21 is configured to use the array subscript to which the set pointer of the time index array points currently as the timing start subscript of the timing task, where the pointer of the time index array always points to the array subscript set corresponding to the current time interval, and the timing start subscript of the timing task indicates: the timing task is set in the time interval corresponding to the timing subscript;
a calculating unit 22, configured to calculate a first ratio of the timing duration to the duration of the time interval, and use an array subscript determined based on a sum of the first ratio and the timing start subscript as a timing end subscript of the timing task, where the timing end subscript of the timing task indicates: the timing task is timed to end in a time interval corresponding to the timing ending subscript;
an adding unit 23, configured to add the timing task to the array element corresponding to the timing end subscript, determine that a pointer of the time index array points to the timing end subscript, and add each timing task included in the array element corresponding to the timing end subscript to a set execution queue;
and the execution unit 24 is configured to execute all the timing tasks in the execution queue in parallel, set the timing task that is finished to be an idle task, and recycle the timing task into an idle task set.
Preferably, when the array subscript determined based on the sum of the first ratio and the timing start subscript is used as the timing end subscript of the timing task, the calculating unit 22 is specifically configured to:
calculating the sum of the first ratio and a timing start subscript;
calculating a second ratio of the sum to a preset array length;
rounding the second ratio to obtain the array cycle times of the timing task;
and (4) taking the second ratio and obtaining the array subscript corresponding to the timing task as the timing termination subscript of the timing task.
Preferably, when the pointer of the time index array is determined to point to the timing termination index, and each timing task included in the array element corresponding to the timing termination index is added to the set execution queue, the adding unit 23 is specifically configured to:
acquiring an array subscript currently pointed by a pointer of a time index array;
determining that the array subscript currently pointed by the pointer is the timing termination subscript, judging whether the array cycle number of the timing tasks is 0, if so, adding each timing task contained in the array elements corresponding to the timing termination subscript to an execution queue;
and if the timing task is determined to be finished in timing, adding each timing task contained in the array elements corresponding to the timing ending subscript into the execution queue.
Preferably, when determining that the timing task timing ends based on the adjusted array cycle number, and adding each timing task included in the array element corresponding to the timing end subscript to the execution queue, the adding unit 23 is further configured to:
the following steps are executed until the number of array cycles is 0: determining that the array subscript currently pointed by the pointer is a timing termination subscript, and when the adjusted array cycle number is not 0, reducing the adjusted array cycle number by one;
and when the array subscript currently pointed by the pointer is determined to be the timing termination subscript and the adjusted array cycle number is 0, adding each timing task contained in the array element corresponding to the timing termination subscript into the execution queue.
Preferably, the execution unit 24 is further configured to:
in the timing process of the timing task, when the execution stopping instruction is determined to represent that the execution of the timing task is stopped based on the received execution stopping instruction, the timing task is set as an idle task and is recycled to an idle task set.
In the embodiment of the application, an idle task is selected from an idle task set to be a timing task, a timing end subscript of a time index array corresponding to the timing task is calculated based on the timing duration of the timing task, the timing task is added to an array element corresponding to the timing end subscript of the time index array, the timing end of the timing task is judged when a pointer of the time index array points to the timing end subscript, the timing task is transferred to an execution queue, all the timing tasks in the execution queue are processed in parallel, further, the timing task after execution is reset to be the idle task and is recycled to the idle task set, therefore, when the high-capacity high-concurrency server executes the timing task, the idle task is directly selected from the idle task set to be the timing task, and when the timing task is executed, the method has the advantages that the idle tasks are reset and recovered into the idle task set, the creation and the deletion of the timing tasks are avoided, the generation of memory fragments is reduced, the system performance is improved, secondly, the multiple timing tasks contained in the array element of a time index array do not need to be sequenced, the timing tasks are added into the corresponding array elements according to the timing duration of the timing tasks, the calculation complexity is simplified, the timing efficiency is improved, furthermore, the timing tasks finished at the timing can be processed simultaneously in parallel, and the timing precision is guaranteed.
As will be appreciated by one of skill in the art, the embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, embodiments of the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
Embodiments of the present application are described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including the preferred embodiment and all changes and modifications that fall within the true scope of the embodiments of the present application.
It is apparent that those skilled in the art can make various changes and modifications to the embodiments of the present application without departing from the spirit and scope of the embodiments of the present application. Thus, if such modifications and variations of the embodiments of the present application fall within the scope of the claims of the embodiments of the present application and their equivalents, the embodiments of the present application are also intended to include such modifications and variations.

Claims (8)

1. A timing implementation method of a server is characterized by comprising the following steps:
determining that a timing instruction containing timing duration is received, selecting an idle task from idle tasks contained in a set idle task set, and setting the idle task as a timing task;
taking an array subscript to which a pointer of a set time index array points currently as a timing start subscript of the timing task, wherein the pointer of the time index array always points to the array subscript which is set corresponding to a current time interval, and the timing start subscript of the timing task indicates that: the timing task is set in a time interval corresponding to the timing starting subscript;
calculating a first ratio of the timing duration to the duration of the time interval, and using an array subscript determined based on the sum of the first ratio and the timing start subscript as a timing end subscript of the timing task, wherein the timing end subscript of the timing task indicates: the timing task is timed to end in a time interval corresponding to the timing ending subscript;
adding the timing tasks to array elements corresponding to the timing termination subscripts, determining that pointers of the time index array point to the timing termination subscripts, and adding each timing task contained in the array elements corresponding to the timing termination subscripts to a set execution queue;
and executing all the timing tasks in the execution queue in parallel, setting the timing tasks after execution as idle tasks and recycling the idle tasks into the idle task set.
2. The method according to claim 1, wherein the array index determined based on the sum of the first ratio and the timing start index is used as the timing end index of the timing task, and specifically includes:
calculating the sum of the first ratio and the timing start subscript;
calculating a second ratio of the sum to a preset array length;
rounding the second ratio to obtain the array cycle number of the timing task;
and the second ratio is subjected to remainder to obtain an array subscript corresponding to the timing task, and the array subscript is used as a timing ending subscript of the timing task.
3. The method according to claim 2, wherein determining that the pointer of the time index array points to the timing end subscript, adding each timing task included in the array element corresponding to the timing end subscript to a set execution queue, specifically includes:
acquiring an array subscript currently pointed by a pointer of the time index array;
determining that the array subscript currently pointed by the pointer is the timing termination subscript, judging whether the array cycle number of the timing task is 0, if so, adding each timing task contained in the array element corresponding to the timing termination subscript to the execution queue;
and if not, subtracting one from the array cycle number of the timing task to obtain an adjusted array cycle number, and when the timing task is determined to end in timing based on the adjusted array cycle number, adding each timing task contained in the array element corresponding to the timing ending subscript to the execution queue.
4. The method of claim 3, wherein when determining that the timing task timing ends based on the adjusted array cycle number, adding each timing task included in the array element corresponding to the timing end index to the execution queue comprises:
executing the following steps until the number of array cycles is 0: determining that the array subscript currently pointed by the pointer is the timing end subscript, and when the adjusted array cycle number is not 0, subtracting one from the adjusted array cycle number;
and when the array subscript currently pointed by the pointer is determined to be the timing ending subscript and the adjusted array cycle number is 0, adding each timing task contained in the array element corresponding to the timing ending subscript into the execution queue.
5. The method of any one of claims 1-4, further comprising:
and in the timing process of the timing task, based on the received execution stopping instruction, setting the timing task as an idle task and recycling the idle task into the idle task set when the execution stopping instruction is determined to represent that the execution of the timing task is stopped.
6. A timing implementation apparatus of a server, comprising:
the device comprises a setting unit, a timing unit and a processing unit, wherein the setting unit is used for determining that a timing instruction containing timing duration is received, selecting an idle task from idle tasks contained in a set idle task set, and setting the idle task as a timing task;
an obtaining unit, configured to use an array subscript to which a pointer of a set time index array currently points as a timing start subscript of the timing task, where the pointer of the time index array always points to the array subscript set corresponding to a current time interval, and the timing start subscript of the timing task indicates: the timing task is set in a time interval corresponding to the timing starting subscript;
a calculating unit, configured to calculate a first ratio of the timing duration to a duration of the time interval, and use an array subscript determined based on a sum of the first ratio and the timing start subscript as a timing end subscript of the timing task, where the timing end subscript of the timing task indicates: the timing task is timed to end in a time interval corresponding to the timing ending subscript;
the adding unit is used for adding the timing tasks to the array elements corresponding to the timing termination subscripts, determining that the pointers of the time index array point to the timing termination subscripts, and adding the timing tasks contained in the array elements corresponding to the timing termination subscripts to a set execution queue;
and the execution unit is used for executing all the timing tasks in the execution queue in parallel, setting the timing tasks after execution as idle tasks and recycling the idle tasks into the idle task set.
7. An electronic device, comprising: one or more processors; and
one or more computer-readable media having stored thereon a program for a timed implementation of a server, wherein the program, when executed by one or more processors, implements the steps of a method as claimed in any one of claims 1 to 5.
8. One or more computer readable media having stored thereon a program for a timing implementation of a server, wherein the program, when executed by one or more processors, causes a communication device to perform the method of any of claims 1 to 5.
CN201710724288.0A 2017-08-22 2017-08-22 Timing implementation method and device for server Active CN109426554B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710724288.0A CN109426554B (en) 2017-08-22 2017-08-22 Timing implementation method and device for server

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710724288.0A CN109426554B (en) 2017-08-22 2017-08-22 Timing implementation method and device for server

Publications (2)

Publication Number Publication Date
CN109426554A CN109426554A (en) 2019-03-05
CN109426554B true CN109426554B (en) 2020-10-09

Family

ID=65498126

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710724288.0A Active CN109426554B (en) 2017-08-22 2017-08-22 Timing implementation method and device for server

Country Status (1)

Country Link
CN (1) CN109426554B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110990141B (en) * 2019-12-12 2024-04-26 深圳前海环融联易信息科技服务有限公司 Timed task processing method, device, computing equipment and storage medium
CN110990144B (en) * 2019-12-17 2022-11-08 深圳市晨北科技有限公司 Task determination method and related equipment
CN113672358A (en) * 2020-05-15 2021-11-19 北京沃东天骏信息技术有限公司 Timing task processing method, device and system, electronic equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1862575A (en) * 2005-08-19 2006-11-15 华为技术有限公司 Method for planing dispatching timing task
EP1678612B1 (en) * 2003-10-29 2008-07-30 Honeywell International Inc. Stochastically based thread budget overrun handling system and method
CN103106222A (en) * 2011-11-15 2013-05-15 阿里巴巴集团控股有限公司 Processing method and processing device of timer
CN105260287A (en) * 2015-09-16 2016-01-20 北京奇虎科技有限公司 Method and device for updating parent task progress

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP1678612B1 (en) * 2003-10-29 2008-07-30 Honeywell International Inc. Stochastically based thread budget overrun handling system and method
CN1862575A (en) * 2005-08-19 2006-11-15 华为技术有限公司 Method for planing dispatching timing task
CN103106222A (en) * 2011-11-15 2013-05-15 阿里巴巴集团控股有限公司 Processing method and processing device of timer
CN105260287A (en) * 2015-09-16 2016-01-20 北京奇虎科技有限公司 Method and device for updating parent task progress

Also Published As

Publication number Publication date
CN109426554A (en) 2019-03-05

Similar Documents

Publication Publication Date Title
CN111381950B (en) Multi-copy-based task scheduling method and system for edge computing environment
CN109426554B (en) Timing implementation method and device for server
CN108776897B (en) Data processing method, device, server and computer readable storage medium
JP2015144020A5 (en)
CN111367630A (en) Multi-user multi-priority distributed cooperative processing method based on cloud computing
US8984527B2 (en) System and method for execution time donation in a time-partitioning scheduler
CN110569252B (en) Data processing system and method
CN103873587B (en) A kind of method and device that scheduling is realized based on cloud platform
CN103500119B (en) A kind of method for allocating tasks based on pre-scheduling
CN109254913B (en) Device sharing method and device, electronic device and computer storage medium
CN108536530B (en) Multithreading task scheduling method and device
CN115617497B (en) Thread processing method, scheduling component, monitoring component, server and storage medium
CN106569917B (en) Data backup method and mobile terminal
CN112199180A (en) Multitask scheduling method and device, electronic equipment and readable storage medium
CN109871270B (en) Scheduling scheme generation method and device
CN114816709A (en) Task scheduling method, device, server and readable storage medium
CN116991949B (en) Data synchronization method, device, equipment, server and readable storage medium
CN111985634B (en) Operation method and device of neural network, computer equipment and storage medium
CN109032779B (en) Task processing method and device, computer equipment and readable storage medium
CN113064705A (en) Thread pool capacity expansion method, device, server, medium and product
CN111143063B (en) Task resource reservation method and device
CN112463340A (en) Tensorflow-based multi-task flexible scheduling method and system
CN110955461B (en) Processing method, device, system, server and storage medium for computing task
US10866833B2 (en) Method and appratus for implementing microkernel architecture of industrial server
CN112671816B (en) File downloading method, device, equipment and medium

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