CN114416320A - Task processing method, device, equipment and storage medium - Google Patents

Task processing method, device, equipment and storage medium Download PDF

Info

Publication number
CN114416320A
CN114416320A CN202210066796.5A CN202210066796A CN114416320A CN 114416320 A CN114416320 A CN 114416320A CN 202210066796 A CN202210066796 A CN 202210066796A CN 114416320 A CN114416320 A CN 114416320A
Authority
CN
China
Prior art keywords
task
target
processed
processing
target thread
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
CN202210066796.5A
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 ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance 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 ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN202210066796.5A priority Critical patent/CN114416320A/en
Publication of CN114416320A publication Critical patent/CN114416320A/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)
  • Debugging And Monitoring (AREA)

Abstract

The disclosure provides a task processing method, a device, equipment and a storage medium, wherein at least one task to be processed is determined by a target thread, and the task to be processed is a non-immediate processing task; predicting the idle time of the target thread under the condition that the target thread is in an idle state; under the condition that the idle time is greater than or equal to a preset specified time, determining a target task from at least one task to be processed according to the task processing time of each task to be processed and the preset specified time; and loading the target task into the target thread for processing. Therefore, the time for putting the task into the thread and the execution time are controlled by processing the non-immediate processing task by using the idle time of the target thread, the task buffer amount of the target thread can be reduced, the pressure of the target thread is relieved, and the probability of no response and blockage of the application is reduced.

Description

