Multi-thread task scheduling optimization method, device and equipment for self-adaptive scheduling strategy

By adopting adaptive scheduling strategies in multi-threaded task scheduling, dynamically switch scheduling strategies according to the resource usage of the task execution system, the problems of waste of resources and slow task execution caused by static scheduling strategies in the existing technology are solved, and task execution efficiency and resource utilization are improved.

CN120011016APending Publication Date: 2025-05-16BEIJING INSIGHT NETWORK CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510095055.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-21
Publication Date
2025-05-16

AI Technical Summary

Technical Problem

The existing multithreaded task scheduling scheme adopts static scheduling strategies, resulting in the inability to fully utilize system resources, and some tasks are slowly executed or resources are wasted.

Method used

It provides a multi-threaded task scheduling optimization method with adaptive scheduling strategy, and dynamically switches scheduling strategies by monitoring the use of software and hardware resources of the task execution system. If the resources are tight, select the thread in the thread pool to submit the task to execute the task; if the resources are not tight, select the policy to abandon the task when the task cannot be executed by the thread pool.

Benefits of technology

It improves task execution efficiency and resource utilization, and avoids the problems of resource waste and slow task execution caused by static scheduling strategies.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120011016A_ABST
    Figure CN120011016A_ABST
Patent Text Reader

Abstract

The invention discloses a multi-thread task scheduling optimization method, device and equipment for a self-adaptive scheduling strategy, and relates to the technical field of multi-thread task scheduling. The method comprises the following steps: firstly, monitoring to obtain the use condition of software and hardware resources of a task execution system, and then selecting a strategy for selecting a thread for submitting a task in a thread pool to execute the task as a multi-thread task scheduling scheme to be implemented if the software and hardware resources of the system are in shortage according to a monitoring result. Otherwise, a strategy used for abandoning execution of the task when the task cannot be executed by the thread pool is selected as a multi-thread task scheduling scheme to be implemented, and finally the scheduling scheme is transmitted to the system and implemented, so that the scheduling strategy is not static any more and is adaptive to the software and hardware resource use condition of the task execution system. The task execution efficiency and the resource utilization rate can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of multi-threaded task scheduling, and in particular relates to a multi-threaded task scheduling optimization method, device and equipment with an adaptive scheduling strategy. Background Art

[0002] Multithreading refers to the technology of implementing multiple threads concurrently in software or hardware. Computers with multithreading capabilities can execute more than one thread at the same time due to hardware support, thereby improving overall processing performance. Systems with this capability include symmetric multiprocessors, multi-core processors, and chip-level multiprocessing or simultaneous multithreading processors.

[0003] At present, the existing multi-threaded task scheduling schemes usually adopt static scheduling strategies, which often fail to fully utilize system resources, resulting in slow execution of some tasks or waste of resources. As the complexity of computer systems increases, the requirements for task scheduling are also getting higher and higher. Therefore, how to provide an adaptive scheduling strategy to optimize task execution efficiency and resource utilization is a topic that technicians in this field need to study urgently. Summary of the invention

[0004] The purpose of the present invention is to provide a multi-threaded task scheduling optimization method, device, computer equipment, computer readable storage medium and computer program product with an adaptive scheduling strategy to solve the problems of existing multi-threaded task scheduling schemes that cannot fully utilize system resources and some tasks are executed slowly or resources are wasted due to static scheduling strategies.

[0005] In order to achieve the above object, the present invention adopts the following technical solutions:

[0006] In a first aspect, a multi-threaded task scheduling optimization method with an adaptive scheduling strategy is provided, comprising:

[0007] Monitor the usage of software and hardware resources of the task execution system;

[0008] Determine whether the software and hardware resources of the task execution system are tight according to the usage of the software and hardware resources; if so, select the first scheduling strategy as the multi-threaded task scheduling scheme to be implemented; otherwise, select the second scheduling strategy as the multi-threaded task scheduling scheme to be implemented, wherein the first scheduling strategy refers to a strategy of selecting a thread that submits a task to execute the task in a thread pool of the task execution system, and the second scheduling strategy refers to a strategy of abandoning execution of the task when the task cannot be executed by the thread pool of the task execution system, and the thread pool includes multiple threads;

