Task processing method and device, equipment and storage medium
By distinguishing key threads from ordinary threads in electronic devices and assigning processing tasks according to task priority, the problem of insufficient resource guarantee when the server handles requests is solved, and the response efficiency and system stability of critical tasks are improved.
Patent Information
- Application Number
- CN202411080439.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2024-12-06
AI Technical Summary
In the prior art, when the server handles requests from different clients according to the FIFO principle, it may lead to insufficient resource guarantee for critical tasks when processing tasks related to system stability, resulting in response delays and system failures.
In electronic devices, differentiate between critical threads and ordinary threads. According to the priority level of the task, tasks are processed through different threads to ensure that tasks with priority higher than the threshold are processed by key threads, and tasks with priority lower than or equal to the threshold are processed by ordinary threads. Thread processing to improve the response efficiency of critical tasks.
By distinguishing threads and prioritizing processing, the response delay of critical tasks is reduced, ensuring that they are performed first, improving the processing efficiency of critical tasks and enhancing system stability.
Smart Images

Figure CN119088515A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and relate to but are not limited to a task processing method and apparatus, device, and storage medium. Background Art
[0002] With the development of computer technology, big data is increasing day by day, and big data computing tasks are also increasing. In the current system, the client generally initiates a task request, and then the server receives the task request and executes it. In the current related technology, when the server selects to execute a task, it will process many requests from different clients according to the first-in-first-out (FIFO) principle, and fairly allocate these tasks to threads according to the order in which the tasks arrive.
[0003] However, the server processes many requests from different clients according to the FIFO principle, so it may face the problem of insufficient resource guarantee when processing key tasks related to system stability. Therefore, how to improve the processing efficiency of key tasks is an urgent problem to be solved. Summary of the invention
[0004] In view of this, the task processing method, device, equipment, and storage medium provided in the embodiments of the present application can improve the processing efficiency of key tasks. The task processing method, device, equipment, and storage medium provided in the embodiments of the present application are implemented as follows:
[0005] The task processing method provided in an embodiment of the present application is applied to an electronic device, wherein the electronic device includes a critical thread and an ordinary thread, the ordinary thread is used to process tasks of all priority levels, and the critical thread is used to process tasks with a priority level higher than a priority threshold. The method includes: obtaining a target task request, wherein the target task request includes the priority level of the target task; when the priority level of the target task is higher than the priority threshold, processing the target task through a first thread, wherein the first thread is a thread in an idle state between the ordinary thread and the critical thread; when the priority level of the target task is lower than or equal to the priority threshold, processing the target task through a second thread, wherein the second thread is a thread in the idle state between the ordinary thread.
[0006] The task processing device provided in an embodiment of the present application is applied to an electronic device, wherein the electronic device includes a critical thread and an ordinary thread, wherein the ordinary thread is used to process tasks of all priority levels, and the critical thread is used to process tasks with a priority level higher than a priority threshold. The device includes: an acquisition module, used to obtain a target task request, wherein the target task request includes the priority level of the target task; a processing module, used to process the target task through a first thread when the priority level of the target task is higher than the priority threshold, wherein the first thread is a thread in an idle state between the ordinary thread and the critical thread; the processing module is also used to process the target task through a second thread when the priority level of the target task is lower than or equal to the priority threshold, wherein the second thread is a thread in the idle state among the ordinary threads.
[0007] The computer device provided in the embodiment of the present application includes a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the program, the processing method of the task described in the embodiment of the present application is implemented.
[0008] The computer-readable storage medium provided in the embodiment of the present application stores a computer program thereon, and when the computer program is executed by a processor, the processing method of the task provided in the embodiment of the present application is implemented.
[0009] The computer program product provided in the embodiment of the present application includes a computer program, which, when executed by a processor, implements the task processing method provided in the embodiment of the present application.
[0010] In the task processing method, device, equipment, and storage medium provided in the embodiments of the present application, the electronic device first obtains a target task request, which includes the priority level of the target task, and then processes the target task through a first thread when the priority level of the target task is higher than the priority threshold, and the first thread is a thread in an idle state among ordinary threads and critical threads. When the priority level of the target task is lower than or equal to the priority threshold, the target task is processed through a second thread, and the second thread is a thread in an idle state among ordinary threads. In the task processing method of the present application, ordinary threads and critical threads, as well as the priority level of tasks, are distinguished in the electronic device, which can reduce the response delay of critical tasks and ensure that they are executed first when facing a large number of backlog tasks, thereby improving the processing efficiency of critical tasks and solving the technical problems raised in the background technology. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and are used together with the specification to illustrate the technical solution of the present application.
[0012] Figure 1 A schematic diagram of a task processing flow between a client and a server provided in one embodiment of the present application;
[0013] Figure 2 A schematic diagram of a task processing process on a server provided in accordance with an embodiment of the present application;
[0014] Figure 3 A schematic diagram of the system architecture of an electronic device provided in one embodiment of the present application;
[0015] Figure 4 A schematic diagram of a process flow for implementing a method for processing a task provided in one embodiment of the present application;
[0016] Figure 5 A schematic diagram of a process flow for implementing a method for processing a task provided in another embodiment of the present application;
[0017] Figure 6 A schematic diagram of the distribution of task request data provided by one embodiment of the present application;
[0018] Figure 7 A schematic diagram of a process flow for implementing a method for processing a task provided in yet another embodiment of the present application;
[0019] Figure 8 An exemplary flow chart of a method for processing a task provided by one embodiment of the present application;
[0020] Fig. 9 An exemplary flow chart of a method for processing a task provided by another embodiment of the present application;
[0021] Fig.10 A schematic diagram of a task processing process provided for an embodiment of the present application;
[0022] Fig.11 A schematic diagram of a task processing process provided for another embodiment of the present application;
[0023] Fig.12 A structural schematic diagram of a task processing device provided by one embodiment of the present application;
[0024] Fig.13 A structural diagram of a computer device provided for one embodiment of the present application. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the specific technical solution of the present application will be further described in detail below in conjunction with the drawings in the embodiments of the present application. The following embodiments are used to illustrate the present application, but are not used to limit the scope of the present application.
[0026] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0027] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0028] It should be pointed out that the terms "first\second\third" involved in the embodiments of the present application are used to distinguish similar or different objects, and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.
[0029] With the development of computer technology, big data is increasing day by day, and big data computing tasks are also increasing. In the current system, generally the client initiates the task request, and then the server receives the task request and executes it.
[0030] In the current related technologies, when the server selects to execute tasks, the requests from different clients are not much different. The client's task will first select any idle service thread and queue up in the task queue of the corresponding service thread to wait for execution. Once all the threads on the server are busy, the task sent by the client will be placed in the shared task queue of the server process. When any thread on the server becomes idle, the shared task queue will process the waiting tasks one by one according to the First Input First Output (FIFO) principle. In other words, the server will process many requests from different clients according to the FIFO principle and fairly allocate these tasks to threads according to the order in which the tasks arrive.
[0031] For example, please refer to Figure 1 , is a schematic diagram of a task processing flow between a client and a server provided in one embodiment of the present application. Figure 1As shown, the client sends a task to the server. First, it determines whether the server has an idle service thread. If the server has an idle service thread, the task can enter thread task queue 1, thread task queue 2, or thread task queue 3 in sequence to queue and wait for execution; if the server has no idle service thread, the task enters the process task queue and waits. When there is an idle thread on the server, the server will first determine whether there are tasks to be executed in thread task queue 1, thread task queue 2, and thread task queue 3. If there are, it will be taken out for execution; if not, it will extract tasks from the process task queue for execution.
[0032] However, since the server processes many requests from different clients based on the FIFO principle, it may face the problem of insufficient resource guarantee when processing critical tasks related to system stability. These critical tasks must compete with general tasks for thread resources, which will result in the critical tasks being unable to obtain the necessary thread resources to run in time when general tasks are slow or abnormal, which may cause system-level failures and even cause the system to restart, seriously affecting the user experience.
[0033] For example, please refer to Figure 2 , is a schematic diagram of the task processing process of the server provided by an embodiment of the present application. Assume that the server includes a task pool and a thread pool, the task pool includes a server task queue, the server task queue includes different types of tasks, such as critical tasks and ordinary tasks, the critical tasks and ordinary tasks are arranged in the order in which the tasks arrive, and the thread pool includes multiple threads. Figure 2 As shown in the figure, the critical tasks and common tasks that have arrived enter the task pool and are arranged in the server task queue. At this time, there are 7 tasks arranged in the server task queue, including 6 common tasks and 1 critical task. The thread pool includes 5 threads, 4 of which are processing tasks, and 1 thread is idle waiting and is pulling the next task from the server task queue to execute. Since common tasks arrive earlier, they are piled up in the queue, making it impossible for critical tasks to obtain thread pool resources in time, which may delay critical tasks and affect the user experience.
[0034] Therefore, how to improve the processing efficiency of key tasks is an urgent problem to be solved.
[0035] In view of this, an embodiment of the present application provides a method for processing a task, which is applied to an electronic device, wherein the electronic device includes a critical thread and an ordinary thread, wherein the ordinary thread is used to process tasks of all priority levels, and the critical thread is used to process tasks whose priority level is higher than a priority threshold. The method specifically includes: the electronic device first obtains a target task request, wherein the target task request includes the priority level of the target task, and then, when the priority level of the target task is higher than the priority threshold, the target task is processed by a first thread, wherein the first thread is an idle thread among the ordinary threads and the critical thread, and when the priority level of the target task is lower than or equal to the priority threshold, the target task is processed by a second thread, wherein the second thread is an idle thread among the ordinary threads. In the task processing method of the present application, ordinary threads and critical threads are distinguished in the electronic device, as well as the priority level of the task, which can reduce the response delay of the critical tasks and ensure that they are executed first when facing a large number of backlog tasks, thereby improving the processing efficiency of the critical tasks.
[0036] It should be understood that the electronic devices involved in the embodiments of the present application may be mobile phones, tablet computers, laptop computers, PDAs, mobile internet devices (MIDs), wearable devices, virtual reality (VR) devices, augmented reality (AR) devices, smart screens, artificial intelligence (AI) speakers, headphones, terminals in industrial control, terminals in self-driving, terminals in remote medical surgery, terminals in smart grids, terminals in transportation safety, terminals in smart cities, terminals in smart homes, personal digital assistants (PDAs), etc., and the embodiments of the present application are not limited to this.
[0037] For example, Figure 3 A schematic diagram of the system architecture of an electronic device provided in one embodiment of the present application. Figure 3 As shown, the electronic device includes components such as a processor 310, a memory 320, a transceiver 330, a display unit 340, an input unit 350 and a power module 360.
[0038] The processor 310 is the control center of the electronic device, and uses various interfaces and lines to connect various parts of the entire electronic device. By running or executing software programs and / or modules stored in the memory 320, and calling data stored in the memory 320, the processor 310 performs various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole. Optionally, the processor 310 may include one or more processing units; optionally, the processor 310 may integrate an application processor, which mainly processes operating devices, user interfaces, and application programs, etc. Of course, other processors may also be included, which are not listed here one by one.
[0039] The memory 320 can be used to store software programs and modules. The processor 310 executes various functional applications and data processing of the electronic device by running the software programs and modules stored in the memory 320. The memory 320 mainly includes a program storage area and a data storage area, wherein the program storage area can store operating devices, at least one application required for a function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the electronic device (such as audio data, a phone book, etc.), etc. In addition, the memory 320 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0040] The transceiver 330 can provide wireless communication solutions for electronic devices, including wireless local area networks (WLAN) (such as Wi-Fi networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc. The transceiver 330 can be one or more devices integrating at least one communication processing module, for example, an antenna and a baseband processor are integrated into the transceiver 330, or an antenna and a modem processor are integrated into the transceiver 330, etc., which are not limited here.
[0041] The display unit 340 may be used to display information input by the user or information provided to the user and various menus of the electronic device. The display unit 340 may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc., which is not limited here.
[0042] The input unit 350 can be used to receive input digital or character information, and to generate key signal input related to user settings and function control of the electronic device. Specifically, the input unit 350 can collect the user's operations on or near it, and drive the corresponding connection device according to a pre-set program. In addition, the input unit 350 may include a touch panel, which can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic waves. In addition to the touch panel, the input unit 350 may also include other input devices. Specifically, other input devices may include, but are not limited to, one or more of function keys (such as volume control keys, switch keys, etc.), trackballs, joysticks, etc.
[0043] The electronic device also includes a power module 360 for supplying power to various components. Optionally, the power module 360 can be logically connected to the processor 310 through a power management device, so that the power management device can manage charging, discharging, power consumption and other functions.
[0044] It is to be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the electronic device. In other embodiments of the present application, the electronic device may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0045] In order to make the purpose and technical solution of this application clearer and more intuitive, the following will be combined with the accompanying drawings and embodiments to describe in detail the task processing method and device, equipment, and storage medium provided in the embodiments of this application. It should be understood that the specific embodiments described herein are only used to explain this application and are not used to limit this application.
[0046] Please refer to Figure 4 , is a schematic diagram of the implementation flow of a task processing method provided by an embodiment of the present application. The method can be applied to Figure 3 The electronic equipment shown, such as Figure 4 As shown, the method may include the following steps 401 to 403:
[0047] Step 401: Obtain a target task request, where the target task request includes a priority level of the target task.
[0048] It should be noted that the electronic device includes key threads and common threads. The common threads are used to process tasks of all priority levels, and the key threads are used to process tasks with a priority level higher than a priority threshold.
[0049] Exemplarily, tasks with a priority level higher than the priority threshold may be critical tasks related to system stability, or some relatively urgent tasks, etc., which are not limited in the embodiments of the present application.
[0050] In some embodiments, the electronic device can be a server, and the server can obtain target task requests from the client. Each target task request has a set of standardized data formats to transmit key information, such as the requested server task type, task parameters, data length, request time, and priority level of the target task.
[0051] Step 402: When the priority level of the target task is higher than the priority threshold, the target task is processed by a first thread, where the first thread is an idle thread among common threads and key threads.
[0052] In some embodiments, when the priority level of the target task is higher than the priority threshold, it can be processed by a common thread or a critical thread, that is, it can be processed by any idle thread among the common thread and the critical thread.
[0053] Exemplarily, when the priority level of the target task is higher than the priority threshold, an idle common thread may be preferred, and if no common thread is available, a critical thread may be selected; or an idle critical thread may be preferred, and if no critical thread is available, a common thread may be selected.
[0054] In some embodiments, the priority threshold may be set based on experience, may be preset in advance, or may be determined by other means, which is not limited in this application.
[0055] Step 403: When the priority level of the target task is lower than or equal to the priority threshold, the target task is processed by a second thread, where the second thread is an idle thread among ordinary threads.
[0056] In some embodiments, when the priority level of the target task is lower than or equal to the priority threshold, it can only be processed by a normal thread.
[0057] Exemplarily, when the priority level of the target task is lower than or equal to the priority threshold, it is detected whether there is an idle common thread in the electronic device. If there is no available common thread, it enters the pending task queue and waits in line.
[0058] In this embodiment, the electronic device first obtains a target task request, which includes the priority level of the target task. Then, when the priority level of the target task is higher than the priority threshold, the target task is processed by a first thread, which is an idle thread among ordinary threads and critical threads. When the priority level of the target task is lower than or equal to the priority threshold, the target task is processed by a second thread, which is an idle thread among ordinary threads. In the task processing method, ordinary threads and critical threads, as well as the priority level of tasks, are distinguished in the electronic device, which can reduce the response delay of critical tasks and ensure that they are executed first when facing a large number of backlog tasks, thereby improving the processing efficiency of critical tasks.
[0059] Based on the above embodiments, Figure 5 A schematic diagram of a process flow for implementing a task processing method provided in another embodiment of the present application is shown in FIG. Figure 5 As shown, the method may include the following steps 501 to 503:
[0060] Step 501: Obtain a target task request, where the target task request includes a priority level of the target task.
[0061] It should be noted that the electronic device includes key threads and common threads. The common threads are used to process tasks of all priority levels, and the key threads are used to process tasks with a priority level higher than a priority threshold.
[0062] Exemplarily, tasks with a priority level higher than the priority threshold may be critical tasks related to system stability, or some relatively urgent tasks, etc., which are not limited in the embodiments of the present application.
[0063] In some embodiments, the electronic device can be a server, and the server can obtain target task requests from the client. Each target task request has a set of standardized data formats to transmit key information, such as the requested server task type, task parameters, data length, request time, and priority level of the target task.
[0064] In some embodiments, the target task request includes a request data packet, and a flag is set in the header of the request data packet, and the flag is used to indicate the priority of the task. For example, a flag can be used in the header of the request data packet to indicate the priority of the task, and different priority numbers can be distinguished as needed, and these flags are represented by binary bits.
[0065] For example, please refer to Figure 6 , which is a distribution diagram of task request data provided by an embodiment of the present application, such as Figure 6As shown in the figure, the request packet includes the header, metadata and request flags of the request packet. If we want to classify 15 tasks of different levels, we only need to allocate 4 bits in the flags for representation, that is, we can mark 15 priority levels by using only a few bits of the flags in the header of the request packet. For example, if we use the 13th to 16th bits of the flags to record the priority level of the task, we can mark 15 priority levels. Figure 6 Take "XXXX 00110101 0101" as an example. Before placing a task into a queue, the electronic device will read the corresponding flags identification bit and determine which threads can execute the task. Tasks with higher priority levels can use more server thread resources.
[0066] Step 502: Detect whether there is an idle thread in the electronic device.
[0067] In some embodiments, after obtaining the target task request, the electronic device first detects whether it has an idle thread, and if it has an idle thread, determines the type of the idle thread, such as a common thread or a critical thread.
[0068] Step 503, in the case where there is an idle thread, determine the target thread for processing the target task according to preset conditions, the preset conditions include the priority level of the target task and / or the type of the idle thread, the type includes a normal thread type or a critical thread type, and the target thread includes a first thread or a second thread.
[0069] The first thread is a thread in an idle state among common threads and key threads, and the second thread is a thread in an idle state among common threads.
[0070] In some embodiments, when there is an idle thread, the electronic device determines whether the priority level of the target task is higher than the priority threshold. When the priority level of the target task is higher than the priority threshold, the idle thread is determined to be the first thread, that is, the target thread is the first thread, that is, the thread that is in an idle state among ordinary threads and critical threads.
[0071] That is, when there is an idle thread, the electronic device determines the target thread according to the priority level of the target task, such as when the priority level of the target task is higher than the priority threshold.
[0072] In other embodiments, when an idle thread exists, the electronic device determines whether the priority level of the target task is higher than the priority threshold, and obtains the type of the idle thread when the priority level of the target task is lower than or equal to the priority threshold; when the type of the idle thread is an ordinary thread type, the idle thread is determined to be the second thread, that is, the target thread is the second thread.
[0073] That is, when there is an idle thread, the electronic device determines the target thread according to the priority level of the target task, such as when the priority level of the target task is lower than or equal to the priority threshold, combined with the type of the idle thread.
[0074] In this embodiment, the electronic device first obtains a target task request, which includes the priority level of the target task, and then detects whether there is an idle thread in the electronic device. Finally, if there is an idle thread, the target thread for processing the target task is determined according to a preset condition. The preset condition includes the priority level of the target task and / or the type of the idle thread, which includes a common thread type or a critical thread type, and the target thread includes a first thread or a second thread. In the task processing method implemented in this embodiment, the electronic device distinguishes between common threads and critical threads, as well as the priority level of the task, and if there is an idle thread, the target thread for processing the target task is determined according to the preset condition. The target thread type obtained is relatively accurate, which can improve the processing efficiency of critical tasks when facing a large number of backlog tasks.
[0075] Based on the above embodiments, Figure 7 A flowchart of a method for processing a task provided in another embodiment of the present application is shown in FIG. Figure 7 As shown, the method may include the following steps 701 to 704:
[0076] Step 701: Obtain a target task request, where the target task request includes a priority level of the target task.
[0077] It should be noted that the electronic device includes key threads and common threads. The common threads are used to process tasks of all priority levels, and the key threads are used to process tasks with a priority level higher than a priority threshold.
[0078] Exemplarily, tasks with a priority level higher than the priority threshold may be critical tasks related to system stability, or some relatively urgent tasks, etc., which are not limited in the embodiments of the present application.
[0079] In some embodiments, the electronic device can be a server, and the server can obtain target task requests from the client. Each target task request has a set of standardized data formats to transmit key information, such as the requested server task type, task parameters, data length, request time, and priority level of the target task.
[0080] In some embodiments, the target task request includes a request data packet, and a flag is set in the header of the request data packet, and the flag is used to indicate the priority of the task. For example, a flag can be used in the header of the request data packet to indicate the priority of the task, and different priority numbers can be distinguished as needed, and these flags are represented by binary bits.
[0081] Step 702: Detect whether there is an idle thread in the electronic device.
[0082] In some embodiments, after obtaining the target task request, the electronic device first detects whether it has an idle thread, and if it has an idle thread, determines the type of the idle thread.
[0083] Step 703: If there is an idle thread, determine whether the type of the idle thread is a common thread type.
[0084] Step 704: When the idle thread is a common thread, determine that the idle thread is a target thread.
[0085] In some embodiments, since a normal thread can process both normal tasks and critical tasks, the electronic device determines that the idle thread is a target thread when the type of the idle thread is a normal thread type.
[0086] In other embodiments, if the type of the existing idle thread is not a common thread type, that is, the type of the idle thread is a critical thread type, the electronic device further determines whether the priority level of the target task is higher than the priority threshold, and in the case where the priority level of the target task is higher than the priority threshold, the idle thread is determined to be the first thread. In other words, the critical thread can only process critical tasks with a priority level higher than the priority threshold. If the idle thread in the electronic device is a critical thread, and the target task is a critical task, the idle thread can process the target task; if the idle thread in the electronic device is a critical thread, and the target task is an ordinary task with a priority level lower than or equal to the priority threshold, the idle thread cannot process the target task, and the target task needs to be placed in the pending task queue for waiting.
[0087] For example, please refer to Figure 8 , is an exemplary flow chart of a task processing method provided by an embodiment of the present application. Taking the electronic device as a server as an example, Figure 8 As shown, the task processing method may include the following steps 801 to 806:
[0088] Step 801: The server obtains a target task request.
[0089] Step 802, determine whether there is an idle common thread? If yes, execute step 803, otherwise, execute step 804.
[0090] Step 803: execute the target task on the corresponding idle thread.
[0091] Step 804, determine whether the priority level of the target task is higher than the priority threshold. If the priority level of the target task is higher than the priority threshold, execute step 805, otherwise execute step 806.
[0092] Step 805, determine whether there is an idle critical thread? If yes, execute step 803, otherwise execute step 806.
[0093] Step 806: The target task enters the queue of tasks to be processed.
[0094] Furthermore, after the target task enters the queue of pending tasks, if there is an idle thread in the electronic device, the task is obtained from the queue of pending tasks. For example, when a critical thread in the electronic device is idle, a critical task with a priority level higher than the priority threshold is selected from the queue of pending tasks for execution; if there is no critical task with a priority level higher than the priority threshold in the queue of pending tasks, the critical thread does not execute the task. When an ordinary thread in the electronic device is idle, the ordinary thread will fairly obtain tasks from the queue of pending tasks and execute them in sequence.
[0095] For example, please refer to Fig. 9 , is an exemplary flow chart of a task processing method provided by another embodiment of the present application. Taking the electronic device as a server as an example, Fig. 9 As shown, the task processing method may include the following steps 901 to 906:
[0096] Step 901: When the task queue of the thread is empty, the server enters an idle state.
[0097] Step 902, determine whether the idle thread is a key thread? If the idle thread is a key thread, execute step 903, otherwise execute step 904.
[0098] Step 903, determining whether there is a critical task in the queue of tasks to be processed, if there is a critical task in the queue of tasks to be processed, executing step 905, otherwise executing step 906.
[0099] Step 904, determine whether there is a task to be processed, if there is a task to be processed, execute step 905, otherwise execute step 906.
[0100] Step 905, executing the corresponding task.
[0101] Step 906: The idle thread goes into sleep mode and waits for a task to call.
[0102] In a possible implementation, the electronic device will also put the target task into a queue of pending tasks when there is no idle thread.
[0103] Furthermore, the tasks in the pending task queue may be arranged into one queue according to the order in which the tasks arrive, or may be arranged into two queues or more queues according to the priority levels of the tasks, and this application does not impose any specific limitation on this.
[0104] In some embodiments, the pending task queue includes tasks of all priority levels. The electronic device can detect whether there is an idle thread in the electronic device all the time, or detect at a preset time interval whether there is an idle thread. Then, if there is an idle thread and the idle thread is an ordinary thread, the first task in the pending task queue is processed by the ordinary thread, and the first task is the first task determined from all tasks in the pending task queue according to the first order; if there is an idle thread and the idle thread is a critical thread, the second task in the pending task queue is processed by the critical thread, and the second task is the first task determined from tasks in the pending task queue whose priority level is higher than the priority threshold according to the second order.
[0105] For example, please refer to Fig.10 , which is a schematic diagram of the task processing process provided by an embodiment of the present application. Assuming that the electronic device is a server, the server includes a task pool and a thread pool. The task pool includes a pending task queue. The pending task queue includes different types of tasks, such as critical tasks and ordinary tasks. The server maintains critical tasks and ordinary tasks in the pending task queue in the order of client submission time, and waits for the scheduling of the thread pool on this basis, that is, critical tasks and ordinary tasks are arranged in the order of arrival of the tasks. The thread pool includes multiple threads. Fig.10As shown in the figure, the critical tasks and common tasks that have arrived enter the task pool and are arranged in the pending task queue. At this time, there are 7 tasks arranged in the pending task queue, including 6 common tasks and 1 critical task. The thread pool includes 6 threads, namely 4 common threads and 2 critical threads. Among them, 3 common threads are processing tasks, 1 common thread is in idle waiting, and is getting the next task from the pending task queue to execute; 1 critical thread is processing tasks, and another critical thread is in idle waiting, and is getting the next critical task from the pending task queue to execute.
[0106] Optionally, the above Fig.10 In the process, if the ordinary thread is idle and there is no task to be executed in the pending task queue, the idle ordinary thread enters the waiting mode until a new task arrives. If the critical thread is idle, the critical thread can search forward from the end of the queue to execute the latest critical task in the queue; if there is no critical task in the pending task queue, the idle critical thread will enter the waiting mode until a new critical task arrives.
[0107] In other embodiments, the queue of tasks to be processed includes a common task queue and a critical task queue, the priority level of the tasks in the common task queue is lower than or equal to the priority threshold, and the priority level of the tasks in the critical task queue is higher than the priority threshold. The electronic device can detect all the time, or detect at preset time intervals whether there is an idle thread in the electronic device; then, if there is an idle thread and the idle thread is a common thread, the third task in the common task queue and the critical task queue is processed by the common thread, and the third task is the first task determined from all the tasks in the common task queue and the critical task queue according to the first order; if there is an idle thread and the idle thread is a critical thread, the fourth task in the critical task queue is processed by the critical thread, and the fourth task is the first task determined from the critical task queue according to the second order.
[0108] For example, please refer to Fig.11 , is a schematic diagram of a task processing process provided by another embodiment of the present application. Assuming that the electronic device is a server, the server includes a task pool and a thread pool, the task pool includes a common task queue and a critical task queue, the common task queue includes common tasks whose priority level is lower than or equal to the priority threshold, the critical task queue includes critical tasks whose priority level is higher than the priority threshold, the server adds the tasks of different priority levels to their respective queues according to the priority level of the task, and the thread pool includes multiple threads. Fig.11As shown, the critical tasks and common tasks that have arrived all enter the task pool and enter the corresponding queues based on the priority level of the tasks. At this time, 6 tasks are arranged in the common task queue and 3 tasks are arranged in the critical task queue. The thread pool includes 6 threads, namely 4 common threads and 2 critical threads. Among them, 3 common threads are processing tasks, 1 common thread is in idle waiting, and is getting the next task from the common task queue and the critical task queue to execute. The next task is the task that arrives first in the common task queue and the critical task queue; 1 critical thread is processing tasks, and another critical thread is in idle waiting, and is getting the next critical task from the critical task queue to execute.
[0109] Optionally, the above Fig.11 In the process, whether it is a common thread or a key thread in an idle state, when there is no available task to execute, it will enter a waiting state until a new task is added to the task queue it monitors.
[0110] In this embodiment, the electronic device first obtains a target task request, which includes a priority level of the target task, and then detects whether there is an idle thread in the electronic device, and if there is an idle thread, determines whether the type of the idle thread is a common thread type, and then determines that the idle thread is a target thread if the type of the idle thread is a common thread type, and further determines whether the priority level of the target task is higher than the priority threshold if the type of the existing idle thread is not a common thread type, and determines that the idle thread is a target thread if the priority level of the target task is higher than the priority threshold. In the task processing method, the priority level is formulated according to the urgency of the task, and a dedicated key thread is provided for tasks with a priority level higher than the priority threshold, so that when the electronic device faces a large number of backlog tasks, the response delay of the key tasks can be reduced and ensured that they are executed first, thereby enhancing the overall stability of the system and allowing the task processing volume to be fine-tuned by dynamically adjusting the proportion of the key threads in the thread pool, forming an efficient hybrid solution.
[0111] In addition, the above Fig.10 and Fig.11 The use of the thread pool in the illustrated embodiment can improve task processing capabilities, distinguish between ordinary tasks and critical tasks, achieve a balance between task processing speed and response time of different tasks, improve processing efficiency of critical tasks, and enhance user experience.
[0112] It should be understood that, although the steps in the above-mentioned flowcharts are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the above-mentioned flowcharts may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0113] Based on the foregoing embodiments, an embodiment of the present application provides a task processing device, which includes the modules included and the units included in the modules, and can be implemented by a processor; of course, it can also be implemented by a specific logic circuit; in the implementation process, the processor can be a central processing unit, a microprocessor, a digital signal processor or a field programmable gate array, etc.
[0114] Fig.12 A structural diagram of a task processing device provided in one embodiment of the present application is shown as follows: Fig.12 As shown, the task processing device 1200 includes an acquisition module 1201 and a processing module 1202, wherein:
[0115] The acquisition module 1201 is used to obtain a target task request, wherein the target task request includes a priority level of the target task; the processing module 1202 is used to process the target task through a first thread when the priority level of the target task is higher than the priority threshold, wherein the first thread is a thread in an idle state among the ordinary threads and the critical threads; the processing module 1202 is also used to process the target task through a second thread when the priority level of the target task is lower than or equal to the priority threshold, wherein the second thread is a thread in the idle state among the ordinary threads.
[0116] In some embodiments, the device further includes: a detection module and a determination module. The detection module is used to detect whether there is an idle thread in the electronic device; the determination module is used to determine the target thread for processing the target task according to preset conditions when the idle thread exists, the preset conditions including the priority level of the target task and / or the type of the idle thread, the type including a common thread type or a critical thread type, and the target thread including the first thread or the second thread.
[0117] In some embodiments, the target thread is the first thread, and the determination module is specifically used to: in the case where the idle thread exists, determine whether the priority level of the target task is higher than the priority threshold; in the case where the priority level of the target task is higher than the priority threshold, determine that the idle thread is the first thread.
[0118] In some embodiments, the target thread is the second thread, and the determination module is specifically used to: in the case where the idle thread exists, determine whether the priority level of the target task is higher than the priority threshold; in the case where the priority level of the target task is lower than or equal to the priority threshold, obtain the type of the idle thread; in the case where the type of the idle thread is the ordinary thread type, determine that the idle thread is the second thread.
[0119] In some embodiments, the determination module is specifically used to: when the idle thread exists, determine whether the type of the idle thread is the ordinary thread type; when the type of the idle thread is the ordinary thread type, determine that the idle thread is the target thread.
[0120] In some embodiments, the target thread is the first thread, and the device further includes: a judgment module. The judgment module is used to judge whether the priority level of the target task is higher than the priority threshold when the type of the idle thread is not the ordinary thread type; and a determination module is also used to determine that the idle thread is the first thread when the priority level of the target task is higher than the priority threshold.
[0121] In some embodiments, the device further comprises: a placing module, which is used to place the target task into a queue of pending tasks when there is no idle thread.
[0122] In some embodiments, the pending task queue includes tasks of all priority levels, and the detection module is further used to detect whether there is an idle thread in the electronic device; the processing module 1202 is further used to process the first task in the pending task queue through the ordinary thread when the idle thread exists and the idle thread is the ordinary thread, and the first task is the first task determined from all tasks in the pending task queue according to the first order; the processing module 1202 is further used to process the second task in the pending task queue through the critical thread when the idle thread exists and the idle thread is the critical thread, and the second task is the first task determined from tasks in the pending task queue whose priority level is higher than the priority threshold according to the second order.
[0123] In some embodiments, the queue of tasks to be processed includes a common task queue and a critical task queue, the priority level of the tasks in the common task queue is lower than or equal to the priority threshold, and the priority level of the tasks in the critical task queue is higher than the priority threshold, and the detection module is also used to detect whether there is an idle thread in the electronic device; the processing module 1202 is also used to process the third task in the common task queue and the critical task queue through the common thread when the idle thread exists and the idle thread is the common thread, and the third task is the first task determined from all the tasks in the common task queue and the critical task queue in the first order; the processing module 1202 is also used to process the fourth task in the critical task queue through the critical thread when the idle thread exists and the idle thread is the critical thread, and the fourth task is the first task determined from the critical task queue in the second order.
[0124] In some embodiments, the target task request includes a request data packet, a header of the request data packet is provided with a flag bit, and the flag bit is used to indicate the priority of the task.
[0125] The description of the above device embodiment is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. For technical details not disclosed in the device embodiment of the present application, please refer to the description of the method embodiment of the present application for understanding.
[0126] It should be noted that in the embodiments of this application Fig.12 The division of modules by the processing device of the task shown is schematic and is only a logical function division. There may be other division methods in actual implementation. In addition, each functional unit in each embodiment of the present application may be integrated into a processing unit, or may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional unit. It may also be implemented in the form of a combination of software and hardware.
[0127] It should be noted that in the embodiment of the present application, if the above method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiment of the present application can be essentially or partly embodied in the form of a software product that contributes to the relevant technology. The computer software product is stored in a storage medium, including several instructions to enable an electronic device to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk. In this way, the embodiment of the present application is not limited to any specific combination of hardware and software.
[0128] The embodiment of the present application provides a computer device, which may be a server, and its internal structure diagram may be as follows: Fig.13 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the above method is implemented.
[0129] An embodiment of the present application provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps in the method provided in the above embodiment are implemented.
[0130] An embodiment of the present application provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute the steps of the method provided in the above method embodiment.
[0131] Those skilled in the art will understand that Fig.13 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0132] In one embodiment, the task processing device provided by the present application can be implemented in the form of a computer program, which can be used in Fig.13The computer device shown in the figure is run. The memory of the computer device can store various program modules constituting the above-mentioned device. The computer program composed of various program modules enables the processor to execute the steps in the method of each embodiment of the present application described in this specification.
[0133] It should be noted here that the description of the above storage medium and device embodiments is similar to the description of the above method embodiments, and has similar beneficial effects as the method embodiments. For technical details not disclosed in the storage medium, storage medium and device embodiments of this application, please refer to the description of the method embodiments of this application for understanding.
[0134] It should be understood that "one embodiment" or "an embodiment" or "some embodiments" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in one embodiment" or "in some embodiments" appearing throughout the specification may not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present application, the size of the sequence number of the above-mentioned processes does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application. The above-mentioned sequence numbers of the embodiments of the present application are only for description and do not represent the advantages and disadvantages of the embodiments. The above description of each embodiment tends to emphasize the differences between the various embodiments, and the same or similar aspects can be referenced to each other. For the sake of brevity, this article will not repeat them.
[0135] The term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there may be three relationships. For example, object A and / or object B can represent three situations: object A exists alone, object A and object B exist at the same time, and object B exists alone.
[0136] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0137] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as: multiple modules or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or modules can be electrical, mechanical or other forms.
[0138] The modules described above as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules; they may be located in one place or distributed on multiple network units; some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.
[0139] In addition, all functional modules in the embodiments of the present application may be integrated into one processing unit, or each module may be a separate unit, or two or more modules may be integrated into one unit; the above-mentioned integrated modules may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0140] A person skilled in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM), magnetic disks or optical disks, etc., various media that can store program codes.
[0141] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application can essentially or in other words, the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling an electronic device to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0142] The methods disclosed in several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.
[0143] The features disclosed in several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.
[0144] The features disclosed in several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments or device embodiments.
[0145] The above is only an implementation method of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A task processing method, characterized in that: Applied to an electronic device, the electronic device includes a critical thread and a common thread, the common thread is used to process tasks of all priority levels, and the critical thread is used to process tasks with a priority level higher than a priority threshold, the method includes: Obtaining a target task request, wherein the target task request includes a priority level of the target task; In a case where the priority level of the target task is higher than the priority threshold, processing the target task through a first thread, where the first thread is an idle thread among the common thread and the critical thread; When the priority level of the target task is lower than or equal to the priority threshold, the target task is processed by a second thread, where the second thread is a thread in the idle state among the common threads.
2. The method according to claim 1, characterized in that After obtaining the target task request, the method further includes: Detecting whether there is an idle thread in the electronic device; In the case where the idle thread exists, the target thread for processing the target task is determined according to preset conditions, the preset conditions include the priority level of the target task and / or the type of the idle thread, the type includes a normal thread type or a critical thread type, and the target thread includes the first thread or the second thread.
3. The method according to claim 2, characterized in that The target thread is the first thread, and when the idle thread exists, determining the target thread for processing the target task according to a preset condition includes: In the case where the idle thread exists, determining whether the priority level of the target task is higher than the priority threshold; When the priority level of the target task is higher than the priority threshold, the idle thread is determined to be the first thread.
4. The method according to claim 2, characterized in that: The target thread is the second thread, and in the case where the idle thread exists, determining the target thread for processing the target task according to a preset condition includes: In the case where the idle thread exists, determining whether the priority level of the target task is higher than the priority threshold; When the priority level of the target task is lower than or equal to the priority threshold, obtaining the type of the idle thread; In a case where the type of the idle thread is the common thread type, the idle thread is determined to be the second thread.
5. The method according to claim 2, characterized in that: The step of determining, in the case where the idle thread exists, a target thread for processing the target task according to a preset condition comprises: In the case where the idle thread exists, determining whether the type of the idle thread is the common thread type; In a case where the type of the idle thread is the common thread type, the idle thread is determined to be the target thread.
6. The method according to claim 5, characterized in that The target thread is the first thread, and the method further includes: In a case where the type of the idle thread is not the common thread type, determining whether the priority level of the target task is higher than the priority threshold; When the priority level of the target task is higher than the priority threshold, the idle thread is determined to be the first thread.
7. The method according to claim 2, characterized in that: The method further comprises: In the absence of the idle thread, the target task is placed in a queue of tasks to be processed.
8. The method according to claim 7, characterized in that The pending task queue includes tasks of all priority levels, and the method further includes: Detecting whether there is an idle thread in the electronic device; In the case where the idle thread exists and the idle thread is the common thread, the first task in the to-be-processed task queue is processed by the common thread, where the first task is the first task determined from all the tasks in the to-be-processed task queue in a first order; In the case that the idle thread exists and the idle thread is the critical thread, the second task in the pending task queue is processed by the critical thread, and the second task is the first task determined in a second order from the tasks in the pending task queue whose priority level is higher than the priority threshold.
9. The method according to claim 7, characterized in that: The to-be-processed task queue includes a common task queue and a critical task queue, the priority level of the tasks in the common task queue is lower than or equal to the priority threshold, and the priority level of the tasks in the critical task queue is higher than the priority threshold, and the method further includes: Detecting whether there is an idle thread in the electronic device; In a case where the idle thread exists and the idle thread is the common thread, a third task in the common task queue and the critical task queue is processed by the common thread, wherein the third task is a first task determined from all tasks in the common task queue and the critical task queue in a first order; In the case that the idle thread exists and the idle thread is the critical thread, the fourth task in the critical task queue is processed by the critical thread, and the fourth task is the first task determined from the critical task queue according to the second order.
10. The method according to claim 1, characterized in that The target task request includes a request data packet, a header of the request data packet is provided with a flag bit, and the flag bit is used to indicate the priority of the task.
11. A task processing device, characterized in that: Applied to an electronic device, the electronic device includes a key thread and a common thread, the common thread is used to process tasks of all priority levels, and the key thread is used to process tasks with a priority level higher than a priority threshold, the device includes: An acquisition module, used for acquiring a target task request, wherein the target task request includes a priority level of the target task; a processing module, configured to process the target task through a first thread when the priority level of the target task is higher than the priority threshold, wherein the first thread is an idle thread among the common thread and the key thread; The processing module is further configured to process the target task through a second thread when the priority level of the target task is lower than or equal to the priority threshold, wherein the second thread is a thread in the idle state among the common threads.
12. A computer device comprising a memory and a processor, wherein the memory stores a computer program executable on the processor, wherein: When the processor executes the program, the steps of the method according to any one of claims 1 to 10 are implemented.
13. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 10 is implemented.
14. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 10 is implemented.
