An optimization method for improving thread execution efficiency and a terminal

By dynamically adjusting the amount of data in each thread through data sharing and monitoring of remaining data, the problem of low thread execution efficiency is solved, and all threads are completed within a consistent time, thus improving system performance.

CN118796392BActive Publication Date: 2025-11-28福建天晴在线互动科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410825733.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-25
Publication Date
2025-11-28
Estimated Expiration
2044-06-25

AI Technical Summary

Technical Problem

In existing technologies, when multi-threaded tasks are processed, the uneven amount of data leads to low thread execution efficiency, making it impossible to terminate tasks in a timely manner and affecting system performance.

Method used

By establishing data sharing between threads, monitoring the remaining data volume of each thread, and sorting and migrating the data based on the remaining data volume, the data volume of each thread is dynamically adjusted to ensure that faster threads process more data and slower threads process less data, so that all threads finish within a consistent time frame.

Benefits of technology

It effectively balances thread load, improves overall processing efficiency, reduces waiting time, and enhances system response speed and performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118796392B_ABST
    Figure CN118796392B_ABST
Patent Text Reader

Abstract

The application discloses an optimization method and a terminal for improving thread execution efficiency, and comprises the following steps: controlling each thread to acquire data for processing; after a preset time length, monitoring and acquiring the residual data amount of each thread; sorting the threads according to the residual data amount of each thread, and migrating and balancing the residual data amount of each thread according to the sorting result. The application monitors the residual data amount in the thread every certain time length, thereby reflecting the data processing efficiency of each thread, and sorts the threads according to the residual data amount, and performs data migration between the threads sorted in the front and the threads sorted in the rear, so that the residual data amount of each thread is dynamically regulated and controlled to ensure that the thread with high processing speed can process more data, and finally, the threads are all ended within a consistent time range, the processing efficiency of the whole thread is improved, and the system performance is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of data processing, in particular to an optimization method for improving thread execution efficiency and a terminal. BACKGROUND

[0002] Many current systems have the function of processing data. Because there are a large amount of data, multi-thread mode is usually used to process the massive data. The most common way is to read the data to be processed, and then distribute the data to a certain number of threads for concurrent processing. However, because the processing logic of the specific data may be different, or the total amount of data associated internally is different, even if the data is evenly distributed to each thread, the time 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, some threads may be faster and some threads may be slower, so that the task cannot be completed until one thread is not completed, and the threads that have been completed cannot be released. SUMMARY

[0003] The technical problem to be solved by the present application is to provide an optimization method for improving thread execution efficiency and a terminal to solve the problem of low thread task execution efficiency.

[0004] To solve the above technical problems, the technical scheme adopted by the present application is:

[0005] An optimization method for improving thread execution efficiency, comprising the steps of:

[0006] S1, establishing data sharing between threads to control each thread to obtain data for processing;

[0007] S2, after a predetermined time, monitoring and obtaining the remaining data amount of each thread;

[0008] S3, sorting the threads according to their remaining data amounts, and migrating and balancing the remaining data amounts of the threads according to the sorting result.

[0009] To solve the above technical problems, another technical scheme adopted by the present application is:

[0010] 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 executes the computer program to complete the following steps:

[0011] S1, establishing data sharing between threads to control each thread to obtain data for processing;

[0012] S2, after experiencing a preset time length, monitoring and acquiring the remaining data amount of each thread;

[0013] S3, sorting the threads according to the remaining data amount of each thread, and performing data migration and balancing according to the sorting result.

[0014] The beneficial effects of the present application at least include: providing an optimization method and terminal for improving thread execution efficiency, monitoring the remaining data amount in the thread every certain time length, reflecting the data processing efficiency of each thread according to the remaining data amount, and sorting the threads according to the size of the remaining data amount, and performing data migration between the threads sorted in the front and the threads sorted in the back, so as to dynamically control the remaining data amount of each thread to ensure that the threads with fast processing can process more data, and the threads with slow processing can process less data, finally realizing that the threads with faster processing can end the task a little slower, and the threads with slower processing can end the task a little faster, finally realizing that the overall threads end within a consistent time range, improving the overall thread processing efficiency, and improving the system performance. BRIEF DESCRIPTION OF DRAWINGS