[0009] The multi-threaded task scheduling scheme is transmitted to the task execution system and implemented.

[0010] Based on the above invention content, a new multi-threaded task scheduling scheme is provided which can adaptively switch scheduling strategies to optimize task execution efficiency and resource utilization, that is, firstly monitor and obtain the usage of software and hardware resources of the task execution system, and then if it is found that the system software and hardware resources are tight according to the monitoring results, a strategy for selecting a thread in a thread pool to submit a task to execute the task is selected as the multi-threaded task scheduling scheme to be implemented, otherwise a strategy for abandoning the execution of the task when the task cannot be executed by the thread pool is selected as the multi-threaded task scheduling scheme to be implemented, and finally the scheduling scheme is transmitted to the system and implemented, so that by making the scheduling strategy no longer static but adaptive to the usage of software and hardware resources of the task execution system, the task execution efficiency and resource utilization can be improved, thereby solving the problems of the existing multi-threaded task scheduling scheme that cannot fully utilize system resources due to the static scheduling strategy and the slow execution of some tasks or waste of resources, which is convenient for practical application and promotion.

[0011] In a possible design, when the software and hardware resource usage includes CPU occupancy and memory usage, judging whether the software and hardware resources of the task execution system are tight according to the software and hardware resource usage includes:

[0012] According to the usage of the software and hardware resources, if it is found that the CPU occupancy rate exceeds the first threshold or the memory usage rate exceeds the second threshold, it is determined that the software and hardware resources of the task execution system are tight; otherwise, it is determined that the software and hardware resources of the task execution system are not tight.

[0013] In one possible design, the method further includes:

[0014] Monitor and obtain the status of each thread in the thread pool and the number of tasks to be executed in the task queue corresponding to the thread pool;

[0015] Determine the number of active threads according to the states of the threads, wherein the active threads refer to threads that are executing tasks or preparing to execute tasks;

[0016] If the number of active threads is equal to the number of core threads of the thread pool and the number of tasks to be executed is greater than zero, then increasing the number of threads in the thread pool until the total number of threads in the thread pool is equal to the maximum allowed number of threads in the thread pool, wherein the number of core threads refers to the number of threads that always remain alive in the thread pool;

[0017] If the number of active threads is less than the number of core threads and the number of tasks to be executed is equal to zero, the number of threads in the thread pool is reduced until the total number of threads in the thread pool is equal to the number of core threads.

[0018] In a possible design, when the thread pool corresponds to the task type one by one and a task queue length threshold is preset for the task type, the method further includes:

[0019] Monitor and obtain the number of tasks to be executed in the task queue corresponding to the thread pool;

[0020] If the number of tasks to be executed is greater than or equal to the task queue length threshold, then refuse to add the new task to the task queue corresponding to the thread pool, or refuse to add the new task to the task queue corresponding to the thread pool and record the rejection log in the database and / or notify the administrator of the rejection message by calling a third-party email API;

[0021] If the number of tasks to be executed is less than the task queue length threshold, new tasks are allowed to be added to the task queue corresponding to the thread pool.

[0022] In a possible design, adding a new task to a task queue corresponding to the thread pool includes:

[0023] Determine whether the task type of the new task is the task type corresponding to the thread pool;

[0024] If so, the new task is added to the task queue corresponding to the thread pool, and the task queue is rearranged in descending order according to the task priority.

[0025] In a possible design, there are multiple thread pools corresponding one-to-one to different task types, and multiple task queue length thresholds corresponding one-to-one to the multiple task types are not equal to each other.

[0026] In a second aspect, a multi-threaded task scheduling optimization device with an adaptive scheduling strategy is provided, including a resource usage monitoring unit, a scheduling strategy selection unit, and a scheduling scheme transmission unit which are sequentially communicatively connected;

[0027] The resource usage monitoring unit is used to monitor the usage of software and hardware resources of the task execution system;

