CN111552548A - Task processing method and device, electronic equipment and machine-readable storage medium - Google Patents

Task processing method and device, electronic equipment and machine-readable storage medium Download PDF

Info

Publication number
CN111552548A
CN111552548A CN202010321248.3A CN202010321248A CN111552548A CN 111552548 A CN111552548 A CN 111552548A CN 202010321248 A CN202010321248 A CN 202010321248A CN 111552548 A CN111552548 A CN 111552548A
Authority
CN
China
Prior art keywords
task
processed
priority
waiting time
time
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010321248.3A
Other languages
Chinese (zh)
Inventor
曹平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Kingsoft Cloud Network Technology Co Ltd
Original Assignee
Beijing Kingsoft Cloud Network 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 Beijing Kingsoft Cloud Network Technology Co Ltd filed Critical Beijing Kingsoft Cloud Network Technology Co Ltd
Priority to CN202010321248.3A priority Critical patent/CN111552548A/en
Publication of CN111552548A publication Critical patent/CN111552548A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the disclosure provides a task processing method and device, electronic equipment and a machine-readable storage medium, and relates to the field of cloud computing. The method comprises the following steps: the method comprises the steps of obtaining the upgrading waiting time and the priority of each task to be processed, upgrading the priority of each task to be processed if the upgrading waiting time of each task to be processed reaches the preset maximum waiting time aiming at any task to be processed, and processing each task to be processed according to the sequence of the priority from high to low when the tasks are processed. The upgrading waiting time of each task to be processed is the accumulated time of each task to be processed at the current priority, if a certain task to be processed is at the current priority for a long time, the task to be processed is not processed for a long time, and the priority of the task to be processed which is not processed for a long time can be increased by actively upgrading the priority of the task to be processed, so that the task to be processed with low priority is prevented from being in a waiting state for a long time, and the task to be processed with low priority is prevented from being blocked.

Description