Task processing method, device, equipment and storage medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a storage medium for processing a task.
Background
With the continuous development of science and technology, intelligent terminals have gradually entered the lives of people, and occupy more and more important components in the lives of people, while in the intelligent terminals, the systems of the intelligent terminals play an important role, mainly including computer programs for managing hardware and software resources of the terminals, and an operating system needs to process basic matters such as managing and configuring memory, determining the priority of supply and demand of system resources, controlling input devices and output devices, operating a network and managing a file system.
For task scheduling in the system, taking the android system as an example, in a task scheduling process and a message delivery mechanism of the android system, if a certain task needs to be processed, a message pump looper of a corresponding thread can be taken, the task is encapsulated into a message and is put into the thread for execution, and under the condition that the task cannot be processed in time or the computational power of equipment is limited, the more the tasks needing to be processed in the thread are accumulated, the more the number of the tasks is uncontrolled, especially in the main thread, if the number of the tasks is accumulated more, the task cannot be responded in time, so that the application is determined to be unresponsive by an ANR detection mechanism, and the phenomenon that a terminal or an application is stuck or crashed occurs.
Disclosure of Invention
The embodiment of the disclosure at least provides a task processing method, a task processing device and a storage medium.
The embodiment of the disclosure provides a task processing method, which comprises the following steps:
determining at least one task to be processed by a target thread, wherein the task to be processed is a non-instantaneity processing task;
predicting the idle time of the target thread under the condition that the target thread is in an idle state;
under the condition that the idle time is greater than or equal to a preset specified time, determining a target task from at least one task to be processed according to the task processing time of each task to be processed and the preset specified time;
and loading the target task into the target thread for processing.
In an optional embodiment, the predicting the idle duration of the target thread in the case that the target thread is in an idle state includes:
acquiring a trained duration prediction model;
and under the condition that the target thread is in an idle state, predicting the idle time of the target thread through the time length prediction model based on the task processing characteristic information of the target thread.
In an alternative embodiment, the duration prediction model is trained by:
acquiring a plurality of sample idle time lengths of the target thread in the idle state and sample characteristic information aiming at each sample idle time length, wherein the sample idle time lengths comprise a positive sample and a negative sample, the time length of the positive sample is greater than the preset specified time length, and the time length of the negative sample is less than the preset specified time length;
and training the constructed duration prediction model by using the plurality of sample idle durations and the sample characteristic information of each sample idle duration.
In an optional implementation manner, the determining a target task from the at least one to-be-processed task according to the task processing time length of each to-be-processed task and the preset specified time length includes:
determining a first candidate task with the task processing duration less than or equal to the preset specified duration from the at least one task to be processed based on the task processing duration of each task to be processed;
and taking the first candidate task as a target task.
In an optional embodiment, after the predicting the idle duration of the target thread, the method includes:
if the idle time length is less than a preset specified time length, determining a preset time length classification range in which the idle time length is located;
determining a second candidate task with the task processing duration in the preset duration classification range from the at least one task to be processed based on the task processing duration of each task to be processed;
and taking the second candidate task as a target task.
In an optional embodiment, in a case where the first candidate task or the second candidate task includes a plurality of candidate tasks, taking the first candidate task as a target task or taking the second candidate task as a target task includes
Determining the latest processing time of each candidate task;
determining a candidate task with the minimum time difference between the latest processing time and the current time from the plurality of candidate tasks as the target candidate task;
and taking the target candidate task as a target task.
In an optional embodiment, after the determining at least one to-be-processed task to be processed by the target thread, the method includes:
taking the at least one task to be processed out of the thread task queue of the target thread;
adding the at least one taken out task to be processed into a custom task queue aiming at the target thread;
the loading the target task into the target thread for processing comprises:
and taking out the determined target task from the custom task queue, and loading the taken out target task into the target thread for processing.
In an optional implementation manner, before predicting the idle duration of the target thread when the target thread is in an idle state, the method includes:
detecting whether a task to be processed exists in the user-defined task queue;
and if the to-be-processed task exists in the custom task queue, executing a step of predicting the idle time of the target thread under the condition that the target thread is in an idle state.
In an optional implementation manner, the loading the target task into the target thread for processing includes:
and encapsulating the target task into a target message, and loading the target message into the target thread for processing.
In an optional embodiment, after the determining at least one to-be-processed task to be processed by the target thread, the method includes:
detecting whether a task to be processed reaching the latest processing time exists in the at least one task to be processed according to the latest processing time of each task to be processed;
and if so, determining the task to be processed reaching the latest processing time as the target task.
And if not, executing the step of predicting the idle time of the target thread under the condition that the target thread is in the idle state.
An embodiment of the present disclosure further provides a task processing device, where the task processing device includes:
the task determining module is used for determining at least one task to be processed by a target thread, wherein the task to be processed is a non-immediate processing task;
the time length prediction module is used for predicting the idle time length of the target thread under the condition that the target thread is in an idle state;
the target task determining module is used for determining a target task from at least one task to be processed according to the task processing time length of each task to be processed and a preset specified time length under the condition that the idle time length is greater than or equal to the preset specified time length;
and the task loading module is used for loading the target task into the target thread for processing.
In an optional implementation manner, the duration prediction module is specifically configured to:
acquiring a trained duration prediction model;
and under the condition that the target thread is in an idle state, predicting the idle time of the target thread through the time length prediction model based on the task processing characteristic information of the target thread.
In an alternative embodiment, the duration prediction module is configured to train the duration prediction model by:
acquiring a plurality of sample idle time lengths of the target thread in the idle state and sample characteristic information aiming at each sample idle time length, wherein the sample idle time lengths comprise a positive sample and a negative sample, the time length of the positive sample is greater than the preset specified time length, and the time length of the negative sample is less than the preset specified time length;
and training the constructed duration prediction model by using the plurality of sample idle durations and the sample characteristic information of each sample idle duration.
In an optional implementation manner, the target task determination module is specifically configured to:
determining a first candidate task with the task processing duration less than or equal to the preset specified duration from the at least one task to be processed based on the task processing duration of each task to be processed;
and taking the first candidate task as a target task.
In an optional embodiment, the target task determination module is further configured to:
if the idle time length is less than a preset specified time length, determining a preset time length classification range in which the idle time length is located;
determining a second candidate task with the task processing duration in the preset duration classification range from the at least one task to be processed based on the task processing duration of each task to be processed;
and taking the second candidate task as a target task.
In an optional implementation manner, when the first candidate task or the second candidate task includes a plurality of candidate tasks, the target task determining module is specifically configured to:
determining the latest processing time of each candidate task;
determining a candidate task with the minimum time difference between the latest processing time and the current time from the plurality of candidate tasks as the target candidate task;
and taking the target candidate task as a target task.
In an optional implementation manner, the task processing device further includes a task adding module, and the task adding module is configured to:
taking the at least one task to be processed out of the thread task queue of the target thread;
adding the at least one taken out task to be processed into a custom task queue aiming at the target thread;
the task loading module is specifically configured to:
and taking out the determined target task from the custom task queue, and loading the taken out target task into the target thread for processing.
In an optional implementation manner, the task processing device further includes a task detection module, and the task detection module is configured to:
detecting whether a task to be processed exists in the user-defined task queue;
and if the to-be-processed task exists in the custom task queue, executing a step of predicting the idle time of the target thread under the condition that the target thread is in an idle state.
In an optional implementation manner, the task loading module is specifically configured to:
and encapsulating the target task into a target message, and loading the target message into the target thread for processing.
In an optional embodiment, the target task determination module is further configured to:
detecting whether a task to be processed reaching the latest processing time exists in the at least one task to be processed according to the latest processing time of each task to be processed;
and if so, determining the task to be processed reaching the latest processing time as the target task.
And if not, executing the step of predicting the idle time of the target thread under the condition that the target thread is in the idle state.
An embodiment of the present disclosure further provides an electronic device, including: the system comprises a processor, a memory and a bus, wherein the memory stores machine readable instructions executable by the processor, the processor and the memory are communicated through the bus when the electronic device runs, and the machine readable instructions are executed by the processor to execute the steps of the task processing method.
The disclosed embodiments also provide a computer storage medium having a computer program stored thereon, where the computer program is executed by a processor to perform the steps of the above task processing method.
According to the task processing method, the task processing device, the task processing equipment and the storage medium, at least one task to be processed is determined to be processed by a target thread, and the task to be processed is a non-immediate processing task; predicting the idle time of the target thread under the condition that the target thread is in an idle state; under the condition that the idle time is greater than or equal to a preset specified time, determining a target task from at least one task to be processed according to the task processing time of each task to be processed and the preset specified time; and loading the target task into the target thread for processing.
Therefore, the time for putting the task into the thread and the execution time are controlled by processing the non-immediate processing task by using the idle time of the target thread, the task buffer amount of the target thread can be reduced, the pressure of the target thread is relieved, and the probability of no response and blockage of the application is reduced.
Furthermore, by combining the latest processing time of the target task which can be processed and is preset for each task to be processed, the situation that the task is not executed for a long time can be effectively avoided, the probability of task omission is reduced, and the task can be smoothly executed.
In order to make the aforementioned objects, features and advantages of the present disclosure more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings required for use in the embodiments will be briefly described below, and the drawings herein incorporated in and forming a part of the specification illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the technical solutions of the present disclosure. It is appreciated that the following drawings depict only certain embodiments of the disclosure and are therefore not to be considered limiting of its scope, for those skilled in the art will be able to derive additional related drawings therefrom without the benefit of the inventive faculty.
Fig. 1 is a flowchart of a task processing method provided in an embodiment of the present disclosure;
FIG. 2 is a flow chart of another task processing method provided by the embodiments of the present disclosure;
FIG. 3 is a schematic diagram of task phases in an embodiment of the disclosure;
fig. 4 is a schematic diagram of a task processing device according to an embodiment of the disclosure;
fig. 5 is a second schematic diagram of a task processing device according to an embodiment of the disclosure;
fig. 6 is a schematic view of an electronic device according to an embodiment of the disclosure.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described clearly and completely 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, not all of the embodiments. The components of the embodiments of the present disclosure, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present disclosure, presented in the figures, is not intended to limit the scope of the claimed disclosure, but is merely representative of selected embodiments of the disclosure. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the disclosure without making creative efforts, shall fall within the protection scope of the disclosure.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The term "and/or" herein merely describes an associative relationship, meaning that three relationships may exist, e.g., a and/or B, may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the term "at least one" herein means any one of a plurality or any combination of at least two of a plurality, for example, including at least one of A, B, C, and may mean including any one or more elements selected from the group consisting of A, B and C.
According to research, in an electronic device, taking a device of an android system as an example, in terms of task processing, a system of the electronic device mostly takes a message pump looper of a corresponding thread, packages the task into a message and places the message into the thread for execution, and under the condition that the task cannot be processed in time or the computational power of the device is limited, the more the tasks needing to be processed in the thread are accumulated, the number is not controlled, especially in a main thread, if the number of the tasks is more overstocked, the task cannot be responded in time, and therefore the application is determined to be unresponsive by an application unresponsive ANR detection mechanism, so that the terminal or the application and the like are stuck or down and the like.
Based on the above research, the present disclosure provides a task processing method, which can process a non-immediate processing task by using an idle duration of a thread, and can further control a time and an execution time when the task is put into the thread by combining a latest processing time of a target task that can be processed and is preset for each task to be processed, so that not only can a processing pressure of the thread task be effectively relieved, but also a frequency and a frequency of no response and no pause of an application can be greatly reduced under a condition that the task is not executed, thereby preventing the task from being executed for a long time, and ensuring smooth execution of the task.
To facilitate understanding of the present embodiment, first, a task processing method disclosed in the embodiments of the present disclosure is described in detail, where an execution subject of the task processing method provided in the embodiments of the present disclosure is generally a computer device with certain computing capability, and the computer device includes, for example: a terminal device, which may be a User Equipment (UE), a mobile device, a User terminal, a cellular phone, a cordless phone, a Personal Digital Assistant (PDA), a handheld device, a computing device, a vehicle mounted device, a wearable device, or a server or other processing device. In some possible implementations, the task processing method may be implemented by a processor calling computer readable instructions stored in a memory.
Referring to fig. 1, fig. 1 is a flowchart of a task processing method according to an embodiment of the disclosure. As shown in fig. 1, a task processing method provided by the embodiment of the present disclosure includes:
s101: determining at least one task to be processed by a target thread, wherein the task to be processed is a non-instantaneity processing task.
In this step, in order to relieve the pressure of the target thread, a plurality of tasks that need to be processed by the target thread may be traversed, for example, each task in a thread task queue of the target thread is traversed, so as to screen out at least one non-immediate task that needs to be processed.
The target thread may be a main thread of the terminal or a sub-thread of the terminal.
S102: and under the condition that the target thread is in an idle state, predicting the idle time of the target thread.
In this step, during the running process of the target thread, the target thread may be monitored in real time to monitor a real-time running state of the target thread, and if the target thread is found to be in an idle state, an idle duration of the target thread in the idle state at this time may be predicted.
The idle state may refer to a state where all the timeliness tasks in the thread task queue of the target thread are processed and no timeliness task needs to be processed, or a state where a time gap without processing a task exists between two adjacent timeliness tasks in the thread task queue when the target thread executes the two tasks.
For predicting the idle time of the target thread, the idle time of the target thread may be predicted by a neural network obtained in a deep learning manner, for example, when the task processed in the target thread is added to the queue out of order and randomly, the prediction is particularly suitable for the prediction by the neural network, or the prediction may be set according to the processing condition, the queuing condition, and the like of the task in the target thread, for example, when the target thread is periodically added to the queue and needs to periodically process the task in the queue, at this time, when the task is periodically processed, a middle processing gap may be inferred according to the processing progress, the processing time, and the like of the two tasks before and after the task is taken as the idle time, and then the non-immediate task may be processed.
Specifically, in an optional implementation manner, for predicting the idle time of the target thread in a neural network manner, a trained time prediction model may be obtained first, and then the idle time of the target thread is predicted by the time prediction model based on the task processing feature information of the target thread when the target thread is in an idle state.
Here, the duration prediction model is obtained by training the neural network in the deep learning manner.
The task processing characteristic information comprises one or more of the following characteristic information related to task scheduling:
the work information of the target thread; processing information of the latest task in the target thread; and calling information of the target thread.
The work information of the target thread may include a work scene where the terminal is currently located, a current application scene of the target thread, a starting type of the target thread, a task processing mode of the target thread, and the like.
The processing information of the latest task in the target thread may include processing time of the latest task in a task queue of the target thread processed before being in an idle state, time of activity of a last thread in the target thread being in an invisible state, and information such as time of a latest moving image disappearance of the target thread, time of a latest animation disappearance of the target thread, time of a latest sliding stop of the target thread, and a latest sliding length of the target thread in a thread work display interface of a terminal.
The calling information of the target thread may include information such as a time when the target thread has last interacted with the user, a time when the target thread has last been applied to a foreground, and a time when the target thread has last stopped drawing.
In an optional embodiment, the duration prediction model may be trained by the following steps:
acquiring a plurality of sample idle time lengths of the target thread in the idle state and sample characteristic information aiming at each sample idle time length, wherein the sample idle time lengths comprise a positive sample and a negative sample, the time length of the positive sample is greater than the preset specified time length, and the time length of the negative sample is less than the preset specified time length;
and training the constructed duration prediction model by using the plurality of sample idle durations and the sample characteristic information of each sample idle duration.
The idle time of the target thread after processing the task can be sampled, so that the sample idle time of the target thread in the idle state and the sample characteristic information of each sample idle time, that is, the sample task characteristic information, can be obtained, the collected multiple sample idle times can be classified through the preset specified time, a positive sample and a negative sample are divided, and then the multiple sample idle times and the sample characteristic information of each sample idle time are input into a constructed neural network as input data for training, so as to obtain the trained time prediction model.
The duration prediction model may be a binary classification model, for example, the idle duration obtained by predicting the target thread has only two classifications, if so, is greater than a certain threshold. Correspondingly, the sample idle time period may include a positive sample and a negative sample, the time period of the positive sample is greater than or equal to the preset specified time period, and the time period of the negative sample is less than the preset specified time period.
In addition, the duration prediction model may be a multi-classification model, for example, the idle duration predicted for the target thread may be obtained to which duration interval is pre-divided, and accordingly, the sample idle duration may include samples located in each pre-divided duration interval.
The constructed neural network may be, for example, a Gradient Boosting decision tree (XGBoost) network.
S103: and under the condition that the idle time is greater than or equal to a preset specified time, determining a target task from the at least one task to be processed according to the task processing time of each task to be processed and the preset specified time.
In this step, if the predicted idle time of the target thread is longer than a preset specified time, the target thread may be considered to have sufficient time to process each task, so that the at least one task to be processed may be screened according to the task processing time of each task to be processed with reference to the preset specified time, and a target task that may be added to the target thread for processing is selected.
The preset specified duration may be a preset fixed time interval, or a time interval dynamically configured according to the condition of each task to be processed.
S104: and loading the target task into the target thread for processing.
In this step, after the target task is determined, the target task may be loaded into the target thread, so that the target task is processed by the target thread.
Specifically, the loading of the target task into the target thread may be to encapsulate the target task into a target message, and then load the target message into the target thread for processing.
The target message may include a task ID of the target task, a task processing object, data of task processing, and the like.
The task processing method provided by the embodiment of the disclosure includes determining at least one to-be-processed task to be processed by a to-be-processed target thread, wherein the to-be-processed task is a non-immediate processing task, predicting idle time of the target thread when the target thread is in an idle state, determining a target task from the at least one to-be-processed task according to task processing time of each to-be-processed task and preset specified time when the idle time is greater than or equal to the preset specified time, and loading the target task into the target thread for processing.
Therefore, the task of non-immediate processing can be processed by using the idle time of the thread, the processing pressure of the thread task can be effectively relieved, the times and frequency of no response and application blocking of the application can be greatly reduced under the condition that the task is not executed, the task is prevented from being executed for a long time, and the task is ensured to be executed smoothly.
Referring to fig. 2, fig. 2 is a flowchart of another task processing method according to an embodiment of the disclosure. As shown in fig. 2, a task processing method provided by the embodiment of the present disclosure includes:
s201: determining at least one task to be processed by a target thread, wherein the task to be processed is a non-instantaneity processing task.
S202: and detecting whether the task to be processed reaching the latest processing time exists in the at least one task to be processed according to the latest processing time of each task to be processed.
In this step, after determining the at least one to-be-processed task, each to-be-processed task may be traversed, the latest processing time of each to-be-processed task is determined, and then whether a to-be-processed task reaching the latest processing time exists is detected, so as to detect whether a non-immediate task urgently needing to be processed exists.
The latest processing time may be time configured for each to-be-processed task when the to-be-processed task is received, or may be the latest time allowed to be delayed for the predicted task, according to factors such as task information of the to-be-processed task, resource occupation information, application information to which the task belongs, and the like, and also according to actual conditions of a terminal, such as hardware configuration, task execution conditions, and the like.
S203: if yes, determining the task to be processed reaching the latest processing time as a target task; and if not, executing the step of predicting the idle time of the target thread under the condition that the target thread is in the idle state.
In this step, if it is detected that there is a task to be processed that reaches the latest processing time, it may be determined that the task to be processed has reached a stage where processing is necessary or impossible, and therefore, the traversed task to be processed may be directly taken as a target task that needs to be processed, and conversely, if there is no task that needs to be processed, it may be determined that there is no task that needs to be processed urgently, and for the at least one task to be processed, the step of predicting the idle duration of the target thread in the case where the target thread is in the idle state may be performed, and the idle duration of the target thread may be matched with the task duration of the target thread.
S204: and under the condition that the target thread is in an idle state, predicting the idle time of the target thread.
S205: and under the condition that the idle time is greater than or equal to a preset specified time, determining a target task from the at least one task to be processed according to the task processing time of each task to be processed and the preset specified time.
S206: and loading the target task into the target thread for processing.
The descriptions of step S201, step S204, step S205, and step S206 may refer to the descriptions of step S101 to step S104, and the same technical effect and the same technical problem can be achieved, which are not described herein again.
Next, this embodiment will be further described with reference to specific embodiments.
In one possible real-time approach, step S205 includes:
determining a first candidate task with the task processing duration less than or equal to the preset specified duration from the at least one task to be processed based on the task processing duration of each task to be processed; and taking the first candidate task as a target task.
In this step, when the target task is screened, the task processing time length of each task to be processed may be determined, and then the determined task processing time length is compared with the preset specified time length, if the task processing time length is less than or equal to the preset specified time length, it may be considered that the idle time of the target thread is sufficient to process the task, that is, the task whose task processing time length is less than or equal to the preset specified time length may be used as a first candidate task, and the first candidate task may be used as a target task for the target thread to process.
Here, the method may be used in a scheme of predicting by using a two-class model mainly when the idle time of the target thread is predicted, that is, only whether the idle time is greater than the preset specified time may be compared.
Correspondingly, when the idle time of the target thread is predicted, if the idle time is predicted by using multiple categories, it is not only possible to see whether the idle time is greater than or equal to the preset specified time.
Accordingly, in a possible implementation, after step S204, the method further includes:
if the idle time length is less than a preset specified time length, determining a preset time length classification range in which the idle time length is located; determining a second candidate task with the task processing duration in the preset duration classification range from the at least one task to be processed based on the task processing duration of each task to be processed; and taking the second candidate task as a target task.
In this step, if the predicted idle duration is less than the preset specified duration, the idle duration may be further detected, and a preset duration classification range in which the idle duration is located may be detected, that is, for a multi-classification result, to which duration classification the idle duration belongs, further, the task processing duration of each task to be processed may be traversed to select a task whose task processing duration is within the preset duration classification range as a second candidate task, where the second candidate task is a target task that can be processed by the target thread.
Further, in order to reduce the computational stress and resource stress of the target thread in both the case of the binary classification and the case of the multi-classification, when the target thread processes the to-be-processed task, only one task is processed at a time, and when the first candidate task or the second candidate task is screened, if the first candidate task or the second candidate task includes a plurality of candidate tasks, the target task to be processed needs to be further selected from the plurality of candidate tasks.
Accordingly, in one possible implementation, in a case where the first candidate task or the second candidate task includes a plurality of candidate tasks, taking the first candidate task as a target task or taking the second candidate task as a target task includes
Determining the latest processing time of each candidate task; determining a candidate task with the minimum time difference between the latest processing time and the current time from the plurality of candidate tasks as the target candidate task; and taking the target candidate task as a target task.
In this step, for a plurality of candidate tasks preliminarily screened, which task has the smallest time difference between the latest processing time and the current time, that is, which task is urgently required to be processed, may be detected according to the latest processing time of the candidate task, and for a target candidate task having the smallest time difference between the latest processing time and the current time, the target candidate task may be used as a target task urgently required to be processed by the target thread.
In a possible implementation, after step S201, the method further includes:
taking the at least one task to be processed out of the thread task queue of the target thread; and adding the at least one taken out task to be processed into a custom task queue aiming at the target thread.
In this step, after determining at least one to-be-processed task to be processed by the target thread, in order to avoid that the target thread is also processed according to a predetermined task arrangement, each to-be-processed task may be taken out from a thread task queue of the target thread, so that task cache pressure of the target thread may be reduced, and then a custom task queue may be created for the target thread, and the at least one to-be-processed task may be added to the custom task queue.
The user-defined task queue can be manually defined and can also be defined by a system.
Further, step S206 includes:
and taking out the determined target task from the custom task queue, and loading the taken out target task into the target thread for processing.
Here, when the target thread can process the target task, the target task may be taken out from the custom task queue and loaded into the target thread for processing.
In an alternative embodiment, before step S204, the method includes:
detecting whether a task to be processed exists in the user-defined task queue;
and if the to-be-processed task exists in the custom task queue, executing a step of predicting the idle time of the target thread under the condition that the target thread is in an idle state.
In this step, under the condition that the target thread is in an idle state, before the step of predicting the idle time of the target thread, it may be detected whether there is a task to be processed in the custom task queue, and if there is a task to be processed in the custom task queue, it is determined that the target task needs to be screened for the target thread, and the step of predicting the idle time of the target thread under the condition that the target thread is in an idle state may be continuously performed.
On the contrary, if there is no task to be processed in the custom task queue, the process may be stopped without executing the step of predicting the idle duration of the target thread.
For example, please refer to fig. 3, and fig. 3 is a schematic diagram of task stages in the embodiment of the present disclosure. As shown in fig. 3, in the process of task processing, three phases, namely a training data acquisition phase, a model training phase and a task processing phase, are mainly included, and these three phases have temporal continuity, but may not have continuity in temporal continuity, for example, for the training data acquisition phase and the model training phase, the two phases and the task processing phase may be separated, that is, before starting the task processing phase, a model to be used needs to be trained in advance through the training data acquisition phase and the model training phase, and after completing the model training, the model may be used in each task processing phase.
Specifically, in the training data acquisition stage, feature data related to task scheduling and duration data related to idle duration of a target thread need to be acquired, then in the model training stage, the acquired feature data and duration data can be preprocessed, for example, dirty data is proposed, then data labeling is performed, for example, the duration data needs to be labeled to indicate whether the sample is a sample with duration longer than the preset specified duration or specifically belongs to which pre-divided duration interval, then the neural network can be trained by using the processed data to obtain a duration prediction model for predicting the idle duration, the two stages can be performed in a background server, correspondingly, the background server can issue the duration prediction model to a terminal of a user, after the terminal receives the duration prediction model and enters the task processing stage, the non-instantaneity tasks in the target thread can be collected and added into a user-defined processing queue, when the tasks exist in the queue, the idle time can be predicted through the model, and the tasks are processed by combining the latest processing time of the tasks, the task processing time and the like.
The task processing method provided by the embodiment of the disclosure determines at least one to-be-processed task to be processed by a to-be-target thread, wherein the to-be-processed task is a non-immediate processing task, detects whether the to-be-processed task reaching the latest processing time exists in the at least one to-be-processed task according to the latest processing time of each to-be-processed task, and determines the to-be-processed task reaching the latest processing time as a target task if the to-be-processed task exists; if not, the step of predicting the idle time of the target thread under the condition that the target thread is in an idle state is executed, and under the condition that the idle time is greater than or equal to a preset specified time, a target task is determined from at least one task to be processed according to the task processing time of each task to be processed and the preset specified time, and the target task is loaded into the target thread for processing.
Therefore, the idle time of the thread can be used for processing the non-immediate processing task, and the time and the execution time of the task put into the thread can be further controlled by combining the latest processing time of the target task which can be processed and is preset for each task to be processed, so that the processing pressure of the thread task can be effectively relieved, the times and the frequency of no response of the application and pause of the application can be greatly reduced under the condition that the task is not executed, the task is prevented from not being executed for a long time, and the smooth execution of the task is ensured.
It will be understood by those skilled in the art that in the method of the present invention, the order of writing the steps does not imply a strict order of execution and any limitations on the implementation, and the specific order of execution of the steps should be determined by their function and possible inherent logic.
Based on the same inventive concept, a task processing device corresponding to the task processing method is also provided in the embodiments of the present disclosure, and because the principle of solving the problem of the device in the embodiments of the present disclosure is similar to the task processing method described above in the embodiments of the present disclosure, the implementation of the device may refer to the implementation of the method, and repeated details are not described again.
Referring to fig. 4 to 5, fig. 4 is a first schematic diagram of a task processing device according to an embodiment of the disclosure, and fig. 5 is a second schematic diagram of a task processing device according to an embodiment of the disclosure.
As shown in fig. 4, a task processing apparatus 400 provided by an embodiment of the present disclosure includes:
the task determining module 410 is configured to determine at least one to-be-processed task to be processed by the target thread, where the to-be-processed task is a non-immediate processing task.
A duration prediction module 420, configured to predict an idle duration of the target thread when the target thread is in an idle state.
And the target task determining module 430 is configured to determine a target task from the at least one to-be-processed task according to the task processing duration of each to-be-processed task and a preset specified duration when the idle duration is greater than or equal to the preset specified duration.
And a task loading module 440, configured to load the target task into the target thread for processing.
In an optional implementation manner, the duration prediction module 420 is specifically configured to:
acquiring a trained duration prediction model;
and under the condition that the target thread is in an idle state, predicting the idle time of the target thread through the time length prediction model based on the task processing characteristic information of the target thread.
In an alternative embodiment, the duration prediction module 420 is configured to train the duration prediction model by:
acquiring a plurality of sample idle time lengths of the target thread in the idle state and sample characteristic information aiming at each sample idle time length, wherein the sample idle time lengths comprise a positive sample and a negative sample, the time length of the positive sample is greater than the preset specified time length, and the time length of the negative sample is less than the preset specified time length;
and training the constructed duration prediction model by using the plurality of sample idle durations and the sample characteristic information of each sample idle duration.
In an optional implementation manner, the target task determining module 430 is specifically configured to:
determining a first candidate task with the task processing duration less than or equal to the preset specified duration from the at least one task to be processed based on the task processing duration of each task to be processed;
and taking the first candidate task as a target task.
In an optional implementation, the target task determination module 430 is further configured to:
if the idle time length is less than a preset specified time length, determining a preset time length classification range in which the idle time length is located;
determining a second candidate task with the task processing duration in the preset duration classification range from the at least one task to be processed based on the task processing duration of each task to be processed;
and taking the second candidate task as a target task.
In an optional implementation manner, when the first candidate task or the second candidate task includes a plurality of candidate tasks, the target task determining module 430 is specifically configured to:
determining the latest processing time of each candidate task;
determining a candidate task with the minimum time difference between the latest processing time and the current time from the plurality of candidate tasks as the target candidate task;
and taking the target candidate task as a target task.
In an alternative embodiment, as shown in fig. 5, the task processing apparatus 400 further includes a task adding module 450, and the task adding module 450 is configured to:
taking the at least one task to be processed out of the thread task queue of the target thread;
adding the at least one taken out task to be processed into a custom task queue aiming at the target thread;
the task loading module 440 is specifically configured to:
and taking out the determined target task from the custom task queue, and loading the taken out target task into the target thread for processing.
In an alternative embodiment, as shown in fig. 5, the task processing device 400 further includes a task detection module 460, and the task detection module 460 is configured to:
detecting whether a task to be processed exists in the user-defined task queue;
and if the to-be-processed task exists in the custom task queue, executing a step of predicting the idle time of the target thread under the condition that the target thread is in an idle state.
In an optional implementation manner, the task loading module 440 is specifically configured to:
and encapsulating the target task into a target message, and loading the target message into the target thread for processing.
In an optional implementation, the target task determination module 430 is further configured to:
detecting whether a task to be processed reaching the latest processing time exists in the at least one task to be processed according to the latest processing time of each task to be processed;
and if so, determining the task to be processed reaching the latest processing time as the target task.
And if not, executing the step of predicting the idle time of the target thread under the condition that the target thread is in the idle state.
The description of the processing flow of each module in the device and the interaction flow between the modules may refer to the related description in the above method embodiments, and will not be described in detail here.
The task processing device provided by the embodiment of the disclosure determines at least one task to be processed by a target thread, wherein the task to be processed is a non-immediate processing task; predicting the idle time of the target thread under the condition that the target thread is in an idle state; under the condition that the idle time is greater than or equal to a preset specified time, determining a target task from at least one task to be processed according to the task processing time of each task to be processed and the preset specified time; and loading the target task into the target thread for processing.
Therefore, the time for putting the task into the thread and the execution time are controlled by processing the non-immediate processing task by using the idle time of the target thread, the task buffer amount of the target thread can be reduced, the pressure of the target thread is relieved, and the probability of no response and blockage of the application is reduced.
Furthermore, by combining the latest processing time of the target task which can be processed and is preset for each task to be processed, the situation that the task is not executed for a long time can be effectively avoided, the probability of task omission is reduced, and the task can be smoothly executed.
Based on the same technical concept, an embodiment of the present application further provides an electronic device 600, as shown in fig. 6, which is a schematic structural diagram of the electronic device 600 provided in the embodiment of the present disclosure, and includes:
a processor 610, a memory 620, and a bus 630; the storage 620 is used for storing execution instructions and includes a memory 621 and an external storage 622; the memory 621 is also referred to as an internal memory, and is used for temporarily storing operation data in the processor 610 and data exchanged with an external memory 622 such as a hard disk, the processor 610 exchanges data with the external memory 622 through the memory 621, and when the electronic device 600 operates, the processor 610 and the memory 620 communicate through the bus 630, so that the processor 610 can execute the steps of the task processing method shown in the above method embodiments.
The embodiments of the present disclosure also provide a computer storage medium, where a computer program is stored on the computer storage medium, and when the computer program is executed by a processor, the computer program performs the steps of the task processing method described in the above method embodiments. Wherein the storage medium may be a volatile or non-volatile computer-readable storage medium.
The embodiments of the present disclosure also provide a computer program product, where the computer program product carries a program code, and instructions included in the program code may be used to execute steps of the task processing method in the foregoing method embodiments, which may be referred to specifically in the foregoing method embodiments, and are not described herein again.
The computer program product may be implemented by hardware, software or a combination thereof. In an alternative embodiment, the computer program product is embodied in a computer storage medium, and in another alternative embodiment, the computer program product is embodied in a Software product, such as a Software Development Kit (SDK), or the like.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the storage medium, the apparatus, and the device described above may refer to corresponding processes in the foregoing method embodiments, and are not described herein again. In the several embodiments provided in the present disclosure, it should be understood that the disclosed storage medium, device, apparatus and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another apparatus, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present disclosure may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-accessible storage medium executable by a processor. Based on such understanding, the technical solution of the present disclosure may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present disclosure. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
Finally, it should be noted that: the above-mentioned embodiments are merely specific embodiments of the present disclosure, which are used for illustrating the technical solutions of the present disclosure and not for limiting the same, and the scope of the present disclosure is not limited thereto, and although the present disclosure is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive of the technical solutions described in the foregoing embodiments or equivalent technical features thereof within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present disclosure, and should be construed as being included therein. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.

