Concurrent thread number control method and device
By dynamically adjusting the number of concurrent threads based on task load information, the problem of unreasonable thread settings in model training is solved, and a more efficient model training process is achieved.
Patent Information
- Application Number
- CN202210272571.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-18
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2042-03-18
AI Technical Summary
In existing technologies, the number of threads in model training lacks flexibility and accuracy, resulting in low training efficiency. In particular, the number of threads is often set unreasonably because the characteristics of the specific training task are not taken into account.
The target number of concurrent threads is determined based on task load information, and the number of concurrent threads in the thread pool is adjusted when the relationship between the initial number of concurrent threads and the target number of concurrent threads meets preset conditions, thereby improving the accuracy and flexibility of thread count settings.
This improves the efficiency of model training, ensures that the number of threads matches the task load, reduces resource waste, and improves task processing efficiency.
Smart Images

Figure CN114706677B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a method and apparatus for controlling the number of concurrent threads. Background Technology
[0002] With the widespread application of models, model training frameworks are an important foundational component in the field of model training, which can significantly reduce the complexity of developing and using models.
[0003] In existing technologies, model training involves complex computational logic. Training frameworks manage and execute various operations during training using concurrent threads. Therefore, the setting of the number of concurrent threads in the thread pool plays a crucial role in the model training process. Generally, the default number of threads can be used when setting the number of threads.
[0004] However, when using the default number of threads, the number of physical or logical cores of the processor is generally used as the default number of threads, without taking into account the characteristics of the specific training task. This reduces the accuracy and flexibility of the thread number setting, and thus affects the training efficiency of the model. Summary of the Invention
[0005] This application provides a method and apparatus for controlling the number of concurrent threads, so as to improve the accuracy and flexibility of thread number settings.
[0006] In a first aspect, embodiments of this application provide a method for controlling the number of concurrent threads, including:
[0007] Determine the target number of concurrent threads based on task load information;
[0008] If the relationship between the initial number of concurrent threads and the target number of concurrent threads meets a preset condition, then the number of concurrent threads in the thread pool is set to the target number of concurrent threads;
[0009] The target task is obtained from the task queue using the thread corresponding to the target number of concurrent threads, and the model is trained based on the target task.
[0010] Optionally, determining the target number of concurrent threads based on task load information includes:
[0011] Obtain the initial number of concurrent threads;
[0012] Determine the average waiting time of tasks and the average idle time of threads;
[0013] The task load information is determined based on the average waiting time and the average idle time.
[0014] The target number of concurrent threads is determined based on the task load information and the initial number of concurrent threads.
[0015] Optionally, determining the average waiting time of the task and the average idle time of the thread includes:
[0016] The average waiting time of a task is determined based on the waiting time of a first target task in the task queue and the waiting time of at least one second target task, wherein the first target task is the unprocessed task in the task queue with the longest waiting time, and the second target task is the task in the task queue that has been processed.
[0017] The average idle time of a thread is determined based on the idle time of each idle thread in the thread pool.
[0018] Optionally, determining the task load information based on the average waiting time and the average idle time includes:
[0019] The task waiting time factor is determined based on the average waiting time and the preset average waiting time threshold.
[0020] The thread idle time factor is determined based on the average idle time and the preset average idle time threshold.
[0021] The task load information is determined based on the task waiting time factor and the thread idle time factor.
[0022] Optionally, determining the task waiting time factor based on the average waiting time and a preset average waiting time threshold includes:
[0023] If the average waiting time is less than the average waiting time threshold, then the task waiting time factor is determined to be 1;
[0024] If the average waiting time is greater than or equal to the average waiting time threshold, then the task waiting time factor is determined to be the ratio of the average waiting time to the average waiting time threshold;
[0025] Correspondingly, determining the thread idle time factor based on the average idle time and a preset average idle time threshold includes:
[0026] If the average idle time is less than the average idle time threshold, then the thread idle time factor is determined to be 1;
[0027] If the average idle time is greater than or equal to the average idle time threshold, then the following is determined:
[0028] The thread idle time factor is the ratio of the average idle time to the average idle time threshold;
[0029] Correspondingly, determining the task load information based on the task waiting time factor and the thread idle time factor includes:
[0030] The task load information is obtained by multiplying the task waiting time factor and the thread idle time factor.
[0031] Optionally, determining the target number of concurrent threads based on the task load information and the initial number of concurrent threads includes:
[0032] The target number of concurrent threads is obtained by multiplying the initial number of concurrent threads with the task load information.
[0033] Optionally, the step of setting the number of concurrent threads in the thread pool to the target number of concurrent threads if the relationship between the initial number of concurrent threads and the target number of concurrent threads meets a preset condition includes:
[0034] If the ratio of the initial number of concurrent threads to the target number of concurrent threads is not within the preset threshold range, then the number of concurrent threads in the thread pool is set to the target number of concurrent threads.
[0035] Optional, also includes:
[0036] If the ratio of the initial number of concurrent threads to the target number of concurrent threads is within a preset threshold range, then the number of concurrent threads in the thread pool is maintained at the initial number of concurrent threads.
[0037] Generate and display a message indicating that the number of concurrent threads remains unchanged.
[0038] Optionally, if the model is a deep learning model, then after training the model according to the target task, the method further includes:
[0039] Multimedia data is processed by the trained deep learning model to obtain processed multimedia data, wherein the multimedia data includes at least one of audio, video and images.
[0040] The processed multimedia data is sent to the terminal device for display.
[0041] Secondly, embodiments of this application provide a concurrent thread count control device, comprising:
[0042] The determination module is used to determine the target number of concurrent threads based on task load information;
[0043] The processing module is used to set the number of concurrent threads in the thread pool to the target number of concurrent threads if the relationship between the initial number of concurrent threads and the target number of concurrent threads meets a preset condition.
[0044] The processing module is further configured to obtain a target task from the task queue through the thread corresponding to the target number of concurrent threads, and train the model based on the target task.
[0045] This application provides a method and apparatus for controlling the number of concurrent threads. By adopting the above scheme, the target number of concurrent threads can be determined based on task load information. Then, when the relationship between the initial number of concurrent threads and the target number of concurrent threads meets a preset condition, the number of concurrent threads in the thread pool is set to the target number of concurrent threads. The target task is then retrieved from the task queue using the thread corresponding to the target number of concurrent threads, and the model is trained based on the target task. By determining the target number of concurrent threads based on the current load and adjusting the number of concurrent threads when the relationship between the initial number of concurrent threads and the target number of concurrent threads meets a preset condition, the accuracy and flexibility of thread number setting are improved, thereby increasing the efficiency of model training. Attached Figure Description
[0046] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0047] Figure 1 This is a schematic diagram illustrating an application scenario of the concurrent thread count control method provided in the embodiments of this application;
[0048] Figure 2 A flowchart illustrating the concurrent thread count control method provided in this application embodiment;
[0049] Figure 3 A flowchart illustrating a concurrent thread count control method provided in another embodiment of this application;
[0050] Figure 4 A system architecture diagram of the concurrent thread count control method provided in the embodiments of this application;
[0051] Figure 5 This is a schematic diagram of the structure of the concurrent thread count control device provided in the embodiments of this application;
[0052] Figure 6 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0053] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0054] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can also include other sequential examples besides those illustrated or described. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0055] Concurrent threads refer to the number of threads that can run simultaneously on a processor. Setting the number of concurrent threads plays a crucial role in the model training process. Too few threads can lead to long task queuing times and low processor utilization, while too many threads increase thread contention and switching overhead. Furthermore, different training tasks have significantly different concurrency requirements, and even different steps in the same task training have vastly different concurrency needs. Simply using the number of physical or logical cores of the processor as the default thread count, without considering the specific characteristics of the training task, reduces the accuracy and flexibility of thread count settings, thus impacting model training efficiency.
[0056] In addition, the number of concurrent threads can be manually set based on the experience of operations and maintenance personnel. However, this method relies too much on human experience and knowledge, and it does not have much reference value for new models. It also reduces the accuracy and flexibility of thread number setting.
[0057] Based on the aforementioned technical issues, this application achieves the technical effect of improving both the accuracy and flexibility of thread number setting and the efficiency of model training by determining the target number of concurrent threads based on the current load and adjusting the number of concurrent threads only when the relationship between the initial number of concurrent threads and the target number of concurrent threads meets preset conditions.
[0058] Figure 1 This is a schematic diagram illustrating an application scenario of the concurrent thread count control method provided in the embodiments of this application, such as... Figure 1As shown, in this embodiment, the task queue contains multiple tasks, and each task is arranged in the task queue according to its submission time. The thread pool contains 1 to n threads. When a thread is idle, it can sequentially retrieve a task from the task queue and execute it, ultimately achieving the training of the model (exemplarily, a deep learning model). Here, n represents the number of threads in the thread pool, and the value of n is variable and can be changed according to the task load.
[0059] Furthermore, when retrieving tasks from the task queue, tasks can be retrieved based on their storage time; that is, tasks with the longest storage time can be retrieved first, or tasks with the shortest storage time can be retrieved first. Other custom rules can also be used for retrieval, but these restrictions will not be detailed here.
[0060] The technical solutions of this application will be described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0061] Figure 2 This is a flowchart illustrating the concurrent thread count control method provided in an embodiment of this application. The method in this embodiment can be executed by a server or a terminal device, and related training tasks can be run on the server or terminal device. Figure 2 As shown, the method in this embodiment may include:
[0062] S201: Determine the target number of concurrent threads based on task load information.
[0063] In this embodiment, different training tasks have significantly different concurrency requirements, and different steps in training the same task also have vastly different concurrency requirements. Therefore, the task load information can be determined first, and then the number of concurrent threads in the thread pool can be adjusted according to the task load information to obtain the target number of concurrent threads. Optionally, the target number of concurrent threads can be a number of concurrent threads that matches the current load situation, in order to reduce the situation where setting too many concurrent threads wastes thread resources, or setting too few concurrent threads affects task processing efficiency.
[0064] The task load information indicates the speed of task processing. A high task load indicates a large task volume or a low number of concurrent threads; a low task load indicates a small task volume or a high number of concurrent threads.
[0065] S202: If the relationship between the initial number of concurrent threads and the target number of concurrent threads meets the preset conditions, then the number of concurrent threads in the thread pool is set to the target number of concurrent threads.
[0066] In this embodiment, after obtaining the target number of concurrent threads, the number of concurrent threads in the thread pool can be directly set as the target number of concurrent threads.
[0067] Furthermore, the target number of concurrent threads can be higher than, lower than, or the same as the initial number of concurrent threads in the thread pool.
[0068] If the target number of concurrent threads is the same as the initial number of concurrent threads in the thread pool, the number of concurrent threads in the thread pool does not need to be modified.
[0069] In addition, after determining the target number of concurrent threads based on task waiting time and thread idle time, the relationship between the target number of concurrent threads and the initial number of concurrent threads can be used to determine whether the number of concurrent threads in the thread pool needs to be updated.
[0070] Furthermore, if the relationship between the initial number of concurrent threads and the target number of concurrent threads meets a preset condition, then the number of concurrent threads in the thread pool is set to the target number of concurrent threads, which may specifically include:
[0071] If the ratio of the initial number of concurrent threads to the target number of concurrent threads is not within the preset threshold range, then the number of concurrent threads in the thread pool is set to the target number of concurrent threads.
[0072] Optionally, the method may further include:
[0073] If the ratio of the initial number of concurrent threads to the target number of concurrent threads is within a preset threshold range, then the number of concurrent threads in the thread pool is maintained at the initial number of concurrent threads.
[0074] Generate and display a message indicating that the number of concurrent threads remains unchanged.
[0075] Specifically, the number of threads only needs to be adjusted when the target number of concurrent threads and the initial number of concurrent threads meet a preset condition. The difference between the target number of concurrent threads and the initial number of concurrent threads can be represented by the ratio of the initial number of concurrent threads to the target number of concurrent threads. Furthermore, in another embodiment, if the ratio of the initial number of concurrent threads to the target number of concurrent threads is within a preset threshold range, the number of concurrent threads in the thread pool is maintained at the initial number of concurrent threads.
[0076] Furthermore, the new number of concurrent threads set for the thread pool can be determined based on the expression:
[0077]
[0078] Where old_thr_count represents the initial number of concurrent threads, ideal_thr_count represents the target number of concurrent threads, and α∈[0,1] is used to control the sensitivity of thread number adjustment.
[0079] In summary, by adjusting the number of threads only when the relationship between the target number of concurrent threads and the initial number of concurrent threads meets a preset condition, the number of times the number of concurrent threads needs to be adjusted is reduced, while the accuracy of the concurrent thread count setting is improved.
[0080] In addition, generating and displaying a message indicating that the number of concurrent threads remains unchanged can remind operations and maintenance personnel that the current number of concurrent threads does not need to be adjusted, indicating that the current number of concurrent threads is set reasonably. This allows operations and maintenance personnel to understand the status of the number of concurrent threads in a timely manner, ensuring the stable execution of tasks.
[0081] S203: Obtain the target task from the task queue using the thread corresponding to the target number of concurrent threads, and train the model based on the target task.
[0082] In this embodiment, after setting the number of concurrent threads in the thread pool to the target number of concurrent threads, a target number of threads can provide services for the model training task. Then, the target task can be retrieved from the task queue using the thread corresponding to the target number of concurrent threads, and the model can be trained based on the target task to obtain a model applicable to different scenarios. By adopting the above scheme, the target number of concurrent threads can be determined based on task load information. Then, when the relationship between the initial number of concurrent threads and the target number of concurrent threads meets a preset condition, the number of concurrent threads in the thread pool is set to the target number of concurrent threads. The target task is then retrieved from the task queue using the thread corresponding to this target number of concurrent threads, and the model is trained based on the target task. By determining the target number of concurrent threads based on the current load and adjusting the number of concurrent threads only when the relationship between the initial number of concurrent threads and the target number of concurrent threads meets the preset condition, the accuracy and flexibility of thread number setting are improved, thereby increasing the efficiency of model training.
[0083] based on Figure 2 In addition to the method described herein, this specification also provides some specific implementation schemes of the method, which will be described below.
[0084] Figure 3 This is a flowchart illustrating a concurrent thread count control method provided in another embodiment of this application, as shown below. Figure 3 As shown, S201: Determine the target number of concurrent threads based on the task load information, which may specifically include:
[0085] S301: Get the initial number of concurrent threads.
[0086] In this embodiment, when determining the target number of concurrent threads, the initial number of concurrent threads in the thread pool can be obtained first. This initial number of concurrent threads indicates the current number of concurrent threads in the thread pool. It can be a default value or the target number of concurrent threads determined before a preset time.
[0087] S302: Determine the average waiting time of the task and the average idle time of the thread.
[0088] In this embodiment, the setting of the number of concurrent threads should comprehensively consider task waiting time and thread space time. If the task waiting time is too long, it indicates that there are too few available idle threads, and the number of concurrent threads should be increased appropriately. If the thread idle time is too long, it indicates that there are too many threads and not enough tasks to execute, and the number of concurrent threads should be reduced appropriately. That is, it is inappropriate for tasks to be queued for too long or for threads to be idle for too long when executing tasks. Ideally, tasks to be executed should not be queued for too long, and each thread should not be idle for too long before new tasks arrive. Therefore, when determining the target number of concurrent threads, the average waiting time of tasks and the average idle time of threads can be determined first.
[0089] Furthermore, determining the average waiting time of tasks and the average idle time of threads can specifically include:
[0090] The average waiting time of a task is determined based on the waiting time of a first target task in the task queue and the waiting time of at least one second target task, wherein the first target task is the unprocessed task in the task queue with the longest waiting time, and the second target task is the task in the task queue that has been processed.
[0091] The average idle time of a thread is determined based on the idle time of each idle thread in the thread pool.
[0092] Specifically, when determining the average waiting time of a task, if only the waiting time of dequeued tasks is used, if there are no idle threads, no tasks will be dequeued, resulting in a zero average waiting time. Furthermore, it's possible that initially there are no idle threads, and tasks in the queue have been waiting for a long time. Then, suddenly many threads become idle, and all tasks in the queue are executed, leaving no tasks in the queue. If only the waiting time of unprocessed tasks is used to determine the average waiting time, the average waiting time will also be zero. Therefore, the task with the longest unprocessed waiting time in the queue can be designated as the first target task. Multiple dequeued tasks can be designated as second target tasks. The average waiting time of the first target task and the average waiting time of each second target task are then calculated as the average waiting time of the task. To ensure the timeliness of task selection, the second target tasks can be selected from the N most recent dequeued tasks or dequeued tasks within the latest preset time period. By combining the waiting time of dequeued tasks with the waiting time of unprocessed tasks to determine the average waiting time, the system avoids situations where the average waiting time cannot accurately reflect the load condition in extreme cases, thus improving the accuracy of the average waiting time determination.
[0093] In addition, when determining the average idle time of a thread, the average idle time of the thread can be calculated by averaging the time interval between each idle thread becoming idle and receiving the next task.
[0094] S303: Determine task load information based on average waiting time and average idle time.
[0095] In this embodiment, after obtaining the average waiting time and average idle time, the task load information can be determined based on the average waiting time and average idle time.
[0096] Furthermore, determining task load information based on the average waiting time and the average idle time may specifically include:
[0097] The task waiting time factor is determined based on the average waiting time and the preset average waiting time threshold.
[0098] The thread idle time factor is determined based on the average idle time and the preset average idle time threshold.
[0099] The task load information is determined based on the task waiting time factor and the thread idle time factor.
[0100] Specifically, when determining task load information through average waiting time and average idle time, the task waiting time factor can first be determined based on the average waiting time and a preset average waiting time threshold. The average waiting time threshold can be customized according to the actual application scenario, typically at the millisecond or microsecond level. This value represents the desired task processing speed; the smaller the value, the better the task response time. Then, the thread idle time factor can be determined based on the average idle time and a preset average idle time threshold. The average idle time threshold can also be customized according to the actual application scenario, typically at the millisecond or microsecond level. This value represents the desired idle time of worker threads; the smaller the value, the busier the thread.
[0101] Furthermore, a task waiting time factor is determined based on the average waiting time and a preset average waiting time threshold, which may specifically include:
[0102] If the average waiting time is less than the average waiting time threshold, then the task waiting time factor is determined to be 1.
[0103] If the average waiting time is greater than or equal to the average waiting time threshold, then the task waiting time factor is determined to be the ratio of the average waiting time to the average waiting time threshold.
[0104] The task waiting time factor can be determined based on the expression:
[0105]
[0106] Where ave_t_w_t represents the average waiting time, and tar_t_w_t represents the average waiting time threshold.
[0107] Correspondingly, determining the thread idle time factor based on the average idle time and a preset average idle time threshold may specifically include:
[0108] If the average idle time is less than the average idle time threshold, then the thread idle time factor is determined to be 1.
[0109] If the average idle time is greater than or equal to the average idle time threshold, then the thread idle time factor is determined to be the ratio of the average idle time to the average idle time threshold.
[0110] The thread idle time factor can be determined based on the expression:
[0111]
[0112] Where ave_t_i_t represents the average idle time, and tar_t_i_t represents the average idle time threshold.
[0113] Correspondingly, determining the task load information based on the task waiting time factor and the thread idle time factor includes:
[0114] The task load information is obtained by multiplying the task waiting time factor and the thread idle time factor.
[0115] The task load information can be determined based on the expression:
[0116] f(system_workload)=g(task_wait_time)*h(thread_idle_time).
[0117] S304: Determine the target number of concurrent threads based on the task load information and the initial number of concurrent threads.
[0118] In this embodiment, after determining the task load information, the initial number of concurrent threads can be adjusted according to the task load information to obtain the target number of concurrent threads.
[0119] Furthermore, determining the target number of concurrent threads based on the task load information and the initial number of concurrent threads may specifically include:
[0120] The target number of concurrent threads is obtained by multiplying the initial number of concurrent threads with the task load information.
[0121] The target number of concurrent threads can be determined based on the expression:
[0122] ideal_thr_count=old_thr_count*f(system_workload).
[0123] Where old_thr_count represents the initial number of concurrent threads.
[0124] For example, if f(system_workload) is 1, the target number of concurrent threads is the initial number of concurrent threads, indicating that the current number of concurrent threads is set reasonably. If f(system_workload) is 2, the target number of concurrent threads is twice the initial number of concurrent threads, indicating that the current number of concurrent threads is set too low and cannot meet the actual needs of the task.
[0125] In summary, by dynamically adjusting the number of concurrent threads in real time according to the task load, the number of concurrent threads is kept at an appropriate level, which not only improves the processing efficiency of tasks, but also reduces the waste of device computing power.
[0126] Furthermore, in another embodiment, where the model is a deep learning model, the method may further include, after training the model according to the target task:
[0127] Multimedia data is processed by a trained deep learning model to obtain processed multimedia data, wherein the multimedia data includes at least one of audio, video and images.
[0128] The processed multimedia data is sent to the terminal device for display.
[0129] In this embodiment, the model can be a deep learning model. After the deep learning model is trained, it can be used to process multimedia data. The multimedia data can include at least one of audio, video, and images.
[0130] For example, multimedia data can be images. Using a deep learning model, cartoon effects can be added to these images, which can then be displayed on the terminal device. The images can be locally stored or captured in real-time by the terminal device.
[0131] In addition, this deep learning model can also be applied to fields such as natural language processing and search recommendation.
[0132] Figure 4 The system architecture diagram of the concurrent thread count control method provided in the embodiments of this application is as follows: Figure 4 As shown, in this embodiment, it may include a system load statistics module, a concurrency optimization module, a thread management module, a task queue, and a task execution module.
[0133] The system includes the following modules: a system load statistics module for real-time tracking of the waiting time for each task and the idle time for each thread; a concurrency optimization module for determining the average waiting time for tasks and the average idle time for threads, and then determining the target number of concurrent threads based on these parameters; a thread management module for adjusting the number of concurrent threads based on the calculation results from the concurrency optimization module; a task queue for storing tasks to be executed; and a task execution module for sequentially executing tasks in the task queue using specific threads.
[0134] Based on the same idea, this specification also provides an apparatus corresponding to the above method. Figure 5 This is a schematic diagram of the structure of the concurrent thread count control device provided in the embodiments of this application, as shown below. Figure 5 As shown,
[0135] The apparatus provided in this embodiment may include:
[0136] The determination module 501 is used to determine the target number of concurrent threads based on the task load information.
[0137] The processing module 502 is used to set the number of concurrent threads in the thread pool to the target number of concurrent threads if the relationship between the initial number of concurrent threads and the target number of concurrent threads meets a preset condition.
[0138] The processing module 502 is further configured to obtain a target task from the task queue through the thread corresponding to the target number of concurrent threads, and to train the model according to the target task.
[0139] By adopting the above scheme, the target number of concurrent threads can be determined based on the task load information. Then, when the relationship between the initial number of concurrent threads and the target number of concurrent threads meets the preset conditions, the number of concurrent threads in the thread pool is set to the target number of concurrent threads. The target task is then retrieved from the task queue through the thread corresponding to the target number of concurrent threads, and the model is trained based on the target task. By determining the target number of concurrent threads based on the current load and adjusting the number of concurrent threads when the relationship between the initial number of concurrent threads and the target number of concurrent threads meets the preset conditions, the accuracy and flexibility of thread number setting are improved, thereby improving the efficiency of model training.
[0140] In another embodiment, the determining module 501 is further configured to:
[0141] Obtain the initial number of concurrent threads.
[0142] Determine the average waiting time for tasks and the average idle time for threads.
[0143] In this embodiment, the determining module 501 is further configured to:
[0144] The average waiting time of a task is determined based on the waiting time of a first target task in the task queue and the waiting time of at least one second target task, wherein the first target task is the unprocessed task in the task queue with the longest waiting time, and the second target task is the task in the task queue that has been processed.
[0145] The average idle time of a thread is determined based on the idle time of each idle thread in the thread pool.
[0146] Task load information is determined based on the average waiting time and the average idle time.
[0147] In this embodiment, the determining module 501 is further configured to:
[0148] The task waiting time factor is determined based on the average waiting time and the preset average waiting time threshold.
[0149] The thread idle time factor is determined based on the average idle time and the preset average idle time threshold.
[0150] The task load information is determined based on the task waiting time factor and the thread idle time factor.
[0151] Furthermore, the determining module 501 is also used for:
[0152] If the average waiting time is less than the average waiting time threshold, then the task waiting time factor is determined to be 1.
[0153] If the average waiting time is greater than or equal to the average waiting time threshold, then the task waiting time factor is determined to be the ratio of the average waiting time to the average waiting time threshold.
[0154] If the average idle time is less than the average idle time threshold, then the thread idle time factor is determined to be 1.
[0155] If the average idle time is greater than or equal to the average idle time threshold, then the thread idle time factor is determined to be the ratio of the average idle time to the average idle time threshold.
[0156] The task load information is obtained by multiplying the task waiting time factor and the thread idle time factor.
[0157] The target number of concurrent threads is determined based on the task load information and the initial number of concurrent threads.
[0158] In this embodiment, the determining module 501 is further configured to:
[0159] The target number of concurrent threads is obtained by multiplying the initial number of concurrent threads with the task load information.
[0160] In this embodiment, the determining module 501 is further configured to:
[0161] If the ratio of the initial number of concurrent threads to the target number of concurrent threads is not within the preset threshold range, then the number of concurrent threads in the thread pool is set to the target number of concurrent threads.
[0162] In addition, the determining module 501 is also used for:
[0163] If the ratio of the initial number of concurrent threads to the target number of concurrent threads is within a preset threshold range, then the number of concurrent threads in the thread pool is maintained at the initial number of concurrent threads.
[0164] Generate and display a message indicating that the number of concurrent threads remains unchanged.
[0165] Furthermore, in another embodiment, where the model is a deep learning model, the processing module 502 is further configured to:
[0166] Multimedia data is processed by a trained deep learning model to obtain processed multimedia data, which includes at least one of audio, video, and images.
[0167] The processed multimedia data is sent to the terminal device for display.
[0168] The apparatus provided in this application embodiment can achieve the above-mentioned... Figure 2 The methods in the embodiments shown are similar in principle and technical effect, and will not be described again here.
[0169] Figure 6 A schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application, such as... Figure 6 As shown, the device 600 provided in this embodiment includes a processor 601 and a memory communicatively connected to the processor. The processor 601 and the memory 602 are connected via a bus 603. In specific implementation, the processor 601 executes computer execution instructions stored in the memory 602, causing the processor 601 to perform the method described in the above method embodiment.
[0170] The specific implementation process of processor 601 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.
[0171] In the above Figure 6 In the illustrated embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.
[0172] The memory may include high-speed RAM, and may also include non-volatile storage (NVM), such as at least one disk storage.
[0173] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.
[0174] This application also provides a computer-readable storage medium storing computer-executable instructions. When a processor executes the computer-executable instructions, it implements the concurrent thread number control method of the above method embodiments.
[0175] This application also provides a computer program product, including a computer program, which, when executed by a processor, implements the concurrent thread count control method described above.
[0176] The aforementioned computer-readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.
[0177] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.
[0178] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0179] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A method for controlling the number of concurrent threads, characterized in that, include: Determine the target number of concurrent threads based on task load information; If the relationship between the initial number of concurrent threads and the target number of concurrent threads meets a preset condition, then the number of concurrent threads in the thread pool is set to the target number of concurrent threads; The target task is retrieved from the task queue using the thread corresponding to the target number of concurrent threads, and the model is trained based on the target task. Before determining the target number of concurrent threads based on task load information, the method further includes: The task waiting time factor is determined based on the average waiting time of the task and a preset average waiting time threshold. The thread idle time factor is determined based on the average idle time of the task and a preset average idle time threshold. The task load information is determined based on the task waiting time factor and the thread idle time factor.
2. The method according to claim 1, characterized in that, Before determining the task load information, the following steps are included: Obtain the initial number of concurrent threads; Determine the average waiting time of tasks and the average idle time of threads; Accordingly, determining the target number of concurrent threads based on the task load information includes: determining the target number of concurrent threads based on the task load information and the initial number of concurrent threads.
3. The method according to claim 2, characterized in that, The determination of the average waiting time of the task and the average idle time of the thread includes: The average waiting time of a task is determined based on the waiting time of a first target task in the task queue and the waiting time of at least one second target task, wherein the first target task is the unprocessed task in the task queue with the longest waiting time, and the second target task is the task in the task queue that has been processed. The average idle time of a thread is determined based on the idle time of each idle thread in the thread pool.
4. The method according to claim 1, characterized in that, The step of determining the task waiting time factor based on the average waiting time and a preset average waiting time threshold includes: If the average waiting time is less than the average waiting time threshold, then the task waiting time factor is determined to be 1; If the average waiting time is greater than or equal to the average waiting time threshold, then the task waiting time factor is determined to be the ratio of the average waiting time to the average waiting time threshold; Correspondingly, determining the thread idle time factor based on the average idle time and a preset average idle time threshold includes: If the average idle time is less than the average idle time threshold, then the thread idle time factor is determined to be 1; If the average idle time is greater than or equal to the average idle time threshold, then the thread idle time factor is determined to be the ratio of the average idle time to the average idle time threshold; Correspondingly, determining the task load information based on the task waiting time factor and the thread idle time factor includes: The task load information is obtained by multiplying the task waiting time factor and the thread idle time factor.
5. The method according to claim 2, characterized in that, The step of determining the target number of concurrent threads based on the task load information and the initial number of concurrent threads includes: The target number of concurrent threads is obtained by multiplying the initial number of concurrent threads with the task load information.
6. The method according to any one of claims 1-5, characterized in that, If the relationship between the initial number of concurrent threads and the target number of concurrent threads meets a preset condition, then the number of concurrent threads in the thread pool is set to the target number of concurrent threads, including: If the ratio of the initial number of concurrent threads to the target number of concurrent threads is not within the preset threshold range, then the number of concurrent threads in the thread pool is set to the target number of concurrent threads.
7. The method according to claim 6, characterized in that, Also includes: If the ratio of the initial number of concurrent threads to the target number of concurrent threads is within a preset threshold range, then the number of concurrent threads in the thread pool is maintained at the initial number of concurrent threads. Generate and display a message indicating that the number of concurrent threads remains unchanged.
8. The method according to any one of claims 1-5, characterized in that, If the model is a deep learning model, then after training the model according to the target task, the method further includes: Multimedia data is processed by the trained deep learning model to obtain processed multimedia data, wherein the multimedia data includes at least one of audio, video and images. The processed multimedia data is sent to the terminal device for display.
9. A concurrent thread count control device, characterized in that, include: The determination module is used to determine the target number of concurrent threads based on task load information; The processing module is used to set the number of concurrent threads in the thread pool to the target number of concurrent threads if the relationship between the initial number of concurrent threads and the target number of concurrent threads meets a preset condition. The processing module is further configured to obtain a target task from the task queue through the thread corresponding to the target number of concurrent threads, and train the model according to the target task; The determining module is specifically used for: The task waiting time factor is determined based on the average waiting time of the task and a preset average waiting time threshold. The thread idle time factor is determined based on the average idle time of the task and a preset average idle time threshold. The task load information is determined based on the task waiting time factor and the thread idle time factor.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, implement the method described in any one of claims 1-8.
11. A computer program product, characterized in that, Includes a computer program, which, when executed by a processor, implements the method as described in any one of claims 1-8.
Citation Information
Patent Citations
Method and device for adjusting thread pool, storage medium and computer equipment
CN108874550A
Thread adjusting method and device, application server and storage medium
CN111324447A
Asynchronous queue processing method and device, electronic equipment and storage medium
CN112463314A
Intelligent control method for congestion of instantaneous high-concurrency server thread pool
CN113194040A