Task processing method and device, electronic equipment and machine-readable storage medium
Technical Field
The disclosure relates to a task processing method and device, an electronic device and a machine-readable storage medium.
Background
At present, when a computer is used for processing tasks, a strategy of adding a first process is generally adopted, although the task processing mode can ensure the real-time performance of task processing to a great extent, because the importance degree of some tasks is higher, priority processing is needed, if the time for adding a certain important task is later and a plurality of tasks are queued for processing before, the important task can not be processed at a later time.
In order to deal with the problems, different priorities are set for the tasks according to the task types of the tasks to be processed, the tasks are processed sequentially according to the sequence of the priorities, if one task is newly added, queue insertion processing can be performed according to the priority of the task, and therefore the important task can be processed preferentially.
However, in the above-described method of performing processing in the order of priority, since the low-priority task must wait until the high-priority task is completed, the low-priority task is in a waiting state for a long time and the low-priority task is blocked if the high-priority task is not in line with the high-priority task.
Disclosure of Invention
An object of the disclosed embodiments is to provide a task processing method, a task processing apparatus, an electronic device, and a machine-readable storage medium, so as to avoid low-priority task congestion. The specific technical scheme is as follows:
in a first aspect, an embodiment of the present disclosure provides a task processing method, where the method includes:
acquiring the upgrading waiting time and the priority of each task to be processed, wherein the upgrading waiting time of each task to be processed is the accumulated time of each task to be processed at the current priority;
for any task to be processed, if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, upgrading the priority of the task to be processed;
and when the tasks are processed, processing the tasks to be processed according to the sequence of the priority from high to low.
Optionally, the step of obtaining the upgrade waiting time of each task to be processed includes:
aiming at any one to-be-processed task which is not upgraded, acquiring the corresponding initial time when the to-be-processed task is created, and calculating the time period between the current time and the initial time of the to-be-processed task to obtain the upgrade waiting time of the to-be-processed task.
Optionally, the step of obtaining the upgrade waiting time of each task to be processed includes:
and aiming at any upgraded task to be processed, acquiring the corresponding upgrading time when the task to be processed is upgraded last time, and calculating the time period between the current time and the upgrading time of the task to be processed to obtain the upgrading waiting time of the task to be processed.
Optionally, the step of obtaining the upgrade waiting time and the priority of each task to be processed includes:
and obtaining the upgrade waiting time and the priority of each task to be processed according to a preset period.
Optionally, for any task to be processed, after the step of upgrading the priority of the task to be processed if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, the method further includes:
refreshing a pre-established task priority queue based on the upgraded tasks to be processed, wherein task identifiers of the tasks to be processed are stored in the task priority queue according to the priority order of the tasks to be processed;
when processing tasks, the step of processing each task to be processed according to the sequence of the priority from high to low comprises the following steps:
when processing tasks, processing each task to be processed according to the sequence of the priorities from high to low in the task priority queue, and deleting the task identifier of the task to be processed from the task priority queue after processing any task to be processed.
Optionally, the task identifiers in the task priority queue are arranged according to the size of the score attribute corresponding to each task identifier, and the score attribute corresponding to each task identifier represents the priority of each task to be processed;
for any task to be processed, if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, the step of upgrading the priority of the task to be processed includes:
for any task to be processed, if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, reducing the score attribute corresponding to the task identifier of the task to be processed, wherein the score attribute is inversely proportional to the priority; alternatively, the first and second electrodes may be,
for any task to be processed, if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, increasing the score attribute corresponding to the task identifier of the task to be processed, wherein the score attribute is in direct proportion to the priority;
based on the upgraded task to be processed, the step of refreshing the pre-established task priority queue comprises the following steps:
and refreshing the task priority queue based on the changed score attribute.
Optionally, the task priority queue is a queue adopting an ordered set zset structure of the remote data service Redis.
Optionally, when processing the tasks, before the step of processing each task to be processed according to the order of the priorities from high to low, the method further includes:
acquiring priority adjustment information input by a user;
and adjusting the priority of each task to be processed according to the priority adjustment information.
In a second aspect, an embodiment of the present disclosure provides a task processing device, including:
the acquisition module is used for acquiring the upgrade waiting time and the priority of each task to be processed, wherein the upgrade waiting time of each task to be processed is the accumulated time of each task to be processed at the current priority;
the upgrading module is used for upgrading the priority of any task to be processed if the upgrading waiting time of the task to be processed reaches the preset maximum waiting time;
and the processing module is used for processing each task to be processed according to the sequence of the priority from high to low when processing the tasks.
Optionally, the obtaining module is specifically configured to, for any one to-be-processed task that has not been upgraded, obtain an initial time corresponding to when the to-be-processed task is created, and calculate a time period between the current time and the initial time of the to-be-processed task to obtain an upgrade waiting time of the to-be-processed task.
Optionally, the obtaining module is specifically configured to, for any upgraded to-be-processed task, obtain an upgrade time corresponding to a last time of upgrading the to-be-processed task, and calculate a time period between a current time and the upgrade time of the to-be-processed task to obtain an upgrade waiting time of the to-be-processed task.
Optionally, the obtaining module is specifically configured to obtain the upgrade waiting time and the priority of each to-be-processed task according to a preset period.
Optionally, the apparatus further comprises:
the refreshing module is used for refreshing a pre-established task priority queue based on the upgraded tasks to be processed, wherein task identifiers of the tasks to be processed are stored in the task priority queue according to the priority order of the tasks to be processed;
and the processing module is specifically used for processing each task to be processed according to the sequence of the priorities from high to low in the task priority queue when the tasks are processed, and deleting the task identifier of the task to be processed from the task priority queue after any task to be processed is processed.
Optionally, the task identifiers in the task priority queue are arranged according to the size of the score attribute corresponding to each task identifier, and the score attribute corresponding to each task identifier represents the priority of each task to be processed;
the upgrading module is specifically used for reducing the score attribute corresponding to the task identifier of the task to be processed if the upgrading waiting time of the task to be processed reaches the preset maximum waiting time aiming at any task to be processed, wherein the score attribute is inversely proportional to the priority; or, for any task to be processed, if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, increasing the score attribute corresponding to the task identifier of the task to be processed, wherein the score attribute is in direct proportion to the priority;
and the refreshing module is specifically used for refreshing the task priority queue based on the changed score attribute.
Optionally, the task priority queue is a queue adopting an ordered set zset structure of the remote data service Redis.
Optionally, the obtaining module is further configured to obtain priority adjustment information input by a user;
the device also includes:
and the adjusting module is used for adjusting the priority of each task to be processed according to the priority adjusting information.
In a third aspect, an embodiment of the present disclosure provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete mutual communication through the communication bus;
a memory for storing a computer program;
a processor, configured to execute the computer program stored in the memory, and implement the method provided in the first aspect of the embodiments of the present disclosure.
In a fourth aspect, the disclosed embodiments provide a machine-readable storage medium, where a computer program is stored, which, when executed by a processor of an electronic device, enables the electronic device to perform the method provided by the first aspect of the disclosed embodiments.
According to the task processing method, the device, the electronic equipment and the machine-readable storage medium provided by the embodiment of the disclosure, by acquiring the upgrade waiting time and the priority of each task to be processed, for any task to be processed, if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, the priority of the task to be processed is upgraded, and when the task is processed, each task to be processed is processed according to the sequence of the priorities from high to low. If one task to be processed is in the current priority for a long time, which indicates that the task to be processed is not processed for a long time, the priority of the task to be processed which is lower in priority originally and is not processed for a long time can be increased by actively upgrading the priority of the task to be processed, so that the task to be processed with low priority is prevented from being in a waiting state for a long time, and the task to be processed with low priority is prevented from being blocked.
Drawings
In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present disclosure, and other drawings can be obtained by those skilled in the art without creative efforts.
Fig. 1 is a schematic flowchart of a task processing method according to an embodiment of the disclosure;
FIG. 2 is a flowchart illustrating a task processing method according to another embodiment of the disclosure;
FIG. 3 is a schematic structural diagram of a task processing device according to an embodiment of the present disclosure;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the disclosure.
Detailed Description
The technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are only a part of the embodiments of the present disclosure, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments disclosed herein without making any creative effort, shall fall within the protection scope of the present disclosure.
In order to avoid the occurrence of task congestion with low priority, the embodiment of the disclosure provides a task processing method, a task processing device, an electronic device and a machine-readable storage medium. Next, a task processing method provided in the embodiment of the present disclosure is first described.
The task processing method provided by the embodiment of the present disclosure may be applied to devices such as a personal computer, a mobile phone, a smart camera, a portable computer, and the like, and is not specifically limited herein. The method for implementing the task processing method provided by the embodiment of the present disclosure may be at least one of software, a hardware circuit, and a logic circuit provided in the electronic device.
As shown in fig. 1, a task processing method provided in an embodiment of the present disclosure may include the following steps:
s101, obtaining the upgrading waiting time and the priority of each task to be processed, wherein the upgrading waiting time of each task to be processed is the accumulated time of each task to be processed at the current priority.
S102, for any task to be processed, if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, the priority of the task to be processed is upgraded.
And S103, processing the tasks to be processed according to the sequence of the priority from high to low when the tasks are processed.
By applying the embodiment of the disclosure, the upgrading waiting time and the priority of each task to be processed are obtained, and for any task to be processed, if the upgrading waiting time of the task to be processed reaches the preset maximum waiting time, the priority of the task to be processed is upgraded, and when the task is processed, each task to be processed is processed according to the sequence of the priorities from high to low. If one task to be processed is in the current priority for a long time, which indicates that the task to be processed is not processed for a long time, the priority of the task to be processed which is lower in priority originally and is not processed for a long time can be increased by actively upgrading the priority of the task to be processed, so that the task to be processed with low priority is prevented from being in a waiting state for a long time, and the task to be processed with low priority is prevented from being blocked.
In the embodiment of the disclosure, different tasks are correspondingly provided with different priorities, the priority of one task is often determined by the task type of the task, for example, the priority of an alarm task is higher than the priority of a general calculation task, and for a task to be processed, the priority is not fixed and constant, and can be dynamically changed according to the requirement.
For a task to be processed, the upgrade waiting duration of the task to be processed refers to the accumulated duration of the task to be processed at the current priority, that is, the priority of the task to be processed is continuously the total duration of the current priority, for example, if a task to be processed has not been upgraded from the addition and is kept at the priority, the upgrade waiting duration of the task to be processed is the accumulated duration from the addition of the task to be processed; for another example, after the priority of a task to be processed is updated last time, the priority of the task to be processed is not updated any more within a long period of time and is kept at the priority all the time, and the update waiting time of the task to be processed is the time accumulated since the task to be processed is updated last time. After a task to be processed is created, the upgrade waiting time of the task to be processed can be counted, and the upgrade waiting time can be recorded in the attribute information of the task to be processed, so that the electronic device can acquire the upgrade waiting time of the task to be processed from the attribute information of the task to be processed.
Optionally, the step of obtaining the upgrade waiting time of each task to be processed may specifically be: aiming at any one to-be-processed task which is not upgraded, acquiring the corresponding initial time when the to-be-processed task is created, and calculating the time period between the current time and the initial time of the to-be-processed task to obtain the upgrade waiting time of the to-be-processed task.
In an implementation manner of the embodiment of the present disclosure, if a to-be-processed task is an unerased to-be-processed task, the upgrade waiting time duration of the to-be-processed task may be obtained by calculating a time period between a current time and an initial time corresponding to when the to-be-processed task is created. For example, when a certain task to be processed is created, the corresponding initial time is 10:00, and the current time is 10:05, then the calculated upgrade waiting time of the task to be processed is 5 minutes. The initial time of one to-be-processed task can be recorded in the data format of the to-be-processed task, so that the data format of the to-be-processed task can be directly analyzed to obtain the corresponding initial time when the to-be-processed task is created.
Optionally, the step of obtaining the upgrade waiting time of each task to be processed may specifically be: and aiming at any upgraded task to be processed, acquiring the corresponding upgrading time when the task to be processed is upgraded last time, and calculating the time period between the current time and the upgrading time of the task to be processed to obtain the upgrading waiting time of the task to be processed.
In another implementation manner of the embodiment of the present disclosure, if one to-be-processed task is a to-be-processed task that has been upgraded, the upgrade waiting time of the to-be-processed task may be obtained by calculating a time period between the current time and the upgrade time corresponding to the last time when the to-be-processed task was upgraded. For example, if the upgrade time corresponding to the last upgrade of a certain task to be processed is 10:30 and the current time is 10:33, the calculated upgrade waiting time of the task to be processed is 3 minutes. The upgrading time of one task to be processed can be recorded in the data format of the task to be processed, so that the data format of the task to be processed can be directly analyzed, and the corresponding upgrading time when the task to be processed is upgraded last time can be obtained.
Specifically, whether the priority of the task to be processed needs to be upgraded is judged based on a comparison result of the upgrade waiting time of the task to be processed and a preset maximum waiting time, and if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, the priority of the task to be processed needs to be upgraded. After the priorities of partial tasks to be processed are upgraded, the priorities of the tasks to be processed are changed, and the priorities of the tasks to be processed with lower priorities are upgraded, so that the tasks can be preferentially processed during processing, the low-priority tasks to be processed are prevented from being in a waiting state for processing for a long time, and the low-priority tasks are prevented from being blocked.
And if a plurality of tasks to be processed are not processed, and the upgrade waiting time of the tasks to be processed also reaches the maximum waiting time, the priorities of the tasks to be processed can be upgraded, so that the tasks to be processed which are still high in priority are guaranteed to be processed preferentially in a plurality of simultaneously created tasks to be processed or a plurality of tasks to be processed created at similar time, and the condition that the tasks to be processed with high priority wait for processing for a long time is avoided.
In an implementation manner of the embodiment of the present disclosure, the upgrade waiting time and the priority of the to-be-processed task may be recorded in the data format of the to-be-processed task, and then the upgrade waiting time and the priority of the to-be-processed task may be obtained by analyzing the data format of the to-be-processed task. In addition, the preset maximum waiting time may also be carried in a data format of the to-be-processed task, and the maximum waiting time set for different to-be-processed tasks may be the same or different, and is not specifically limited herein.
In an implementation manner of the embodiment of the present disclosure, a data format of the to-be-processed task may include a task identifier of the to-be-processed task, a maximum waiting time, an initial time corresponding to adding, and an upgrade time corresponding to last priority upgrade. Illustratively, the data format of a certain task to be processed is:
{
“jobID”:1,
5,// min "maxWaitTime
“submitTime”:20191220080020,
“updateTime”:20191220080500
}
The task identifier representing the task to be processed is 1; the maximum waiting time is 5 minutes, and if the priority of the to-be-processed task is always the current priority after 5 minutes are accumulated, the priority of the to-be-processed task is increased by one level; the initial time corresponding to the creation of the task to be processed is 08:00:20 in 12 months and 20 days in 2019, the upgrading time corresponding to the last time of upgrading the priority of the task to be processed is 08:05:00 in 12 months and 20 days in 2019, so that the upgrading waiting time can be determined by calculating the time period between the current time and the upgrading time of 08:05:00 in 12 months and 20 days in 2019, and if the upgrading waiting time reaches 5 minutes, the priority of the task to be processed is upgraded again.
Optionally, S101 may specifically be: and obtaining the upgrade waiting time and the priority of each task to be processed according to a preset period.
The embodiment of the disclosure can execute the priority refreshing operation at regular time, that is, the upgrade waiting time and the priority of each to-be-processed task are obtained every preset period, and whether the priority of some to-be-processed tasks needs to be upgraded is judged based on the obtained upgrade waiting time and the obtained priority of each to-be-processed task. The operation of performing priority refreshing and the operation of performing task processing may be performed asynchronously.
Optionally, before executing S103, the method provided in the embodiment of the present disclosure may further execute: acquiring priority adjustment information input by a user; and adjusting the priority of each task to be processed according to the priority adjustment information.
Before task processing, a user can manually adjust the priority of each task to be processed, the user can input priority adjustment information on an interactive interface, specifically, what the priority of the task to be processed is adjusted to is input, after the electronic equipment obtains the priority adjustment information, the priority of each task to be processed can be adjusted according to the priority adjustment information, and therefore when the task is processed, the tasks to be processed can be selected from high to low according to the adjusted priority.
Based on the embodiment shown in fig. 1, an embodiment of the present disclosure further provides a task processing method, as shown in fig. 2, which may include the following steps:
s201, obtaining the upgrade waiting time and the priority of each task to be processed, wherein the upgrade waiting time of each task to be processed is the accumulated time of each task to be processed at the current priority.
S202, aiming at any task to be processed, if the upgrading waiting time of the task to be processed reaches the preset maximum waiting time, upgrading the priority of the task to be processed.
S203, refreshing a pre-established task priority queue based on the upgraded to-be-processed tasks, wherein task identifiers of the to-be-processed tasks are stored in the task priority queue according to the priority order of the to-be-processed tasks.
And S204, when processing the tasks, processing each task to be processed according to the sequence of the priorities from high to low in the task priority queue, and deleting the task identifier of the task to be processed from the task priority queue after processing any task to be processed.
In an implementation manner of the embodiment of the present disclosure, a task priority queue may be pre-established, where task identifiers of tasks to be processed are stored in the queue according to the priority order of the tasks to be processed, that is, for each task to be processed, the task identifier of each task to be processed may be added to the task priority queue in advance based on the priority order of each task to be processed. The task identifier of each to-be-processed task in the task priority queue may be stored according to a sequence from high to low of the priority of each to-be-processed task, or may be stored according to a sequence from low to high of the priority of each to-be-processed task, which is not specifically limited herein. The task priority queue may only store the task identifier of each to-be-processed task, and may also store the current priority of each to-be-processed task, an initial time corresponding to the to-be-processed task when adding, an upgrade time corresponding to the last upgrade, and the like, which is not specifically limited herein.
After the priority of the task to be processed is upgraded based on the judgment result of whether the upgrade waiting time reaches the preset maximum waiting time, the task priority queue can be refreshed based on the upgraded task to be processed, that is, the sequence of the task identifier of the task to be processed in the task priority queue is adjusted.
Correspondingly, when processing the tasks, the tasks to be processed can be processed according to the sequence of the priorities from high to low in the task priority queue. If the task identifiers of the tasks to be processed in the task priority queue are stored according to the sequence of the priorities of the tasks to be processed from high to low, the tasks to be processed can be sequentially processed according to the sequence of the task priority queue from front to back; if the task identifiers of the tasks to be processed in the task priority queue are stored according to the sequence from low to high of the priority of the tasks to be processed, the tasks to be processed can be sequentially processed according to the sequence from back to front of the task priority queue.
After any task to be processed is processed, the task identifier of the task to be processed needs to be deleted from the task priority queue because the task is processed, and subsequently, if the task is to be processed, the task identifier of the task is reinserted into the task priority queue.
Optionally, the task identifiers in the task priority queue are arranged according to the size of the score attribute corresponding to each task identifier, and the score attribute corresponding to each task identifier represents the priority of each task to be processed.
Correspondingly, S202 may specifically be: for any task to be processed, if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, reducing the score attribute corresponding to the task identifier of the task to be processed, wherein the score attribute is inversely proportional to the priority; or, for any task to be processed, if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, increasing the score attribute corresponding to the task identifier of the task to be processed, wherein the score attribute is in direct proportion to the priority.
S203 may specifically be: and refreshing the task priority queue based on the changed score attribute.
Each task identifier in the task priority queue may be specifically arranged according to the size of the score attribute corresponding to each task identifier, and the score attribute corresponding to each task identifier represents the priority of each task to be processed. The priority of each task to be processed can be specifically represented by a score attribute, the score attribute is a numerical value for representing the priority, and the score attribute can be in direct proportion to the priority or in inverse proportion to the priority.
Correspondingly, under the condition that the score attribute is inversely proportional to the priority, the specific mode of upgrading the priority may be realized by reducing the score attribute corresponding to the task identifier of the task to be processed, for example, if the score attribute of one task to be processed is 3, the priority of the task to be processed may be upgraded by setting the score attribute of the task to be processed to be 2. Under the condition that the score attribute is proportional to the priority, the specific way of upgrading the priority may be implemented by increasing the score attribute corresponding to the task identifier of the task to be processed, for example, if the score attribute of one task to be processed is 3, the priority of the task to be processed may be upgraded by setting the score attribute of the task to be processed to 4. After the priority is upgraded, the task priority queue needs to be refreshed, specifically, the task priority queue 4 is refreshed based on the changed score attribute.
The task priority queue stores the task identifiers of the tasks to be processed, the storage sequence of the task identifiers in the task priority queue represents the priority of the tasks to be processed, the task identifiers in the task priority queue are adjusted through the score attributes (namely the score attributes corresponding to the task identifiers of the tasks to be processed with the current priority for a long time are reduced or increased), the task identifiers in the task priority queue can be sorted and adjusted, and when the tasks are processed, the tasks can be directly selected and processed based on the task priority queue.
Optionally, the task priority queue is a queue adopting a zset (ordered set) structure of a Remote data service (Remote directory Server).
In an implementation manner of the embodiment of the present disclosure, a queue manner of a zset structure of Redis may be selected to store task identifiers of tasks to be processed, Redis is a database based on Key-Value, and the Redis database is a database in an internal memory, and compared with a conventional database, the reading speed is faster, the zset structure is based on score (fractional attribute) of elements to arrange the elements, and score of the element arranged at a position closer to the front is lower. Based on the characteristics of Redis and zset, a zset structure queue of Redis is used as a task priority queue to store task identifiers of various tasks to be processed, which can indicate the priority of the tasks to be processed, and the task to be processed which is closer to the task identifier has higher priority.
Since the score of the element arranged at the front position in the task priority queue based on the zset structure of Redis lower, the specific way of upgrading the priority can be realized by reducing the score corresponding to the task identifier of the task to be processed.
The task priority queue adopting the zset structure of Redis stores the task identifiers of the tasks to be processed, the storage sequence of the task identifiers in the task priority queue represents the priority of the tasks to be processed, the order adjustment of the task identifiers in the task priority queue can be realized by adjusting the score attribute of the zset (namely reducing the score attribute corresponding to the task identifier of the task to be processed with the priority not upgraded for a long time), the task can be directly selected and processed based on the task priority queue during task processing, and the Redis has high reading speed, so that the real-time performance of the method execution is ensured, and the low-priority task blockage is effectively avoided.
Corresponding to the foregoing method embodiment, an embodiment of the present disclosure provides a task processing apparatus, and as shown in fig. 3, the apparatus may include:
an obtaining module 310, configured to obtain an upgrade waiting time and a priority of each to-be-processed task, where the upgrade waiting time of each to-be-processed task is an accumulated time of each to-be-processed task at the current priority;
the upgrading module 320 is configured to, for any task to be processed, upgrade the priority of the task to be processed if the upgrade waiting time of the task to be processed reaches a preset maximum waiting time;
and the processing module 330 is configured to process each task to be processed according to the order of priority from high to low when processing the task.
Optionally, the obtaining module 310 may be specifically configured to, for any one to-be-processed task that has not been upgraded yet, obtain an initial time corresponding to when the to-be-processed task is created, and calculate a time period between the current time and the initial time of the to-be-processed task to obtain an upgrade waiting time of the to-be-processed task.
Optionally, the obtaining module 310 may be specifically configured to, for any upgraded to-be-processed task, obtain an upgrade time corresponding to the last time of upgrading the to-be-processed task, and calculate a time period between the current time and the upgrade time of the to-be-processed task, to obtain an upgrade waiting time of the to-be-processed task.
Optionally, the obtaining module 310 may be specifically configured to obtain the upgrade waiting time and the priority of each to-be-processed task according to a preset period.
Optionally, the apparatus may further include:
the refreshing module is used for refreshing a pre-established task priority queue based on the upgraded tasks to be processed, wherein task identifiers of the tasks to be processed are stored in the task priority queue according to the priority order of the tasks to be processed;
the processing module 330 may be specifically configured to, when processing a task, process each to-be-processed task according to a sequence from high to low priority in the task priority queue, and delete a task identifier of the to-be-processed task from the task priority queue after any to-be-processed task is processed.
Optionally, the task identifiers in the task priority queue are arranged according to the size of the score attribute corresponding to each task identifier, and the score attribute corresponding to each task identifier represents the priority of each task to be processed;
the upgrading module 320 may be specifically configured to, for any task to be processed, reduce a score attribute corresponding to a task identifier of the task to be processed if the upgrade waiting time of the task to be processed reaches a preset maximum waiting time, where the score attribute is inversely proportional to the priority; or, for any task to be processed, if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, increasing the score attribute corresponding to the task identifier of the task to be processed, wherein the score attribute is in direct proportion to the priority;
the refreshing module may be specifically configured to refresh the task priority queue based on the changed score attribute.
Optionally, the task priority queue is a queue adopting an ordered set zset structure of the remote data service Redis.
Optionally, the obtaining module 310 may be further configured to obtain priority adjustment information input by the user;
the apparatus may further include:
and the adjusting module is used for adjusting the priority of each task to be processed according to the priority adjusting information.
By applying the embodiment of the disclosure, the upgrading waiting time and the priority of each task to be processed are obtained, and for any task to be processed, if the upgrading waiting time of the task to be processed reaches the preset maximum waiting time, the priority of the task to be processed is upgraded, and when the task is processed, each task to be processed is processed according to the sequence of the priorities from high to low. If one task to be processed is in the current priority for a long time, which indicates that the task to be processed is not processed for a long time, the priority of the task to be processed which is lower in priority originally and is not processed for a long time can be increased by actively upgrading the priority of the task to be processed, so that the task to be processed with low priority is prevented from being in a waiting state for a long time, and the task to be processed with low priority is prevented from being blocked.
The embodiment of the present disclosure provides an electronic device, as shown in fig. 4, including a processor 401, a communication interface 402, a memory 403, and a communication bus 404, where the processor 401, the communication interface 402, and the memory 403 complete mutual communication through the communication bus 404;
a memory 403 for storing a computer program;
the processor 401 is configured to implement the task processing method according to any one of the above embodiments when executing the computer program stored in the memory 403.
It can be seen that, in the scheme provided in the embodiment of the present disclosure, the electronic device may obtain the upgrade waiting time and the priority of each to-be-processed task, and for any to-be-processed task, if the upgrade waiting time of the to-be-processed task reaches the preset maximum waiting time, upgrade the priority of the to-be-processed task, and process each to-be-processed task according to the order of the priorities from high to low when processing the tasks. If one task to be processed is in the current priority for a long time, which indicates that the task to be processed is not processed for a long time, the priority of the task to be processed which is lower in priority originally and is not processed for a long time can be increased by actively upgrading the priority of the task to be processed, so that the task to be processed with low priority is prevented from being in a waiting state for a long time, and the task to be processed with low priority is prevented from being blocked.
The communication bus mentioned in the electronic device may be a PCI (Peripheral component interconnect) bus, an EISA (Extended Industry standard architecture) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a RAM (Random Access Memory) or an NVM (Non-Volatile Memory), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor including a CPU (Central Processing Unit), an NP (Network Processor), and the like; but also a DSP (Digital Signal Processing), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other Programmable logic device, discrete Gate or transistor logic device, discrete hardware component.
The embodiments of the present disclosure also provide a machine-readable storage medium, where when a computer program in the machine-readable storage medium is executed by a processor of an electronic device, the electronic device is enabled to execute the task processing method described in any of the above embodiments.
It can be seen that, in the solution provided in the embodiment of the present disclosure, when the computer program is executed by the processor, the upgrade waiting time and the priority of each to-be-processed task may be obtained, and for any to-be-processed task, if the upgrade waiting time of the to-be-processed task reaches the preset maximum waiting time, the priority of the to-be-processed task is upgraded, and when processing the tasks, the to-be-processed tasks are processed according to the order of the priorities from high to low. If one task to be processed is in the current priority for a long time, which indicates that the task to be processed is not processed for a long time, the priority of the task to be processed which is lower in priority originally and is not processed for a long time can be increased by actively upgrading the priority of the task to be processed, so that the task to be processed with low priority is prevented from being in a waiting state for a long time, and the task to be processed with low priority is prevented from being blocked.
For the above device, electronic device and machine-readable storage medium embodiments, since they are substantially similar to the method embodiments, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiments.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus, the electronic device, and the machine-readable storage medium embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and in relation to the description, reference may be made to some portions of the method embodiments.
The above description is only for the preferred embodiment of the present disclosure, and is not intended to limit the scope of the present disclosure. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present disclosure are included in the scope of protection of the present disclosure.