Claims (13)

1. A method for processing a task, the method comprising:
determining at least one task to be processed by a target thread, wherein the task to be processed is a non-instantaneity processing task;
predicting the idle time of the target thread under the condition that the target thread is in an idle state;
under the condition that the idle time is greater than or equal to a preset specified time, determining a target task from at least one task to be processed according to the task processing time of each task to be processed and the preset specified time;
and loading the target task into the target thread for processing.
2. The method of claim 1, wherein predicting the idle duration of the target thread if the target thread is in an idle state comprises:
acquiring a trained duration prediction model;
and under the condition that the target thread is in an idle state, predicting the idle time of the target thread through the time length prediction model based on the task processing characteristic information of the target thread.
3. The method of claim 2, wherein the duration prediction model is trained by:
acquiring a plurality of sample idle time lengths of the target thread in the idle state and sample characteristic information aiming at each sample idle time length, wherein the sample idle time lengths comprise a positive sample and a negative sample, the time length of the positive sample is greater than the preset specified time length, and the time length of the negative sample is less than the preset specified time length;
and training the constructed duration prediction model by using the plurality of sample idle durations and the sample characteristic information of each sample idle duration.
4. The method according to claim 1, wherein the determining a target task from the at least one task to be processed according to the task processing time length of each task to be processed and the preset specified time length comprises:
determining a first candidate task with the task processing duration less than or equal to the preset specified duration from the at least one task to be processed based on the task processing duration of each task to be processed;
and taking the first candidate task as a target task.
5. The method of claim 1, wherein after predicting the idle duration of the target thread, the method comprises:
if the idle time length is less than a preset specified time length, determining a preset time length classification range in which the idle time length is located;
determining a second candidate task with the task processing duration in the preset duration classification range from the at least one task to be processed based on the task processing duration of each task to be processed;
and taking the second candidate task as a target task.
6. The method of claim 4 or 5, wherein in the event that the first candidate task or the second candidate task comprises a plurality of candidate tasks, targeting the first candidate task or the second candidate task comprises targeting the first candidate task or the second candidate task, comprising
Determining the latest processing time of each candidate task;
determining a candidate task with the minimum time difference between the latest processing time and the current time from the plurality of candidate tasks as the target candidate task;
and taking the target candidate task as a target task.
7. The method of claim 1, wherein after the determining at least one pending task to be processed by the target thread, the method comprises:
taking the at least one task to be processed out of the thread task queue of the target thread;
adding the at least one taken out task to be processed into a custom task queue aiming at the target thread;
the loading the target task into the target thread for processing comprises:
and taking out the determined target task from the custom task queue, and loading the taken out target task into the target thread for processing.
8. The method of claim 7, wherein before predicting the idle duration of the target thread if the target thread is in an idle state, the method comprises:
detecting whether a task to be processed exists in the user-defined task queue;
and if the to-be-processed task exists in the custom task queue, executing a step of predicting the idle time of the target thread under the condition that the target thread is in an idle state.
9. The method of claim 1, wherein loading the target task into the target thread for processing comprises:
and encapsulating the target task into a target message, and loading the target message into the target thread for processing.
10. The method of claim 1, wherein after the determining at least one pending task to be processed by the target thread, the method comprises:
detecting whether a task to be processed reaching the latest processing time exists in the at least one task to be processed according to the latest processing time of each task to be processed;
if yes, determining the task to be processed reaching the latest processing time as a target task;
and if not, executing the step of predicting the idle time of the target thread under the condition that the target thread is in the idle state.
11. A task processing apparatus, comprising:
the task determining module is used for determining at least one task to be processed by a target thread, wherein the task to be processed is a non-immediate processing task;
the time length prediction module is used for predicting the idle time length of the target thread under the condition that the target thread is in an idle state;
the target task determining module is used for determining a target task from at least one task to be processed according to the task processing time length of each task to be processed and a preset specified time length under the condition that the idle time length is greater than or equal to the preset specified time length;
and the task loading module is used for loading the target task into the target thread for processing.
12. An electronic device, comprising: a processor, a memory and a bus, the memory storing machine-readable instructions executable by the processor, the processor and the memory communicating via the bus when the electronic device is operating, the machine-readable instructions when executed by the processor performing the steps of the task processing method according to any one of claims 1 to 10.
13. A computer storage medium, characterized in that the computer storage medium has stored thereon a computer program which, when being executed by a processor, performs the steps of the task processing method according to any one of claims 1 to 10.
CN202210066796.5A 2022-01-20 2022-01-20 Task processing method, device, equipment and storage medium Pending CN114416320A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210066796.5A CN114416320A (en) 2022-01-20 2022-01-20 Task processing method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210066796.5A CN114416320A (en) 2022-01-20 2022-01-20 Task processing method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114416320A true CN114416320A (en) 2022-04-29

