CN111813552A - Scheduling execution method, device and medium based on multi-thread task - Google Patents

Scheduling execution method, device and medium based on multi-thread task Download PDF

Info

Publication number
CN111813552A
CN111813552A CN202010686320.2A CN202010686320A CN111813552A CN 111813552 A CN111813552 A CN 111813552A CN 202010686320 A CN202010686320 A CN 202010686320A CN 111813552 A CN111813552 A CN 111813552A
Authority
CN
China
Prior art keywords
timer event
task
time
timer
time counter
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
CN202010686320.2A
Other languages
Chinese (zh)
Other versions
CN111813552B (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.)
Jinan Inspur Data Technology Co Ltd
Original Assignee
Jinan Inspur Data 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 Jinan Inspur Data Technology Co Ltd filed Critical Jinan Inspur Data Technology Co Ltd
Priority to CN202010686320.2A priority Critical patent/CN111813552B/en
Publication of CN111813552A publication Critical patent/CN111813552A/en
Application granted granted Critical
Publication of CN111813552B publication Critical patent/CN111813552B/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/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • 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/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • G06F9/4887Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues involving deadlines, e.g. rate based, periodic
    • 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/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5018Thread allocation

Abstract

The embodiment of the invention discloses a scheduling execution method, a device and a medium based on a multi-thread task, wherein a constructed timer event is sequentially cached to a task queue according to the time sequence of task execution; and updating the global time counter by using a preset working thread, and taking the current time recorded by the global time counter as the initial time of all local time counters. When the current time recorded by the local time counter of the first timer event reaches the task execution time corresponding to the first timer event, executing the task to be processed corresponding to the first timer event by using the corresponding working thread; and taking the current time recorded by the local time counter of the first timer event as the initial time of the next timer event, and ending the operation until all the timer events in the task queue are polled. On the premise of not increasing the cost, the clock synchronization problem in the process of scheduling and executing the multi-thread task is solved.

Description

