Thread data processing method, device, equipment and storage medium
By creating multiple new thread entities and load scheduling in a multi-core and multi-threaded system, the load balancing problem during thread overload is solved, the frequency of code modification is reduced, and processing efficiency and stability is improved.
Patent Information
- Application Number
- CN202310714913.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-15
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2043-06-15
AI Technical Summary
Existing multi-core and multi-threaded systems are difficult to achieve payload balancing when dealing with thread overload, resulting in frequent modification of code to split threads, which cannot completely solve the problem, and there may be load imbalance between the split threads.
By creating multiple new thread entities in the scheduling module and scheduling their operations based on the thread load, we determine the message communication path between the upstream and downstream threads to achieve load balancing, and at the same time, using read and write locks to reduce using read and write locks when there are many read operations. The additional load brought by the mutex.
It realizes dynamic balancing scheduling of thread loads, reduces the frequency of code modification, improves the processing efficiency and stability of the system, and avoids load imbalance between threads.
Smart Images

Figure CN116860436B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of computer technology, and specifically relates to a thread data processing method, device, equipment and storage medium. Background Art
[0002] With the rapid development of information technology, the number of users and data has increased rapidly in recent years, which has put a test on the data processing and load balancing capabilities of computer systems. In the application of embedded Linux systems, multi-core multi-threaded systems are usually used for data or message processing and communication transmission. Among them, the operation of each thread on the multi-core can be scheduled by the system, or the designer can specify the thread to run on a specified core. However, when the load of a thread running on a single core is overloaded, whether it is running on a specified core or scheduled by the system, the multi-core multi-threaded system has no way to solve the thread overload problem.
[0003] The current method to solve the overload problem in a multi-core multi-threaded system mainly adopts the method of modifying the code to split the overloaded thread into two sub-threads, with the two sub-threads being in an upstream and downstream relationship, and assigning the two sub-threads to run on two different cores to solve the thread overload problem. However, this method is relatively complicated; moreover, it cannot completely solve the thread overload problem. Specifically, if the system faces the overload problem again after the modification is successful, the code needs to be modified twice, three times or even more times, which consumes a lot of time. Summary of the invention
[0004] In order to solve the above technical problems, the present application provides a thread data processing method, device, equipment and storage medium. The present application creates multiple new threads according to the original thread when the thread load is overloaded, and schedules the communication between the multiple new threads and the upstream and downstream threads through a scheduling module, thereby realizing load balancing scheduling of threads and avoiding secondary modification of the code.
[0005] On the one hand, the present application proposes a thread data processing method, which is applied to a scheduling module, and the method includes:
[0006] In the case where the first thread is executed to obtain the data to be processed of the original second thread, a target processing thread is determined from multiple current second threads; the target processing thread is a thread that meets the preset processing requirements; the multiple current second threads are threads created based on the original second thread when the original second thread is overloaded; the processing capacity of each current second thread is consistent with that of the original second thread;
[0007] A target processing instruction is sent to the first thread, wherein the target processing instruction instructs the first thread to send the to-be-processed data of the original second thread to the target processing thread, so that the target processing thread is executed to process the to-be-processed data.
[0008] Optionally, when the first thread is executed to obtain the data to be processed of the original second thread, before determining the target processing thread from multiple current second threads, the method also includes: when the original second thread is overloaded, creating multiple current second threads based on the original second thread; the processing capability of each current second thread is consistent with that of the original second thread.
[0009] Optionally, determining a target processing thread from multiple current second threads includes: determining a thread load of each current second thread; determining a target load that meets a first preset load requirement from the thread load of each current second thread, and determining the current second thread corresponding to the target load as the target processing thread.
[0010] Optionally, determining the target processing thread from the multiple current second threads includes: determining a data object of the to-be-processed data of the original second thread; and determining the target processing thread from the multiple current second threads based on the data object.
[0011] Optionally, based on the data object, a target processing thread is determined from multiple current second threads, including: when the data object meets the first preset object requirement, determining the thread load of each current second thread; determining a target load that meets the second preset load requirement from the thread load of each current second thread, and determining the current second thread corresponding to the target load as the target processing thread; or; when the data object meets the second preset object requirement, determining a thread among multiple current second threads that has processed data of the data object as the target processing thread.
[0012] Optionally, the scheduling module is located in the first thread, and the method also includes: receiving a thread selection request sent by a third thread; the thread selection request is generated after the third thread processes the third thread's pending data to obtain return data; the third thread's pending data is obtained by the target processing thread processing the original second thread's pending data; determining a target return thread from multiple current second threads; the target return thread is a thread thread that meets a preset return requirement; sending thread selection information to the third thread; the thread selection information includes information of the target return thread, and the thread selection information is used to instruct the third thread to send the return data to the target return thread.
[0013] Optionally, determining a target return thread from a plurality of original second threads and a current second thread includes: determining a thread load of each current second thread; determining a target load that meets a third preset load requirement from the thread load of each current second thread, and determining the original second thread and the current second thread corresponding to the target load as the target return thread; or; determining a thread that has processed data of a data object from a plurality of current second threads as the target return thread; wherein the thread selection request includes information of the data object of the return information.
[0014] On the other hand, an embodiment of the present application provides a thread data processing device, the device comprising:
[0015] A determination module is used to determine a target processing thread from a plurality of current second threads when the first thread is executed to obtain data to be processed of the original second thread; the target processing thread is a thread that meets the preset processing requirement; the plurality of current second threads are threads created based on the original second thread when the original second thread is overloaded; and the processing capacity of each current second thread is consistent with that of the original second thread;
[0016] The sending module is used to send a target processing instruction to the first thread, wherein the target processing instruction instructs the first thread to send the original to-be-processed data of the second thread to the target processing thread, so that the target processing thread is executed to process the to-be-processed data.
[0017] Optionally, the determination module is used to: when the first thread is run to obtain the data to be processed of the original second thread, before determining the target processing thread from multiple current second threads, when the original second thread is overloaded, create multiple current second threads based on the original second thread; the processing capability of each current second thread is consistent with that of the original second thread.
[0018] Optionally, the determination module is used to: determine the thread load of each current second thread in the process of determining the target processing thread from multiple current second threads; determine the target load that meets the first preset load requirement from the thread load of each current second thread, and determine the current second thread corresponding to the target load as the target processing thread.
[0019] Optionally, the determination module is used to: determine the data object of the to-be-processed data of the original second thread in the process of determining the target processing thread from multiple current second threads; and determine the target processing thread from multiple current second threads based on the data object.
[0020] Optionally, the determination module is used to, in the process of determining a target processing thread from multiple current second threads based on a data object, determine the thread load of each current second thread when the data object meets the first preset object requirement; determine a target load that meets the second preset load requirement from the thread load of each current second thread, and determine the current second thread corresponding to the target load as the target processing thread; or; when the data object meets the second preset object requirement, determine the thread that has processed the data of the data object among the multiple current second threads as the target processing thread.
[0021] Optionally, the scheduling module is located in the first thread, and the determination module is used to: receive a thread selection request sent by a third thread; the thread selection request is generated after the third thread processes the third thread's pending data to obtain return data; the third thread's pending data is obtained by the target processing thread processing the original second thread's pending data; determine the target return thread from multiple current second threads; the target return thread is a thread thread that meets preset return requirements; send thread selection information to the third thread; the thread selection information includes information of the target return thread, and the thread selection information is used to instruct the third thread to send the return data to the target return thread.
[0022] Optionally, the determination module is used to: determine the thread load of each current second thread in the process of determining the target return thread from multiple original second threads and the current second thread; determine the target load that meets the third preset load requirement from the thread load of each current second thread, and determine the original second thread and the current second thread corresponding to the target load as the target return thread; or; determine the thread that has processed the data of the data object among the multiple current second threads as the target return thread; wherein the thread selection request includes information of the data object of the return information.
[0023] On the other hand, the present application proposes an electronic device for thread data processing, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement the thread data processing method as described above.
[0024] On the other hand, the present application proposes a computer-readable storage medium, which stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by a processor to implement the thread data processing method as described above.
[0025] The thread data processing method, device, electronic device and storage medium proposed in the embodiment of the present application, by adding a scheduling module, the scheduling module can create multiple thread entities based on the thread when the thread is overloaded, and assign the multiple thread entities to different cores for processing, so that different cores can share the load of the thread. It is used to schedule the message communication between the thread and its upstream thread and downstream thread. The scheduling module creates multiple thread entities based on the thread that needs to balance the load, and determines to which thread entity the upstream thread sends the pending message and to which thread entity the downstream thread sends the return message, so as to assign the message to the appropriate thread entity for processing according to the specific situation of the pending message, thereby achieving load balancing between multiple thread entities. Furthermore, in the embodiment of the present application, when the read operation of the thread is more than the write operation, the mutex lock is removed and the read-write lock is adopted, which can avoid the additional load increase caused by the mutex lock, thereby further reducing the thread load. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions and advantages of the embodiments of the present application or the prior art, the drawings required for use in the embodiments or the prior art description are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work.
[0027] Figure 1 is a schematic diagram of an implementation environment of a thread data processing method according to an exemplary embodiment;
[0028] Figure 2 is a flowchart of a thread data processing method according to an exemplary embodiment;
[0029] Figure 3 is a flowchart of a thread data processing method according to an exemplary embodiment;
[0030] Figure 4 is a flowchart of a thread data processing method according to an exemplary embodiment;
[0031] Figure 5 is a flowchart of a thread data processing method according to an exemplary embodiment;
[0032] Figure 6 is a flowchart of a thread data processing method according to an exemplary embodiment;
[0033] Figure 7 is a flowchart of a thread data processing method according to an exemplary embodiment;
[0034] Figure 8 The figure is a block diagram of a thread data processing device according to an exemplary embodiment.
[0035] Fig. 9 The present invention is a hardware structure block diagram of a server of a thread data processing method provided according to an exemplary embodiment. DETAILED DESCRIPTION
[0036] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0037] It should be noted that the terms "first", "second", etc. in the specification and claims of the embodiments of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or server comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.
[0038] In order to make the purpose, technical solution and advantages disclosed in the embodiments of the present application more clearly understood, the embodiments of the present application are further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the embodiments of the present application and are not used to limit the embodiments of the present application.
[0039] Embedded Linux systems are basically multi-core multi-threaded systems, in which the operation of each thread on the multi-core can be scheduled by the system, or the designer can specify that the thread runs on one of the multi-cores. However, when a single thread is overloaded, that is, the load of a single thread running on a single core reaches 100%, no matter it is specified by the designer or scheduled by the system, other cores have no way to share the load on the overloaded core, and there is no way to solve the overload problem of the thread. When encountering this problem, the existing method is generally to split the thread into two threads with upstream and downstream relationships. For example, when the thread processing flow is "ABCD", the thread can be split into "AB" and "CD", and the thread function call between "BC" can be changed to message passing between threads. This method is more cumbersome; and if the overload situation occurs again after one split, the thread has to be split again; furthermore, there is also a load imbalance between the split threads.
[0040] Based on this, the embodiment of the present application proposes a thread data processing method, which is used to schedule the message communication between the thread that needs to balance the load and its upstream thread and downstream thread by adding a scheduling module. The scheduling module creates multiple thread entities based on the thread that needs to balance the load, and determines to which thread entity the upstream thread sends the pending message for processing, and determines to which thread entity the downstream thread sends the return message, so as to assign the message to the appropriate thread entity for processing according to the specific situation of the pending message, thereby realizing load balancing between multiple thread entities.
[0041] Figure 1FIG. 1 is a schematic diagram showing an implementation environment of a thread data processing method according to an exemplary embodiment. Figure 1 As shown, the implementation environment may include at least a client 01 and a server 02. The client 01 and the server 02 may be directly or indirectly connected via wired or wireless communication, and this application does not impose any limitation thereto.
[0042] Specifically, the client 01 can be used to receive input of text to be recognized, display search results, etc. Optionally, the client 01 can include physical devices such as smart phones, desktop computers, tablet computers, laptop computers, digital assistants, augmented reality (AR) / virtual reality (VR) devices, intelligent voice interaction devices, smart home appliances, smart wearable devices, vehicle-mounted terminal devices, etc., and can also include software running in physical devices, such as applications, etc.
[0043] Specifically, the server 02 can be used to process the back-link data, including encoding and vectorizing each feature information, and then performing feature crossover and recommendation prediction, so as to obtain the prediction recommendation results of multiple business goals. The server 02 can also be used to train the thread data processing model, and send a recommendation instruction to the recommendation system corresponding to the target object, wherein the recommendation instruction can be used to instruct the recommendation system to recommend information. Optionally, the server 02 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms. Specifically, the above-mentioned servers may include physical devices, which may specifically include network communication submodules, processors and memories, etc., and may also include software running in physical devices, which may specifically include applications, etc.
[0044] It should be noted that Figure 1 This is just an example. In other scenarios, other implementation environments may also be included.
[0045] Figure 2 is a flowchart of a thread data processing method according to an exemplary embodiment. The method can be used for Figure 1In the implementation environment of the embodiment. This specification provides the thread data processing method operation steps as described in the embodiment or flowchart, but may include more or fewer operation steps based on conventional or non-creative labor. The order of steps listed in the embodiment is only one way of executing the steps among many steps, and does not represent the only execution order. When the actual system or server product is executed, it can be executed in sequence or in parallel according to the method shown in the embodiment or the accompanying drawings (for example, in a parallel processor or multi-threaded processing environment). Specifically, Figure 2 As shown, the method may include:
[0046] S101: When a first thread is executed to obtain data to be processed by an original second thread, a target processing thread is determined from a plurality of current second threads.
[0047] In step S101, when the first thread is executed to process data to be processed by the first thread and obtain data to be processed by the second thread, the scheduling module may determine a target thread from a plurality of current second threads.
[0048] In an optional implementation, the multiple current second threads are threads created based on the original second thread when the original second thread is overloaded; wherein the processing capability of each current second thread is consistent with that of the original second thread.
[0049] Optionally, before step S101, the method may further include: when the original second thread is overloaded, creating multiple current second threads based on the original second thread. Optionally, the scheduling module may create multiple current second threads based on the original second thread, and specify each current second thread to run on a different core. The codes of the multiple current second threads and the code of the original second thread may be the same code.
[0050] It should be noted that the multiple current second threads in the embodiment of the present application refer to all current second threads created when overloaded.
[0051] In an optional implementation, the target processing thread may be a thread among multiple current second threads that meets a preset processing requirement. Optionally, the preset processing requirement may be that the load of the current second thread meets a preset load requirement.
[0052] In an embodiment of the present application, the scheduling module needs to determine a qualified current second thread from multiple current second threads, and assign the to-be-processed data of the original second thread to the qualified current second thread for processing, so as to avoid overloading of multiple current second threads.
[0053] Optionally, the scheduling module may be located in the first thread, the second thread, or the third thread. In other optional implementations, the scheduling module may also be located at other locations in the system, which is not determined in the embodiments of the present application.
[0054] In the embodiment of the present application, since the scheduling module creates multiple current second threads, it is necessary to protect the global variables in the second thread. Optionally, a mutex lock or a read-write lock can be used, and the code range of the lock should be as small as possible to reduce the performance degradation caused by the lock. Optionally, in the case where the number of times the global variable is read in the code is greater than the number of times it is written, a read-write lock can be used, which can reduce the suspension of read operations caused by the lock, thereby improving the processing efficiency of the second thread.
[0055] The following is based on Figure 3 The specific implementation of step S101 is further described. As an example, the target thread can be determined from multiple current second threads based on the first preset load requirement. Figure 3 , Figure 3 is a flowchart of a thread data processing method according to an exemplary embodiment. Figure 3 As shown in the figure, when the first thread is executed to obtain the to-be-processed data of the original second thread, determining the target processing thread from the multiple current second threads includes:
[0056] S1011: Determine the thread load of each current second thread.
[0057] In step S1011, the scheduling module may determine the thread load of each current second thread. In an optional implementation, the thread load or thread load rate of each current second thread may be determined, wherein the thread load rate is calculated based on the actual load and the rated load. The actual load or actual load rate may be the load information of the core corresponding to the current second thread.
[0058] S1013: Determine a target load that meets a first preset load requirement from the thread load of each current second thread, and determine the current second thread corresponding to the target load as a target processing thread.
[0059] In step S1013, the scheduling module may determine a target load that meets the first preset load requirement from the thread load of each current second thread, and determine the current second thread corresponding to the target load as the target processing thread.
[0060] Optionally, the first preset load requirement may be that the thread load is less than the first preset load value. Optionally, the first preset load requirement may be that the thread load rate is less than the first preset load value. Optionally, the first preset load requirement may also be that the thread load is the thread load with the lowest load among the thread loads corresponding to the multiple current second threads.
[0061] In an optional implementation, if the data to be processed is data that needs to be processed in parallel, steps S1011-S1013 may be executed to allocate the data to be processed to a suitable current second thread for processing, so as to avoid overloading the current second thread.
[0062] The following is based on Figure 4 The specific implementation of step S101 is further described. As an example, the target thread can be determined from multiple current second threads based on the data object of the data to be processed. Figure 4 , Figure 4 A flowchart of a thread data processing method according to an exemplary embodiment is shown as follows: Figure 4 As shown in the figure, when the first thread is executed to obtain the to-be-processed data of the original second thread, determining the target processing thread from the multiple current second threads includes:
[0063] S1012: Determine the data object of the original second thread's to-be-processed data.
[0064] In step S1012, the data object of the to-be-processed data of the original second thread may be determined.
[0065] S1014: Determine a target processing thread from a plurality of current second threads based on the data object.
[0066] In step S1014, based on the data object, a current second thread corresponding to the data object among multiple current second threads may be determined as a target processing thread.
[0067] Optionally, there may be a correspondence between the data object and the current second thread. Optionally, each data object may correspond to a current second thread, and each current second thread may correspond to one or more data objects. In this embodiment, the scheduling module may determine the target processing thread from multiple current second threads based on the correspondence between the data object and the second thread.
[0068] In an optional implementation, if the data to be processed is data that needs to be processed serially, steps S1012 to S1014 may be executed to assign all messages or data of an object or a user to the designated current second thread.
[0069] As an example, when the data object of the data to be processed has a corresponding current second thread, it can be allocated to the corresponding current second thread to ensure that the data to be processed is processed by the thread that is processing or has processed the object or user; and when the data object of the data to be processed does not have a corresponding current second thread, that is, when the data object is a new object, data allocation can be performed according to thread load. Figure 5 The specific implementation of step S1014 is further introduced. Figure 5 FIG. 1 is a flow chart showing a thread data processing method according to an exemplary embodiment. Figure 5 As shown in the figure, based on the data object, determining the target processing thread from multiple current second threads may include steps S10141-S10142 or step S10143:
[0070] S10141: When the data object meets the first preset object requirement, determine the thread load of each current second thread.
[0071] In step S10141, the thread load of each current second thread may be determined if the data object meets the first preset object requirement. Optionally, the first preset object requirement may include: the data object is an unprocessed data object or a data object that has no corresponding relationship with the current second thread.
[0072] Optionally, the thread load or thread load rate of each current second thread may be determined, wherein the thread load rate is calculated based on the actual load and the rated load. The actual load or actual load rate may be the load information of the core corresponding to the current second thread.
[0073] S10142: Determine a target load that meets a second preset load requirement from the thread load of each current second thread, and determine the current second thread corresponding to the target load as a target processing thread.
[0074] In step S10142, a target load that meets the second preset load requirement can be determined from the thread load of each current second thread, and the current second thread corresponding to the target load is determined as the target processing thread. Optionally, the second preset load requirement can be that the thread load is less than the second preset load value. Optionally, the second preset load requirement can be that the thread load rate is less than the second preset load value. Optionally, the second preset load requirement can also be that the thread load is the thread load with the lowest load among the thread loads corresponding to multiple current second threads.
[0075] In an embodiment of the present application, the scheduling module can allocate the data to be processed according to the load situation when the data object is processed or an object that already has a corresponding relationship with the thread, thereby allocating the data to be processed to the core with low load for processing to avoid overload.
[0076] S10143: When the data object meets the second preset object requirement, a thread among the multiple current second threads that has processed data of the data object is determined as a target processing thread.
[0077] In step S10143, if the data object meets the second preset object requirement, a thread that has processed data of the data object among the multiple current second threads can be determined as the target processing thread. Optionally, the second preset object requirement may include: the data object is a processed data object or a data object that has a corresponding relationship with the current second thread.
[0078] In an embodiment of the present application, the scheduling module can allocate the data to be processed according to the data object when the data object has not been processed or there is no object corresponding to the thread, thereby allocating the data to be processed to the corresponding core for processing to ensure normal processing of serial data.
[0079] S102: Send a target processing instruction to the first thread.
[0080] In step S102, the scheduling module may send a target processing instruction to the first thread, wherein the target processing instruction may be used to instruct the first thread to send the to-be-processed data of the original second thread to the target processing thread, so that the target processing thread is executed to process the to-be-processed data of the original second thread.
[0081] The embodiment of the present application adds a scheduling module to schedule message communication between threads that need to balance loads and their upstream threads and downstream threads. The scheduling module creates multiple thread entities based on threads that need to balance loads, and determines to which thread entity the upstream thread sends the pending message for processing, so as to assign the message to the appropriate thread entity for processing according to the specific situation of the pending message, thereby achieving load balancing between multiple thread entities.
[0082] The following is based on Figure 6A thread data processing method according to an embodiment of the present application is further described. As an example, the scheduling module may be located in the first thread, and the first thread may provide a thread entity selection interface to the third thread. In this embodiment, the scheduling module may control the first thread to send the data to be processed to the specified current second thread. After the current second thread processes the data to be processed of the third thread and sends the data to be processed of the third thread to the third thread, the third thread may query the scheduling module in the second thread for target return threads among multiple current second threads, and send the return data to the target return thread. Please refer to Figure 6 , Figure 6 FIG. 1 is a flow chart showing a thread data processing method according to an exemplary embodiment. Figure 6 As shown in the figure, a thread data processing method of an embodiment of the present application includes:
[0083] S201: When the first thread is executed to obtain the to-be-processed data of the original second thread, a target processing thread is determined from a plurality of current second threads.
[0084] The content of step S201 can refer to the above description of step S101, which will not be repeated here.
[0085] S202: Send a target processing instruction to the first thread.
[0086] The content of step S202 can refer to the above description of step S102 and will not be repeated here.
[0087] S203: Receive a thread selection request sent by a third thread.
[0088] In step S203, the scheduling module may receive a thread selection request sent by the third thread through an interface. Optionally, the thread selection request is generated by the third thread processing the to-be-processed data of the third thread to obtain return data, and the to-be-processed data of the third thread is obtained by the target processing thread processing the to-be-processed data of the original second thread.
[0089] S204: Determine a target return thread from a plurality of current second threads.
[0090] In step S204, the scheduling module may determine a target return thread from a plurality of current second threads, wherein the target return thread is a thread that meets a preset return requirement. Optionally, the preset return requirement may be that the load of the current second thread meets a preset load requirement.
[0091] The following is based on Figure 7 The specific implementation of step S204 is further introduced. Figure 7 FIG. 1 is a flow chart showing a thread data processing method according to an exemplary embodiment. Figure 7 As shown, the exemplary process of step S204 may include steps S2041-S2041 or step S2043:
[0092] S2041: Determine the thread load of each current second thread.
[0093] In step S2041, when the data to be processed is data that needs to be processed in parallel, the thread load of each current second thread can be determined. Optionally, the thread load or thread load rate of each current second thread can be determined, wherein the thread load rate is calculated based on the actual load and the rated load. The actual load or the actual load rate can be the load information of the core corresponding to the current second thread.
[0094] S2042: Determine a target load that meets a third preset load requirement from the thread load of each current second thread, and determine the original second thread corresponding to the target load and the current second thread as the target return thread.
[0095] In step S2042, a target load that meets the third preset load requirement can be determined from the thread load of each current second thread, and the original second thread corresponding to the target load is determined as the target return thread. Optionally, the third preset load requirement can be that the thread load is less than the third preset load value. Optionally, the third preset load requirement can be that the thread load rate is less than the third preset load value. Optionally, the third preset load requirement can also be that the thread load is the thread load with the lowest load among the thread loads corresponding to multiple current third threads.
[0096] In an embodiment of the present application, the scheduling module can distribute the return data according to the load situation, so as to distribute the return data to the core with low load to receive, so as to avoid the occurrence of overload.
[0097] S2043: Determine a thread that has processed data of the data object among the multiple current second threads as a target return thread.
[0098] In this embodiment, the thread selection request in step S2041 includes information of the data object of the returned information.
[0099] In step S2043, when the data to be processed is data that needs to be processed serially, a thread among the multiple current second threads that has processed the data of the data object may be determined as a target processing thread.
[0100] In an embodiment of the present application, the scheduling module can allocate return data according to the data object when the data object has not been processed or there is no object corresponding to the thread, thereby allocating the return data to the corresponding core for receiving, so as to ensure normal processing of serial data.
[0101] Next, we will continue based on Figure 6 To elaborate.
[0102] S205: Send thread selection information to the third thread.
[0103] In step S205, the scheduling module may send thread selection information to the third thread, wherein the thread selection information includes information of a target return thread, and the thread selection information is used to instruct the third thread to send return data to the target return thread.
[0104] The embodiment of the present application adds a scheduling module to schedule message communications between threads that need to balance loads and their upstream threads and downstream threads. The scheduling module can create multiple thread entities based on the threads that need to balance loads, and determine to which thread entity the upstream thread sends the message to be processed and to which thread entity the downstream thread sends the return message, so as to allocate the message to the appropriate thread entity for data processing or data return according to the specific circumstances of the message to be processed, thereby achieving load balancing between multiple thread entities.
[0105] The present application also provides a thread data processing device, Figure 8 FIG. 1 is a block diagram of a thread data processing device according to an exemplary embodiment. Figure 8 As shown, the thread data processing device 200 may at least include:
[0106] The determination module 201 is used to determine a target processing thread from a plurality of current second threads when the first thread is executed to obtain the data to be processed of the original second thread; the target processing thread is a thread that meets the preset processing requirement; the plurality of current second threads are threads created based on the original second thread when the original second thread is overloaded; and the processing capability of each current second thread is consistent with that of the original second thread;
[0107] The sending module 202 is used to send a target processing instruction to the first thread, where the target processing instruction instructs the first thread to send the original second thread's to-be-processed data to the target processing thread, so that the target processing thread is executed to process the to-be-processed data.
[0108] Optionally, the determination module 201 is used to: when the first thread is executed to obtain the data to be processed of the original second thread, before determining the target processing thread from multiple current second threads, when the original second thread is overloaded, create multiple current second threads based on the original second thread; the processing capability of each current second thread is consistent with that of the original second thread.
[0109] Optionally, the determination module 201 is used to: determine the thread load of each current second thread in the process of determining the target processing thread from multiple current second threads; determine the target load that meets the first preset load requirement from the thread load of each current second thread, and determine the current second thread corresponding to the target load as the target processing thread.
[0110] Optionally, the determination module 201 is used to: determine the data object of the to-be-processed data of the original second thread in the process of determining the target processing thread from multiple current second threads; and determine the target processing thread from multiple current second threads based on the data object.
[0111] Optionally, the determination module 201 is used to: in the process of determining a target processing thread from multiple current second threads based on a data object, determine the thread load of each current second thread when the data object meets the first preset object requirement; determine a target load that meets the second preset load requirement from the thread load of each current second thread, and determine the current second thread corresponding to the target load as the target processing thread; or; when the data object meets the second preset object requirement, determine the thread that has processed the data of the data object among the multiple current second threads as the target processing thread.
[0112] Optionally, the scheduling module is located in the first thread, and the determination module 201 is used to: receive a thread selection request sent by a third thread; the thread selection request is generated after the third thread processes the third thread's pending data to obtain return data; the third thread's pending data is obtained by the target processing thread processing the original second thread's pending data; determine the target return thread from multiple current second threads; the target return thread is a thread thread that meets preset return requirements; send thread selection information to the third thread; the thread selection information includes information of the target return thread, and the thread selection information is used to instruct the third thread to send the return data to the target return thread.
[0113] Optionally, the determination module 201 is used to: determine the thread load of each current second thread in the process of determining the target return thread from multiple original second threads and the current second thread; determine the target load that meets the third preset load requirement from the thread load of each current second thread, and determine the original second thread and the current second thread corresponding to the target load as the target return thread; or; determine the thread that has processed the data of the data object among the multiple current second threads as the target return thread; wherein the thread selection request includes information about the data object of the return information.
[0114] It should be noted that the thread data processing device embodiment provided in the embodiment of the present application and the above-mentioned thread data processing method embodiment are based on the same inventive concept.
[0115] An embodiment of the present application also provides an electronic device for thread data processing, the electronic device comprising a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement a thread data processing method provided in any of the above embodiments.
[0116] An embodiment of the present application also provides a computer-readable storage medium, which can be set in a terminal to store at least one instruction or at least one program for implementing a thread data processing method in a method embodiment, and the at least one instruction or at least one program is loaded and executed by a processor to implement the thread data processing method provided in the above method embodiment.
[0117] Optionally, in the embodiment of this specification, the storage medium may be located in at least one of the multiple network servers of the computer network. Optionally, in this embodiment, the above storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.
[0118] The memory of the embodiment of this specification can be used to store software programs and modules, and the processor executes various functional applications and thread data processing by running the software programs and modules stored in the memory. The memory may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, applications required for functions, etc.; the data storage area may store data created according to the use of the device, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. Accordingly, the memory may also include a memory controller to provide the processor with access to the memory.
[0119] The embodiment of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the thread data processing method provided by the above method embodiment.
[0120] The thread data processing method embodiment provided in the embodiment of the present application can be executed in a terminal, a computer terminal, a server or a similar computing device. Taking running on a server as an example, Fig. 9FIG. 1 is a hardware structure diagram of a server of a thread data processing method provided according to an exemplary embodiment. Fig. 9 As shown, the server 300 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 33 (the central processing unit 33 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 330 for storing data, and one or more storage media 320 (such as one or more mass storage devices) for storing application programs 323 or data 322. Among them, the memory 330 and the storage medium 320 can be short-term storage or permanent storage. The program stored in the storage medium 320 may include one or more modules, each of which may include a series of instruction operations on the server. Furthermore, the central processing unit 33 can be configured to communicate with the storage medium 320 and execute a series of instruction operations in the storage medium 320 on the server 300. The server 300 may also include one or more power supplies 360, one or more wired or wireless network interfaces 350, one or more input and output interfaces 340, and / or one or more operating systems 321, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
[0121] The input / output interface 340 may be used to receive or send data via a network. The specific example of the network may include a wireless network provided by a communication provider of the server 300. In one example, the input / output interface 340 includes a network adapter (Network Interface Controller, NIC), which may be connected to other network devices via a base station so as to communicate with the Internet. In one example, the input / output interface 340 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0122] It can be understood by those skilled in the art that Fig. 9 The structure shown is only for illustration and does not limit the structure of the above electronic device. Fig. 9 More or fewer components as shown, or with Fig. 9 Different configurations are shown.
[0123] It should be noted that the above-mentioned sequence of the embodiments of the present application is for description only and does not represent the advantages and disadvantages of the embodiments. The above-mentioned specific embodiments of this specification are described. Other embodiments are within the scope of the attached claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0124] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and server embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0125] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware, or by a program to instruct the relevant hardware, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0126] The above are only preferred embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. A thread data processing method, characterized in that: Applied to the scheduling module, the method includes: In the case where the first thread is executed to obtain the data to be processed of the original second thread, a target processing thread is determined from a plurality of current second threads; the target processing thread is a thread that meets a preset processing requirement; the preset processing requirement includes that the load of the second thread meets a preset load requirement; the plurality of current second threads are threads created based on the original second thread when the original second thread is overloaded; and the processing capacity of each of the current second threads is consistent with that of the original second thread; Sending a target processing instruction to the first thread, wherein the target processing instruction instructs the first thread to send the to-be-processed data of the original second thread to the target processing thread, so that the target processing thread is executed to process the to-be-processed data; The scheduling module is located in the first thread, and the method further includes: receiving a thread selection request sent by a third thread; the thread selection request is generated by the third thread processing the to-be-processed data of the third thread and obtaining return data; the to-be-processed data of the third thread is obtained by the target processing thread processing the to-be-processed data of the original second thread; Determine a target return thread from the multiple current second threads; the target return thread is a thread that meets a preset return requirement; Thread selection information is sent to the third thread; the thread selection information includes information of the target return thread, and the thread selection information is used to instruct the third thread to send the return data to the target return thread.
2. A thread data processing method according to claim 1, characterized in that: In the case where the first thread is executed to obtain the to-be-processed data of the original second thread, before determining the target processing thread from the multiple current second threads, the method further includes: In the case that the original second thread is overloaded, multiple current second threads are created based on the original second thread; and the processing capability of each current second thread is consistent with that of the original second thread.
3. A thread data processing method according to claim 1 or 2, characterized in that: The step of determining a target processing thread from a plurality of current second threads comprises: Determining a thread load of each of the current second threads; A target load that meets a first preset load requirement is determined from the thread load of each current second thread, and the current second thread corresponding to the target load is determined as the target processing thread.
4. A thread data processing method according to claim 1 or 2, characterized in that: The step of determining a target processing thread from a plurality of current second threads comprises: Determine a data object of the to-be-processed data of the original second thread; Based on the data object, a target processing thread is determined from among the plurality of current second threads.
5. A thread data processing method according to claim 4, characterized in that: The step of determining a target processing thread from the plurality of current second threads based on the data object comprises: In a case where the data object meets the first preset object requirement, determining a thread load of each of the current second threads; Determine a target load that meets a second preset load requirement from the thread load of each current second thread, and determine the current second thread corresponding to the target load as the target processing thread; or; In a case where the data object meets the second preset object requirement, a thread among the multiple current second threads that has processed the data of the data object is determined as the target processing thread.
6. A thread data processing method according to claim 1, characterized in that: The step of determining a target return thread from the plurality of current second threads comprises: Determining a thread load of each of the current second threads; Determine a target load that meets a third preset load requirement from the thread load of each current second thread, and determine the current second thread corresponding to the target load as the target return thread; or; The thread among the multiple current second threads that has processed the data of the data object is determined as the target return thread; wherein the thread selection request includes information of the data object of the return information.
7. A thread data processing device, characterized in that: Applied to a scheduling module, the device comprises: A determination module, configured to determine a target processing thread from a plurality of current second threads when a first thread is executed to obtain data to be processed of an original second thread; the target processing thread is a thread that meets a preset processing requirement; the preset processing requirement includes that a load of the second thread meets a preset load requirement; the plurality of current second threads are threads created based on the original second thread when the original second thread is overloaded; and each of the current second threads has the same processing capability as the original second thread; a sending module, configured to send a target processing instruction to the first thread, wherein the target processing instruction instructs the first thread to send the to-be-processed data of the original second thread to the target processing thread, so that the target processing thread is executed to process the to-be-processed data; The scheduling module is located in the first thread, and the determination module is used to: receive a thread selection request sent by a third thread; the thread selection request is generated after the third thread processes the to-be-processed data of the third thread to obtain return data; the to-be-processed data of the third thread is obtained by the target processing thread processing the to-be-processed data of the original second thread; determine the target return thread from multiple current second threads; the target return thread is a thread that meets the preset return requirements; send thread selection information to the third thread; the thread selection information includes information of the target return thread, and the thread selection information is used to instruct the third thread to send the return data to the target return thread.
8. An electronic device, characterized in that: The device includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded by the processor and executes the thread data processing method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The storage medium stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement the thread data processing method according to any one of claims 1 to 6.