[0028] The scheduling strategy selection unit is used to determine whether the software and hardware resources of the task execution system are tight according to the usage of the software and hardware resources. If so, a first scheduling strategy is selected as the multi-threaded task scheduling scheme to be implemented, otherwise a second scheduling strategy is selected as the multi-threaded task scheduling scheme to be implemented, wherein the first scheduling strategy refers to a strategy for selecting a thread that submits a task to execute the task in a thread pool of the task execution system, and the second scheduling strategy refers to a strategy for abandoning execution of the task when the task cannot be executed by the thread pool of the task execution system, and the thread pool includes multiple threads;

[0029] The scheduling scheme transmitting unit is used to transmit the multi-threaded task scheduling scheme to the task execution system and execute it.

[0030] In a third aspect, the present invention provides a computer device comprising a memory, a processor and a transceiver which are communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program to execute the multi-threaded task scheduling optimization method as described in the first aspect or any possible design of the first aspect.

[0031] In a fourth aspect, the present invention provides a computer-readable storage medium having instructions stored thereon. When the instructions are executed on a computer, the multi-threaded task scheduling optimization method as described in the first aspect or any possible design of the first aspect is executed.

[0032] In a fifth aspect, the present invention provides a computer program product, comprising a computer program or instructions, which, when executed by a computer, implements the multi-threaded task scheduling optimization method as described in the first aspect or any possible design of the first aspect.

[0033] Beneficial effects of the above scheme:

[0034] (1) The present invention creatively provides a new multi-threaded task scheduling scheme that can adaptively switch scheduling strategies to optimize task execution efficiency and resource utilization, that is, first monitor the software and hardware resource usage of the task execution system, and then if the monitoring results show that the system software and hardware resources are tight, select the strategy for selecting the thread that submits the task in the thread pool to execute the task as the multi-threaded task scheduling scheme to be implemented, otherwise select the strategy for abandoning the execution of the task when the task cannot be executed by the thread pool as the multi-threaded task scheduling scheme to be implemented, and finally transmit the scheduling scheme to the system and implement it. In this way, by making the scheduling strategy no longer static but adaptive to the software and hardware resource usage of the task execution system, the task execution efficiency and resource utilization can be improved, thereby solving the problems of the existing multi-threaded task scheduling scheme that cannot fully utilize system resources due to the static scheduling strategy and some tasks are executed slowly or resources are wasted, and facilitating practical application and promotion;

[0035] (2) The number of threads can be dynamically adjusted according to the status of the thread pool to further fully utilize system resources;

[0036] (3) A strategy for abandoning execution of a task when the task cannot be executed by the thread pool can be specifically implemented based on the comparison result between the number of tasks to be executed and the task queue length threshold, so as to further make full use of system resources. Tasks can also be classified and sorted according to their type and priority to ensure that high-priority tasks are executed in a timely manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0038] Figure 1 A flowchart of a multi-threaded task scheduling optimization method based on an adaptive scheduling strategy provided in an embodiment of the present application.

[0039] Figure 2 A flowchart of whether to increase or decrease the number of threads in a multi-threaded task scheduling optimization method provided in an embodiment of the present application.

[0040] Figure 3 A flowchart of whether to add a new task in a multi-threaded task scheduling optimization method provided in an embodiment of the present application.

[0041] Figure 4 A schematic diagram of the structure of a multi-threaded task scheduling optimization device with an adaptive scheduling strategy provided in an embodiment of the present application.

[0042] Figure 5 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the present invention will be briefly introduced below in combination with the drawings and the description of the embodiments or the prior art. Obviously, the following description of the structures of the drawings is only some embodiments of the present invention. For ordinary technicians in this field, other embodiments can be obtained based on these embodiments without creative work. It should be noted that the description of these embodiments is used to help understand the present invention, but does not constitute a limitation of the present invention.

[0044] It should be understood that although the terms first and second, etc. may be used herein to describe various objects, these objects should not be limited by these terms. These terms are only used to distinguish one object from another object. For example, a first object can be referred to as a second object, and similarly, a second object can be referred to as a first object without departing from the scope of the exemplary embodiments of the present invention.