Scheduling execution method, device and medium based on multi-thread task
Technical Field
The present invention relates to the field of storage system technologies, and in particular, to a scheduling execution method and apparatus based on a multi-threaded task, and a computer-readable storage medium.
Background
As the number of IO requests (i.e., tasks to be performed) to be handled by the storage system increases, the performance requirements on the storage system also increases. In order to improve task processing performance under the condition that more and more tasks are required to be executed, a method of creating as many threads as possible to increase concurrency is often adopted at present. In the context of multi-threaded task scheduling execution, the selection and design of the timer processing mode is particularly critical.
In the existing computer multi-node system, two ideas of hardware and software are generally adopted to realize the function of a timer. The hardware mode can include satellite signal timing and electronic device pulse timing, but the hardware mode needs to purchase a third-party equipment entry system additionally, so that the construction cost is increased, and the complexity of system construction is increased. In order to reduce the construction cost, a software timer represented by a multimedia timer becomes a concept with a wide application range. The software timer is dependent on an operating system, has high accuracy, and is seriously influenced by time zone and system clock modification. In the field of storage systems with stable performance requirements, the existing software timer thought is not a good choice.
Therefore, how to solve the problem of clock synchronization in the process of scheduling and executing a multi-thread task without increasing the cost is a problem to be solved by the technical personnel in the field.
Disclosure of Invention
The embodiment of the invention aims to provide a scheduling execution method, a scheduling execution device and a computer readable storage medium based on a multi-thread task, which can solve the problem of clock synchronization in the scheduling execution process of the multi-thread task on the premise of not increasing the cost.
To solve the foregoing technical problem, an embodiment of the present invention provides a scheduling execution method based on a multithread task, including:
sequentially caching the constructed timer events to a task queue according to the time sequence of task execution; each timer event comprises a corresponding local time counter and a working thread;
updating a global time counter by using a preset working thread, and taking the current time recorded by the global time counter as the initial time of a local time counter of all the timer events;
when the current time recorded by the local time counter of the first timer event reaches the task execution time corresponding to the first timer event, executing the task to be processed corresponding to the first timer event by using the corresponding working thread;
and taking the current time recorded by the local time counter of the first timer event as the initial time of the next timer event, and ending the operation until all the timer events in the task queue are polled.
Optionally, the sequentially buffering the constructed timer events to the task queue according to the time sequence of task execution includes:
constructing a timer event based on the task to be processed; each timer event comprises a front node pointing pointer, a back node pointing pointer, a trigger time, an iteration cycle and increment trigger time;
and according to the triggering time of each timer event, all the timer events are sorted and buffered to a task queue in an ascending order.
Optionally, after the sequentially buffering the constructed timer events to the task queue according to the time sequence of task execution, the method further includes:
when a new task to be processed is received, constructing a new timer event for the new task to be processed;
and inserting the new timer event into the task queue according to the trigger time of the new timer event, and updating a front-back node pointing pointer and an increment trigger time of two timer events which are adjacent to the front-back of the new timer event.
Optionally, the updating the global time counter by using a preset work thread includes:
the global time counter is updated with a plurality of high priority worker threads in a lock protected manner.
Optionally, after the executing, by using the corresponding worker thread, the task to be processed corresponding to the first timer event further includes:
and deleting the first timer event from the task queue after the task to be processed corresponding to the first timer event is completed.
Optionally, the method further comprises:
calculating the difference value between the current time recorded by each local time counter and the current time recorded by the global time counter;
and when a target local time counter with the difference value larger than a preset value exists, carrying out error reporting prompt on the working process corresponding to the target local time counter.
The embodiment of the invention also provides a scheduling execution device based on the multi-thread task, which comprises a cache unit, an updating unit, an execution unit and an acting unit;
the storage unit is used for sequentially caching the constructed timer events to the task queue according to the time sequence of task execution; each timer event comprises a corresponding local time counter and a working thread;
the updating unit is used for updating a global time counter by using a preset working thread, and taking the current time recorded by the global time counter as the initial time of the local time counters of all the timer events;
the execution unit is configured to execute the to-be-processed task corresponding to the first timer event by using the corresponding working thread when the current time recorded by the local time counter of the first timer event reaches the task execution time corresponding to the first timer event;
and the acting unit is used for taking the current time recorded by the local time counter of the first timer event as the initial time of the next timer event, and ending the operation until all the timer events in the task queue are polled.
Optionally, the cache-to-cache unit includes a construction subunit and an arrangement subunit;
the construction subunit is used for constructing a timer event based on the task to be processed; each timer event comprises a front node pointing pointer, a back node pointing pointer, a trigger time, an iteration cycle and increment trigger time;
and the arranging subunit is used for arranging and caching all the timer events to the task queue in an ascending order according to the triggering time of each timer event.
Optionally, the system further comprises a construction unit, an insertion unit and a pointer updating unit;
the construction unit is used for constructing a new timer event for a new task to be processed when the new task to be processed is received;
the inserting unit is used for inserting the new timer event into the task queue according to the triggering time of the new timer event;
and the pointer updating unit is used for updating the front and back node pointing pointers and the increment triggering time of two timer events which are adjacent to the front and back of the new timer event.
Optionally, the updating unit includes updating the global time counter with a plurality of high priority worker threads in a lock protected manner.
Optionally, a deleting unit is further included;
and the deleting unit is used for deleting the first timer event from the task queue after the task to be processed corresponding to the first timer event is completed.
Optionally, the system further comprises a computing unit and a prompting unit;
the computing unit is used for computing the difference value between the current time recorded by each local time counter and the current time recorded by the global time counter;
and the prompting unit is used for carrying out error notification on the working process corresponding to the target local time counter when the target local time counter with the difference value larger than the preset value exists.
The embodiment of the invention also provides a scheduling execution device based on the multi-thread task, which comprises:
a memory for storing a computer program;
a processor for executing the computer program to implement the steps of the method for scheduling execution based on multi-threaded tasks as described in any one of the above.
An embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the scheduling execution method based on the multi-thread task are implemented as any one of the above.
According to the technical scheme, the constructed timer events are sequentially cached to the task queue according to the time sequence of task execution; each timer event comprises a corresponding local time counter and a working thread; and updating the global time counter by using a preset working thread, and taking the current time recorded by the global time counter as the initial time of the local time counters of all timer events. The global time counter is maintained by using the preset working thread, so that the influence of time zone or system clock modification on the global time counter can be effectively avoided. When the current time recorded by the local time counter of the first timer event reaches the task execution time corresponding to the first timer event, executing the task to be processed corresponding to the first timer event by using the corresponding working thread; and taking the current time recorded by the local time counter of the first timer event as the initial time of the next timer event, and ending the operation until all the timer events in the task queue are polled. The next timer event depends on the time of the previous timer event adjacent to the next timer event, so that the relative synchronization of the time of each timer event is ensured, and the clock synchronization problem in the scheduling execution process of the multi-thread task is solved on the premise of not increasing the cost. In the technical scheme, the tasks to be processed are cached to the task queue in the form of timer events, the corresponding working threads are set for each timer event, and the timer events are matched with the multi-thread working queue to perform triggering monitoring and task execution, so that the system performance under the high-concurrency IO scene is improved.
Drawings
In order to illustrate the embodiments of the present invention more clearly, the drawings that are needed in the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and that other drawings can be obtained by those skilled in the art without inventive effort.
Fig. 1 is a flowchart of a scheduling execution method based on multi-thread tasks according to an embodiment of the present invention;
FIG. 2 is a diagram illustrating a timer event linked list according to an embodiment of the present invention;
FIG. 3 is a schematic structural diagram of a scheduling execution apparatus based on multi-thread tasks according to an embodiment of the present invention;
fig. 4 is a schematic hardware structure diagram of a scheduling execution apparatus based on multi-thread tasks according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, 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 invention without any creative work belong to the protection scope of the present invention.
In order that those skilled in the art will better understand the disclosure, the invention will be described in further detail with reference to the accompanying drawings and specific embodiments.
Next, a scheduling execution method based on multi-thread tasks according to an embodiment of the present invention is described in detail. Fig. 1 is a flowchart of a scheduling execution method based on a multi-thread task according to an embodiment of the present invention, where the method includes:
s101: and sequentially caching the constructed timer events to a task queue according to the time sequence of task execution.
Each timer event has a corresponding local time counter and a worker thread.
The local time counter is used for recording the current time corresponding to the timer event.
In practical application, a corresponding number of working threads can be created according to the number of CPU cores; and allocating a corresponding working thread for each timer event so as to execute the tasks to be processed contained in the timer events by using the working threads.
In the embodiment of the invention, in order to manage the tasks to be executed, namely the tasks to be processed, a timer event can be constructed based on the tasks to be processed; and according to the triggering time of each timer event, all the timer events are sorted and buffered to the task queue in an ascending order.
The trigger time is used for representing the execution time of the task to be processed contained in the timer event.
The task to be processed in the timer event may be a one-time task or a task that needs to be repeatedly executed according to the cycle time, so to facilitate identifying whether the task to be processed needs to be repeatedly executed, an iteration cycle may be set for the timer event, and the iteration cycle is used to represent how often the task to be processed corresponding to the timer event is executed.
For example, if the iteration cycle of the timer event is 0, it means that the task to be processed included in the timer event is executed once. Taking the time precision of 10ms as an example, when the iteration period is 5, the task to be processed is executed every 50ms from the first time.
In order to facilitate management of the timer events in the task queue, the timer events may include front and back node pointing pointers and incremental trigger times in addition to trigger times and iteration cycles.
The front-back node pointing pointers are used for indicating the pointing relationship of the current timer event, the previous timer event adjacent to the current timer event and the next timer event adjacent to the current timer event.
The point pointers of the front node and the back node are set for each timer event, so that management of the timer events can be facilitated, and when a new timer event needs to be put into a task queue, the position where the new timer event needs to be stored can be quickly determined by depending on the point pointers of the front node and the back node.
The incremental trigger time is used to characterize the difference in the trigger time of the current timer event relative to its immediately preceding timer event.
S102: and updating the global time counter by using a preset working thread, and taking the current time recorded by the global time counter as the initial time of the local time counters of all timer events.
The storage system comprises a plurality of nodes, and each node is provided with a corresponding global time counter. The master control node can synchronize the global time counters of all nodes of the whole system by using a heartbeat mechanism, so that the running functional modules of all the nodes are ensured to have consistent clocks, and synchronous timing is realized.
In the embodiment of the present invention, in order to avoid the influence of time zone or system clock modification on the time of the global time counter, a preset working thread may be used to update and maintain the global time counter.
A single working thread may cause delay due to high load, which may result in that the global time counter is not updated timely enough, and therefore, in practical application, a plurality of working threads with high priority may be used to update and maintain the global time counter.
In order to avoid confusion of updating the global time counter due to the fact that a plurality of high-priority working threads update the time of the global time counter at the same time, in a specific implementation, the global time counter can be updated by using the plurality of high-priority working threads according to a lock protection mode.
By setting a lock protection mode, when any one of a plurality of high-priority working threads updates the time of the global time counter, other working threads cannot simultaneously execute the updating operation on the global time counter.
In the embodiment of the present invention, the update period of the global time counter may be set according to actual requirements, for example, the time of the global time counter may be updated once every 10 ms.
In the initial state, the current time recorded by the global time counter may be used as the initial time of the local time counter for all timer events.
S103: and when the current time recorded by the local time counter of the first timer event reaches the task execution time corresponding to the first timer event, executing the task to be processed corresponding to the first timer event by using the corresponding working thread.
The timer events are sorted in the task queue according to the time sequence of task execution, so that the task contained in the first timer event in the task queue is the earliest task to be executed.
For the first timer event, since there is no adjacent previous timer event, the trigger time of the first timer event may be used as the task execution time.
In the initial state, after the global time counter completes updating the time, the current time recorded by the global time counter is used as the initial time of the local time counter of the first timer event. At this time, the local time counter of the first timer event starts to count time, and when the current time recorded by the local time counter of the first timer event reaches the trigger time of the first timer event, the to-be-processed task corresponding to the first timer event may be executed by using the working thread allocated to the first timer event.
In the embodiment of the present invention, in order to avoid repeatedly executing the timer event recorded in the task queue, after the task to be processed corresponding to the first timer event is completed, the first timer event may be deleted from the task queue.
S104: and taking the current time recorded by the local time counter of the first timer event as the initial time of the next timer event, and ending the operation until all the timer events in the task queue are polled.
In the embodiment of the invention, the timer events are placed in the task queue according to the time sequence of task execution, so that for each timer event, the task can be executed depending on the time of the previous timer event adjacent to the timer event.
When the current time recorded by the local time counter of the first timer event reaches the task execution time corresponding to the first timer event, the current time recorded by the local time counter of the first timer event may be used as the initial time of the next timer event, that is, the second timer event. Correspondingly, the local time counter corresponding to the second timer event starts to time, when the current time recorded by the local time counter of the second timer event reaches the task execution time corresponding to the second timer event, the corresponding working thread is used for executing the task to be processed corresponding to the second timer event, and so on, until all the timer events in the task queue are traversed, the operation is ended.
Referring to the linked list of timer events shown in fig. 2, the first box on the left in fig. 2 is used to represent a global time counter, and each of the remaining boxes represents a timer Event, which is respectively denoted as Event1, Event2, Event3 and Event 4. The "count" in the global time counter indicates the number of times the global time counter time has currently been updated. In practical applications, the worker thread may update the time recorded by the global time counter every 10 ms. The "time" in each timer event represents the incremental trigger time. In fig. 2, 4 timer events are taken as an example, the 1 st timer event occurs after 10 ticks, and the 1 tick indicates 10ms, that is, 100ms later, the task to be processed of the 1 st timer event is triggered. The 2 nd timer event is triggered after 5 ticks after the 1 st timer event, i.e. 100+5 × 10-150 ms after the 2 nd timer event. The 3 rd timer event delta trigger time is set to 0, indicating that it triggered immediately after the 2 nd timer event trigger. The 4 th timer event is triggered after 7 ticks after the 3 rd timer event, i.e. 150+7 × 10-220 ms after the 1 st timer event.
According to the technical scheme, the constructed timer events are sequentially cached to the task queue according to the time sequence of task execution; each timer event comprises a corresponding local time counter and a working thread; and updating the global time counter by using a preset working thread, and taking the current time recorded by the global time counter as the initial time of the local time counters of all timer events. The global time counter is maintained by using the preset working thread, so that the influence of time zone or system clock modification on the global time counter can be effectively avoided. When the current time recorded by the local time counter of the first timer event reaches the task execution time corresponding to the first timer event, executing the task to be processed corresponding to the first timer event by using the corresponding working thread; and taking the current time recorded by the local time counter of the first timer event as the initial time of the next timer event, and ending the operation until all the timer events in the task queue are polled. The next timer event depends on the time of the previous timer event adjacent to the next timer event, so that the relative synchronization of the time of each timer event is ensured, and the clock synchronization problem in the scheduling execution process of the multi-thread task is solved on the premise of not increasing the cost. In the technical scheme, the tasks to be processed are cached to the task queue in the form of timer events, the corresponding working threads are set for each timer event, and the timer events are matched with the multi-thread working queue to perform triggering monitoring and task execution, so that the system performance under the high-concurrency IO scene is improved.
In practical applications, the pending tasks are not fixed, and as the pending tasks in the task queue are executed, there may be a new pending task that needs to be added to the task queue.
In a specific implementation, when a new task to be processed is received, a new timer event is established for the new task to be processed; and inserting the new timer event into the task queue according to the triggering time of the new timer event.
When a new timer event is inserted between two adjacent timer events, since the front-back pointing relationship of the two adjacent timer events originally changes, after the new timer event is inserted into the task queue, the front-back node pointing pointers and the incremental trigger time of the two adjacent timer events before and after the new timer event need to be updated.
In conjunction with the timer event linked list shown in fig. 2, assuming that the triggering time of the new timer event is 180ms, at this time, the new timer event needs to be inserted into the middle of the original 3 rd timer event and the original 4 th timer event, the incremental triggering time "of the newly inserted timer event is recorded as (180 + 150)/10 ═ 3, the original 4 th timer event becomes the 5 th timer event at this time, and the corresponding incremental triggering time" needs to be modified to (220 + 180)/10 ═ 4.
The newly added timer event can be put into a proper position of the task queue by depending on the triggering time, and the correctness of the parameter information of each timer event in the task queue is ensured and the smooth execution of each timer event is ensured by updating the front and back node pointing pointers and the increment triggering time of two timer events which are adjacent to the front and back of the new timer event.
The local time counter of each timer event is maintained by a working thread, and when a problem occurs in the working thread of a certain timer event, the local time counter of the timer event is not updated timely, so that the current time recorded by the local time counter and the current time recorded by the global time counter have a larger deviation.
Therefore, in the embodiment of the present invention, the difference between the current time recorded by each local time counter and the current time recorded by the global time counter can be calculated; when the target local time counter with the difference value larger than the preset value exists, the fact that the working thread corresponding to the target local time counter is possibly blocked results in the local time counter of the timer event not being updated for a long time is indicated, and therefore when the target local time counter with the difference value larger than the preset value exists, an error prompt can be conducted on the working process corresponding to the target local time counter.
By comparing the time recorded by the local time counter with the time recorded by the global time counter, the situation that the local time counter is not updated timely can be found in time, so that timely error reporting prompt can be performed on possible problems of a working thread, and managers can process the problems in time.
Fig. 3 is a schematic structural diagram of a scheduling execution apparatus based on multi-thread tasks according to an embodiment of the present invention, including a cache unit 31, an update unit 32, an execution unit 33, and an execution unit 34;
the storage unit 31 is configured to sequentially buffer the constructed timer events to the task queue according to the time sequence of task execution; each timer event comprises a corresponding local time counter and a working thread;
an updating unit 32, configured to update the global time counter by using a preset working thread, and use the current time recorded by the global time counter as the initial time of the local time counters of all timer events;
the execution unit 33 is configured to execute the to-be-processed task corresponding to the first timer event by using the corresponding working thread when the current time recorded by the local time counter of the first timer event reaches the task execution time corresponding to the first timer event;
and a unit 34, configured to use the current time recorded by the local time counter of the first timer event as the initial time of the next timer event, and end the operation until all timer events in the task queue are polled.
Optionally, the caching to caching unit includes a construction subunit and an arrangement subunit;
the construction subunit is used for constructing a timer event based on the task to be processed; each timer event comprises a front node pointing pointer, a back node pointing pointer, a trigger time, an iteration cycle and increment trigger time;
and the arranging subunit is used for arranging and buffering all the timer events to the task queue in an ascending order according to the triggering time of each timer event.
Optionally, the system further comprises a construction unit, an insertion unit and a pointer updating unit;
the construction unit is used for constructing a new timer event for the new task to be processed when the new task to be processed is received;
the inserting unit is used for inserting the new timer event into the task queue according to the triggering time of the new timer event;
and the pointer updating unit is used for updating the front and back node pointing pointers and the increment triggering time of two timer events which are adjacent to the front and back of the new timer event.
Optionally, the updating unit comprises updating the global time counter with a plurality of high priority worker threads in a lock protected manner.
Optionally, a deleting unit is further included;
and the deleting unit is used for deleting the first timer event from the task queue after the task to be processed corresponding to the first timer event is completed.
Optionally, the system further comprises a computing unit and a prompting unit;
the computing unit is used for computing the difference value between the current time recorded by each local time counter and the current time recorded by the global time counter;
and the prompting unit is used for carrying out error-reporting prompting on the working process corresponding to the target local time counter when the target local time counter with the difference value larger than the preset value exists.
The description of the features in the embodiment corresponding to fig. 3 may refer to the related description of the embodiment corresponding to fig. 1, and is not repeated here.
According to the technical scheme, the constructed timer events are sequentially cached to the task queue according to the time sequence of task execution; each timer event comprises a corresponding local time counter and a working thread; and updating the global time counter by using a preset working thread, and taking the current time recorded by the global time counter as the initial time of the local time counters of all timer events. The global time counter is maintained by using the preset working thread, so that the influence of time zone or system clock modification on the global time counter can be effectively avoided. When the current time recorded by the local time counter of the first timer event reaches the task execution time corresponding to the first timer event, executing the task to be processed corresponding to the first timer event by using the corresponding working thread; and taking the current time recorded by the local time counter of the first timer event as the initial time of the next timer event, and ending the operation until all the timer events in the task queue are polled. The next timer event depends on the time of the previous timer event adjacent to the next timer event, so that the relative synchronization of the time of each timer event is ensured, and the clock synchronization problem in the scheduling execution process of the multi-thread task is solved on the premise of not increasing the cost. In the technical scheme, the tasks to be processed are cached to the task queue in the form of timer events, the corresponding working threads are set for each timer event, and the timer events are matched with the multi-thread working queue to perform triggering monitoring and task execution, so that the system performance under the high-concurrency IO scene is improved.
Fig. 4 is a schematic hardware structure diagram of a scheduling execution apparatus 40 based on multi-thread tasks according to an embodiment of the present invention, including:
a memory 41 for storing a computer program;
a processor 42 for executing a computer program for implementing the steps of the method for scheduled execution based on multi-threaded tasks according to any of the embodiments described above.
The embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the scheduling execution method based on the multi-thread task according to any of the embodiments described above are implemented.
The foregoing details a scheduling execution method, apparatus, and computer-readable storage medium based on multi-threaded tasks according to embodiments of the present invention. The embodiments are described in a progressive manner in the specification, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description. It should be noted that, for those skilled in the art, it is possible to make various improvements and modifications to the present invention without departing from the principle of the present invention, and those improvements and modifications also fall within the scope of the claims of the present invention.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