Claims (18)

1. A method for processing a task, the method comprising:
acquiring the upgrading waiting time and the priority of each task to be processed, wherein the upgrading waiting time of each task to be processed is the accumulated time of each task to be processed at the current priority;
for any task to be processed, if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, upgrading the priority of the task to be processed;
and when the tasks are processed, processing the tasks to be processed according to the sequence of the priority from high to low.
2. The method according to claim 1, wherein the obtaining of the upgrade waiting time of each task to be processed comprises:
aiming at any one to-be-processed task which is not upgraded, acquiring the corresponding initial time when the to-be-processed task is created, and calculating the time period between the current time and the initial time of the to-be-processed task to obtain the upgrade waiting time of the to-be-processed task.
3. The method according to claim 1, wherein the obtaining of the upgrade waiting time of each task to be processed comprises:
and aiming at any upgraded task to be processed, acquiring the corresponding upgrading time when the task to be processed is upgraded last time, and calculating the time period between the current time and the upgrading time of the task to be processed to obtain the upgrading waiting time of the task to be processed.
4. The method according to any one of claims 1 to 3, wherein the obtaining of the upgrade waiting time and the priority of each task to be processed comprises:
and obtaining the upgrade waiting time and the priority of each task to be processed according to a preset period.
5. The method according to claim 1, wherein after the upgrading the priority of the task to be processed if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time for any task to be processed, the method further comprises:
refreshing a pre-established task priority queue based on the upgraded tasks to be processed, wherein task identifiers of the tasks to be processed are stored in the task priority queue according to the priority order of the tasks to be processed;
when processing the tasks, processing the tasks to be processed according to the sequence of the priority from high to low, comprising:
and when processing the tasks, processing the tasks to be processed according to the sequence of the priorities from high to low in the task priority queue, and deleting the task identifier of the task to be processed from the task priority queue after processing any task to be processed.
6. The method according to claim 5, wherein task identifiers in the task priority queue are arranged according to the size of a score attribute corresponding to each task identifier, and the score attribute corresponding to each task identifier represents the priority of each task to be processed;
for any task to be processed, if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, upgrading the priority of the task to be processed, including:
for any task to be processed, if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, reducing the score attribute corresponding to the task identifier of the task to be processed, wherein the score attribute is inversely proportional to the priority; alternatively, the first and second electrodes may be,
for any task to be processed, if the upgrade waiting time of the task to be processed reaches the preset maximum waiting time, increasing the score attribute corresponding to the task identifier of the task to be processed, wherein the score attribute is in direct proportion to the priority;
the refreshing of the pre-established task priority queue based on the upgraded to-be-processed task comprises the following steps:
refreshing the task priority queue based on the changed score attributes.
7. The method of claim 6, wherein the task priority queue is a queue that employs an ordered set zset structure of remote data services (Redis).
8. The method according to claim 1, wherein before processing the tasks to be processed in the order of priority from high to low while processing the tasks, the method further comprises:
acquiring priority adjustment information input by a user;
and adjusting the priority of each task to be processed according to the priority adjustment information.
9. A task processing apparatus, characterized in that the apparatus comprises:
the system comprises an acquisition module, a processing module and a processing module, wherein the acquisition module is used for acquiring the upgrading waiting time and the priority of each task to be processed, and the upgrading waiting time of each task to be processed is the accumulated time of each task to be processed at the current priority;
the upgrading module is used for upgrading the priority of any task to be processed if the upgrading waiting time of the task to be processed reaches the preset maximum waiting time;
and the processing module is used for processing the tasks to be processed according to the sequence of the priority from high to low when the tasks are processed.
10. The apparatus according to claim 9, wherein the obtaining module is specifically configured to, for any one to-be-processed task that has not been upgraded, obtain an initial time corresponding to when the to-be-processed task is created, and calculate a time period between a current time and the initial time of the to-be-processed task to obtain an upgrade waiting time of the to-be-processed task.
11. The apparatus according to claim 9, wherein the obtaining module is specifically configured to, for any upgraded to-be-processed task, obtain an upgrade time corresponding to a last time of upgrading the to-be-processed task, and calculate a time period between a current time and the upgrade time of the to-be-processed task to obtain an upgrade waiting time of the to-be-processed task.
12. The apparatus according to any one of claims 9 to 11, wherein the obtaining module is specifically configured to obtain the upgrade waiting duration and the priority of each to-be-processed task according to a preset period.
13. The apparatus of claim 9, further comprising:
the refreshing module is used for refreshing a pre-established task priority queue based on the upgraded tasks to be processed, wherein task identifiers of the tasks to be processed are stored in the task priority queue according to the priority order of the tasks to be processed;
the processing module is specifically configured to, when processing tasks, process the tasks to be processed according to the sequence from high to low in priority in the task priority queue, and delete the task identifier of the task to be processed from the task priority queue after processing any task to be processed.
14. The apparatus according to claim 13, wherein the task identifiers in the task priority queue are arranged according to the size of the score attribute corresponding to each task identifier, and the score attribute corresponding to each task identifier represents the priority of each task to be processed;
the upgrading module is specifically configured to, for any task to be processed, reduce a score attribute corresponding to a task identifier of the task to be processed if the upgrade waiting time of the task to be processed reaches a preset maximum waiting time, where the score attribute is inversely proportional to the priority; or, for any task to be processed, if the upgrade waiting time of the task to be processed reaches a preset maximum waiting time, increasing the score attribute corresponding to the task identifier of the task to be processed, wherein the score attribute is in direct proportion to the priority;
the refreshing module is specifically configured to refresh the task priority queue based on the changed score attribute.
15. The apparatus of claim 14, wherein the task priority queue is a queue that employs an ordered set zset structure of remote data services (Redis).
16. The apparatus according to claim 9, wherein the obtaining module is further configured to obtain priority adjustment information input by a user;
the device further comprises:
and the adjusting module is used for adjusting the priority of each task to be processed according to the priority adjusting information.
17. An electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete communication with each other through the communication bus;
the memory is used for storing a computer program;
the processor, when executing the computer program stored on the memory, implementing the method of any of claims 1-8.
18. A machine readable storage medium, wherein a computer program in the machine readable storage medium, when executed by a processor of an electronic device, enables the electronic device to perform the method of any of claims 1-8.
CN202010321248.3A 2020-04-22 2020-04-22 Task processing method and device, electronic equipment and machine-readable storage medium Pending CN111552548A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010321248.3A CN111552548A (en) 2020-04-22 2020-04-22 Task processing method and device, electronic equipment and machine-readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010321248.3A CN111552548A (en) 2020-04-22 2020-04-22 Task processing method and device, electronic equipment and machine-readable storage medium