[0015] Figure 1 A flowchart of an optimization method for improving thread execution efficiency in an embodiment of the present application;

[0016] Figure 2 A schematic diagram of an optimization terminal for improving thread execution efficiency in an embodiment of the present application;

[0017] Label explanation:

[0018] 1. An optimization terminal for improving thread execution efficiency; 2. A memory; 3. A processor. DETAILED DESCRIPTION

[0019] To explain the technical content, purposes and effects of the present application in detail, the following will be explained in combination with the embodiments and the drawings.

[0020] Please refer to Figure 1 An optimization method for improving thread execution efficiency, comprising the steps of:

[0021] S1, establishing data sharing between threads, and controlling each thread to acquire data for processing;

[0022] S2, after experiencing a preset time length, monitoring and acquiring the remaining data amount of each thread;

[0023] S3, sorting the threads according to the remaining data amount of each thread, and performing data migration and balancing according to the sorting result.

[0024] From the above description, the beneficial effects of the present application are that the remaining data amount in the thread is monitored every certain time length, which reflects the data processing efficiency of each thread, and the threads are sorted according to the size of the remaining data amount, and data migration is performed between the threads sorted in the front and the threads sorted in the rear, so as to dynamically regulate the remaining data amount of each thread to ensure that the threads with fast processing can process more data, and the threads with slow processing process less data, so as to finally realize that the threads with faster processing can end the task a little slower, and the threads with slower processing can end the task a little faster, and finally realize that the overall threads end within a consistent time range, improve the processing efficiency of the overall thread, and improve the system performance.

[0025] Specifically, the preset time length can be a plurality of periods according to the system performance, for example, one period is 5s, and the preset time length is three periods.

[0026] In the embodiment of the present application, the step S3 specifically comprises the steps of:

[0027] The threads are sorted according to the size of the remaining data amount, and data migration is performed between the threads in a mirror symmetry according to the sorting.

[0028] From the above description, by migrating the data of the threads with more remaining data amount to the threads with less remaining data amount, the load of each thread is effectively balanced, and some threads are prevented from exhausting resources too early due to too large data amount, for example, ten threads are sorted, part of the data of the thread sorted first (with the largest remaining data amount) is migrated to the thread sorted tenth (with the smallest remaining data amount), part of the data of the thread sorted second is migrated to the thread sorted ninth, and so on. Through such a way, the continuous data migration enables the system to dynamically adjust the load distribution between threads, adapt to the processing speed of different threads, and improve the overall processing efficiency.

[0029] In the embodiment of the present application, the step S3 further comprises the steps of:

[0030] The average remaining data amount of all threads is calculated;

[0031] For each thread, the difference between the average remaining data amount and the remaining data amount of the thread is calculated;

[0032] According to the difference, the migration data amount is determined, data migration is performed between the threads in a mirror symmetry according to the sorting, and the step S1 is returned.

[0033] From the above description, by calculating the average remaining data amount and the difference, the data migration amount can be more accurately determined, the data distribution is more reasonable, the load of each thread is further balanced, and the accurate regulation and control of the data migration manner can reduce the waiting time between threads, so that the threads with slower processing can complete the task as soon as possible, and the response speed of the overall system is improved.

[0034] In the embodiments of the present application, the monitoring of the remaining data amount and the data migration operation are both managed and recorded through the Redis database.

[0035] From the above description, it can be seen that by managing the remaining data amount and the data migration operation through the Redis database, the consistency and reliability of the data are ensured, and the problem of data inconsistency caused by concurrent operations is avoided. Among them, Redis as a high-performance in-memory database can quickly store and retrieve data, ensuring the efficient operation and real-time response of the system, at the same time, the management mode based on Redis is convenient for system expansion, and can easily cope with the demand of data amount increase and system scale expansion.