[0045] It should be understood that the term "and / or" that may appear in this document is merely a description of the association relationship between associated objects, indicating that there may be three relationships. For example, A and / or B can indicate three situations: A exists alone, B exists alone, or A and B exist at the same time. For another example, A, B and / or C can indicate the existence of any one of A, B and C or any combination of them. The term " / and" that may appear in this document describes another type of association object relationship, indicating that there may be two relationships. For example, A / and B can indicate two situations: A exists alone or A and B exist at the same time. In addition, the character " / " that may appear in this document generally indicates that the previous and next associated objects are in an "or" relationship.

[0046] Example

[0047] like Figure 1 As shown, the multi-threaded task scheduling optimization method provided by the first aspect of this embodiment and the adaptive scheduling strategy can be, but is not limited to, executed by a computer device with certain computing resources, such as a cloud server, a personal computer (PC, which refers to a multi-purpose computer with a size, price and performance suitable for personal use; desktops, laptops, small laptops, tablets and ultrabooks are all personal computers), smart phones, personal digital assistants (PDA) or wearable devices. Figure 1As shown, the multi-threaded task scheduling optimization method may include but is not limited to the following steps S1 to S3.

[0048] S1. Monitor the usage of software and hardware resources of the task execution system.

[0049] In step S1, the task execution system is an existing system with multi-threaded processing capabilities, such as but not limited to symmetric multiprocessors, multi-core processors, and chip-level multiprocessors or simultaneous multithreaded processors. The software and hardware resource usage specifically refers to the usage of software and hardware resources such as CPU (Central Processing Unit), memory and / or disk, that is, specifically, the software and hardware resource usage includes but is not limited to CPU occupancy and memory usage, etc., which can be obtained by conventional monitoring using existing monitoring technologies. In addition, the software and hardware resource usage can be monitored periodically (for example, CPU occupancy and memory usage are monitored every 1 minute), or it can be monitored non-periodically.

[0050] S2. Determine whether the software and hardware resources of the task execution system are tight based on the usage of the software and hardware resources. If so, select the first scheduling strategy as the multi-threaded task scheduling scheme to be implemented, otherwise select the second scheduling strategy as the multi-threaded task scheduling scheme to be implemented, wherein the first scheduling strategy refers to a strategy for selecting the thread that submits the task to execute the task in the thread pool of the task execution system, and the second scheduling strategy refers to a strategy for abandoning the execution of the task when the task cannot be executed by the thread pool of the task execution system, and the thread pool includes multiple threads.

[0051] In the step S2, the number of the thread pools in the task execution system can be multiple and correspond to different multiple task types one by one, that is, for each task type, a corresponding thread pool is pre-built. At the same time, for each thread pool, there will be a corresponding task queue, so as to obtain the first task from the task queue one by one (the first task will be removed from the task queue after acquisition) and assign it to a thread in the corresponding multiple threads for execution. Specifically, when the software and hardware resource usage includes CPU occupancy and memory usage, it is judged whether the software and hardware resources of the task execution system are tight according to the software and hardware resource usage, including but not limited to: according to the software and hardware resource usage, if it is found that the CPU occupancy exceeds the first threshold or the memory usage exceeds the second threshold, it is judged that the software and hardware resources of the task execution system are tight, otherwise it is judged that the software and hardware resources of the task execution system are not tight. The aforementioned first threshold can be exemplified as 0.7, and the aforementioned second threshold can be exemplified as 85%.

[0052] In step S2, when the software and hardware resources are tight, the thread pool may be saturated, making it impossible for new tasks to enter the task queue and be processed by the thread pool normally. Therefore, the first scheduling strategy is adopted to ensure that tasks will not be easily discarded (because if the tasks are simply discarded, important business logic may not be executed, causing data inconsistency or business process interruption and other problems), and by allowing the thread that submits the task to execute the task, the part that submits the task (such as a business module) can feel the load pressure of the system (that is, it is actually a feedback mechanism): if a business module frequently triggers this situation, it means that the module may need to optimize or adjust the frequency of task submission, which also plays a role of load balancing to a certain extent, because the thread that submits the task shares the pressure of the thread pool when executing the rejected task, avoiding the thread pool from over-concentrating on processing tasks and causing system crashes. In addition, in scenarios with high resource utilization, the execution efficiency of threads in the thread pool may be reduced due to resource competition. The use of the first scheduling strategy can also utilize the resource environment where the task submitting thread is located (for example, it may have some local cache or other resources that can be used) to execute tasks, thereby reducing dependence on thread pool resources, alleviating the resource shortage to a certain extent, and ensuring the continuous processing of tasks, so that the system can still complete important tasks as much as possible under high load conditions.