Publications (1)

Publication Number Publication Date
CN111552548A true CN111552548A (en) 2020-08-18

Family

ID=72005839

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010321248.3A Pending CN111552548A (en) 2020-04-22 2020-04-22 Task processing method and device, electronic equipment and machine-readable storage medium

Country Status (1)

Country Link
CN (1) CN111552548A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112040001A (en) * 2020-09-07 2020-12-04 平安科技(深圳)有限公司 Request processing method and device based on distributed storage
CN116737330A (en) * 2022-09-02 2023-09-12 荣耀终端有限公司 Task processing method and electronic equipment

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103324525A (en) * 2013-07-03 2013-09-25 东南大学 Task scheduling method in cloud computing environment
CN105824698A (en) * 2016-03-31 2016-08-03 乐视控股(北京)有限公司 Task priority correcting method and device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103324525A (en) * 2013-07-03 2013-09-25 东南大学 Task scheduling method in cloud computing environment
CN105824698A (en) * 2016-03-31 2016-08-03 乐视控股(北京)有限公司 Task priority correcting method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
DAVID A.RUSLING 等著,朱珂 等译: "《ARM9嵌入式系统设计基础教程(第2版)》", 北京:北京航空航天大学出版社, pages: 108 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112040001A (en) * 2020-09-07 2020-12-04 平安科技(深圳)有限公司 Request processing method and device based on distributed storage
CN116737330A (en) * 2022-09-02 2023-09-12 荣耀终端有限公司 Task processing method and electronic equipment
CN116737330B (en) * 2022-09-02 2024-05-07 荣耀终端有限公司 Task processing method and electronic equipment