Family

ID=81275244

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210066796.5A Pending CN114416320A (en) 2022-01-20 2022-01-20 Task processing method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114416320A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116737673A (en) * 2022-09-13 2023-09-12 荣耀终端有限公司 Scheduling method, equipment and storage medium of file system in embedded operating system
CN116861798A (en) * 2023-09-01 2023-10-10 华侨大学 Online real-time residual life prediction method for vacuum dry pump based on XGBoost algorithm

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116737673A (en) * 2022-09-13 2023-09-12 荣耀终端有限公司 Scheduling method, equipment and storage medium of file system in embedded operating system
CN116737673B (en) * 2022-09-13 2024-03-15 荣耀终端有限公司 Scheduling method, equipment and storage medium of file system in embedded operating system
CN116861798A (en) * 2023-09-01 2023-10-10 华侨大学 Online real-time residual life prediction method for vacuum dry pump based on XGBoost algorithm
CN116861798B (en) * 2023-09-01 2023-12-26 华侨大学 Online real-time residual life prediction method for vacuum dry pump based on XGBoost algorithm

Similar Documents

Publication Publication Date Title
CN109656722B (en) Memory optimization method and device, mobile terminal and storage medium
CN114416320A (en) Task processing method, device, equipment and storage medium
CN107506240B (en) Background application program control method and device, storage medium and electronic equipment
CN110764906B (en) Memory recovery processing method and device, electronic equipment and storage medium
US20140143791A1 (en) System, method, and apparatus for improving application-launch latencies
CN107615250B (en) Application-oriented processing method and device and intelligent terminal
US10467054B2 (en) Resource management method and system, and computer storage medium
CN110737606B (en) Memory recovery processing method and device, electronic equipment and storage medium
CN116089096B (en) Load resource scheduling method and electronic equipment
CN115016866A (en) Data processing method during application starting, electronic equipment and storage medium
CN111625456A (en) Stuck positioning method and device
CN113190427A (en) Caton monitoring method and device, electronic equipment and storage medium
CN111050388B (en) Doze mode control method, device, mobile terminal and storage medium
CN113660173A (en) Flow control method and device, computer equipment and storage medium
CN113495787A (en) Resource allocation method, device, storage medium and electronic equipment
CN112764959B (en) Method, device, equipment and storage medium for monitoring application program locking problem
CN106503543A (en) A kind of method and apparatus of management application program
CN111045507B (en) List management and control method, device, mobile terminal and storage medium
CN116700816B (en) Resource management method and electronic equipment
CN113064660A (en) Device control method, device, electronic device and storage medium
CN111078405B (en) Memory allocation method and device, storage medium and electronic equipment
CN115617518A (en) Thread management method and device, electronic equipment and storage medium
CN110874277B (en) Electronic red packet processing method, electronic red packet processing device and mobile terminal
CN111090627B (en) Log storage method and device based on pooling, computer equipment and storage medium
CN110046030B (en) Application program processing method and device, electronic equipment and computer readable 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
CB02 Change of applicant information

Address after: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant after: Douyin Vision Co.,Ltd.

Address before: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant before: Tiktok vision (Beijing) Co.,Ltd.

Address after: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant after: Tiktok vision (Beijing) Co.,Ltd.

Address before: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant before: BEIJING BYTEDANCE NETWORK TECHNOLOGY Co.,Ltd.

CB02 Change of applicant information