[0053] In the step S2, when the hardware and software resources are not tight, it means that the overall system resources are relatively sufficient, and the thread pool has sufficient capacity to process tasks under normal circumstances. Even if the thread pool is saturated and the task queue is full occasionally, the impact of directly discarding the newly submitted tasks on the overall system functions and business processes is relatively small (because there will be enough resources to process the newly generated tasks in the future, and there is no need to take complex measures to ensure that the tasks can be executed as when the resources are tight). If the task is not discarded, but some more complex processing methods are adopted (such as letting the thread that submits the task execute, etc.), it may consume unnecessary system resources in the case of sufficient resources, such as taking up more CPU time or memory space, and may also disrupt the normal task execution order and thread scheduling logic, and have potential adverse effects on the performance and stability of the system. Therefore, the relatively "simple and crude" second scheduling strategy is adopted, under the background of normal resource use, it can efficiently maintain the operation of the thread pool, ensure that the thread pool focuses on processing the tasks that have been received and are waiting in line for processing, and avoid the problems of resource waste and performance fluctuation caused by excessive processing of rejected tasks.

[0054] S3. Transmit the multi-threaded task scheduling solution to the task execution system and execute it.

[0055] Therefore, based on the multi-threaded task scheduling optimization method described in the aforementioned steps S1 to S3, a new multi-threaded task scheduling scheme is provided that can adaptively switch scheduling strategies to optimize task execution efficiency and resource utilization, that is, first monitor the usage of the software and hardware resources of the task execution system, and then if it is found that the system software and hardware resources are tight according to the monitoring results, a strategy for selecting a thread in the thread pool to submit a task to execute the task is selected as the multi-threaded task scheduling scheme to be implemented, otherwise a strategy for abandoning the execution of the task when the task cannot be executed by the thread pool is selected as the multi-threaded task scheduling scheme to be implemented, and finally the scheduling scheme is transmitted to the system and implemented. In this way, by making the scheduling strategy no longer static but adaptive to the usage of the software and hardware resources of the task execution system, the task execution efficiency and resource utilization can be improved, thereby solving the problems of the existing multi-threaded task scheduling scheme that cannot fully utilize system resources due to the static scheduling strategy and some tasks are executed slowly or resources are wasted, which is convenient for practical application and promotion.

[0056] Based on the technical solution of the first aspect, this embodiment further provides a possible design of how to dynamically increase or decrease the number of threads in the thread pool. Figure 2 As shown, the method also includes but is not limited to the following steps S41 to S44.

[0057] S41. Monitor and obtain the status of each thread in the thread pool and the number of tasks to be executed in the task queue corresponding to the thread pool.

[0058] In step S41, the thread state specifically includes but is not limited to a RUNNABLE state, a TERMINATED state (for example, the thread has completed the task), a BLOCKED state (for example, waiting to acquire a lock, and it cannot continue to execute the task before the lock is released), a WAITING state and / or a TIMED_WAITING state (for example, waiting for a condition to be satisfied or waiting for a timeout to arrive), etc. These states can be obtained by conventional monitoring of existing monitoring technologies. At the same time, the number of tasks to be executed can also be obtained by conventional monitoring of existing monitoring technologies. In addition, the states of each thread and the number of tasks to be executed can be obtained by periodic monitoring (for example, monitoring the CPU occupancy rate and memory usage rate every 1 minute, etc.), or by non-periodic monitoring.

[0059] S42. Determine the number of active threads according to the states of the threads, wherein the active threads refer to threads that are executing tasks or are about to execute tasks.