[0036] Preferably, the Redis database is provided with an asynchronous thread, and the asynchronous thread monitors the remaining data amount of each thread in Redis. By monitoring the data in Redis in real time through the asynchronous thread, the remaining data amount 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 thread avoids the blocking of main thread, improves the overall performance and concurrent processing capacity of the system.

[0037] Please refer to Figure 2 An optimization terminal for dynamically adjusting a sampling rate, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the computer program to complete the steps of the optimization method for dynamically adjusting a sampling rate.

[0038] From the above description, it can be seen that an execution carrier of the optimization method for dynamically adjusting a sampling rate is provided. In the execution of the above steps, the remaining data amount in the thread is monitored every certain time length to reflect the data processing efficiency of each thread, and the threads are sorted according to the size of the remaining data amount, and data migration is performed between the threads sorted in the front and the threads sorted at the back, so as to dynamically control the remaining data amount of each thread to ensure that the threads with faster processing can process more data and the threads with slower processing can process less data, finally realizing that the threads with faster processing can end the task a little slower, the threads with slower processing can end the task a little faster, and finally realizing that the overall threads end within a consistent time range, improving the processing efficiency of the overall threads and improving the system performance.

[0039] The present application provides an optimization method and terminal for dynamically adjusting a sampling rate, mainly applied to balancing the processing time of each thread in the system, thereby improving the task completion efficiency, which will be described in detail below in conjunction with embodiments.

[0040] Please refer to Figure 1 Embodiment one of the present application is:

[0041] An optimization method for improving thread execution efficiency, comprising the steps of:

[0042] S1, establishing data sharing between threads, controlling each thread to obtain data for processing;

[0043] S2, after a predetermined time, monitoring and obtaining the remaining data amount of each thread;

[0044] S3, sorting the threads according to their own remaining data amount, and migrating and balancing the remaining data amount of each thread according to the sorting result.

[0045] Specifically, by adopting the parameter data sharing mode, the parameter data is uniformly shared and stored, and the remaining data amount of each thread is monitored in real time, and the remaining data amount of each thread is dynamically controlled to ensure that the threads that process faster can process more data, and the threads that process slower can process less data, so that the threads that process faster can end the task slower, and the threads that process slower can end the task faster, and finally the overall threads end within a consistent time range, improving the processing efficiency of the overall threads and improving the system performance.

[0046] Please refer to Figure 1 , the second embodiment of the present application is:

[0047] Based on the first embodiment, step S3 specifically comprises the steps of:

[0048] The threads are sorted according to their own remaining data amount, and the data migration between the threads is performed according to the sorting mirror symmetry.

[0049] The specific application is as follows: among the existing ten threads, the remaining data amount of the first sorted thread is 9000, and the remaining data amount of the tenth sorted thread is 8000, then part of the data of the first sorted thread is migrated to the tenth sorted thread, and the following migration rule can be used: 25%-50% of the difference between the two is migrated, 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 , the third embodiment of the present application is:

[0051] Based on the second embodiment, step S3 further comprises the steps of:

[0052] Calculating the average remaining data amount of all threads; for each thread, calculating the difference between it and the average remaining data amount; according to the difference, determining the migration data amount, and performing data migration between threads according to the sorting mirror symmetry; returning to step S1.

[0053] The specific application is as follows:

[0054] Suppose there are 10 threads (T1, T2,..., T10) processing 100,000 data, and each thread is initially allocated 10,000 data. After a period of time, it is detected that the remaining data amounts of each thread are (T1: 12000, T2: 11500, T3: 11000,..., T10: 9000).

[0055] Calculate the average remaining data amount:

[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 migration data amount:

[0063] Migrate a part (e.g. 750) of T1's 1500 data to T10 to make T10 close to the average data amount.

[0064] Migrate a part (e.g. 500) of T2's 1000 data to T9 to make T10 close to the average data amount.

[0065] Preferably, the migration ratio of the difference between each thread and the average remaining data amount is between 20% and 50%, preferably 30%, 40%, and 50%.

[0066] Other threads follow the same strategy for data migration.

[0067] In addition, in this example, priority adjustment and dynamic adjustment strategies are set:

[0068] If T2 and T10 are high-priority threads, more data is preferentially migrated to them to ensure their efficient operation.

[0069] Real-time monitoring of the load of each thread is performed, and the migration data amount ratio is dynamically adjusted to ensure that the system is always in the best operating state.

[0070] Please refer to Figure 2 , embodiment four of the present application 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, and the processor 3 completes the steps in the optimization method for dynamically adjusting the sampling rate in any one of the above embodiments I to III when executing the computer program.

[0072] In summary, the present application provides an optimization method and terminal for improving thread execution efficiency, which monitors the remaining data amount in the thread every certain time length, thereby reflecting the data processing efficiency of each thread, and sorts the threads according to the size of the remaining data amount, and migrates data between the threads sorted in the front and the threads sorted in the rear, thereby dynamically regulating the remaining data amount of each thread to ensure that the threads with fast processing can process more data, and the threads with slow processing can process less data, finally realizing that the threads with faster processing can end the task a little slower, and the threads with slower processing can end the task a little faster, and finally realizing that the overall threads end within a consistent time range, improving the overall thread processing efficiency, and improving the system performance.

[0073] The above is only an embodiment of the present application, and does not limit the patent range of the present application, and any equivalent transformation or direct or indirect application in the related technical field by using the content of the present application specification and drawings is also included in the patent protection range of the present application.

Claims

1. An optimization method for improving thread execution efficiency, characterized in that: The method comprises the steps of: S1, establishing data sharing between threads, and controlling each thread to acquire data for processing; S2, after a preset time period, monitoring and acquiring the remaining data amount of each thread; S3, sorting the threads according to the remaining data amount of each thread, and performing migration balancing on the remaining data amount of each thread according to the sorting result; The step S3 specifically comprises the steps of: sorting the threads according to the remaining data amount of each thread, and performing data migration between the threads in a mirror symmetry manner according to the sorting result; The step S3 further comprises the steps of: calculating the average remaining data amount of all threads; for each thread, calculating the difference between the average remaining data amount and the remaining data amount of the thread; determining the migration data amount according to the difference, and performing data migration between the threads in a mirror symmetry manner according to the sorting result; and returning to step S1.

2. The optimization method for improving the execution efficiency of threads according to claim 1, wherein: the monitoring of the remaining data amount and the data migration operation are managed and recorded through a Redis database.

3. The optimization method for improving thread execution efficiency according to claim 2, 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 the Redis.

4. An optimization terminal for improving thread execution efficiency, characterized by: A computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to complete the following steps: S1, establishing data sharing between threads, and controlling each thread to acquire data for processing; S2, after a preset time period, monitoring and acquiring the remaining data amount of each thread; S3, sorting the threads according to the remaining data amount of each thread, and performing migration balancing on the remaining data amount of each thread according to the sorting result; The step S3 specifically comprises the steps of: sorting the threads according to the remaining data amount of each thread, and performing data migration between the threads in a mirror symmetry manner according to the sorting result; The step S3 further comprises the steps of: calculating the average remaining data amount of all threads; for each thread, calculating the difference between the average remaining data amount and the remaining data amount of the thread; determining the migration data amount according to the difference, and performing data migration between the threads in a mirror symmetry manner according to the sorting result; and returning to step S1.

5. The optimization terminal for improving the execution efficiency of threads according to claim 4, wherein: the monitoring of the remaining data amount and the data migration operation are managed and recorded through a Redis database.

6. The optimization terminal for improving thread execution efficiency according to claim 5, 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 the Redis.

Citation Information

Patent Citations

  • Load balancing method for parallel processing of stream data

    CN105022671A

  • Method for processing service data and terminal equipment

    CN109344153A