Claims (10)

1. A scheduling execution method based on multi-thread tasks is characterized by comprising the following steps:
sequentially caching the constructed timer events to a task queue according to the time sequence of task execution; each timer event comprises a corresponding local time counter and a working thread;
updating a global time counter by using a preset working thread, and taking the current time recorded by the global time counter as the initial time of a local time counter of all the timer events;
when the current time recorded by the local time counter of the first timer event reaches the task execution time corresponding to the first timer event, executing the task to be processed corresponding to the first timer event by using the corresponding working thread;
and taking the current time recorded by the local time counter of the first timer event as the initial time of the next timer event, and ending the operation until all the timer events in the task queue are polled.
2. The method of claim 1, wherein the sequentially buffering the built timer events to the task queue according to the time sequence of task execution comprises:
constructing a timer event based on the task to be processed; each timer event comprises a front node pointing pointer, a back node pointing pointer, a trigger time, an iteration cycle and increment trigger time;
and according to the triggering time of each timer event, all the timer events are sorted and buffered to a task queue in an ascending order.
3. The method of claim 2, wherein after the sequentially buffering the built timer events to the task queue according to the time sequence of task execution, the method further comprises:
when a new task to be processed is received, constructing a new timer event for the new task to be processed;
and inserting the new timer event into the task queue according to the trigger time of the new timer event, and updating a front-back node pointing pointer and an increment trigger time of two timer events which are adjacent to the front-back of the new timer event.
4. The method of claim 1, wherein updating the global time counter with the predetermined working thread comprises:
the global time counter is updated with a plurality of high priority worker threads in a lock protected manner.
5. The method of claim 1, further comprising, after the executing the task to be processed corresponding to the first timer event by using the corresponding worker thread:
and deleting the first timer event from the task queue after the task to be processed corresponding to the first timer event is completed.
6. A method for scheduling execution based on multi-threaded tasks according to any of claims 1-5, further comprising:
calculating the difference value between the current time recorded by each local time counter and the current time recorded by the global time counter;
and when a target local time counter with the difference value larger than a preset value exists, carrying out error reporting prompt on the working process corresponding to the target local time counter.
7. The scheduling execution device based on the multi-thread task is characterized by comprising a cache unit, an updating unit, an execution unit and an acting unit;
the storage unit is used for sequentially caching the constructed timer events to the task queue according to the time sequence of task execution; each timer event comprises a corresponding local time counter and a working thread;
the updating unit is used for updating a global time counter by using a preset working thread, and taking the current time recorded by the global time counter as the initial time of the local time counters of all the timer events;
the execution unit is configured to execute the to-be-processed task corresponding to the first timer event by using the corresponding working thread when the current time recorded by the local time counter of the first timer event reaches the task execution time corresponding to the first timer event;
and the acting unit is used for taking the current time recorded by the local time counter of the first timer event as the initial time of the next timer event, and ending the operation until all the timer events in the task queue are polled.
8. The multithreading task-based scheduling execution apparatus of claim 7, wherein the cache-to-cache unit comprises a build subunit and an order subunit;
the construction subunit is used for constructing a timer event based on the task to be processed; each timer event comprises a front node pointing pointer, a back node pointing pointer, a trigger time, an iteration cycle and increment trigger time;
and the arranging subunit is used for arranging and caching all the timer events to the task queue in an ascending order according to the triggering time of each timer event.
9. A scheduling execution apparatus based on multithread tasks, comprising:
a memory for storing a computer program;
a processor for executing the computer program to carry out the steps of the method of scheduling execution based on multi-threaded tasks according to any one of claims 1 to 6.
10. A computer-readable storage medium, having stored thereon a computer program which, when being executed by a processor, carries out the steps of the method for scheduling execution based on multi-threaded tasks according to any one of claims 1 to 6.
CN202010686320.2A 2020-07-16 2020-07-16 Scheduling execution method, device and medium based on multi-thread task Active CN111813552B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010686320.2A CN111813552B (en) 2020-07-16 2020-07-16 Scheduling execution method, device and medium based on multi-thread task

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010686320.2A CN111813552B (en) 2020-07-16 2020-07-16 Scheduling execution method, device and medium based on multi-thread task

