A task execution method and device
By determining the execution order based on the estimated duration of the task, required system resources and priorities, and reasonably allocating system resources, the crash problem caused by uneven resource allocation when handling multiple task requests is solved, and the stability of the system and task execution efficiency are improved.
Patent Information
- Application Number
- CN202110502203.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-08
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2041-05-08
AI Technical Summary
When existing systems process multiple task requests, due to the influx of uneven thread resources, the memory is exhausted, and the system crashes, reducing the stability and reliability of the system.
By determining the execution order of tasks, the system resources are reasonably allocated according to the estimated duration of the task, required system resources and priorities, to prevent crashes caused by performance bottlenecks. The specific method includes calculating the feature value that represents the execution order, determining the execution order of the task based on the size of the feature value, placing the task in the task thread pool, and allowing the thread to execute the task in the execution order.
It improves the execution efficiency of system tasks, ensures the stability and reliability of the system, improves user experience and satisfaction, and prevents system crashes.
Smart Images

Figure CN113238861B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a task execution method and device. Background Art
[0002] The backend management system can handle various tasks, including generating reports, processing routine business data, unlocking accounts, etc.
[0003] After receiving multiple task requests, the existing system background randomly selects threads to execute tasks. When there are many tasks to be executed, the irregular influx of tasks to be executed will lead to uneven allocation of thread resources, memory exhaustion and system crash, thus reducing the stability and reliability of the system. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a task execution method and device, which can reasonably allocate system resources, prevent system crashes caused by performance bottlenecks, improve the execution efficiency of system tasks, ensure system stability and reliability, and enhance user experience and satisfaction.
[0005] To achieve the above object, according to one aspect of an embodiment of the present invention, a task execution method is provided, comprising:
[0006] determining one or more tasks to be performed;
[0007] Determining the execution order of the one or more tasks to be executed according to the task information of the tasks to be executed; the task information indicates any one or more of the following: an estimated execution time of the task, system resources required to execute the task, and a task priority;
[0008] The one or more tasks to be executed are placed in a task thread pool according to the execution order, so that the threads in the task thread pool execute the tasks according to the execution order.
[0009] Optionally, determining the execution order of the one or more tasks to be executed according to the task information of the tasks to be executed includes:
[0010] Calculate a characteristic value representing the execution order according to the estimated execution time of the task, the system resources required for the execution of the task, the task priority and a preset calculation strategy;
[0011] The execution order is determined according to the magnitude of the characteristic value.
[0012] Optionally, it also includes:
[0013] The characteristic value and the task identifier of the task to be executed are stored correspondingly.
[0014] Optionally, it also includes:
[0015] The task identifier and the task execution path of the task to be executed are stored in correspondence.
[0016] Optionally, placing the one or more tasks to be executed in a task thread pool according to the execution order includes:
[0017] Determining the number of tasks to be placed in the task thread pool;
[0018] Select one or more target feature values that are not greater than the number of tasks from the feature values, wherein a maximum value among the one or more target feature values is not greater than a minimum value among unselected feature values;
[0019] The target task identifier corresponding to the target feature value is determined, and according to the task execution path corresponding to the target task identifier, the to-be-executed task corresponding to the target task identifier is placed in the task thread pool.
[0020] Optionally, after placing the one or more tasks to be executed in the task thread pool according to the execution order, the method further includes:
[0021] Determine whether the system resources occupied by the task thread pool are greater than a warning threshold, and if so, suspend placing other to-be-executed tasks that are not placed in the task thread pool in the task thread pool.
[0022] Optionally, after pausing to place other tasks to be executed in the task thread pool, the method further includes:
[0023] Re-determine the execution order of other tasks to be executed that are not placed in the task thread pool according to the task information;
[0024] When the system resources occupied by the task thread pool are not greater than the warning threshold, the other tasks to be executed are placed in the task thread pool according to the re-determined execution order.
[0025] Optionally, a bidirectional linked list is used to store the task identifier and the task execution path correspondingly.
[0026] Optionally, placing the one or more tasks to be executed in a task thread pool according to the execution order includes:
[0027] Determine system load;
[0028] When the system load is less than a preset load threshold, executing the plurality of threads in parallel;
[0029] When the system load is not less than a preset load threshold, execution of some tasks is suspended.
[0030] According to another aspect of an embodiment of the present invention, there is provided a task execution device, comprising:
[0031] A determination module, used to determine one or more tasks to be performed;
[0032] A data processing module, configured to determine the execution order of the one or more tasks to be executed according to the task information of the tasks to be executed; the task information indicates any one or more of the following: an estimated execution time of the task, system resources required to execute the task, and a task priority;
[0033] The task processing module is used to place the one or more tasks to be executed in the task thread pool according to the execution order, so that the threads in the task thread pool execute the tasks according to the execution order.
[0034] According to another aspect of an embodiment of the present invention, there is provided a task execution electronic device, comprising:
[0035] one or more processors;
[0036] a storage device for storing one or more programs,
[0037] When the one or more programs are executed by the one or more processors, the one or more processors implement the task execution method provided by the present invention.
[0038] According to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the task execution method provided by the present invention is implemented.
[0039] An embodiment of the above invention has the following advantages or beneficial effects: because a technical means is adopted to determine the execution order of tasks according to parameters such as task priority, estimated execution time, and required resources, the technical problems of uneven system resource allocation and poor operating performance are overcome, thereby achieving the technical effect of being able to reasonably allocate system resources, prevent system crashes caused by performance bottlenecks, improve the execution efficiency of system tasks, and ensure the stability and reliability of the system.
[0040] The embodiment of the present invention provides a task execution method, which can ensure the stability and availability of the system by combining the priority of the task to be executed, the estimated execution cost and the load level of the system. When the system load is low, a multi-task concurrent execution mode can be adopted to make full use of hardware resources, speed up the task execution speed and increase the system throughput; when the system load is high, the purpose of reducing the system load is achieved by controlling the number of concurrent tasks or even suspending the execution of some tasks.
[0041] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0043] Figure 1 An exemplary system architecture diagram of a task execution method or a task execution device suitable for application in an embodiment of the present invention is shown;
[0044] Figure 2 is a flowchart of a task execution method according to an embodiment of the present invention;
[0045] Figure 3 is a flowchart of a method for determining a task execution order according to an embodiment of the present invention;
[0046] Figure 4 is a flow chart of a method for scheduling tasks to be executed according to an embodiment of the present invention;
[0047] Figure 5 is a schematic diagram of main modules of a task execution device according to an embodiment of the present invention;
[0048] Figure 6 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0049] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0050] Hash table: is a key-value data structure.
[0051] Figure 1 An exemplary system architecture diagram of a task execution method or a task execution device suitable for application in an embodiment of the present invention is shown. Figure 1 As shown, an exemplary system architecture of the task execution method or task execution device according to an embodiment of the present invention includes:
[0052] like Figure 1As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0053] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as security applications, data processing applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0054] The terminal devices 101 , 102 , and 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0055] The server 105 may be a server that provides various services, such as a background management server that provides support for security websites browsed by users using the terminal devices 101, 102, and 103. The background management server may analyze and process the received data such as the security performance report query request, and feed back the processing results (such as the security performance report) to the terminal devices 101, 102, and 103.
[0056] It should be noted that the task execution method provided in the embodiment of the present invention is generally executed by the server 105 , and accordingly, the task execution device is generally disposed in the server 105 .
[0057] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0058] Figure 2 is a schematic diagram of the main process of the task execution method according to an embodiment of the present invention, such as Figure 2 As shown, the task execution method of the present invention includes:
[0059] Step S201, determining one or more tasks to be executed.
[0060] In the embodiment of the present invention, after receiving the task processing request, the system analyzes the task processing request and determines the tasks to be executed therefrom. The tasks to be executed may include one or more tasks.
[0061] In an embodiment of the present invention, a task processing request may be a task that needs to be executed. For example, after receiving a task processing request for generating a report, the task processing request is analyzed to determine that the task to be executed is generating a report; after receiving a task processing request for data processing, the task to be executed is determined to be processing data; after receiving a task processing request for unlocking an account, the task to be executed is determined to be unlocking the account.
[0062] In an embodiment of the present invention, the tasks to be executed may be to generate monthly charts and monthly reports; pre-process the data generated by the business to increase the speed of business data aggregation; and unlock the user's account when it is locked due to too many incorrect password inputs.
[0063] Step S202, determining the execution order of the one or more tasks to be executed according to the task information of the tasks to be executed; the task information indicates any one or more of the following: estimated execution time of the task, system resources required to execute the task, and task priority.
[0064] In an embodiment of the present invention, after determining one or more tasks to be executed, the execution order of the one or more tasks to be executed is determined according to the task information of the tasks to be executed. The task information indicates any one or more of the following: task identification, estimated time to execute the task, system resources required to execute the task, task execution path, task name, task description, task issuer, and task priority, etc.
[0065] In an embodiment of the present invention, a task processing request may carry a tag related to the determination of task priority. When determining the task to be executed, the priority of the task to be executed is determined based on the task priority tag in the task processing request; wherein, the task priority can be represented by a number between 0 and 1, and the larger the number, the higher the priority of the task.
[0066] In the embodiment of the present invention, Figure 3 As shown, the present invention discloses a method for determining a task execution order, which mainly includes the following steps:
[0067] Step S301: Calculate a characteristic value representing the execution order according to the estimated execution time of the task, the system resources required for the task, the task priority, and the preset calculation strategy.
[0068] In an embodiment of the present invention, the preset calculation strategy can be a weighted calculation method, which takes the logarithm of the estimated duration of the task and the system resources required for the task with the benchmark duration and the benchmark resources as the base, and determines the first variable of the estimated duration of the task and the second variable of the system resources required for the task of the characteristic value; the task priority is represented by a number between 0 and 1, and the third task priority variable of the characteristic value is determined, the smaller the value, the higher the task priority; a certain weight is assigned to each variable of the characteristic value; after weighted calculation, the characteristic value is obtained.
[0069] In the embodiment of the present invention, the preset calculation strategy may also be a quadratic function, a multi-time function, etc. of multiple variables of the eigenvalue.
[0070] In the embodiment of the present invention, the characteristic value may be a value between 0 and 1. The larger the value, the greater the execution cost required to represent the task to be executed; the smaller the value, the smaller the execution cost required to represent the task to be executed.
[0071] Exemplarily, the estimated duration of the task is 5h and the base is 12h, and the variable of the estimated duration of the first task is determined to be 0.65; the system resources required for the task are 866M and the base is 1024M, and the variable of the system resources required for the second task is determined to be 0.98; the task priority is 0.3, and the variable of the third task priority is determined to be 0.3; the weight values of the three variables are 0.5, 0.2, and 0.4, respectively, and the obtained characteristic value is: 0.641.
[0072] In the embodiment of the present invention, when calculating the characteristic value according to the task information and the preset calculation strategy, it is determined whether the calculation time exceeds the preset time threshold. If yes, the characteristic value of the task to be executed is determined to be 1; if not, the calculation is continued according to the preset calculation strategy. For example, the preset time threshold is 3 seconds. When calculating the characteristic value, if the characteristic value of the task to be executed is not calculated after more than 3 seconds, the characteristic value of the task to be executed is determined to be 1; wherein the preset time threshold is usually no more than 5 seconds.
[0073] Step S302: The characteristic value and the task identifier of the task to be executed are stored in correspondence.
[0074] In the embodiment of the present invention, after determining the characteristic value of the task to be executed, the task identifier of the task to be executed and the determined characteristic value of the task to be executed are stored correspondingly. The task identifier can directly adopt the task identifier in the task processing request, or can redefine the task identifier of the task to be executed.
[0075] In an embodiment of the present invention, a hash table may be used to store the task identifier uuid and the characteristic value cost of the corresponding task to be executed. A hash table may correspond to one or more tasks to be executed, and each task to be executed corresponds to a hash table. When a hash table is used for storage, the task identifier uuid and the characteristic value cost of the corresponding task to be executed may be randomly stored.
[0076] In the embodiment of the present invention, the key-value pairs of task identifiers uuid and characteristic values cost corresponding to the plurality of tasks to be executed in the hash table may be arranged in ascending order of characteristic values.
[0077] Furthermore, the search time complexity of the hash table is O(1). No matter how large the data size is, the search time of the hash table remains unchanged, and the target data can be found after one calculation.
[0078] Step S303: Determine the execution order according to the size of the characteristic value.
[0079] In the embodiment of the present invention, the characteristic values of multiple tasks to be executed are sorted in descending order, and the execution order of the tasks to be executed is determined according to the sorting result. By sorting the tasks to be executed according to the execution cost, the system can reasonably allocate resources, give priority to the tasks with lower execution cost, and improve the task execution efficiency of the system.
[0080] Step S304: The task identifier and the task execution path of the task to be executed are stored in correspondence.
[0081] In the embodiment of the present invention, step S304 may be performed before any step among steps S301 - 303 , and may also be performed before step S202 .
[0082] In an embodiment of the present invention, a bidirectional linked list can be used to store the task identifier and task execution path of the corresponding task to be executed. The bidirectional linked list includes a head task node head and a tail task node tail. According to the execution order determined by the characteristic value cost, the task identifier and task execution path of the task to be executed are inserted into the specified position by inserting the node addNode. The bidirectional linked list has a fast insertion speed, which further improves the execution efficiency of the task. The head task node head of the bidirectional linked list is a virtual node, and the front pointer prev of the head task node head points to itself, which is convenient for the initialization of the linked list. Among them, the task storage path classpath is composed of the package name, class name and method name, for example, com.xx.yy.ReportService.runTask().
[0083] Furthermore, the bidirectional linked list also stores the task name, task description, task issuer, task execution status, task execution result, etc. The task issuer may be an account that sends a task processing request, such as an email address; the task execution status may be the status of whether the task to be executed is currently being executed; and the task execution result may be the result of whether the task execution is successful.
[0084] Furthermore, the insertion and deletion time complexities of a doubly linked list are both O(1), so that no matter how large the system data scale is, the time required for insertion and deletion of a doubly linked list remains unchanged, and the target data can be found after one calculation.
[0085] In an embodiment of the present invention, by calculating a characteristic value characterizing the execution order based on the estimated execution time of the task, the system resources required for the execution of the task, the task priority and the preset calculation strategy; determining the execution order based on the size of the characteristic value; storing the characteristic value and the task identifier of the task to be executed in correspondence; storing the task identifier and the task execution path of the task to be executed in correspondence, etc., the execution order of the tasks can be determined according to different parameter indicators of the tasks to be executed, so that the tasks to be executed can be executed in the determined execution order, thereby rationally utilizing system resources.
[0086] Step S203: placing the one or more tasks to be executed in a task thread pool according to the execution order, so that the threads in the task thread pool execute the tasks according to the execution order.
[0087] In an embodiment of the present invention, after determining the execution order of the tasks to be executed, one or more tasks to be executed are placed in the task thread pool according to the execution order, so that the threads in the task thread pool execute the tasks according to the execution order. By placing the tasks to be executed in the task thread pool according to the size of the characteristic value, that is, the execution cost, so that the thread pool executes the tasks to be executed in order, the tasks with low execution cost can be quickly executed to release resources, and then the tasks with high cost can be executed, which greatly improves the task execution efficiency. When executing tasks with high cost, there is no need to worry about whether resources are consumed, because the tasks with low cost have been executed first, so that the system can calmly execute the tasks with high cost, and further prevent the problem of system crash caused by memory exhaustion.
[0088] In the embodiment of the present invention, Figure 4 As shown, the present invention discloses a method for scheduling tasks to be executed, which mainly includes the following steps:
[0089] Step S401: determine the current system load and judge whether the current system load is not greater than the warning threshold. If yes, go to step S402; if not, go to step S406.
[0090] In an embodiment of the present invention, the warning threshold may be 90% of the rated system load. Before placing the task to be executed in the task thread pool, the current system load is determined, and then it is determined whether the task to be executed can be placed in the task thread pool according to the current system load. The current system load is the system resources occupied by the task thread pool.
[0091] Step S402: When the current system load is not greater than the warning threshold, the number of tasks to be placed in the task thread pool is determined.
[0092] In an embodiment of the present invention, when the current system load is not greater than the early warning threshold, according to the current load of the system, and / or the early warning threshold, and / or the system resources required for the execution of one or more tasks to be executed, and / or the number of idle threads in the task thread pool, determine the number of tasks to be placed in the task thread pool. For example, there are 3 idle threads in the task thread pool, then determine that the number of tasks to be placed in the task thread pool is 3. For another example, the current load of the system is 10G, the early warning threshold is 12G, the system resources required for the execution of 2 tasks to be executed are 2G, and there are 3 idle threads in the task thread pool, then determine that the number of tasks to be placed in the task thread pool is 2.
[0093] Step S403: Select one or more target feature values that are not greater than the number of tasks from the feature values, wherein the maximum value of the one or more target feature values is not greater than the minimum value of the unselected feature values.
[0094] In an embodiment of the present invention, after determining the number of tasks to be placed in the task thread pool, a target feature value that is not greater than the number of tasks is selected from the feature value according to the sorting of the feature values; wherein the target feature value may be one or more, and the maximum value of one or more target feature values is not greater than the minimum value of the unselected feature values. For example, the number of tasks is 8, and 3 target feature values are selected from the feature values, and the target feature values are 0.1, 0.5, and 0.6. The number of tasks to be executed with a target feature value of 0.1 is 3, the number of tasks to be executed with a target feature value of 0.5 is 4, and the number of tasks to be executed with a target feature value of 0.6 is 1. The minimum value of the unselected feature values is 0.6, and the number of tasks corresponding to the unselected feature value of 0.6 is 6; or, the minimum value of the unselected feature values is 0.75.
[0095] In the embodiment of the present invention, after determining the number of tasks to be placed in the task thread pool, the hash table is traversed to sort the characteristic values cost of all tasks to be executed, and a target characteristic value that is not greater than the number of tasks is found.
[0096] Step S404: determine the target task identifier corresponding to the target feature value, and place the to-be-executed task corresponding to the target task identifier into the task thread pool according to the task execution path corresponding to the target task identifier.
[0097] In an embodiment of the present invention, after determining one or more target characteristic values that are not greater than the number of tasks, the target task identifier corresponding to the target characteristic value is determined based on the target characteristic value; based on the target task identifier, the task execution path corresponding to the target task identifier is determined, and then the task to be executed corresponding to the target task identifier is placed in the thread of the task thread pool, so that the task to be executed is executed.
[0098] In an embodiment of the present invention, after traversing the hash table to find out the target feature value that is not greater than the number of tasks, the target task identifier corresponding to the target feature value is determined according to the key-value pair structure in the hash table. According to the target task identifier, the task execution path corresponding to the target task identifier in the doubly linked list is determined, and the removeNode method is called to remove the node corresponding to the target task identifier from the doubly linked list, and the task to be executed corresponding to the target task identifier is placed in the thread of the task thread pool, and the pointer relationship between the nodes before and after the removed node is reset. The speed of deleting the doubly linked list is fast, which further improves the execution efficiency of the task.
[0099] Step S405: Execute in a single thread or in parallel in multiple threads according to the number of tasks to be executed placed in the task thread pool.
[0100] In the embodiment of the present invention, after placing one or more tasks to be executed in the task thread pool, the tasks to be executed are executed. When there is one task to be executed, a single thread executes the task to be executed; when there are multiple tasks to be executed, multiple threads execute the tasks to be executed in parallel.
[0101] Step S406: When the current system load is greater than the warning threshold, determine whether the current system load is less than the preset load threshold. If yes, go to step 407; if not, go to step S408.
[0102] In the embodiment of the present invention, the preset load threshold may be 98% of the system rated load.
[0103] Step S407: Pause placing the tasks to be executed in the thread pool, and redetermine the execution order of the tasks to be executed, and go to step S401.
[0104] In an embodiment of the present invention, when it is determined that the current system load is greater than the warning threshold and less than the preset load threshold, the placement of tasks to be executed in the task thread pool is suspended, that is, the placement of other tasks to be executed that are not placed in the task thread pool in the task thread pool is suspended, so that the thread pool will first complete the execution of the tasks in the pool and release system resources before receiving new tasks to be executed. After suspending the placement of tasks to be executed in the thread pool, the multiple tasks to be executed are re-judged, and the execution order of other tasks to be executed that are not placed in the task thread pool is re-determined based on the task information of the tasks to be executed.
[0105] In an embodiment of the present invention, after proceeding to step S401, when it is determined that the current system load (i.e., the system resources occupied by the task thread pool) is not greater than the warning threshold, other tasks to be executed that have not been placed in the task thread pool are placed in the task thread pool according to the re-determined execution order.
[0106] Step S408: suspend execution of tasks of some threads in the task thread pool.
[0107] In an embodiment of the present invention, when it is determined whether the current system load is not less than a preset load threshold, the tasks of some threads in the task thread pool are suspended until it is determined that the system load is reduced below the warning threshold, and then the suspended tasks are gradually resumed to ensure stable operation of the system.
[0108] In an embodiment of the present invention, an update instruction corresponding to a received task processing request can be received at any time, and then the updated task processing request can be analyzed to determine the updated tasks to be executed, and the execution order of one or more tasks to be executed can be updated according to the task information of the tasks to be executed corresponding to the updated task processing request, so that the threads in the task thread pool execute tasks according to the updated execution order.
[0109] Exemplarily, the task execution method of the embodiment of the present invention can be executed by a scheduler. The scheduler applies to the system for a container to accommodate the task queue. The container has a maximum capacity (volume). Accordingly, the task queue has a limited number of tasks to prevent a large number of tasks from entering the task queue in a short period of time, thereby causing the system memory to be occupied / exhausted, causing the system service to crash. The task queue provides dequeue and enqueue methods. When the scheduler receives a task processing request, it calls the dequeue method, determines the task identifier uuid and the characteristic value cost (i.e., the execution cost) of the task to be executed based on the task information of multiple tasks to be executed, and stores them in the hash table; traverses the hash table, sorts the cost characteristic values of multiple tasks to be executed, and calls the addNode method of the bidirectional linked list to insert multiple tasks to be executed into the specified position in order.
[0110] The scheduler needs to monitor the system load at all times. When the system load is not greater than the warning threshold (for example, 90% of the system's rated load), the dequeue method is called to traverse the hash table to find the pending tasks whose characteristic value cost meets the conditions. The task identifier uuid of the pending tasks that meet the conditions is determined based on the key-value pair correspondence. Based on the task identifier uuid, the removeNode method is called to remove the corresponding node from the doubly linked list, and the forward and backward pointer relationship of the doubly linked list nodes is reset, and the pending tasks that meet the conditions are placed in the task thread pool.
[0111] After placing the tasks to be executed in the thread pool, the system load increases. When the scheduler monitors that the system load is greater than the warning threshold, it is determined whether the system load is less than the preset load threshold (for example, 98% of the rated load of the system). If so, suspend placing other tasks to be executed that are not placed in the task thread pool in the task thread pool, and redetermine the execution order of other tasks to be executed; if not, suspend the tasks of some threads in the task thread pool, and when the scheduler monitors that the system load drops below the warning threshold, gradually resume the suspended tasks, thereby ensuring the stable operation of the system. Further, after suspending the tasks of some threads, when the scheduler monitors that the system load drops below the resumption execution threshold, gradually resume the suspended tasks; wherein the resumption execution threshold can be 80% of the rated load of the system.
[0112] By determining the execution order of tasks to be executed based on the execution cost, the system pressure can be relieved, resources can be allocated reasonably, the system crash caused by performance bottlenecks can be prevented, and the execution efficiency of system tasks can be improved.
[0113] In an embodiment of the present invention, by determining one or more tasks to be executed; determining the execution order of the one or more tasks to be executed based on the task information of the tasks to be executed; placing the one or more tasks to be executed in a task thread pool according to the execution order so that the threads in the task thread pool execute the tasks according to the execution order, etc., it is possible to reasonably allocate system resources, prevent system crashes caused by performance bottlenecks, improve the execution efficiency of system tasks, and enhance user experience and satisfaction.
[0114] Figure 5 is a schematic diagram of the main modules of the task execution device according to an embodiment of the present invention, such as Figure 5 As shown, the task execution device 500 of the present invention includes:
[0115] The determination module 501 is used to determine one or more tasks to be executed.
[0116] In the embodiment of the present invention, after receiving the task processing request, the determination module 501 system analyzes the task processing request and determines the tasks to be executed therefrom. The tasks to be executed may include one or more.
[0117] The data processing module 502 is used to determine the execution order of the one or more tasks to be executed based on the task information of the tasks to be executed; the task information indicates any one or more of the following: the estimated execution time of the task, the system resources required to execute the task, and the task priority.
[0118] In the embodiment of the present invention, after the determination module 501 determines one or more tasks to be executed, the data processing module 502 determines the execution order of the one or more tasks to be executed according to the task information of the tasks to be executed. The task information indicates any one or more of the following: task identification, estimated time to execute the task, system resources required to execute the task, task execution path, task name, task description, task issuer, and task priority, etc.
[0119] Specifically, the data processing module 502 calculates a characteristic value representing the execution order according to the estimated execution time of the task, the system resources required for the task, the task priority and the preset calculation strategy; and determines the execution order according to the size of the characteristic value.
[0120] The task processing module 503 is used to place the one or more tasks to be executed in the task thread pool according to the execution order, so that the threads in the task thread pool execute the tasks according to the execution order.
[0121] In the embodiment of the present invention, after the data processing module 502 determines the execution order of the tasks to be executed, the task processing module 503 places one or more tasks to be executed in the task thread pool according to the execution order, so that the threads in the task thread pool execute the tasks according to the execution order. By placing the tasks to be executed in the task thread pool according to the size of the characteristic value, that is, the execution cost, the thread pool executes the tasks to be executed in order, and the tasks with low execution cost can be quickly executed to release resources, and then the tasks with high execution cost can be executed, which greatly improves the task execution efficiency. When executing tasks with high execution cost, there is no need to worry about whether resources are consumed, because the tasks with low execution cost have been executed first, so that the system can calmly execute the tasks with high execution cost, and further prevent the problem of system crash caused by memory exhaustion.
[0122] In the embodiment of the present invention, by determining modules such as modules, data processing modules and task processing modules, system resources can be reasonably allocated, system crashes caused by performance bottlenecks can be prevented, the execution efficiency of system tasks can be improved, and user experience and satisfaction can be improved.
[0123] Figure 6is a schematic diagram of the structure of a computer system of a terminal device suitable for implementing an embodiment of the present invention, such as Figure 6 As shown, the computer system 600 of the terminal device in the embodiment of the present invention includes:
[0124] A central processing unit (CPU) 601 can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage section 608 into a random access memory (RAM) 603. Various programs and data required for the operation of the system 600 are also stored in the RAM 603. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0125] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.
[0126] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present invention are executed.
[0127] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0128] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0129] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be arranged in a processor, for example, may be described as: a processor includes a determination module, a data processing module and a task processing module. The names of these modules do not constitute a limitation on the modules themselves in certain circumstances, for example, the task processing module may also be described as "a module that places tasks to be executed in a task thread pool in the order of execution".
[0130] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: determining one or more tasks to be executed; determining the execution order of the one or more tasks to be executed according to the task information of the tasks to be executed; the task information indicates any one or more of the following: the estimated execution time of the task, the system resources required to execute the task, and the task priority; placing the one or more tasks to be executed in the task thread pool according to the execution order, so that the threads in the task thread pool execute the tasks according to the execution order.
[0131] According to the technical solution of the embodiment of the present invention, system resources can be reasonably allocated, crashes caused by system performance bottlenecks can be prevented, the execution efficiency of system tasks can be improved, and user experience and satisfaction can be enhanced.
[0132] The existing system runs well at low load, but when the system load increases, the thread execution time becomes longer, the system resources cannot be released in time, and a large number of tasks are blocked, which leads to the system service crash. The technical solution of the embodiment of the present invention determines the execution order of tasks according to the execution cost, and dynamically adjusts the task execution mechanism according to the system load, which can realize the effective management of the tasks to be executed, first execute the tasks with low cost, then execute the tasks with high cost, and dynamically adjust according to the system load, so as to reasonably allocate system resources and prevent system crash. Different from the system crash caused by the accumulation of massive tasks in the prior art, the tasks with high priority can be executed first, for example, the security plan report of the month is checked at the beginning of each month, and it is set to the highest priority at the beginning of the month, the calculated characteristic value is low, and the priority execution can quickly check the monthly report; for example, the forecast report or user-specified report is not needed in the short term, and the amount of data processed by the report is extremely large, so it is set to a low priority. Due to the large time and system resources required for task execution, the execution cost is high, and the execution order is late, it can be executed when the system is idle to obtain the expected forecast report or user-specified report.
[0133] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A task execution method, characterized in that: include: determining one or more tasks to be performed; Determining the execution order of the one or more tasks to be executed according to the task information of the tasks to be executed; The task information indicates any one or more of the following: the estimated duration of the task, the system resources required for the task, and the task priority; specifically includes: calculating the characteristic value characterizing the execution order according to the estimated duration of the task, the system resources required for the task, the task priority, and the preset calculation strategy; determining the execution order according to the size of the characteristic value; wherein, calculating the characteristic value characterizing the execution order includes: taking the logarithm of the estimated duration of the task and the system resources required for the task with the benchmark duration and the benchmark resources as the base, and determining the first variable of the characteristic value for the estimated duration of the task and the second variable of the system resources required for the task; and setting the third priority variable of the characteristic value to a constant between 0 and 1, and the higher the priority, the smaller the corresponding value; setting weights for the first variable for the estimated duration of the task, the second variable for the system resources required for the task, and the third priority variable, and obtaining the characteristic value through weighted calculation; Placing the one or more tasks to be executed in the task thread pool according to the execution order, so that the threads in the task thread pool execute the tasks according to the execution order; specifically comprising: using a bidirectional linked list to store task identifiers and task execution paths of the tasks to be executed in correspondence; according to the task execution path corresponding to the target task identifier in the bidirectional linked list, removing the node corresponding to the target task identifier from the bidirectional linked list, placing the task to be executed corresponding to the target task identifier in the thread of the task thread pool, and resetting the pointer relationship between the previous and next nodes of the removed node; Placing the one or more tasks to be executed in the task thread pool according to the execution order includes: Determining the number of tasks to be placed in the task thread pool; Select one or more target feature values that are not greater than the number of tasks from the feature values, wherein a maximum value among the one or more target feature values is not greater than a minimum value among unselected feature values; The target task identifier corresponding to the target feature value is determined, and according to the task execution path corresponding to the target task identifier, the to-be-executed task corresponding to the target task identifier is placed in the task thread pool.
2. The method according to claim 1, characterized in that Also includes: The characteristic value and the task identifier of the task to be executed are stored correspondingly.
3. The method according to claim 1, characterized in that After placing the one or more tasks to be executed in the task thread pool according to the execution order, the method further includes: Determine whether the system resources occupied by the task thread pool are greater than a warning threshold, and if so, suspend placing other to-be-executed tasks that are not placed in the task thread pool in the task thread pool.
4. The method according to claim 3, characterized in that After the pausing of placing other tasks to be executed that are not placed in the task thread pool into the task thread pool, the method further includes: Re-determine the execution order of other tasks to be executed that are not placed in the task thread pool according to the task information; When the system resources occupied by the task thread pool are not greater than the warning threshold, the other tasks to be executed are placed in the task thread pool according to the re-determined execution order.
5. The method according to claim 1, characterized in that Placing the one or more tasks to be executed in the task thread pool according to the execution order includes: Determine system load; When the system load is less than a preset load threshold, executing the plurality of threads in parallel; When the system load is not less than a preset load threshold, execution of some tasks is suspended.
6. A task execution device, characterized in that: include: A determination module, used to determine one or more tasks to be performed; A data processing module, used to determine the execution order of the one or more tasks to be executed according to the task information of the tasks to be executed; the task information indicates any one or more of the following: an estimated execution time of the task, system resources required for execution of the task, and a task priority; specifically used to calculate a characteristic value representing the execution order according to the estimated execution time of the task, the system resources required for execution of the task, the task priority, and a preset calculation strategy; Determine the execution order according to the size of the characteristic value; wherein, calculate the characteristic value characterizing the execution order includes: taking the logarithm of the estimated execution time of the task and the system resources required for the task with the base time and base resources as the base, and determining the first estimated execution time variable of the characteristic value and the second required system resources variable of the task; and setting the third priority variable of the characteristic value to a constant between 0 and 1, and the higher the priority, the smaller the corresponding value; setting weights for the first estimated execution time variable of the task, the second required system resources variable of the task, and the third priority variable, and obtaining the characteristic value through weighted calculation; The task processing module is used to place the one or more tasks to be executed in the task thread pool according to the execution order, so that the threads in the task thread pool execute the tasks according to the execution order; specifically, it is used to use a bidirectional linked list to store task identifiers and task execution paths of the tasks to be executed in a corresponding manner; according to the task execution path corresponding to the target task identifier in the bidirectional linked list, remove the node corresponding to the target task identifier from the bidirectional linked list, place the task to be executed corresponding to the target task identifier in the thread of the task thread pool, and reset the pointer relationship between the previous and next nodes of the removed node; The task processing module is also used for: Determining the number of tasks to be placed in the task thread pool; Select one or more target feature values that are not greater than the number of tasks from the feature values, wherein a maximum value among the one or more target feature values is not greater than a minimum value among unselected feature values; The target task identifier corresponding to the target feature value is determined, and according to the task execution path corresponding to the target task identifier, the to-be-executed task corresponding to the target task identifier is placed in the task thread pool.
7. A task execution electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.
8. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Distributed task scheduling method, device and system
CN109144699A
Concurrent task processing method and device, computer equipment and storage medium
CN110990142A
Data processing method and device and electronic equipment
CN111400005A