Similar Documents

Publication Publication Date Title
CN108063818B (en) Data downloading method, device, terminal and computer readable storage medium
US20150012513A1 (en) Providing a query results page
CN111552548A (en) Task processing method and device, electronic equipment and machine-readable storage medium
CN112100204A (en) Virtual resource regulation and control method and device, computer equipment and storage medium
CN110020383B (en) Page data request processing method and device
CN111159160B (en) Version rollback method and device, electronic equipment and storage medium
CN115827162A (en) Method, device, medium and equipment for intelligently processing mirror image warehouse data
US20220035666A1 (en) Method and apparatus for data processing, server and storage medium
CN111638892A (en) Method, device, system and storage medium for optimizing application update sequencing
CN114553786B (en) Network request fusing method and device, computer equipment and storage medium
CN111294377A (en) Network request sending method of dependency relationship, terminal device and storage medium
CN113988559B (en) Disturbance-free method and device for questionnaire delivery
CN111258676B (en) Module preloading method, device, equipment and readable storage medium
CN115278786A (en) Service access method, device, electronic equipment and storage medium
US11288140B2 (en) Point in time blob restore
CN113282601A (en) Data updating method and device and electronic equipment
CN110888690A (en) Application starting method and device, electronic equipment and storage medium
CN110889066A (en) Method and device for opening webpage in client software and electronic equipment
CN112861041B (en) Media content display method and device, electronic equipment and storage medium
CN113849133B (en) Processing method and device of privacy data, electronic equipment and storage medium
CN113128897B (en) Crowd-sourced task resource configuration method and device, electronic equipment and storage medium
CN113382310B (en) Information recommendation method and device, electronic equipment and medium
CN111782323B (en) Bullet screen obtaining method, computing equipment and computer storage medium
CN110187957B (en) Queuing method and device for downloading tasks and electronic equipment
CN114186845A (en) Method and device for executing index calculation task at fixed time

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