[0060] In the step S42, the threads in the RUNNABLE state may be regarded as the active threads, and the number of the active threads may be obtained by counting. In addition, the threads in other states such as the TERMINATED state, the BLOCKED state, the WAITING state or the TIMED_WAITING state may be regarded as inactive threads.

[0061] S43. If the number of active threads is equal to the number of core threads of the thread pool and the number of tasks to be executed is greater than zero, the number of threads in the thread pool is increased until the total number of threads in the thread pool is equal to the maximum allowed number of threads in the thread pool, wherein the number of core threads refers to the number of threads that always remain alive in the thread pool.

[0062] In the step S43, the number of core threads can be exemplified as 3, that is, after the thread pool is just started, there is no thread running at first, and then when a task is submitted, the thread pool will create a new thread to process the task until the number of threads reaches 3, and these 3 threads will always survive, even if they are in an idle state, they will wait for the arrival of new tasks. When a new task is submitted to the thread pool, as long as the current number of active threads is less than the number of core threads, the thread pool will create a new thread to process the task. The maximum number of threads allowed specifies the upper limit of the number of threads that the thread pool can create, that is, when the task queue is full and the current number of threads is less than the maximum number of threads, the thread pool can create a new thread to process the task; and assuming that the 3 core threads in the thread pool are all busy and the task queue is full, if there are new tasks coming in, the thread pool will continue to create new threads until the total number of threads reaches 8 (that is, the maximum number of threads allowed is 8), so that when the task load is heavy, the task can be processed faster by increasing the number of threads.

[0063] S44. If the number of active threads is less than the number of core threads and the number of tasks to be executed is equal to zero, reduce the number of threads in the thread pool until the total number of threads in the thread pool is equal to the number of core threads.

[0064] Therefore, based on the above possible design one, the number of threads can be dynamically adjusted according to the state of the thread pool to further fully utilize system resources.

[0065] Based on the technical solution of the first aspect or possible design one described above, this embodiment further provides a possible design two for adding or rejecting a new task, that is, Figure 3 As shown, when the thread pool corresponds to the task type one by one and a task queue length threshold has been preset for the task type, the method further includes but is not limited to the following steps S51 to S53.

[0066] S51. Monitor and obtain the number of tasks to be executed in the task queue corresponding to the thread pool.

[0067] S52. If the number of tasks to be executed is greater than or equal to the task queue length threshold, refuse to add new tasks to the task queue corresponding to the thread pool, or refuse to add new tasks to the task queue corresponding to the thread pool and record the rejection log in the database and / or notify the administrator of the rejection message by calling a third-party email API.

[0068] S53. If the number of tasks to be executed is less than the task queue length threshold, allow new tasks to be added to the task queue corresponding to the thread pool.

[0069] In the aforementioned steps S51 to S53, if there are multiple thread pools corresponding one-to-one to different multiple task types, there may also be multiple task queue length thresholds corresponding one-to-one to the multiple task types that are not equal to each other; for example, for three different task types, the corresponding task queue length thresholds may be configured as 10, 8, and 4, respectively, according to specific needs. Specifically, adding a new task to the task queue corresponding to the thread pool includes but is not limited to: determining whether the task type of the new task is the task type corresponding to the thread pool; if so, adding the new task to the task queue corresponding to the thread pool, and reordering the task queue from high to low according to the task priority. In addition, for multiple different tasks with the same task priority in the task queue, it is also possible to add timestamps based on the tasks, and arrange the multiple different tasks in the task queue in order from early to late according to the adding time.

[0070] Therefore, based on the aforementioned possible design two, a strategy for abandoning execution of a task when the task cannot be executed by the thread pool can be specifically implemented according to the comparison result of the number of tasks to be executed and the task queue length threshold, so as to further make full use of system resources, and the tasks can also be classified and sorted according to their type and priority to ensure that high-priority tasks are executed in a timely manner.

[0071] like Figure 4 As shown, the second aspect of this embodiment provides a virtual device for implementing the multi-threaded task scheduling optimization method described in the first aspect or any possible design in the first aspect, including a resource usage monitoring unit, a scheduling strategy selection unit, and a scheduling scheme transmission unit that are sequentially connected in communication;

