Optimization method for improving thread execution efficiency and terminal
Through inter-thread data sharing and dynamic data migration, the problem of thread execution time inconsistency in multi-thread processing is solved, and the coordinated end of thread tasks and system performance improvement are achieved.
Patent Information
- Application Number
- CN202410825733.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-25
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2044-06-25
AI Technical Summary
When multi-threads process massive amounts of data, due to different data processing logic and inconsistent data volumes, thread execution times are inconsistent, causing tasks to fail to end in time, thus affecting system performance.
By establishing data sharing between threads and monitoring the remaining data amount of each thread, sorting and data migration are performed according to the remaining data amount, and the load of each thread is dynamically controlled to ensure that fast threads process more data and slow threads process less data to achieve the coordinated end of thread tasks.
It achieves the overall time consistency of thread tasks, improves thread execution efficiency and system performance, and avoids resource waste and waiting time caused by excessive data volume.
Smart Images

Figure CN118796392A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing, and in particular to an optimization method and a terminal for improving thread execution efficiency. Background Art
[0002] Many current systems have the function of processing data in tasks. Because there is a large amount of data, multi-threading is usually used to process massive data. The most common way is to read the amount of data to be processed, evenly distribute this amount of data to a certain number of threads, and let these threads process this data concurrently. However, since the processing logic of specific data may be different, or the total amount of data associated again within the data may be different, even if all the input data has been evenly distributed to each thread, the time it takes for the thread to process all the data may be inconsistent, which may be fast or slow. Therefore, even if the data is evenly distributed to each thread for execution, and all threads are executed, some may be fast and some may be slow. Therefore, as long as there is only one thread that has not been completed, the task will not end, and thus the terminated thread cannot be released. Summary of the invention
[0003] The technical problem to be solved by the present invention is to provide an optimization method and a terminal for improving thread execution efficiency, so as to solve the problem of low thread task execution efficiency.
[0004] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0005] An optimization method for improving thread execution efficiency comprises the steps of:
[0006] S1. Establish data sharing between threads and control each thread to obtain data for processing;
[0007] S2. After a preset time, monitor and obtain the remaining data volume of each thread;
[0008] S3. Sort the threads according to the amount of their remaining data, and perform migration balancing on the remaining data of each thread according to the sorting result.
[0009] In order to solve the above technical problems, another technical solution adopted by the present invention is:
[0010] An optimization terminal for dynamically adjusting a sampling rate comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor completes the following steps when executing the computer program:
[0011] S1. Establish data sharing between threads and control each thread to obtain data for processing;
[0012] S2. After a preset time, monitor and obtain the remaining data volume of each thread;
[0013] S3. Sort the threads according to the amount of their remaining data, and perform migration balancing on the remaining data of each thread according to the sorting result.
[0014] The beneficial effects of the present invention include at least: providing an optimization method and terminal for improving thread execution efficiency, monitoring the amount of remaining data in the thread at regular intervals to reflect the data processing efficiency of each thread, and sorting the threads according to the amount of remaining data, performing data migration between threads with a higher order and threads with a lower order, thereby dynamically regulating the amount of remaining data of each thread to ensure that threads with a faster processing speed can process more data and threads with a slower processing speed can process less data, ultimately achieving that threads with a faster processing speed can end tasks more slowly and threads with a slower processing speed can end tasks faster, ultimately achieving that all threads as a whole end within a consistent time range, thereby improving the processing efficiency of the overall thread and improving system performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 A flowchart of an optimization method for improving thread execution efficiency in an embodiment of the present invention;
[0016] Figure 2 A schematic diagram of an optimization terminal for improving thread execution efficiency in an embodiment of the present invention;
[0017] Description of labels:
[0018] 1. An optimized terminal for improving thread execution efficiency; 2. Memory; 3. Processor. DETAILED DESCRIPTION
[0019] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in combination with the implementation modes and the accompanying drawings.
[0020] Please refer to Figure 1 , an optimization method for improving thread execution efficiency, comprising the steps of:
[0021] S1. Establish data sharing between threads and control each thread to obtain data for processing;
[0022] S2. After a preset time, monitor and obtain the remaining data volume of each thread;
[0023] S3. Sort the threads according to the amount of their remaining data, and perform migration balancing on the remaining data of each thread according to the sorting result.
[0024] From the above description, it can be seen that the beneficial effects of the present invention are: monitoring the amount of remaining data in the thread at regular intervals to reflect the data processing efficiency of each thread, and sorting the threads according to the amount of remaining data, performing data migration between threads with a higher order and threads with a lower order, thereby dynamically adjusting the amount of remaining data of each thread to ensure that threads with faster processing can process more data, and threads with slower processing can process less data, ultimately achieving that threads with faster processing can end tasks more slowly, and threads with slower processing can end tasks faster, ultimately achieving that all threads as a whole end within a consistent time range, thereby improving the overall thread processing efficiency and improving system performance.
[0025] Specifically, the preset time length may be a plurality of cycles formulated according to system performance, for example, one cycle is 5 seconds and the preset time length is three cycles.
[0026] In an embodiment of the present invention, step S3 specifically includes the following steps:
[0027] The threads are sorted according to the amount of their own remaining data, and data migration between threads is performed symmetrically according to the sorting mirror.
[0028] From the above description, it can be seen that by migrating the data of the thread with a large amount of remaining data to the thread with a small amount of remaining data, the load of each thread is effectively balanced to prevent some threads from exhausting resources prematurely due to excessive data volume. For example, if there are ten threads, part of the data of the thread ranked first (with the largest amount of remaining data) is migrated to the thread ranked tenth (with the least amount of remaining data), and part of the data of the thread ranked second is migrated to the thread ranked ninth, and so on. In this way, continuous data migration enables the system to dynamically adjust the load distribution between threads, adapt to the processing speeds of different threads, and improve the overall processing efficiency.
[0029] In an embodiment of the present invention, step S3 further includes the steps of:
[0030] Calculate the average amount of remaining data for all threads;
[0031] For each thread, calculate the difference between it and the average amount of remaining data;
[0032] According to the difference, the amount of data to be migrated is determined, and data migration between threads is performed symmetrically according to the sorted mirror; and the process returns to step S1.
[0033] From the above description, it can be seen that by calculating the average remaining data volume and the difference, the data migration volume can be determined more accurately, making the data allocation more reasonable and further balancing the load of each thread. This precisely controlled data migration method can reduce the waiting time between threads, allowing the slower processing threads to complete the task as soon as possible, thereby improving the response speed of the overall system.
[0034] In an embodiment of the present invention, the monitoring of the remaining data volume and the data migration operations are both managed and recorded through a Redis database.
[0035] From the above description, we can see that the remaining data volume and data migration operations are managed through the Redis database to ensure data consistency and reliability and avoid data inconsistency problems caused by concurrent operations. Among them, Redis, as a high-performance memory database, can quickly store and retrieve data to ensure efficient operation and real-time response of the system. At the same time, the management method based on Redis facilitates system expansion and can easily cope with the needs of increasing data volume and expanding system scale.
[0036] Preferably, the Redis database is provided with an asynchronous thread, and the asynchronous thread monitors the remaining data volume of each thread in Redis. By real-time monitoring of the data in Redis by the asynchronous thread, the remaining data volume information of each thread can be obtained in time, ensuring the timeliness and accuracy of the data migration operation. At the same time, the use of asynchronous threads avoids blocking the main thread, and improves the overall performance and concurrent processing capability of the system.
[0037] Please refer to Figure 2 , an optimization terminal for dynamically adjusting the sampling rate, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor completes the steps in the above-mentioned optimization method for dynamically adjusting the sampling rate when executing the computer program.
[0038] From the above description, it can be seen that an execution carrier of an optimization method for dynamically adjusting the sampling rate is provided. In executing the above steps, the amount of remaining data in the thread is monitored at regular intervals to reflect the data processing efficiency of each thread, and the threads are sorted according to the amount of remaining data, and data migration is performed between threads with a higher order and threads with a lower order, so as to dynamically adjust the amount of remaining data of each thread to ensure that faster processing threads can process more data and slower processing threads can process less data, and finally achieve that faster processing threads can end tasks more slowly and slower processing threads can end tasks faster, and finally achieve that the overall threads are terminated within a consistent time range, thereby improving the overall thread processing efficiency and improving system performance.
[0039] The present invention provides an optimization method and terminal for dynamically adjusting a sampling rate, which are mainly used to balance the processing time of each thread in a system, thereby improving the efficiency of task completion, and are specifically described below in conjunction with an embodiment.
[0040] Please refer to Figure 1 , Embodiment 1 of the present invention is:
[0041] An optimization method for improving thread execution efficiency comprises the steps of:
[0042] S1. Establish data sharing between threads and control each thread to obtain data for processing;
[0043] S2. After a preset time, monitor and obtain the remaining data volume of each thread;
[0044] S3. Sort the threads according to the amount of their remaining data, and perform migration balancing on the remaining data of each thread according to the sorting result.
[0045] Specifically, by adopting the method of input parameter data sharing, the input parameter data is uniformly shared and stored, and the remaining data amount of each thread is monitored in real time. By dynamically adjusting the remaining data amount of each thread, it is ensured that the faster processing thread can process more data, and the slower processing thread can process less data. Ultimately, the faster processing thread can end the task more slowly, and the slower processing thread can end the task faster. Ultimately, the overall threads are terminated within a consistent time range, thereby improving the overall thread processing efficiency and system performance.
[0046] Please refer to Figure 1 , Embodiment 2 of the present invention is:
[0047] Based on the first embodiment, step S3 specifically includes the following steps:
[0048] The threads are sorted according to the amount of their own remaining data, and data migration between threads is performed symmetrically according to the sorting mirror.
[0049] The specific application is as follows: among the ten existing threads, the remaining data volume of the first-ranked thread is 9,000, and the remaining data volume of the tenth-ranked thread is 8,000. Then, part of the data of the first-ranked thread is migrated to the tenth-ranked thread. The following migration rule can be used to migrate 25%-50% of the difference between the two, that is, the migration amount is 250-500, thereby effectively balancing the load of each thread, adapting to the processing speed of different threads, and improving the overall processing efficiency.
[0050] Please refer to Figure 1 , Embodiment 3 of the present invention is:
[0051] Based on the second embodiment, step S3 further includes the following steps:
[0052] Calculate the average remaining data volume of all threads; for each thread, calculate the difference between the average remaining data volume and the average remaining data volume; determine the migration data volume according to the difference, and perform data migration between threads according to the sorting mirror symmetry; return to step S1.
[0053] The specific applications are as follows:
[0054] Assume that there are 10 threads (T1, T2, ..., T10) processing 100,000 data items, and each thread is initially allocated 10,000 data items. After a period of time, it is detected that the remaining data of each thread is (T1: 12000, T2: 11500, T3: 11000, ..., T10: 9000).
[0055] Calculate the average amount of remaining data:
[0056] AverageData=(12000+11500+11000+...+9000) / 10=10500
[0057] Calculate the difference between each thread and the average remaining data amount:
[0058] T1:12000-10500=1500
[0059] T2: 11500-10500=1000 ...
[0061] T10:9000-10500=-500
[0062] Determine the amount of data to migrate:
[0063] A portion of the 1500 data items of T1 (eg, 750 items) is migrated to T10, so that T10 is close to the average data amount.
[0064] A portion (eg, 500) of the 1000 data items in T2 is migrated to T9 so that T10 is close to the average data amount.
[0065] Preferably, the migration ratio of the difference between each thread and the average remaining data volume is between 20% and 50%, preferably 30%, 40% and 50%.
[0066] Other threads perform data migration according to the same strategy.
[0067] In addition, in this example, set the priority adjustment and dynamic adjustment policies:
[0068] If T2 and T10 are high-priority threads, more data will be migrated to them first to ensure their efficient operation.
[0069] Monitor the load of each thread in real time and dynamically adjust the proportion of migrated data to ensure that the system is always in the best operating state.
[0070] Please refer to Figure 2 , Embodiment 4 of the present invention is:
[0071] An optimization terminal 1 for dynamically adjusting a sampling rate comprises a memory 2, a processor 3, and a computer program stored in the memory 2 and executable on the processor 3. When the processor 3 executes the computer program, the steps of any one of the optimization methods for dynamically adjusting a sampling rate in the above-mentioned embodiments 1 to 3 are completed.
[0072] In summary, the present invention provides an optimization method and terminal for improving thread execution efficiency, which monitors the amount of remaining data in the thread at regular intervals to reflect the data processing efficiency of each thread, and sorts the threads according to the amount of remaining data, performs data migration between threads with a higher order and threads with a lower order, thereby dynamically regulating the amount of remaining data of each thread to ensure that threads with a faster processing speed can process more data and threads with a slower processing speed can process less data, and ultimately achieve that threads with a faster processing speed can end tasks more slowly and threads with a slower processing speed can end tasks faster, and ultimately achieve that all threads as a whole end within a consistent time range, thereby improving the processing efficiency of the overall thread and improving system performance.
[0073] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. An optimization method for improving thread execution efficiency, characterized in that: Includes steps: S1. Establish data sharing between threads and control each thread to obtain data for processing; S2. After a preset time, monitor and obtain the remaining data volume of each thread; S3. Sort the threads according to the amount of their remaining data, and perform migration balancing on the remaining data of each thread according to the sorting result.
2. The optimization method for improving thread execution efficiency according to claim 1, characterized in that: The step S3 specifically comprises the following steps: The threads are sorted according to the amount of their own remaining data, and data migration between threads is performed symmetrically according to the sorting mirror.
3. The optimization method for improving thread execution efficiency according to claim 2, characterized in that: The step S3 further comprises the steps of: Calculate the average amount of remaining data for all threads; For each thread, calculate the difference between it and the average amount of remaining data; Determine the amount of data to be migrated based on the difference, and migrate data between threads symmetrically according to the sorted mirror. Return to step S1.
4. The optimization method for improving thread execution efficiency according to claim 1, characterized in that: The monitoring of the remaining data volume and the data migration operations are managed and recorded through the Redis database.
5. The optimization method for improving thread execution efficiency according to claim 4, characterized in that: The Redis database is provided with an asynchronous thread, and the asynchronous thread monitors the remaining data amount of each thread in Redis.
6. An optimization terminal for improving thread execution efficiency, characterized in that: The invention comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the following steps are performed: S1. Establish data sharing between threads and control each thread to obtain data for processing; S2. After a preset time, monitor and obtain the remaining data volume of each thread; S3. Sort the threads according to the amount of their remaining data, and perform migration balancing on the remaining data of each thread according to the sorting result.
7. The optimization terminal for improving thread execution efficiency according to claim 6, characterized in that: The step S3 specifically comprises the following steps: The threads are sorted according to the amount of their own remaining data, and data migration between threads is performed symmetrically according to the sorting mirror.
8. The optimization terminal for improving thread execution efficiency according to claim 7, characterized in that: The step S3 further comprises the steps of: Calculate the average amount of remaining data for all threads; For each thread, calculate the difference between it and the average amount of remaining data; Determine the amount of data to be migrated based on the difference, and migrate data between threads symmetrically according to the sorted mirror. Return to step S1.
9. The optimization terminal for improving thread execution efficiency according to claim 6, characterized in that: The monitoring of the remaining data volume and the data migration operations are managed and recorded through the Redis database.
10. The optimization terminal for improving thread execution efficiency according to claim 9, characterized in that: The Redis database is provided with an asynchronous thread, and the asynchronous thread monitors the remaining data amount of each thread in Redis.
Citation Information
Patent Citations
Load balancing method for parallel processing of stream data
CN105022671A
Method for processing service data and terminal equipment
CN109344153A
Data monitoring method and device, server and storage medium
CN110019372A
Sorted data processing method and device, storage medium and server
CN110781217A
Data migration method and system
CN112241398A