Publications (2)

Publication Number Publication Date
CN111813552A true CN111813552A (en) 2020-10-23
CN111813552B CN111813552B (en) 2021-12-03

Family

ID=72865279

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010686320.2A Active CN111813552B (en) 2020-07-16 2020-07-16 Scheduling execution method, device and medium based on multi-thread task

Country Status (1)

Country Link
CN (1) CN111813552B (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112631858A (en) * 2020-12-18 2021-04-09 苏州浪潮智能科技有限公司 Thread monitoring method, system, device and medium
CN112925618A (en) * 2021-02-22 2021-06-08 北京达佳互联信息技术有限公司 Distributed task processing method and device
CN112925631A (en) * 2021-04-08 2021-06-08 上海科世达-华阳汽车电器有限公司 Task scheduling method and device, electronic equipment and storage medium
CN115469991A (en) * 2022-11-14 2022-12-13 苏州浪潮智能科技有限公司 Timer queue setting method, device and equipment and readable storage medium
CN116069475A (en) * 2023-02-27 2023-05-05 麦岩智能科技(北京)有限公司 Timing task processing method, storage medium and equipment
CN116346918A (en) * 2023-05-30 2023-06-27 天翼云科技有限公司 Performance bottleneck identification method and system for network event
CN117032916A (en) * 2023-07-24 2023-11-10 杭州观远数据有限公司 Event-based task scheduling algorithm, device and storage medium

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020059503A1 (en) * 1999-02-04 2002-05-16 Sun Microsystems, Inc. Protocol for coordinating the distribution of shared memory
US20040064580A1 (en) * 2002-09-30 2004-04-01 Lee Booi Lim Thread efficiency for a multi-threaded network processor
US20090235099A1 (en) * 2008-03-11 2009-09-17 Alexander Branover Protocol for Transitioning In and Out of Zero-Power State
CN101599027A (en) * 2009-06-30 2009-12-09 中兴通讯股份有限公司 A kind of thread pool management method and system thereof
CN101727352A (en) * 2009-12-15 2010-06-09 四川长虹电器股份有限公司 Method for realizing timer
CN108536530A (en) * 2018-04-02 2018-09-14 北京中电普华信息技术有限公司 A kind of multithreading method for scheduling task and device
US20180349177A1 (en) * 2017-06-04 2018-12-06 Apple Inc. Scheduler for amp architecture using a closed loop performance controller and deferred inter-processor interrupts
CN110134500A (en) * 2019-04-15 2019-08-16 平安普惠企业管理有限公司 Method of data synchronization, device, equipment and storage medium based on multithreading

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020059503A1 (en) * 1999-02-04 2002-05-16 Sun Microsystems, Inc. Protocol for coordinating the distribution of shared memory
US20040064580A1 (en) * 2002-09-30 2004-04-01 Lee Booi Lim Thread efficiency for a multi-threaded network processor
US20090235099A1 (en) * 2008-03-11 2009-09-17 Alexander Branover Protocol for Transitioning In and Out of Zero-Power State
CN101599027A (en) * 2009-06-30 2009-12-09 中兴通讯股份有限公司 A kind of thread pool management method and system thereof
CN101727352A (en) * 2009-12-15 2010-06-09 四川长虹电器股份有限公司 Method for realizing timer
US20180349177A1 (en) * 2017-06-04 2018-12-06 Apple Inc. Scheduler for amp architecture using a closed loop performance controller and deferred inter-processor interrupts
CN108536530A (en) * 2018-04-02 2018-09-14 北京中电普华信息技术有限公司 A kind of multithreading method for scheduling task and device
CN110134500A (en) * 2019-04-15 2019-08-16 平安普惠企业管理有限公司 Method of data synchronization, device, equipment and storage medium based on multithreading

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
王嘉等: "一种改进型多线程机制在数据采集系统中的应用", 《计算技术与自动化》 *

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112631858A (en) * 2020-12-18 2021-04-09 苏州浪潮智能科技有限公司 Thread monitoring method, system, device and medium
CN112925618A (en) * 2021-02-22 2021-06-08 北京达佳互联信息技术有限公司 Distributed task processing method and device
CN112925631A (en) * 2021-04-08 2021-06-08 上海科世达-华阳汽车电器有限公司 Task scheduling method and device, electronic equipment and storage medium
CN112925631B (en) * 2021-04-08 2022-11-04 上海科世达-华阳汽车电器有限公司 Task scheduling method and device, electronic equipment and storage medium
CN115469991A (en) * 2022-11-14 2022-12-13 苏州浪潮智能科技有限公司 Timer queue setting method, device and equipment and readable storage medium
CN116069475A (en) * 2023-02-27 2023-05-05 麦岩智能科技(北京)有限公司 Timing task processing method, storage medium and equipment
CN116346918A (en) * 2023-05-30 2023-06-27 天翼云科技有限公司 Performance bottleneck identification method and system for network event
CN116346918B (en) * 2023-05-30 2023-10-10 天翼云科技有限公司 Performance bottleneck identification method and system for network event
CN117032916A (en) * 2023-07-24 2023-11-10 杭州观远数据有限公司 Event-based task scheduling algorithm, device and storage medium

Also Published As

Publication number Publication date
CN111813552B (en) 2021-12-03

Similar Documents

Publication Publication Date Title
CN111813552B (en) Scheduling execution method, device and medium based on multi-thread task
Haban et al. Application of real-time monitoring to scheduling tasks with random execution times
US9639361B2 (en) Tracing speculatively executed instructions
US7353346B2 (en) Read-copy-update (RCU) operations with reduced memory barrier usage
US8402463B2 (en) Hardware threads processor core utilization
US20070226440A1 (en) Read-copy-update (RCU) operations with reduced memory barrier usage
US8707106B2 (en) Key allocation when tracing data processing systems
US10776120B2 (en) Apparatus and method to generate trace data in response to transactional execution
US20120272246A1 (en) Dynamically scalable per-cpu counters
US9785587B2 (en) Method for executing, within a multitasking onboard system, an application timed according to a plurality of different time domains including interruption management
CN102541642A (en) Task management method for enhancing real-time performance
CN112199170A (en) Timing processing method, device and equipment of real-time operating system and storage medium
US9600023B2 (en) Method and data processing unit for providing a timestamp
EP3765963B1 (en) Tracing branch instructions
US20240036921A1 (en) Cascading of Graph Streaming Processors
CN110502322A (en) The triggering method and device of timer-triggered scheduler
US6766508B1 (en) Object-oriented system having anonymous scheduler design pattern
Zamorano et al. Implementing Ada. Real Time. Clock and absolute delays in real-time kernels
Xu et al. Towards fault-tolerant real-time scheduling in the seL4 microkernel
KR101083049B1 (en) Simulation system and simulation method
US20120124582A1 (en) Calculating Processor Load
US20040039956A1 (en) System and method for implementing a timer facility
CN117112160A (en) Timing task scheduling method, device, equipment and medium
Wan et al. Exploiting aperiodic server to improve aperiodic responsiveness for LET-based real-time systems
CN117290068A (en) Task scheduling method, device, electronic equipment and storage 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