Data processing method, device and equipment
By dynamically managing the task discard rate of the thread pool and adjusting the discard rate according to the number of threads in the thread pool and the task execution time, the problem of resource waste caused by the fixed rejection policy of the thread pool is solved, and the task execution efficiency and resource utilization are improved.
Patent Information
- Application Number
- CN202410374818.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-28
- Publication Date
- 2024-09-17
AI Technical Summary
The rejection policy of the existing thread pool is fixed, resulting in a waste of resources and affecting task execution efficiency.
By dynamically managing the task discard rate of the thread pool, the discard rate is adjusted according to the number of threads in the thread pool and the task execution time to maximize resource utilization.
Improved task execution efficiency, reduced resource consumption, and rationally utilized resources.
Smart Images

Figure CN118656182A
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a data processing method, device and equipment. Background Art
[0002] The thread pool is a comprehensive multi-thread management tool, which mainly consists of three parts: threads, blocking queues, and rejection strategies. When a task is added to the thread pool, if there are idle threads in the thread pool, the idle threads will execute the task; if there are no idle threads in the thread pool, the task will be saved in the blocking queue and wait for idle threads to execute the task; if there are no idle threads in the thread pool and the blocking queue is full, the corresponding rejection strategy in the thread pool will be triggered to process these tasks, that is, to process these tasks based on the task discard rate set in the thread pool's rejection strategy.
[0003] Since the rejection strategy of the thread pool in the prior art is a fixed strategy, it may cause a certain waste of resources, thereby affecting the task execution efficiency. Summary of the invention
[0004] The embodiments of the present application provide a data processing method, apparatus and device for dynamically managing the task discard rate of a thread pool, improving task execution efficiency and maximizing resource utilization.
[0005] In a first aspect, the present application provides a data processing method, the method comprising:
[0006] Obtaining a first number of first threads in a thread pool within a first time period, wherein the first threads are threads that are executing tasks;
[0007] If the first number is greater than a preset thread threshold, determining a target task whose execution end time of the task executed in the thread pool is within the first time period;
[0008] Acquire valid tasks whose task execution time is less than a preset time threshold from the target tasks, and calculate the effective task ratio of the valid tasks in the target tasks;
[0009] The valid task proportion is compared with a preset proportion threshold to obtain a first comparison result, the first task discard rate of the thread pool in the first time period is compared with a preset discard threshold to obtain a second comparison result, and the second task discard rate of the thread pool in the second time period is determined based on the first comparison result and the second comparison result, wherein the first time period is adjacent to the second time period.
[0010] In an embodiment of the present application, a first number of first threads in a thread pool within a first time period is obtained. When the first number is greater than a preset thread threshold, a target task whose execution end time of a task executed in the thread pool is within the first time period is determined, and valid tasks whose task execution time is less than a preset time threshold are obtained from the target tasks, and the proportion of valid tasks in the target tasks is calculated, thereby reflecting the proportion of valid tasks whose task execution time is less than the preset time threshold within the first time period. When the proportion of valid tasks is relatively small, it indicates that the number of valid tasks in the first time period is small, and the threads in the thread pool need to spend a long time to execute each target task. The target task may need to wait for a long time before being executed by the threads in the thread pool, thereby causing the thread pool to consume a lot of resources, and the probability that the proportion of valid tasks in the second time period is relatively small is relatively high. Therefore, a higher second task discard rate is required to discard more target tasks, reduce the waiting time for the target task to be executed by the threads in the thread pool, reduce resource consumption, and improve task execution efficiency; and when the proportion of valid tasks is relatively small, it indicates that the number of valid tasks in the first time period is large, and the threads in the thread pool need to spend less time to execute each target task. The target task may need to wait for a shorter time before being executed by the threads in the thread pool, which may cause resource waste, and the probability that the proportion of valid tasks in the second time period is relatively large is relatively high. Therefore, a lower second task discard rate is required to discard fewer target tasks and make rational use of resources. Therefore, the present application compares the proportion of valid tasks with a preset proportion threshold to obtain a first comparison result, compares the first task discard rate of the thread pool in the first time period with the preset discard threshold to obtain a second comparison result, and determines the second task discard rate of the thread pool in a second time period adjacent to the first time period based on the first comparison result and the second comparison result, thereby realizing dynamic management of the rejection strategy of the thread pool, thereby improving task execution efficiency and maximizing resource utilization.
[0011] In a second aspect, the present application provides a data processing device, the device comprising:
[0012] An acquisition module, configured to acquire a first number of first threads in a thread pool within a first time period, wherein the first threads are threads that are executing tasks;
[0013] A first determination module, configured to determine, if the first number is greater than a preset thread threshold, a target task whose execution end time of the task executed in the thread pool is within the first time period;
[0014] A calculation module, used to obtain valid tasks whose task execution time is less than a preset time threshold from the target tasks, and calculate the effective task ratio of the valid tasks in the target tasks;
[0015] The second determination module is used to compare the valid task ratio with a preset ratio threshold to obtain a first comparison result, compare the first task discard rate of the thread pool in the first time period with a preset discard threshold to obtain a second comparison result, and determine the second task discard rate of the thread pool in the second time period based on the first comparison result and the second comparison result, wherein the first time period is adjacent to the second time period.
[0016] In a third aspect, the present application provides an electronic device, including:
[0017] A memory for storing program instructions;
[0018] The processor is used to call the program instructions stored in the memory, and execute the steps included in any one of the methods in the first aspect according to the obtained program instructions.
[0019] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a computer, the computer executes any one of the methods described in the first aspect.
[0020] In a fifth aspect, the present application provides a computer program product, comprising: a computer program code, when the computer program code is run on a computer, the computer executes any one of the methods described in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0022] Figure 1 is a schematic diagram of an application scenario according to an exemplary embodiment;
[0023] Figure 2 is a flow chart of a data processing method according to an exemplary embodiment;
[0024] Figure 3 is a specific flow chart of a data processing method according to an exemplary embodiment;
[0025] Figure 4 is a flow chart showing a method for determining whether a task is a valid task according to an exemplary embodiment;
[0026] Figure 5is a detailed flow chart of a method for determining whether a task is a valid task according to an exemplary embodiment;
[0027] Figure 6 is a detailed flow chart of a data processing method according to an exemplary embodiment;
[0028] Figure 7 is a schematic diagram of a data processing device according to an exemplary embodiment;
[0029] Figure 8 The invention is a schematic diagram of an electronic device showing a data processing method according to an exemplary embodiment. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical scheme and advantages of the present application clearer, the technical scheme in the embodiment of the present application will be clearly and completely described below in conjunction with the drawings in the embodiment of the present application. Obviously, the described embodiment is only a part of the embodiment of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application. In the absence of conflict, the embodiments in the present application and the features in the embodiments can be arbitrarily combined with each other. In addition, although the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in an order different from that here.
[0031] The terms "first" and "second" in the specification and claims of the present application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the term "comprising" and any of their variations are intended to cover non-exclusive protection. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices. "Multiple" in the present application can mean at least two, for example, two, three or more, and the embodiments of the present application are not limited.
[0032] In the technical solution of this application, the collection, dissemination, and use of data are in compliance with the requirements of relevant national laws and regulations.
[0033] Before introducing the data processing method provided in the embodiment of the present application, in order to facilitate understanding, the technical background of the embodiment of the present application is first introduced in detail below.
[0034] The thread pool is a comprehensive multi-thread management tool, which mainly consists of three parts: threads, blocking queues, and rejection strategies. When a task is added to the thread pool, if there are idle threads in the thread pool, the idle threads will execute the task; if there are no idle threads in the thread pool, the task will be saved in the blocking queue and wait for idle threads to execute the task; if there are no idle threads in the thread pool and the blocking queue is full, the corresponding rejection strategy in the thread pool will be triggered to process these tasks, that is, to process these tasks based on the task discard rate set in the thread pool's rejection strategy.
[0035] Currently, there are four rejection strategies: the first rejection strategy is DiscardPolicy. When a task is rejected when added to the thread pool, this rejection strategy discards the rejected task by default; the second rejection strategy is DiscardOldestPolicy: when a task is rejected when added to the thread pool, this rejection strategy abandons the oldest unprocessed task in the blocking queue and adds the rejected task to the blocking queue; the third rejection strategy is CallerRunsPolicy: when a task is rejected when added to the thread pool, this rejection strategy prohibits the thread pool from executing the rejected task, that is, the rejected task will be executed by the caller thread; the fourth rejection strategy is AbortPolicy: when a task is rejected when added to the thread pool, this rejection strategy will throw a RejectedExecutionException.
[0036] In the prior art, one of the above four rejection strategies is usually randomly selected as the rejection strategy of the thread pool, that is, the rejection strategy of the thread pool is a fixed strategy (the task discard rate is fixed), which may cause a certain waste of resources and thus affect the task execution efficiency.
[0037] In order to solve the above problems, the present application provides a data processing method, device and equipment for realizing dynamic management of the task abandonment rate of the thread pool, improving the task execution efficiency and maximizing resource utilization.
[0038] First reference Figure 1, which is a schematic diagram of an application scenario of an embodiment, including a collector 10 and a server 11. The collector 10 and the server 11 are connected in communication via a network, and the network may be a local area network, a wide area network, etc. The server 11 may be any device that can provide Internet services. The collector 10 may be a device for monitoring a thread pool. The collector 10 is used to collect a first number of first threads in a thread pool within a first time period, and send the first number to the server 11. When the first number is greater than a preset thread threshold, the server 11 determines the target task of the execution end time of the task executed in the thread pool within the first time period, and determines the second task discard rate of the thread pool in the second time period based on the target task in the first time period and the first task discard rate of the thread pool in the first time period.
[0039] A possible form of communication between the collector 10 and the server 11 is that the server 11 obtains a first number of first threads in the thread pool within a first time period collected by the collector 10, wherein the first thread is a thread that is executing a task; if the first number is greater than a preset thread threshold, then the target task whose execution end time of the task executed in the thread pool is within the first time period is determined; valid tasks whose task execution time is less than a preset time threshold are obtained from the target task, and the proportion of valid tasks in the target task is calculated; the proportion of valid tasks is compared with the preset proportion threshold to obtain a first comparison result, the first task discard rate of the thread pool in the first time period is compared with the preset discard threshold to obtain a second comparison result, and the second task discard rate of the thread pool in the second time period is determined based on the first comparison result and the second comparison result, wherein the first time period is adjacent to the second time period.
[0040] In some embodiments, a data processing method is described below through a specific embodiment. Figure 2 As shown, including:
[0041] Step 201, obtaining a first number of first threads in a thread pool within a first time period;
[0042] The first thread is a thread that is executing a task, and the first thread can also be called an active thread. The first time period can be set according to actual conditions, for example, the first time period can be 1 minute or 10 seconds. Taking the first time period of 10 seconds as an example, the first number of first threads in the thread pool from 1:00:00 to 1:00:10 is obtained.
[0043] A thread pool can be created through ThreadPoolExecutor (a service), which is the base class of thread pool provided by JDK (Java Development Kit, software development kit), which defines the core framework of the thread pool and allows the client to implement a custom thread pool by inheritance.
[0044] Step 202, if the first number is greater than a preset thread threshold, determining a target task whose execution end time of the task executed in the thread pool is within the first time period;
[0045] The preset thread threshold can be set according to actual conditions. For example, the preset thread threshold can be the sum of the number of core threads and the number of temporary threads. The number of core threads is the maximum number of threads that will be retained in the thread pool. When there are no idle core threads in the thread pool, new tasks will be added to the blocking queue. When the tasks in the blocking queue are full, the thread pool will create temporary threads to support task processing. Temporary threads are threads that release resources after reaching the set survival time.
[0046] After obtaining the first number of first threads in the thread pool within the first time period, the present application further includes: if the first number is less than or equal to a preset thread threshold, controlling the threads in the thread pool to execute tasks.
[0047] Step 203, obtaining valid tasks whose task execution time is less than a preset time threshold from the target tasks, and calculating the valid task ratio of the valid tasks in the target tasks;
[0048] The preset time threshold may be set according to actual conditions. For example, the preset time threshold may be 3 seconds or 5 seconds.
[0049] Optionally, the effective task ratio of the effective tasks in the target tasks is calculated, including:
[0050] The effective task ratio is determined based on the second number of effective tasks in the target tasks and the total number of target tasks.
[0051] Step 204: compare the proportion of valid tasks with a preset proportion threshold to obtain a first comparison result, compare the first task discard rate of the thread pool in the first time period with the preset discard threshold to obtain a second comparison result, and determine the second task discard rate of the thread pool in the second time period based on the first comparison result and the second comparison result.
[0052] The first time period is adjacent to the second time period, for example, the first time period is 1:00:00-1:00:10, and the second time period is 1:00:10-1:00:20. The proportion threshold includes a first proportion threshold and a second proportion threshold, the first proportion threshold is less than the second proportion threshold, and the first proportion threshold and the second proportion threshold can be set according to actual conditions, for example, the first proportion threshold can be 0.2, and the second proportion threshold can be 0.35. The discard threshold includes a first discard threshold and a second discard threshold, the first discard threshold is less than the second discard threshold, and the first discard threshold and the second discard threshold can be set according to actual conditions, for example, the first discard threshold can be 0.05, and the second discard threshold can be 1.
[0053] In an embodiment of the present application, a first number of first threads in a thread pool within a first time period is obtained. When the first number is greater than a preset thread threshold, a target task whose execution end time of a task executed in the thread pool is within the first time period is determined, and valid tasks whose task execution time is less than a preset time threshold are obtained from the target tasks, and the proportion of valid tasks in the target tasks is calculated, thereby reflecting the proportion of valid tasks whose task execution time is less than the preset time threshold within the first time period. When the proportion of valid tasks is relatively small, it indicates that the number of valid tasks in the first time period is small, and the threads in the thread pool need to spend a long time to execute each target task. The target task may need to wait for a long time before being executed by the threads in the thread pool, thereby causing the thread pool to consume a lot of resources, and the probability that the proportion of valid tasks in the second time period is relatively small is relatively high. Therefore, a higher second task discard rate is required to discard more target tasks, reduce the waiting time for the target task to be executed by the threads in the thread pool, reduce resource consumption, and improve task execution efficiency; and when the proportion of valid tasks is relatively small, it indicates that the number of valid tasks in the first time period is large, and the threads in the thread pool need to spend less time to execute each target task. The target task may need to wait for a shorter time before being executed by the threads in the thread pool, which may cause resource waste, and the probability that the proportion of valid tasks in the second time period is relatively large is relatively high. Therefore, a lower second task discard rate is required to discard fewer target tasks and make rational use of resources. Therefore, the present application compares the proportion of valid tasks with a preset proportion threshold to obtain a first comparison result, compares the first task discard rate of the thread pool in the first time period with the preset discard threshold to obtain a second comparison result, and determines the second task discard rate of the thread pool in a second time period adjacent to the first time period based on the first comparison result and the second comparison result, thereby realizing dynamic management of the rejection strategy of the thread pool, thereby improving task execution efficiency and maximizing resource utilization.
[0054] The specific steps of the data processing method provided above are described in detail below. Figure 3 As shown:
[0055] Step 301, obtaining a first number of first threads in a thread pool within a first time period.
[0056] Before obtaining the first number of first threads in the thread pool within the first time period, the present application needs to determine whether the tasks executed by the threads in the thread pool are valid tasks. Figure 4 is a flowchart showing a method for determining whether a task is a valid task according to an exemplary embodiment. Figure 4 As shown, including:
[0057] Step 401, for any task, determining the execution start time and execution end time of any task executed by the thread pool;
[0058] Specifically, the hook function is used to determine the execution start time and execution end time of any task executed by the thread pool.
[0059] Among them, the hook function includes beExecute method and afterExecute method. This application rewrites the beExecute method and afterExecute method of the thread pool to use the beExecute method to determine the execution start time of any task executed by the thread pool, and uses the afterExecute method to determine the execution end time of any task executed by the thread pool. Each thread in the thread pool can save the execution start time and execution end time of each task it executes.
[0060] Step 402, determining the task execution duration of any task based on the execution start time and execution end time of any task;
[0061] Specifically, the difference between the execution end time of any task and the execution start time of any task is used as the task execution duration of any thread task.
[0062] This application can use the following formula to determine the task execution time of any thread task:
[0063] useTime=endTime-startTime;
[0064] Among them, endTime is the execution end time of any task, and startTime is the execution start time of any task.
[0065] For example, the beExecute method is used to determine that the execution start time of task A executed by the thread pool is 2:00:00, and the afterExecute method is used to determine that the execution end time of task A executed by the thread pool is 2:00:01, and the task execution duration of task A is determined to be 1 second.
[0066] Step 403: If the task execution time of any task is less than the time threshold, then any task is determined to be a valid task.
[0067] The time threshold can be set according to actual conditions. For example, the time threshold is 5 seconds.
[0068] Optionally, after determining the task execution duration of any thread task based on the execution start time and the execution end time of any task, the method further includes:
[0069] If the task execution time of any task is greater than or equal to the time threshold, then the task is determined to be a non-valid task.
[0070] Taking the time threshold of 5 seconds as an example, if the hook function is used to determine that the execution start time of Task 1 executed by the thread pool is 2:00:00 and the execution end time of Task 1 is 2:00:03, then the task execution time of Task 1 is determined to be 3 seconds, and the task execution time of Task 1 is less than 5 seconds, so Task 1 is determined to be a valid task. If the hook function is used to determine that the execution start time of Task 2 executed by the thread pool is 2:00:01 and the execution end time of Task 2 is 2:00:07, then the task execution time of Task 2 is determined to be 6 seconds, and the task execution time of Task 2 is greater than 5 seconds, so Task 2 is determined to be an invalid task.
[0071] After determining that any task is a valid task, the present application can mark any task with a set first tag value to characterize any task as a valid task, wherein the first tag value can be set according to actual conditions, for example, the first tag value can be 1. In addition, the present application can save the first tag value of any task, the task execution duration, the execution end time and other data in a database, which can be Redis (Remote Dictionary Server, remote dictionary service) or other databases. In the embodiment of the present application, the database takes Redis as an example. After determining that any task is a non-valid task, the present application can mark any task with a set second tag value to characterize any task as a non-valid task, wherein the second tag value can be set according to actual conditions, for example, the second tag value can be 0. In addition, the present application can save the second tag value of any task, the task execution duration, the execution end time and other data in Redis.
[0072] The specific steps of the method for determining whether each task is a valid task provided above are described in detail below. Figure 5 As shown, including:
[0073] Step 501, using a hook function to determine the execution start time and execution end time of the task executed by the thread pool;
[0074] Step 502, determining the task execution duration of the task based on the execution start time and the execution end time of the task;
[0075] Step 503, determine whether the task execution time of the task is less than the time threshold, if so, execute step 504, otherwise, execute step 505;
[0076] Step 504, determining that the task is a valid task;
[0077] Step 505: determine whether the task is a non-valid task.
[0078] In an embodiment of the present application, based on the execution start time and execution end time of any task executed by the determined thread pool, the task execution duration of any thread task is determined, thereby improving the accuracy of the determined task execution duration of any thread task, and when the task execution duration of any task is less than a time threshold, any task is determined to be a valid task, thereby improving the accuracy of judging whether any thread task is a valid task.
[0079] Step 302 , determining whether the first number is less than or equal to the thread threshold, if so, executing step 303 , otherwise executing step 304 .
[0080] Step 303, controlling the threads in the thread pool to execute tasks.
[0081] Among them, the method of controlling the threads in the thread pool to execute tasks is a prior art and will not be described in detail here.
[0082] Step 304: Determine the target task whose execution end time of the task executed in the thread pool is within the first time period.
[0083] Specifically, the data of all tasks are retrieved from Redis, the data of each task including the tag value, task execution duration, execution end time and other data, and the execution end time of the task executed in the thread pool is determined to be a target task within the first time period.
[0084] For example, the first time period is 10 seconds, i.e., 2:00:00-2:00:10. If the execution end time of Task 1 is 2:00:01, the execution end time of Task 2 is 1:59:58, and the execution end time of Task 3 is 2:00:09, then it is determined that the execution end time of Task 1 and Task 3 is within the first time period. Therefore, Task 1 and Task 2 are target tasks.
[0085] In addition to the above method, the present application can also filter out target tasks whose difference between the end time of the first time period and the task execution end time is less than or equal to the first time period based on the task execution end time and the first time period.
[0086] Specifically, the target tasks can be filtered out using the following formula:
[0087] currentTime-endTime<=timeGap;
[0088] Among them, currentTime is the end time of the first time period, endTime is the execution end time of the task, and timeGap is the first time period.
[0089] For example, the first time period is 10 seconds, i.e., 2:00:00-2:00:10, and the end time of the first time period is 2:00:10. If the execution end time of Task 1 is 2:00:03, the execution end time of Task 2 is 1:59:56, the execution end time of Task 3 is 2:00:08, and the execution end time of Task 4 is 2:00:04, then the difference between the end time of the first time period and the execution end time of Task 1 is 7 seconds, the difference between the end time of the first time period and the execution end time of Task 2 is 14 seconds, the difference between the end time of the first time period and the execution end time of Task 3 is 2 seconds, and the difference between the end time of the first time period and the execution end time of Task 4 is 6 seconds. It is determined that the difference between Task 1, Task 3, and Task 4 is less than the first time period, and therefore, Task 1, Task 3, and Task 4 are determined to be target tasks.
[0090] Step 305 , obtaining valid tasks whose task execution time is less than a preset time threshold from the target tasks, and calculating the valid task ratio of the valid tasks in the target tasks.
[0091] Since the data of the target task includes data such as the tag value, task execution time, and execution end time, where the tag value is used to indicate whether the task is a valid task, a first tag value can be used to indicate that the task is a valid task, and a second tag value can be used to indicate that the task is an invalid task, therefore, the present application can obtain a valid task with a first tag value from the target task based on the tag value in the data of the target task. If the data of the target task includes data such as task execution time, execution end time, etc., then obtain a valid task whose task execution time is less than a preset time threshold from the target task.
[0092] Optionally, the effective task ratio of the effective tasks in the target tasks is calculated, including:
[0093] The effective task ratio is determined based on the second number of effective tasks in the target tasks and the total number of target tasks.
[0094] Specifically, the ratio between the second number of valid tasks in the target tasks and the total number of target tasks is taken as the valid task ratio.
[0095] This application can determine the valid task ratio validRate through the following formula:
[0096] validRate=validNumber / totalNumber;
[0097] Wherein, validNumber is the second number of valid tasks in the target task, and totalNumber is the total number of target tasks.
[0098] For example, if the number of target tasks is determined to be 100, and the target tasks include 80 valid tasks, then the valid task ratio validRate=80 / 100=0.8.
[0099] In an embodiment of the present application, after calculating the effective task ratio of effective tasks in the target tasks, the present application may delete the data of the target tasks whose execution end time in Redis is within the first time period.
[0100] Step 306: compare the proportion of valid tasks with a preset proportion threshold to obtain a first comparison result, compare the first task discard rate of the thread pool in the first time period with the preset discard threshold to obtain a second comparison result, and determine the second task discard rate of the thread pool in the second time period based on the first comparison result and the second comparison result.
[0101] Among them, the first time period is adjacent to the second time period, the proportion threshold includes a first proportion threshold and a second proportion threshold, the first proportion threshold is less than the second proportion threshold, the discard threshold includes a first discard threshold and a second discard threshold, and the first discard threshold is less than the second discard threshold.
[0102] The first task discard rate of the thread pool in the first time period is the probability of discarding tasks by the rejection strategy of the thread pool in the first time period. The first task discard rate can be any value between 0 and 1. If the first task discard rate is 0, it means that the probability of discarding tasks by the rejection strategy of the thread pool in the first time period is 0, that is, no tasks are discarded; if the first task discard rate is 1, it means that the probability of discarding tasks by the rejection strategy of the thread pool in the first time period is 1, that is, tasks are directly discarded; if the first task discard rate is 0.1, it means that the probability of discarding tasks by the rejection strategy of the thread pool in the first time period is 0.1. The second task discard rate of the thread pool in the second time period is the probability of discarding tasks by the rejection strategy of the thread pool in the second time period. The second task discard rate can be any value between 0 and 1.
[0103] Optionally, determining a second task discard rate of the thread pool in the second time period based on the first comparison result and the second comparison result includes:
[0104] If the effective task ratio is less than or equal to the first ratio threshold, or the effective task ratio is greater than or equal to the second ratio threshold, determining the second task discard rate based on the second comparison result;
[0105] If the valid task ratio is greater than the first ratio threshold and less than the second ratio threshold, the first task discard rate is used as the second task discard rate.
[0106] Specifically, if the proportion of valid tasks is less than or equal to the first proportion threshold, it indicates that the number of valid tasks in the first time period is small, the threads in the thread pool need to spend a long time to execute each target task, and the target task may need to wait for a long time before being executed by the threads in the thread pool, so that the thread pool consumes a lot of resources, and the probability that the proportion of valid tasks in the second time period is small is large, so it is necessary to determine the second task discard rate based on the second comparison result. If the proportion of valid tasks is greater than or equal to the second proportion threshold, it indicates that the number of valid tasks in the second time period is large, the threads in the thread pool need to spend a short time to execute each target task, and the target task may need to wait for a short time before being executed by the threads in the thread pool, which may cause waste of resources, and the probability that the proportion of valid tasks in the second time period is large is large, so it is necessary to determine the second task discard rate based on the second comparison result. If the proportion of valid tasks is greater than the first proportion threshold and less than the second proportion threshold, it indicates that the number of valid tasks in the first time period has not reached the extreme value, and the time for the target task to wait for execution by the threads in the thread pool is acceptable, so the first task discard rate is used as the second task discard rate.
[0107] For example, the first proportion threshold is 0.1, and the second proportion threshold is 0.3. If the valid task proportion is 0.09 and it is determined that the valid task proportion is less than 0.1, the second task discard rate is determined based on the second comparison result; if the valid task proportion is 0.4 and it is determined that the valid task proportion is less than 0.3, the second task discard rate is determined based on the second comparison result; if the valid task proportion is 0.2 and it is determined that the valid task proportion is greater than 0.1 and less than 0.3, the first task discard rate is used as the second task discard rate.
[0108] In an embodiment of the present application, when the proportion of valid tasks is less than or equal to the first proportion threshold, or the proportion of valid tasks is greater than or equal to the second proportion threshold, the second task discard rate is determined based on the second comparison result to ensure that when the proportion of valid tasks is less than or equal to the first proportion threshold, the second task discard rate of the thread pool in the second time period is relatively large, and when the proportion of valid tasks is greater than or equal to the second proportion threshold, the second task discard rate of the thread pool in the second time period is relatively small; and when the proportion of valid tasks is greater than the first proportion threshold and less than the second proportion threshold, the first task discard rate is used as the second task discard rate to ensure that when the proportion of valid tasks does not reach the proportion threshold, the task discard rate remains unchanged, thereby realizing dynamic management of the task discard rate of the thread pool, improving task execution efficiency, and maximizing resource utilization.
[0109] Optionally, determining the second task discard rate based on the second comparison result includes:
[0110] If the valid task ratio is less than or equal to the first ratio threshold, determining the second task discard rate based on the first task discard rate and the second discard threshold;
[0111] If the valid task ratio is greater than or equal to the second ratio threshold, the second task discard rate is determined based on the first task discard rate and the first discard threshold.
[0112] Specifically, if the proportion of valid tasks is less than or equal to the first proportion threshold, it indicates that the number of valid tasks in the first time period is small, and the threads in the thread pool need to spend a long time to execute each target task. The target task may need to wait for a long time before it can be executed by the threads in the thread pool, which causes the thread pool to consume a lot of resources. In addition, the probability that the proportion of valid tasks in the second time period is small is high, so it is necessary to determine a higher second task discard rate based on the first task discard rate and the second discard threshold. If the proportion of valid tasks is greater than or equal to the second proportion threshold, it indicates that the number of valid tasks in the second time period is large, and the threads in the thread pool need to spend less time to execute each target task. The target task may need to wait for a shorter time before it can be executed by the threads in the thread pool, which may cause a waste of resources. In addition, the probability that the proportion of valid tasks in the second time period is large is high, so it is necessary to determine a lower second task discard rate based on the first task discard rate and the first discard threshold.
[0113] For example, the first proportion threshold is 0.1 and the second proportion threshold is 0.3. If the valid task proportion is 0.08 and it is determined that the valid task proportion is less than 0.1, then the second task discard rate is determined based on the first task discard rate and the second discard threshold; if the valid task proportion is 0.3 and it is determined that the valid task proportion is equal to 0.3, then the second task discard rate is determined based on the first task discard rate and the first discard threshold.
[0114] In an embodiment of the present application, when the proportion of valid tasks is less than or equal to the first proportion threshold, in order to ensure a larger second task discard rate, the second task discard rate is determined based on the first task discard rate and the second discard threshold; when the proportion of valid tasks is greater than or equal to the second proportion threshold, in order to ensure a smaller second task discard rate, the second task discard rate is determined based on the first task discard rate and the first discard threshold, thereby realizing dynamic management of the task discard rate of the thread pool, improving task execution efficiency, and maximizing resource utilization.
[0115] Optionally, determining the second task discard rate based on the first task discard rate and the second discard threshold includes:
[0116] If the first task discard rate is less than the second discard threshold, the first task discard rate is increased, and the increased first task discard rate is used as the second task discard rate;
[0117] If the first task discard rate is greater than or equal to the second discard threshold, the first task discard rate is used as the second task discard rate.
[0118] Specifically, if the proportion of valid tasks is less than or equal to the first proportion threshold, it indicates that the number of valid tasks in the first time period is small, and the threads in the thread pool need to spend a long time to execute each target task. The target task may need to wait for a long time before it can be executed by the threads in the thread pool, which causes the thread pool to consume a lot of resources. In addition, the probability that the proportion of valid tasks in the second time period is small is high, so the thread pool needs a higher second task discard rate. If the first task discard rate is less than the second discard threshold, it indicates that the first task discard rate is low, and it is necessary to increase the first task discard rate, and use the increased first task discard rate as the second task discard rate, thereby obtaining a higher second task discard rate. If the first task discard rate is greater than or equal to the second discard threshold, it indicates that the first task discard rate is high, and it is not necessary to increase the first task discard rate. The first task discard rate is directly used as the second task discard rate, thereby obtaining a higher second task discard rate.
[0119] For example, the first proportion threshold is 0.1, the second proportion threshold is 0.3, the first discard threshold is 0.05, and the second discard threshold is 1. If the valid task proportion is 0.08, the first task discard rate is 0.5, it is determined that the valid task proportion is less than 0.1, and the first task discard rate is less than 1, then the first task discard rate is increased, and the increased first task discard rate is used as the second task discard rate; if the valid task proportion is 0.08, the first task discard rate is 1, it is determined that the valid task proportion is less than 0.1, and the first task discard rate is equal to 1, then the first task discard rate is used as the second task discard rate, that is, the second task discard rate is 1.
[0120] In an embodiment of the present application, since the proportion of valid tasks is less than or equal to the first proportion threshold, it indicates that the number of valid tasks in the first time period is small. If the first task discard rate is low, fewer target tasks will be discarded, and the target task may need to wait for a longer time before being executed by the thread in the thread pool. The thread pool needs to consume a lot of resources to execute the target task, which reduces the task execution efficiency. In addition, the probability that the proportion of valid tasks in the second time period is small is relatively high. Therefore, when the first task discard rate is less than the second discard threshold, the first task discard rate is increased, and the increased first task discard rate is used as the second task discard rate. When the first task discard rate is greater than or equal to the second discard threshold, the first task discard rate is directly used as the second task discard rate, thereby discarding more target tasks, reducing the time the target task waits to be executed by the thread in the thread pool, reducing resource consumption, and improving task execution efficiency.
[0121] Optionally, determining the second task discard rate based on the first task discard rate and the first discard threshold includes:
[0122] If the first task discard rate is greater than the first discard threshold, the first task discard rate is reduced, and the reduced first task discard rate is used as the second task discard rate;
[0123] If the first task discard rate is less than or equal to the first discard threshold, the first task discard rate is used as the second task discard rate.
[0124] Specifically, if the proportion of valid tasks is greater than or equal to the second proportion threshold, it indicates that the number of valid tasks in the second time period is large, and the threads in the thread pool need to spend less time to execute each target task. The target task may need to wait for a shorter time before it can be executed by the threads in the thread pool, which may cause waste of resources, and the probability that the proportion of valid tasks in the second time period is large is high, so a lower second task discard rate is required. If the first task discard rate is greater than the first discard threshold, it indicates that the first task discard rate is high, and the first task discard rate needs to be reduced. The reduced first task discard rate is used as the second task discard rate, thereby obtaining a lower second task discard rate. If the first task discard rate is less than or equal to the first discard threshold, it indicates that the first task discard rate is low, and there is no need to reduce the first task discard rate. The first task discard rate is directly used as the second task discard rate, thereby obtaining a lower second task discard rate.
[0125] For example, the first proportion threshold is 0.1, the second proportion threshold is 0.3, the first discard threshold is 0.05, and the second discard threshold is 1. If the valid task proportion is 0.4, the first task discard rate is 0.5, and it is determined that the valid task proportion is greater than 0.3 and the first task discard rate is greater than 0.05, then the first task discard rate is reduced and the reduced first task discard rate is used as the second task discard rate; if the valid task proportion is 0.4, the first task discard rate is 0.05, and it is determined that the valid task proportion is greater than 0.3 and the first task discard rate is equal to 0.05, then the first task discard rate is used as the second task discard rate, that is, the second task discard rate is 0.05.
[0126] In the embodiment of the present application, since the proportion of valid tasks is greater than or equal to the second proportion threshold, it indicates that the number of valid tasks in the first time period is large. If the first task discard rate is high, more target tasks will be discarded, which may cause waste of resources and reduce the task execution efficiency. In addition, the probability that the proportion of valid tasks in the second time period is large is large. Therefore, based on the relationship between the first task discard rate and the first discard threshold, the second task discard rate is determined, that is, when the first task discard rate is greater than the second discard threshold, the first task discard rate is reduced, and the reduced first task discard rate is used as the second task discard rate. When the first task discard rate is less than or equal to the first discard threshold, the first task discard rate is directly used as the second task discard rate, thereby discarding fewer target tasks, improving task execution efficiency, and maximizing resource utilization.
[0127] Therefore, the determination of the second task discard rate of the thread pool in the second time period based on the first comparison result and the second comparison result in step 306 specifically includes the following five situations:
[0128] In the first case, if the valid task ratio is less than or equal to the first ratio threshold, and the first task discard rate is less than the second discard threshold, the first task discard rate is increased, and the increased first task discard rate is used as the second task discard rate.
[0129] For example, the first proportion threshold is 0.1, the second proportion threshold is 0.3, the first discard threshold is 0.1, and the second discard threshold is 0.9. If the valid task proportion is 0.09 and the first task discard rate is 0.8, it is determined that the valid task proportion is less than 0.1 and the first task discard rate is less than 0.9, then the first task discard rate is increased, and the increased first task discard rate is used as the second task discard rate.
[0130] In the embodiment of the present application, since the proportion of valid tasks is less than or equal to the first proportion threshold, it indicates that the number of valid tasks in the first time period is small, and the threads in the thread pool need to spend a long time to execute each target task. The target task may need to wait for a long time before being executed by the threads in the thread pool, thereby causing the thread pool to consume a large amount of resources, and the probability that the proportion of valid tasks in the second time period is small is high, so a higher second task discard rate is required. And if the first task discard rate is less than the second discard threshold, it indicates that the first task discard rate is low, and the first task discard rate needs to be increased, and the increased first task discard rate is used as the second task discard rate, thereby discarding more target tasks, reducing the time the target task waits to be executed by the threads in the thread pool, reducing resource consumption, and improving task execution efficiency.
[0131] Optionally, increasing the first task discard rate includes the following two methods:
[0132] The first method is to increase the first task discard rate according to the preset first step length.
[0133] The first preset length can be set according to actual conditions, for example, the first step length is 0.1.
[0134] For example, the first proportion threshold is 0.1, the second proportion threshold is 0.3, the first discard threshold is 0.1, and the second discard threshold is 0.9. If the effective task proportion is 0.08 and the first task discard rate is 0.75, it is determined that the effective task proportion is less than 0.1 and the first task discard rate is less than 0.9, then the first task discard rate is increased based on the preset first step length. If the first step length is 0.1, the increased first task discard rate is determined to be 0.75+0.1=0.85. Therefore, the second task discard rate is determined to be 0.85.
[0135] In a second method, a task discard rate in the preset first data set that is greater than the first task discard rate and has the smallest difference with the first task discard rate is used as the increased first task discard rate.
[0136] The first data set includes multiple task discard rates, and the first data set can be set according to actual conditions. For example, the first data set can include 0.1, 0.3, 0.45, 0.6, 0.75 and 0.95.
[0137] For example, if the first proportion threshold is 0.1, the second proportion threshold is 0.3, the first discard threshold is 0.1, and the second discard threshold is 0.9, if the effective task proportion is 0.09, and the first task discard rate is 0.65, it is determined that the effective task proportion is less than 0.1 and the first task discard rate is less than 0.9, then the first task discard rate is increased based on the preset first data set. If the first data set includes 0.1, 0.3, 0.45, 0.6, 0.75 and 0.95, it is determined that the task discard rate in the first data set is greater than the first task discard rate and has the smallest difference with the first task discard rate is 0.75, therefore, the second task discard rate is determined to be 0.75.
[0138] In addition to the above two methods for increasing the first task discard rate, the present application also supports using other methods to increase the first task discard rate.
[0139] In the embodiment of the present application, the first task discard rate is increased by a preset first step length or a preset first data set, thereby improving the efficiency of increasing the first task discard rate.
[0140] In the second case, if the effective task proportion is less than or equal to the first proportion threshold, and the first task discard rate is greater than or equal to the second discard threshold, the first task discard rate is used as the second task discard rate.
[0141] For example, the first proportion threshold is 0.1, the second proportion threshold is 0.3, the first discard threshold is 0.1, and the second discard threshold is 0.9. If the valid task proportion is 0.09 and the first task discard rate is 0.92, it is determined that the valid task proportion is less than 0.1 and the first task discard rate is greater than 0.9, then the second task discard rate is determined to be 0.92.
[0142] In the embodiment of the present application, since the proportion of valid tasks is less than or equal to the first proportion threshold, it indicates that the number of valid tasks in the first time period is small, and the threads in the thread pool need to spend a long time to execute each target task. The target task may need to wait for a long time before being executed by the thread in the thread pool, thereby causing the thread pool to consume a large amount of resources, and the probability that the proportion of valid tasks in the second time period is small is high, so a higher second task discard rate is required. And if the first task discard rate is greater than or equal to the second discard threshold, it indicates that the first task discard rate is high, and there is no need to increase the first task discard rate. The first task discard rate is directly used as the second task discard rate, thereby discarding more target tasks, reducing the time the target task waits to be executed by the thread in the thread pool, reducing resource consumption, and improving task execution efficiency.
[0143] In the third case, if the valid task ratio is greater than or equal to the second ratio threshold, and the first task discard rate is greater than the first discard threshold, the first task discard rate is reduced, and the reduced first task discard rate is used as the second task discard rate.
[0144] For example, the first proportion threshold is 0.1, the second proportion threshold is 0.3, the first discard threshold is 0.1, and the second discard threshold is 0.9. If the valid task proportion is 0.4 and the first task discard rate is 0.3, it is determined that the valid task proportion is greater than 0.3 and the first task discard rate is greater than 0.1, then the first task discard rate is reduced and the reduced first task discard rate is used as the second task discard rate.
[0145] In the embodiment of the present application, since the proportion of effective tasks is greater than or equal to the second proportion threshold, it indicates that the number of effective tasks in the second time period is large, and the threads in the thread pool need to spend less time to execute each target task. The target task may need to wait for a shorter time before it can be executed by the threads in the thread pool, which may cause resource waste and reduce the efficiency of task execution. In addition, the probability that the proportion of effective tasks in the second time period is large is high, so a lower second task discard rate is required. And if the first task discard rate is greater than the first discard threshold, it indicates that the first task discard rate is high, and the first task discard rate needs to be reduced, and the reduced first task discard rate is used as the second task discard rate, thereby discarding fewer target tasks, improving task execution efficiency, and maximizing resource utilization.
[0146] Optionally, reducing the first task discard rate includes the following two methods:
[0147] Method 1, reducing the first task discard rate according to a preset second step length.
[0148] The preset second step length can be set according to actual conditions, for example, the first step length is 0.2. The preset second step length can be the same as the preset first step length, or different from the preset first step length.
[0149] For example, if the first proportion threshold is 0.1, the second proportion threshold is 0.3, the first discard threshold is 0.1, and the second discard threshold is 0.9, if the effective task proportion is 0.4 and the first task discard rate is 0.5, it is determined that the effective task proportion is greater than 0.3 and the first task discard rate is greater than 0.1, then the first task discard rate is reduced based on the preset second step length, and if the second step length is 0.15, the reduced first task discard rate is determined to be 0.5-0.15=0.35. Therefore, the second task discard rate is determined to be 0.35.
[0150] Method 2: The task discard rate in the preset second data set that is smaller than the first task discard rate and has the smallest difference with the first task discard rate is used as the reduced first task discard rate.
[0151] The second data set includes multiple task discard rates, which can be set according to actual conditions, and the second data set can be the same as or different from the first data set. For example, the preset second data set can include 0.1, 0.3, 0.45, 0.6, and 0.9.
[0152] For example, if the first proportion threshold is 0.1, the second proportion threshold is 0.3, the first discard threshold is 0.1, and the second discard threshold is 0.9, if the effective task proportion is 0.4 and the first task discard rate is 0.3, it is determined that the effective task proportion is greater than 0.3 and the first task discard rate is greater than 0.1, then the first task discard rate is reduced based on the preset second data set. If the second data set includes 0.1, 0.3, 0.45, 0.6 and 0.9, it is determined that the task discard rate in the second data set is less than the first task discard rate and the task discard rate with the smallest difference from the first task discard rate is 0.1, therefore, the second task discard rate is determined to be 0.1.
[0153] In addition to the above two methods for reducing the first task discard rate, the present application also supports using other methods to reduce the first task discard rate.
[0154] In the embodiment of the present application, the first task discard rate is reduced by a preset second step size or a preset second data set, thereby improving the efficiency of reducing the second task discard rate.
[0155] In a fourth case, if the valid task proportion is greater than or equal to the second proportion threshold, and the first task discard rate is less than or equal to the first discard threshold, the first task discard rate is used as the second task discard rate.
[0156] For example, the first proportion threshold is 0.1, the second proportion threshold is 0.3, the first discard threshold is 0.1, and the second discard threshold is 0.9. If the valid task proportion is 0.5 and the first task discard rate is 0.1, it is determined that the valid task proportion is greater than 0.3 and the first task discard rate is equal to 0.1, then the second task discard rate is determined to be 0.1.
[0157] In the embodiment of the present application, the number of valid tasks in the second time period is large, and the threads in the thread pool need to spend less time to execute each target task. The target task may need to wait for a shorter time before it can be executed by the threads in the thread pool, which may cause resource waste and reduce the efficiency of task execution. In addition, the probability that the valid tasks in the second time period account for a large proportion is high, so a lower second task discard rate is required. And if the first task discard rate is less than or equal to the first discard threshold, it indicates that the first task discard rate is low, and there is no need to reduce the first task discard rate. The first task discard rate is directly used as the second task discard rate, thereby discarding fewer target tasks, improving task execution efficiency, and maximizing resource utilization.
[0158] In the fifth case, if the effective task ratio is greater than the first ratio threshold and less than the second ratio threshold, the first task discard rate is used as the second task discard rate.
[0159] For example, the first proportion threshold is 0.1, the second proportion threshold is 0.3, if the effective task proportion is 0.2, and the first task discard rate is 0.3, it is determined that the effective task proportion is greater than 0.1 and less than 0.3, then the second task discard rate is determined to be 0.3.
[0160] In an embodiment of the present application, since the proportion of valid tasks is greater than the first proportion threshold and less than the second proportion threshold, it indicates that the number of valid tasks in the first time period has not reached the extreme value, and the length of time the target task waits to be executed by the thread in the thread pool is acceptable. Therefore, the first task discard rate is directly used as the second task discard rate, thereby realizing dynamic management of the task discard rate of the thread pool, improving task execution efficiency, and maximizing resource utilization.
[0161] The following takes the time threshold as 3 seconds, the first proportion threshold as 0.1, the second proportion threshold as 0.3, the first discard threshold as 0.01, and the second discard threshold as 0.9 as an example to describe the specific steps of the data processing method provided above in detail. Figure 6 As shown:
[0162] Step 601, obtaining a first number of first threads in a thread pool within a first time period;
[0163] Step 602, determining whether the first number is less than or equal to the thread threshold, if so, executing step 603, otherwise executing step 604;
[0164] Step 603, controlling the threads in the thread pool to execute tasks;
[0165] Step 604, determining the target task whose execution end time of the task executed in the thread pool is within the first time period;
[0166] Step 605, obtaining valid tasks with a task execution time of less than 3 seconds from the target tasks, and calculating the valid task ratio of the valid tasks in the target tasks;
[0167] Step 606, determine whether the effective task ratio is less than or equal to 0.1, if so, execute step 607, otherwise execute step 610;
[0168] Step 607, determining whether the first task discard rate is less than 0.9, if so, executing step 608, otherwise executing step 608;
[0169] The first task discard rate is a task discard rate of the thread pool in the first time period.
[0170] Step 608, increasing the first task discard rate, and using the increased first task discard rate as the second task discard rate;
[0171] The second task discard rate is a task discard rate of the thread pool in the second time period, and the first time period is adjacent to the second time period.
[0172] For example, if the effective task ratio is 0.08 and the first task discard rate is 0.5, it is determined that the effective task ratio is less than 0.1 and the first task discard rate is less than 0.9, then the first task discard rate is increased based on the preset first data set. If the first data set includes 0.01, 0.05, 0.1, 0.5 and 0.9, it is determined that the task discard rate in the first data set that is greater than the first task discard rate and has the smallest difference with the first task discard rate is 0.8, therefore, the second task discard rate is determined to be 0.9.
[0173] Step 609, using the first task discard rate as the second task discard rate;
[0174] Step 610, determine whether the effective task ratio is greater than or equal to 0.3, if so, execute step 611, otherwise execute step 613;
[0175] Step 611, determine whether the first task discard rate is greater than 0.01, if so, execute step 612, otherwise execute step 613;
[0176] Step 612, reducing the first task discard rate, and using the reduced first task discard rate as the second task discard rate;
[0177] For example, if the effective task ratio is 0.45 and the first task discard rate is 0.1, it is determined that the effective task ratio is greater than 0.3 and the first task discard rate is greater than 0.01, then the first task discard rate is increased based on the preset second data set. If the first data set is the same as the second data set, and the first data set includes 0.01, 0.05, 0.1, 0.5 and 0.9, it is determined that the task discard rate in the second data set is less than the first task discard rate and the task discard rate with the smallest difference from the first task discard rate is 0.05, therefore, the second task discard rate is determined to be 0.05.
[0178] Step 613: Use the first task discard rate as the second task discard rate.
[0179] Based on the same inventive concept, the present application embodiment provides a data processing device, please refer to Figure 7 , the device comprises:
[0180] An acquisition module 701 is used to acquire a first number of first threads in a thread pool within a first time period, wherein the first threads are threads that are executing tasks;
[0181] A first determination module 702 is used to determine the target task whose execution end time of the task executed in the thread pool is within the first time period if the first number is greater than a preset thread threshold;
[0182] A calculation module 703 is used to obtain valid tasks whose task execution time is less than a preset time threshold from the target tasks, and calculate the effective task ratio of the valid tasks in the target tasks;
[0183] The second determination module 704 is used to compare the valid task ratio with a preset ratio threshold to obtain a first comparison result, compare the first task discard rate of the thread pool in the first time period with a preset discard threshold to obtain a second comparison result, and determine the second task discard rate of the thread pool in the second time period based on the first comparison result and the second comparison result, wherein the first time period is adjacent to the second time period.
[0184] As an optional implementation manner, the proportion threshold includes a first proportion threshold and a second proportion threshold, the first proportion threshold is less than the second proportion threshold, and the second determination module 704 is used to:
[0185] If the effective task proportion is less than or equal to the first proportion threshold, or the effective task proportion is greater than or equal to the second proportion threshold, determining the second task discard rate based on the second comparison result;
[0186] If the valid task ratio is greater than the first ratio threshold and less than the second ratio threshold, the first task discard rate is used as the second task discard rate.
[0187] As an optional implementation manner, the discarding threshold includes a first discarding threshold and a second discarding threshold, the first discarding threshold is less than the second discarding threshold, and the second determining module 704 is used to:
[0188] If the valid task ratio is less than or equal to the first ratio threshold, determining the second task discard rate based on the first task discard rate and the second discard threshold;
[0189] If the valid task ratio is greater than or equal to the second ratio threshold, the second task discard rate is determined based on the first task discard rate and the first discard threshold.
[0190] As an optional implementation manner, the second determining module 704 is configured to:
[0191] If the first task discard rate is less than the second discard threshold, increasing the first task discard rate, and using the increased first task discard rate as the second task discard rate;
[0192] If the first task discard rate is greater than or equal to the second discard threshold, the first task discard rate is used as the second task discard rate.
[0193] As an optional implementation manner, the second determining module 704 is configured to:
[0194] If the first task discard rate is greater than the first discard threshold, reducing the first task discard rate, and using the reduced first task discard rate as the second task discard rate;
[0195] If the first task discard rate is less than or equal to the first discard threshold, the first task discard rate is used as the second task discard rate.
[0196] As an optional implementation manner, the second determining module 704 is configured to:
[0197] increasing the first task discard rate according to the preset first step length; or,
[0198] The task discard rate in a preset first data set that is greater than the first task discard rate and has the smallest difference from the first task discard rate is used as the increased first task discard rate, wherein the first data set includes multiple task discard rates.
[0199] As an optional implementation manner, the second determining module 704 is configured to:
[0200] Reduce the first task discard rate according to a preset second step size; or,
[0201] The task discard rate in the preset second data set that is less than the first task discard rate and has the smallest difference from the first task discard rate is used as the reduced first task discard rate, wherein the second data set includes multiple task discard rates.
[0202] As an optional implementation manner, before obtaining the first number of first threads in the thread pool within the first time period, the obtaining module 701 is further used to:
[0203] For any task, determine the execution start time and execution end time of the thread pool executing the any task;
[0204] Determine the task execution duration of the any task based on the execution start time and the execution end time of the any task;
[0205] If the task execution duration of any one of the tasks is less than the time threshold, the any one of the tasks is determined to be a valid task.
[0206] Based on the same inventive concept, the embodiment of the present application provides an electronic device, which can implement the cluster capacity management function discussed above. Please refer to Figure 8 , the device comprises a processor 801 and a memory 802, wherein the memory 802 is used to store program instructions;
[0207] The processor 801 calls the program instructions stored in the memory and executes the program instructions to implement the following steps:
[0208] Obtaining a first number of first threads in a thread pool within a first time period, wherein the first threads are threads that are executing tasks;
[0209] If the first number is greater than a preset thread threshold, determining a target task whose execution end time of the task executed in the thread pool is within the first time period;
[0210] Acquire valid tasks whose task execution time is less than a preset time threshold from the target tasks, and calculate the effective task ratio of the valid tasks in the target tasks;
[0211] The valid task proportion is compared with a preset proportion threshold to obtain a first comparison result, the first task discard rate of the thread pool in the first time period is compared with a preset discard threshold to obtain a second comparison result, and the second task discard rate of the thread pool in the second time period is determined based on the first comparison result and the second comparison result, wherein the first time period is adjacent to the second time period.
[0212] As an optional implementation, the proportion threshold includes a first proportion threshold and a second proportion threshold, the first proportion threshold is less than the second proportion threshold, and determining the second task discard rate of the thread pool in the second time period based on the first comparison result and the second comparison result includes:
[0213] If the effective task proportion is less than or equal to the first proportion threshold, or the effective task proportion is greater than or equal to the second proportion threshold, determining the second task discard rate based on the second comparison result;
[0214] If the valid task ratio is greater than the first ratio threshold and less than the second ratio threshold, the first task discard rate is used as the second task discard rate.
[0215] As an optional implementation manner, the discard threshold includes a first discard threshold and a second discard threshold, the first discard threshold is less than the second discard threshold, and determining the second task discard rate based on the second comparison result includes:
[0216] If the valid task ratio is less than or equal to the first ratio threshold, determining the second task discard rate based on the first task discard rate and the second discard threshold;
[0217] If the valid task ratio is greater than or equal to the second ratio threshold, the second task discard rate is determined based on the first task discard rate and the first discard threshold.
[0218] As an optional implementation manner, determining the second task discard rate based on the first task discard rate and the second discard threshold includes:
[0219] If the first task discard rate is less than the second discard threshold, increasing the first task discard rate, and using the increased first task discard rate as the second task discard rate;
[0220] If the first task discard rate is greater than or equal to the second discard threshold, the first task discard rate is used as the second task discard rate.
[0221] As an optional implementation manner, determining the second task discard rate based on the first task discard rate and the first discard threshold includes:
[0222] If the first task discard rate is greater than the first discard threshold, reducing the first task discard rate, and using the reduced first task discard rate as the second task discard rate;
[0223] If the first task discard rate is less than or equal to the first discard threshold, the first task discard rate is used as the second task discard rate.
[0224] As an optional implementation manner, increasing the first task discard rate includes:
[0225] increasing the first task discard rate according to the preset first step length; or,
[0226] The task discard rate in a preset first data set that is greater than the first task discard rate and has the smallest difference from the first task discard rate is used as the increased first task discard rate, wherein the first data set includes multiple task discard rates.
[0227] As an optional implementation manner, reducing the first task discard rate includes:
[0228] Reduce the first task discard rate according to a preset second step size; or,
[0229] The task discard rate in a preset second data set that is smaller than the first task discard rate and has the smallest difference from the first task discard rate is used as the reduced first task discard rate, wherein the second data set includes multiple task discard rates.
[0230] As an optional implementation, before obtaining the first number of first threads in the thread pool within the first time period, the processor 801 is further configured to execute:
[0231] For any task, determine the execution start time and execution end time of the thread pool executing the any task;
[0232] Determine the task execution duration of the any task based on the execution start time and the execution end time of the any task;
[0233] If the task execution duration of any one of the tasks is less than the time threshold, the any one of the tasks is determined to be a valid task.
[0234] Based on the same inventive concept, the embodiment of the present application provides a computer-readable storage medium, and the computer program product includes: computer program code, when the computer program code is run on a computer, the computer executes any of the data processing methods discussed above. Since the principle of solving the problem by the above-mentioned computer-readable storage medium is similar to that of the data processing method, the implementation of the above-mentioned computer-readable storage medium can refer to the implementation of the method, and the repeated parts will not be repeated.
[0235] Based on the same inventive concept, the embodiment of the present application also provides a computer program product, which includes: computer program code, when the computer program code is run on a computer, the computer executes any of the data processing methods discussed above. Since the principle of solving the problem by the above computer program product is similar to that of the data processing method, the implementation of the above computer program product can refer to the implementation of the method, and the repeated parts will not be repeated.
[0236] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0237] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0238] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0239] These computer program instructions may also be loaded onto a computer or other programmable data processing device so that a series of user-operated steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0240] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A data processing method, characterized in that: The method includes: Obtaining a first number of first threads in a thread pool within a first time period, wherein the first threads are threads that are executing tasks; If the first number is greater than a preset thread threshold, determining a target task whose execution end time of the task executed in the thread pool is within the first time period; Acquire valid tasks whose task execution time is less than a preset time threshold from the target tasks, and calculate the effective task ratio of the valid tasks in the target tasks; The valid task proportion is compared with a preset proportion threshold to obtain a first comparison result, the first task discard rate of the thread pool in the first time period is compared with a preset discard threshold to obtain a second comparison result, and the second task discard rate of the thread pool in the second time period is determined based on the first comparison result and the second comparison result, wherein the first time period is adjacent to the second time period.
2. The method according to claim 1, characterized in that The proportion threshold includes a first proportion threshold and a second proportion threshold, the first proportion threshold is less than the second proportion threshold, and determining the second task discard rate of the thread pool in the second time period based on the first comparison result and the second comparison result includes: If the effective task proportion is less than or equal to the first proportion threshold, or the effective task proportion is greater than or equal to the second proportion threshold, determining the second task discard rate based on the second comparison result; If the valid task ratio is greater than the first ratio threshold and less than the second ratio threshold, the first task discard rate is used as the second task discard rate.
3. The method according to claim 2, characterized in that The discarding threshold includes a first discarding threshold and a second discarding threshold, the first discarding threshold is less than the second discarding threshold, and determining the second task discarding rate based on the second comparison result includes: If the valid task ratio is less than or equal to the first ratio threshold, determining the second task discard rate based on the first task discard rate and the second discard threshold; If the valid task ratio is greater than or equal to the second ratio threshold, the second task discard rate is determined based on the first task discard rate and the first discard threshold.
4. The method according to claim 3, characterized in that The determining the second task discard rate based on the first task discard rate and the second discard threshold includes: If the first task discard rate is less than the second discard threshold, increasing the first task discard rate, and using the increased first task discard rate as the second task discard rate; If the first task discard rate is greater than or equal to the second discard threshold, the first task discard rate is used as the second task discard rate.
5. The method according to claim 3, characterized in that The determining the second task discard rate based on the first task discard rate and the first discard threshold includes: If the first task discard rate is greater than the first discard threshold, reducing the first task discard rate, and using the reduced first task discard rate as the second task discard rate; If the first task discard rate is less than or equal to the first discard threshold, the first task discard rate is used as the second task discard rate.
6. The method according to claim 4, characterized in that The increasing the first task discard rate comprises: increasing the first task discard rate according to the preset first step length; or, The task discard rate in a preset first data set that is greater than the first task discard rate and has the smallest difference from the first task discard rate is used as the increased first task discard rate, wherein the first data set includes multiple task discard rates.
7. The method according to claim 5, characterized in that The reducing the first task discard rate comprises: Reduce the first task discard rate according to a preset second step size; or, The task discard rate in a preset second data set that is smaller than the first task discard rate and has the smallest difference from the first task discard rate is used as the reduced first task discard rate, wherein the second data set includes multiple task discard rates.
8. The method according to claim 1, characterized in that Before obtaining the first number of first threads in the thread pool within the first time period, the method further includes: For any task, determine the execution start time and execution end time of the thread pool executing the any task; Determine the task execution duration of the any task based on the execution start time and the execution end time of the any task; If the task execution duration of any one of the tasks is less than the time threshold, the any one of the tasks is determined to be a valid task.
9. A data processing device, characterized in that: The device includes: An acquisition module, configured to acquire a first number of first threads in a thread pool within a first time period, wherein the first threads are threads that are executing tasks; A first determination module, configured to determine, if the first number is greater than a preset thread threshold, a target task whose execution end time of the task executed in the thread pool is within the first time period; A calculation module, used to obtain valid tasks whose task execution time is less than a preset time threshold from the target tasks, and calculate the effective task ratio of the valid tasks in the target tasks; The second determination module is used to compare the valid task ratio with a preset ratio threshold to obtain a first comparison result, compare the first task discard rate of the thread pool in the first time period with a preset discard threshold to obtain a second comparison result, and determine the second task discard rate of the thread pool in the second time period based on the first comparison result and the second comparison result, wherein the first time period is adjacent to the second time period.
10. An electronic device, characterized in that: include: A memory for storing program instructions; A processor is used to call the program instructions stored in the memory, and execute the steps included in any one of the methods of claims 1-8 according to the obtained program instructions.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a computer, the computer executes the method according to any one of claims 1 to 8.
12. A computer program product, characterized in that The computer program product comprises: a computer program code, and when the computer program code is run on a computer, the computer is enabled to execute the method according to any one of claims 1 to 8.