[0072] The resource usage monitoring unit is used to monitor the usage of software and hardware resources of the task execution system;

[0073] The scheduling strategy selection unit is used to determine whether the software and hardware resources of the task execution system are tight according to the usage of the software and hardware resources. If so, a first scheduling strategy is selected as the multi-threaded task scheduling scheme to be implemented, otherwise a second scheduling strategy is selected as the multi-threaded task scheduling scheme to be implemented, wherein the first scheduling strategy refers to a strategy for selecting a thread that submits a task to execute the task in a thread pool of the task execution system, and the second scheduling strategy refers to a strategy for abandoning execution of the task when the task cannot be executed by the thread pool of the task execution system, and the thread pool includes multiple threads;

[0074] The scheduling scheme transmitting unit is used to transmit the multi-threaded task scheduling scheme to the task execution system and execute it.

[0075] The working process, working details and technical effects of the aforementioned device provided in the second aspect of this embodiment can be referred to the first aspect or any possible design of the multi-threaded task scheduling optimization method described in the first aspect, and will not be repeated here.

[0076] like Figure 5 As shown, the third aspect of this embodiment provides a computer device for executing the multi-threaded task scheduling optimization method as described in the first aspect or any possible design in the first aspect, including a memory, a processor and a transceiver connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program, and execute the multi-threaded task scheduling optimization method as described in the first aspect or any possible design in the first aspect. Specifically, the memory may include, but is not limited to, a random access memory (Random-Access Memory, RAM), a read-only memory (Read-Only Memory, ROM), a flash memory (FlashMemory), a first-in-first-out memory (First Input First Output, FIFO) and / or a first-in-last-out memory (First Input Last Output, FILO), etc.; the processor may be, but is not limited to, a microprocessor of the STM32F105 series. In addition, the computer device may also include, but is not limited to, a power module, a display screen and other necessary components.

[0077] The working process, working details and technical effects of the aforementioned computer device provided in the third aspect of this embodiment can be referred to the multi-threaded task scheduling optimization method described in the first aspect or any possible design in the first aspect, and will not be repeated here.

[0078] The fourth aspect of this embodiment provides a computer-readable storage medium storing instructions including the multi-threaded task scheduling optimization method described in the first aspect or any possible design in the first aspect, that is, the computer-readable storage medium stores instructions, and when the instructions are executed on a computer, the multi-threaded task scheduling optimization method described in the first aspect or any possible design in the first aspect is executed. Wherein, the computer-readable storage medium refers to a carrier for storing data, which may include but is not limited to computer-readable storage media such as floppy disks, optical disks, hard disks, flash memories, USB flash drives and / or memory sticks, and the computer may be a general-purpose computer, a special-purpose computer, a computer network or other programmable devices.

[0079] The working process, working details and technical effects of the aforementioned computer-readable storage medium provided in the fourth aspect of this embodiment can be referred to the multi-threaded task scheduling optimization method described in the first aspect or any possible design in the first aspect, and will not be repeated here.

[0080] A fifth aspect of this embodiment provides a computer program product, including a computer program or an instruction, wherein the computer program or the instruction, when executed by a computer, implements the multi-threaded task scheduling optimization method as described in the first aspect or any possible design in the first aspect. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device.

[0081] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A multi-threaded task scheduling optimization method with an adaptive scheduling strategy, characterized in that: include: Monitor the usage of software and hardware resources of the task execution system; Determine whether the software and hardware resources of the task execution system are tight according to the usage of the software and hardware resources; if so, select the first scheduling strategy as the multi-threaded task scheduling scheme to be implemented; otherwise, select the second scheduling strategy as the multi-threaded task scheduling scheme to be implemented, wherein the first scheduling strategy refers to a strategy of selecting a thread that submits a task to execute the task in a thread pool of the task execution system, and the second scheduling strategy refers to a strategy of abandoning execution of the task when the task cannot be executed by the thread pool of the task execution system, and the thread pool includes multiple threads; The multi-threaded task scheduling scheme is transmitted to the task execution system and implemented.

2. The multi-threaded task scheduling optimization method according to claim 1, characterized in that: When the software and hardware resource usage includes CPU occupancy and memory usage, judging whether the software and hardware resources of the task execution system are tight according to the software and hardware resource usage includes: According to the usage of the software and hardware resources, if it is found that the CPU occupancy rate exceeds the first threshold or the memory usage rate exceeds the second threshold, it is determined that the software and hardware resources of the task execution system are tight; otherwise, it is determined that the software and hardware resources of the task execution system are not tight.

3. The multi-threaded task scheduling optimization method according to claim 1, characterized in that: The method further comprises: Monitor and obtain the status of each thread in the thread pool and the number of tasks to be executed in the task queue corresponding to the thread pool; Determine the number of active threads according to the states of the threads, wherein the active threads refer to threads that are executing tasks or preparing to execute tasks; If the number of active threads is equal to the number of core threads of the thread pool and the number of tasks to be executed is greater than zero, then increasing the number of threads in the thread pool until the total number of threads in the thread pool is equal to the maximum allowed number of threads in the thread pool, wherein the number of core threads refers to the number of threads that always remain alive in the thread pool; If the number of active threads is less than the number of core threads and the number of tasks to be executed is equal to zero, the number of threads in the thread pool is reduced until the total number of threads in the thread pool is equal to the number of core threads.

4. The multi-threaded task scheduling optimization method according to claim 1, characterized in that: When the thread pool corresponds to the task type one by one and a task queue length threshold is preset for the task type, the method further includes: Monitor and obtain the number of tasks to be executed in the task queue corresponding to the thread pool; If the number of tasks to be executed is greater than or equal to the task queue length threshold, then refuse to add the new task to the task queue corresponding to the thread pool, or refuse to add the new task to the task queue corresponding to the thread pool and record the rejection log in the database and / or notify the administrator of the rejection message by calling a third-party email API; If the number of tasks to be executed is less than the task queue length threshold, new tasks are allowed to be added to the task queue corresponding to the thread pool.

5. The multi-threaded task scheduling optimization method according to claim 4, characterized in that: Adding a new task to the task queue corresponding to the thread pool includes: Determine whether the task type of the new task is the task type corresponding to the thread pool; If so, the new task is added to the task queue corresponding to the thread pool, and the task queue is rearranged in descending order according to the task priority.

6. The multi-threaded task scheduling optimization method according to claim 4, characterized in that: There are multiple thread pools corresponding one-to-one to different task types, and multiple task queue length thresholds corresponding one-to-one to the multiple task types are not equal to each other.

7. A multi-threaded task scheduling optimization device with an adaptive scheduling strategy, characterized in that: It includes a resource usage monitoring unit, a scheduling strategy selection unit and a scheduling scheme transmission unit which are sequentially connected in communication; The resource usage monitoring unit is used to monitor the usage of software and hardware resources of the task execution system; The scheduling strategy selection unit is used to determine whether the software and hardware resources of the task execution system are tight according to the usage of the software and hardware resources. If so, a first scheduling strategy is selected as the multi-threaded task scheduling scheme to be implemented, otherwise a second scheduling strategy is selected as the multi-threaded task scheduling scheme to be implemented, wherein the first scheduling strategy refers to a strategy for selecting a thread that submits a task to execute the task in a thread pool of the task execution system, and the second scheduling strategy refers to a strategy for abandoning execution of the task when the task cannot be executed by the thread pool of the task execution system, and the thread pool includes multiple threads; The scheduling scheme transmitting unit is used to transmit the multi-threaded task scheduling scheme to the task execution system and execute it.

8. A computer device, characterized in that: It includes a memory, a processor and a transceiver which are communicatively connected in sequence, wherein the memory is used to store computer programs, the transceiver is used to send and receive messages, and the processor is used to read the computer program to execute the multi-threaded task scheduling optimization method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores instructions, and when the instructions are executed on the computer, the multi-threaded task scheduling optimization method as described in any one of claims 1 to 6 is executed.

10. A computer program product comprising a computer program or instructions, characterized in that When the computer program or the instruction is executed by a computer, the multi-threaded task scheduling optimization method as claimed in any one of claims 1 to 6 is implemented.