Job multithreading running method and device and electronic equipment
By introducing an execution control unit into the execution thread pool and dynamically adjusting the fragment count value to generate instructions, the problem of low resource utilization in the fragmented multi-threaded operation mode is solved, and more efficient batch job execution is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 中国邮政储蓄银行股份有限公司
- Filing Date
- 2022-12-30
- Publication Date
- 2026-04-17
AI Technical Summary
The existing sharded multithreaded execution method has the problem of low resource utilization, which leads to message consumption timeouts and duplicate consumption, or uncontrollable execution time and serious resource waste.
An execution control unit is introduced to maintain the count of running and waiting shards in the execution thread pool, generate instructions to pause and resume message consumption, and dynamically adjust the consumption behavior of the thread pool based on the count value to avoid resource waste and consumption failure.
By employing an active feedback mechanism, the resource utilization of the execution thread pool is improved, consumption timeouts and failures are avoided, and the execution efficiency of batch processing jobs is increased.
Smart Images

Figure CN116302214B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of multithreaded operation, and more specifically, to a method, apparatus, and electronic device for multithreaded operation of a job. Background Technology
[0002] There are two existing multi-threaded execution methods for sharding. The first method utilizes a message consumption thread pool, allowing shards to execute directly within the consumption thread. The drawback of this method is that it can cause message consumption timeouts. In practice, some shards, due to large data volumes or waiting for specific events to trigger, may take ten minutes or even more than half an hour to execute, exceeding the maximum message consumption time set by a typical message queue. Message consumption timeouts can lead to message re-delivery, resulting in duplicate consumption and other problems.
[0003] The second approach is to create a separate execution thread pool and transfer the shards from the consumer thread to a dedicated execution thread for execution. However, when the number of shards exceeds the thread pool's capacity, some shards will inevitably fail to be submitted to the execution thread and will return as failed. Furthermore, the more retries there are, the longer the retry interval becomes, and the longer the thread pool remains idle. Therefore, the disadvantages of this approach are that the overall job execution time is uncontrollable, the execution thread pool resource utilization is low, and the job execution efficiency is low. Summary of the Invention
[0004] The main objective of this application is to provide a method, apparatus, and electronic device for multi-threaded operation of a job, so as to at least solve the problem of low resource utilization in the existing fragmented multi-threaded operation mode.
[0005] To achieve the above objectives, according to one aspect of this application, a method for multi-threaded job execution is provided, comprising: constructing an execution control unit, the execution control unit being used to maintain a count of running shards in an execution thread pool, the count of running shards including the number of shards being executed and the number of shards waiting to be executed in the execution thread pool; incrementing the count of running shards by one when a shard is successfully submitted to the execution thread pool; decrementing the count of running shards by one after a shard in the execution thread pool has been executed; and generating a pause consumption message instruction and a resume consumption message instruction based on the count of running shards, the pause consumption message instruction being used to control the execution threads in the execution thread pool to pause consuming new shards, and the resume consumption message instruction being used to control the execution threads in the execution thread pool to resume consuming new shards.
[0006] Optionally, generating a pause consumption message instruction based on the running shard count includes: determining a pause threshold, wherein the pause threshold is the product of the execution thread pool capacity and a first constant, and the execution thread pool capacity is the sum of the number of threads in the execution thread pool and the thread queue length; and generating the pause consumption message instruction if the running shard count is greater than or equal to the pause threshold.
[0007] Optionally, generating a recovery consumption message instruction based on the running shard count includes: determining a recovery threshold, wherein the recovery threshold is the product of the execution thread pool capacity and a second constant, and the execution thread pool capacity is the sum of the number of threads in the execution thread pool and the length of the thread queue; and generating the recovery consumption message instruction if the running shard count is less than the recovery threshold.
[0008] Optionally, after generating a recovery consumption message instruction based on the running shard count, the method further includes: controlling the new shard to be consumed by the target consumption thread; controlling the target consumption thread to submit the new shard to the execution thread pool queue in the execution thread pool; while the new shard is waiting to be executed in the execution thread pool queue, controlling the execution thread pool to return the waiting execution instruction to the execution control unit; and after the new shard has been executed in the execution thread pool queue, controlling the execution thread pool to return the execution success instruction to the execution control unit.
[0009] Optionally, while the new shard is waiting to be executed in the execution thread pool queue, controlling the execution thread pool to return the waiting execution instruction to the execution control unit includes: while the new shard is waiting to be executed in the execution thread pool queue, controlling the execution thread pool to send the waiting execution instruction to the target consumer thread, so as to control the target consumer thread to send the waiting execution instruction to the execution control unit; after the new shard is executed in the execution thread pool queue, controlling the execution thread pool to return the execution success instruction to the execution control unit includes: after the new shard is executed in the execution thread pool queue, controlling the execution thread pool to send the execution success instruction to the target consumer thread, so as to control the target consumer thread to send the execution success instruction to the execution control unit.
[0010] Optionally, after controlling the target consumer thread to submit the new shard to the execution thread pool queue in the execution thread pool, the method further includes: controlling the target consumer thread to return the consumption success message to the message queue.
[0011] Optionally, the multiple execution threads in the execution thread pool are distributed across different execution machines.
[0012] Optionally, the pause message consumption instruction is further used to control the message queue to pause forwarding new shards to the execution thread pool, and the resume message consumption instruction is further used to control the message queue to resume forwarding new shards to the execution thread pool.
[0013] According to another aspect of this application, a multi-threaded job execution apparatus is provided, comprising: a construction unit for constructing an execution control unit, the execution control unit for maintaining a count of running shards in an execution thread pool, the count of running shards including the number of shards being executed and the number of shards waiting to be executed in the execution thread pool; the count of running shards being incremented by one when a shard is successfully submitted to the execution thread pool, and the count of running shards being decremented by one after a shard in the execution thread pool is completed; and a generation unit for generating a pause consumption message instruction and a resume consumption message instruction based on the count of running shards, the pause consumption message instruction controlling the execution threads in the execution thread pool to pause consuming new shards, and the resume consumption message instruction controlling the execution threads in the execution thread pool to resume consuming new shards.
[0014] According to another aspect of this application, an electronic device is provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including methods for performing any of the described job multithreading methods.
[0015] Applying the technical solution of this application, the above-mentioned multi-threaded job execution method first constructs an execution control unit. The execution control unit is used to maintain the running shard count value in the execution thread pool. The running shard count value includes the number of shards being executed and the number of shards waiting to be executed in the execution thread pool. When a shard is successfully submitted to the execution thread pool, the running shard count value is incremented by one. After a shard in the execution thread pool is completed, the running shard count value is decremented by one. Then, based on the running shard count value, a pause consumption message instruction and a resume consumption message instruction are generated. The pause consumption message instruction is used to control the execution threads in the execution thread pool to pause consuming new shards, and the resume consumption message instruction is used to control the execution threads in the execution thread pool to resume consuming new shards. This method introduces an execution control unit to implement an active feedback mechanism for the running status of the execution thread pool. Based on this mechanism, it performs pause and resume consumption operations in a timely manner, thereby solving the consumption timeout problem and effectively avoiding message consumption failures. This improves the resource utilization of the execution thread pool, thereby improving the execution efficiency of batch processing jobs and solving the problem of low resource utilization in the existing multi-threaded operation mode of sharding. Attached Figure Description
[0016] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0017] Figure 1 A hardware structure block diagram of a mobile terminal for performing a multi-threaded job execution method according to an embodiment of this application is shown.
[0018] Figure 2 A flowchart illustrating a multi-threaded job execution method according to an embodiment of this application is shown.
[0019] Figure 3 This diagram illustrates how sharding is performed directly in the consumer thread pool in the prior art;
[0020] Figure 4 This diagram illustrates the process in the prior art where the first consumption of a fragmented message fails after being submitted from the consumer thread to the execution thread for execution.
[0021] Figure 5 This diagram illustrates the process in the prior art where a shard is successfully consumed after a retry following an initial failure when it is submitted from the consumer thread to the execution thread.
[0022] Figure 6This diagram illustrates the process in the prior art where multiple consumption failures occur when a shard is submitted from the consumer thread to the execution thread.
[0023] Figure 7 A schematic diagram illustrating the process of triggering a consumption pause in a multi-threaded job execution method according to an embodiment of this application is shown.
[0024] Figure 8 The diagram illustrates the process of triggering and resuming consumption in a multi-threaded job execution method according to an embodiment of this application.
[0025] Figure 9 A schematic diagram illustrating a multi-threaded operation mode according to an embodiment of this application is shown;
[0026] Figure 10 A structural block diagram of a job multithreading apparatus provided according to an embodiment of this application is shown. Detailed Implementation
[0027] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0028] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0029] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0030] For ease of description, the following explains some of the nouns or terms used in the embodiments of this application:
[0031] Sharding (P): A batch processing job splits the data to be processed into different parts according to a certain strategy. These parts are called shards, and each shard is responsible for processing different data.
[0032] Batch processing executor: The machine or device responsible for actually processing the batches.
[0033] Consumer Thread (CT): A thread created by the message queue client for consuming messages.
[0034] Execution Thread (ET): The thread used to execute the slice.
[0035] As described in the background section, existing multi-threaded execution methods suffer from uncontrollable actual job execution time, low batch processing execution machine resource utilization, and low job execution efficiency when the number of job fragments exceeds the number of execution machine thread resources. To address the problem of low resource utilization in existing fragmented multi-threaded execution methods, embodiments of this application provide a job multi-threaded execution method, apparatus, and electronic device.
[0036] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
[0037] The methods and embodiments provided in this application can be executed on a mobile terminal, computer terminal, or similar computing device. Taking running on a mobile terminal as an example, Figure 1 This is a hardware structure block diagram of a mobile terminal for a multi-threaded job execution method according to an embodiment of the present invention. Figure 1 As shown, a mobile terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal described above. For example, the mobile terminal may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0038] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the device information display method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory and non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. The transmission device 106 is used to receive or send data via a network. Specific examples of the aforementioned networks may include wireless networks provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0039] This embodiment provides a method for multi-threaded operation of a job running on a mobile terminal, computer terminal, or similar computing device. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Also, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0040] Currently, there are two main methods for multi-threaded execution of message sharding in existing technologies. One method utilizes a message consumption thread pool, allowing sharding to be executed directly within the consumption thread. For example... Figure 3 As shown, shard P1 in the message queue is consumed and executed by consumer thread CT1, and shard P2 is consumed and executed by consumer thread CT2.
[0041] Second, a separate execution thread pool is created to submit shards from the consumer thread to the execution thread for execution. When the execution thread pool has idle thread resources, the shard is submitted to the execution thread normally, and a success consumption result is returned. When the execution thread pool resources are exhausted and cannot accommodate new shards, a consumption failure result is returned. At this time, according to the message queue retry mechanism, the shard will be consumed again later, and the process will be re-executed.
[0042] like Figure 4 As shown, Figure 4This illustrates the process of a fragmented message failing to be consumed on its first attempt:
[0043] ① Shard P6 is consumed by thread CT1;
[0044] ②Consumer thread CT1 submits shard P6 to the execution thread pool;
[0045] ③ Execution thread ET1 is executing shard P1, execution thread ET2 is executing shard P2, and there are shards P3, P4, and P5 waiting to be executed in the execution thread pool queue. At this time, the execution thread pool can no longer accommodate new shards, so it returns a rejection.
[0046] ④ The consumer thread CT1 returned a message queue consumption failure.
[0047] In this case, the message queue will retry the shard P6. Figure 5 This illustrates the process of successfully consuming the fragment during a retry:
[0048] ⑤ Shard P6 is consumed by thread CT1;
[0049] ⑥ Consumer thread CT1 submits shard P6 to the execution thread pool;
[0050] ⑦ At this point, shard P1 has finished executing, and shard P3 will start executing from execution thread ET1. There is one position left in the execution thread pool queue, so shard P6 is successfully submitted to the execution thread pool queue, and the submission is successful.
[0051] ⑧ The consumer thread CT1 returned a message queue consumption success message.
[0052] In existing methods, creating separate execution thread pools means that in the event of a consumption failure, the message queue relies on its retry mechanism to prompt the message to be consumed again. The retry interval for messages in the message queue typically increases progressively, such as 1 second, 5 seconds, 10 seconds, 30 seconds, 1 minute, 2 minutes, 3 minutes, 4 minutes, 5 minutes, 6 minutes, 7 minutes, 8 minutes, 9 minutes, 10 minutes, 20 minutes, 30 minutes, 1 hour, and 2 hours. With increasingly longer retry intervals, if a message fails to be consumed multiple times, it can lead to uncontrollable overall job execution time and a decrease in batch processing machine efficiency. Figure 6As shown, shard P6 is consumed at time T, but the execution thread pool is exhausted by then, consumption fails, and a retry is initiated. Time points T1, T2, T3, T4, and T5 represent the first five retries for this shard, but the execution thread pool remains exhausted, and consumption still fails. The execution thread pool becomes idle at time T6. Although the thread pool is idle at this time, shard P6 is not consumed until the retry interval is reached at time T7, when shard P6 is successfully consumed. Between times T6 and T7, the execution thread pool is idle, but the remaining shards are not executed, resulting in wasted thread resources. Therefore, the more retries there are, the longer the retry interval becomes, and the longer the thread pool remains idle. Thus, the disadvantages of this approach are that the overall job execution time is uncontrollable, the execution thread pool resource utilization is low, and the job execution efficiency is low.
[0053] To address the shortcomings of the aforementioned two multi-threaded execution methods, this application proposes a method for multi-threaded job execution. Figure 2 This is a flowchart of a multi-threaded job execution method according to an embodiment of this application. For example... Figure 2 As shown, the method includes the following steps:
[0054] Step S201: Construct an execution control unit. The execution control unit is used to maintain the running shard count value in the execution thread pool. The running shard count value includes the number of shards being executed and the number of shards waiting to be executed in the execution thread pool. When a shard is successfully submitted to the execution thread pool, the running shard count value is incremented by one. After a shard in the execution thread pool is completed, the running shard count value is decremented by one.
[0055] Step S202: Based on the currently running shard count, generate a pause message consumption instruction and a resume message consumption instruction. The pause message consumption instruction controls the execution threads in the execution thread pool to pause consuming new shards, and the resume message consumption instruction controls the execution threads in the execution thread pool to resume consuming new shards. After pausing, the execution control unit will no longer consume new messages until it resumes consuming subsequent messages from the paused position.
[0056] The specific steps for generating a pause message consumption command based on the currently running shard count are as follows:
[0057] Step S301: Determine the pause threshold, which is the product of the execution thread pool capacity and the first constant. The execution thread pool capacity is the sum of the number of threads in the execution thread pool and the length of the thread queue. Generally, the first constant is 100%.
[0058] Step S302: If the count of the currently running shards is greater than or equal to the pause threshold, generate the pause consumption message instruction. This indicates that the execution thread pool resources have been exhausted.
[0059] The specific steps for generating a resume consumption message instruction based on the currently running shard count are as follows:
[0060] Step S401: Determine the recovery threshold. The recovery threshold is the product of the execution thread pool capacity and the second constant. The execution thread pool capacity is the sum of the number of threads in the execution thread pool and the length of the thread queue. Generally, the second constant is 50%.
[0061] In step S402, if the count of the currently running shards is less than the recovery threshold, the recovery consumption message instruction is generated. This indicates that a portion of the execution thread pool has become idle.
[0062] The above-mentioned pause and resume threshold settings can effectively prevent message consumption failures while solving the consumption timeout problem.
[0063] In an alternative approach, after generating a resume consumption message instruction based on the currently running shard count, the method further includes:
[0064] Step S203: Control the new shard to be consumed by the target consumer thread;
[0065] Step S204: Control the target consumer thread to submit the new shard to the execution thread pool queue in the execution thread pool.
[0066] Step S205: While the new shard is waiting to be executed in the execution thread pool queue, the execution thread pool is controlled to return the waiting execution instruction to the execution control unit.
[0067] While the new shard is waiting to be executed in the execution thread pool queue, the execution thread pool is controlled to send the waiting execution instruction to the target consumer thread, so that the target consumer thread can send the waiting execution instruction to the execution control unit.
[0068] Step S206: After the new slice is executed in the execution thread pool queue, the execution thread pool is controlled to return the execution success instruction to the execution control unit.
[0069] After the new shard is executed in the execution thread pool queue, the execution thread pool is controlled to send the execution success instruction to the target consumer thread, so that the target consumer thread can send the execution success instruction to the execution control unit.
[0070] After controlling the target consumer thread to submit the new shard to the execution thread pool queue in the execution thread pool, the method further includes: controlling the target consumer thread to return the successful consumption message to the message queue.
[0071] Specifically, the diagram illustrating the process of triggering a consumption pause is as follows: Figure 7 As shown:
[0072] ① Shard P5 is consumed by thread CT1;
[0073] ②Consumer thread CT1 submits shard P5 to the execution thread pool;
[0074] ③ Since there is 1 position left in the execution thread pool queue, shard P5 is successfully submitted to the execution thread pool queue to wait for execution, and the execution thread pool returns a successful submission;
[0075] ④ The controller counter value C is incremented by 1;
[0076] ⑤ At this time, the count of the running shard is 5, and the capacity of the execution thread pool is 5. The count of the running shard is greater than or equal to the above-mentioned pause threshold, so the message queue pause consumption interface is called.
[0077] ⑥ The consumer thread CT1 returned a message queue consumption success message.
[0078] A diagram illustrating the process of triggering the resumption of consumption is shown below. Figure 8 As shown:
[0079] ⑦ After the fragments P1, P2, and P3 are executed in sequence, the fragment count value C being executed is decremented by 1 a total of 3 times.
[0080] ⑧ At this time, the count of the currently running shard is 2, and the capacity of the execution thread pool is 5, which satisfies the requirement of the execution thread pool capacity. Call the message queue to resume the consumption interface.
[0081] ⑨ Shard P6 is consumed by thread CT1;
[0082] ⑩ Consumer thread CT1 submits shard P6 to the execution thread pool. ;
[0083] Because there are 3 slots remaining in the execution thread pool. , Shard P6 was successfully submitted to the execution thread pool queue to await execution, and the execution thread pool returned a successful submission.
[0084] The running fragment count value is incremented by 1. ;
[0085] Consumer thread CT1 returned a message queue consumption success message. 。
[0086] The proactive feedback mechanism described above can actively report the running status of the execution thread to the message queue and perform corresponding operations. When the pause condition is met, consumption will be paused immediately, and when the resume condition is met, consumption will be resumed immediately. Therefore, when the number of shards is greater than the thread pool capacity, consumption failures will not occur, and the execution machine will not be idle due to waiting for re-consumption after a consumption failure.
[0087] In one optional embodiment, the multiple execution threads in the aforementioned execution thread pool are distributed across different execution machines. Specifically, when a batch processing job needs to process a large amount of data, it is typically split into different shards. These shards are asynchronously sent to the batch processing execution machine cluster via message queues, and the shards are processed in parallel. Each shard corresponds to one execution machine thread. Figure 9 As shown. This multi-threaded execution method can improve the execution efficiency of batch jobs.
[0088] For example, the above-mentioned pause message consumption instruction is also used to control the message queue to pause forwarding new shards to the above-mentioned execution thread pool, and the above-mentioned resume message consumption instruction is also used to control the above-mentioned message queue to resume forwarding new shards to the above-mentioned execution thread pool.
[0089] The multi-threaded execution method of this application first constructs an execution control unit, which maintains a count of running shards in the execution thread pool. This count includes the number of shards currently being executed and the number of shards waiting to be executed. When a shard is successfully submitted to the execution thread pool, the count is incremented by one. After a shard in the execution thread pool completes execution, the count is decremented by one. Then, based on the running shard count, a pause consumption message instruction and a resume consumption message instruction are generated. The pause consumption message instruction controls the execution threads in the execution thread pool to pause consuming new shards, and the resume consumption message instruction controls the execution threads in the execution thread pool to resume consuming new shards. This method introduces an execution control unit to implement an active feedback mechanism for the running status of the execution thread pool. Based on this mechanism, it performs pause and resume consumption operations in a timely manner, thereby solving the consumption timeout problem and effectively avoiding message consumption failures. This improves the resource utilization of the execution thread pool, thereby improving the execution efficiency of batch processing jobs and solving the problem of low resource utilization in the existing multi-threaded operation mode of sharding.
[0090] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.
[0091] This application also provides a multi-threaded job execution apparatus. It should be noted that the multi-threaded job execution apparatus of this application can be used to execute the multi-threaded job execution method provided in this application. This apparatus is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0092] The following describes the multi-threaded job execution apparatus provided in the embodiments of this application.
[0093] Figure 10 This is a schematic diagram of a multi-threaded operation apparatus according to an embodiment of this application. Figure 10 As shown, the device includes: a construction unit 10, used to construct an execution control unit, which maintains a count of running shards in the execution thread pool. The count includes the number of shards being executed and the number of shards waiting to be executed. When a shard is successfully submitted to the execution thread pool, the count is incremented by one, and after a shard in the execution thread pool is completed, the count is decremented by one. A generation unit 20 is used to generate a pause consumption message instruction and a resume consumption message instruction based on the count. The pause consumption message instruction controls the execution threads in the execution thread pool to pause consuming new shards, and the resume consumption message instruction controls the execution threads in the execution thread pool to resume consuming new shards.
[0094] As an optional solution, the generation unit includes a first determining module and a first generating module. The first determining module is used to determine a pause threshold, which is the product of the execution thread pool capacity and a first constant. The execution thread pool capacity is the sum of the number of threads in the execution thread pool and the length of the thread queue. The first generating module is used to generate the pause message consumption instruction when the count of the currently running shards is greater than or equal to the pause threshold. This can effectively prevent message consumption failures while solving the consumption timeout problem.
[0095] In one optional scheme, the generation unit further includes a second determining module and a second generation module. The second determining module is used to determine a recovery threshold, which is the product of the execution thread pool capacity and a second constant. The execution thread pool capacity is the sum of the number of threads in the execution thread pool and the length of the thread queue. The second generation module is used to generate the recovery consumption message instruction when the count of the currently running shards is less than the recovery threshold. This can effectively prevent message consumption failures while solving the consumption timeout problem.
[0096] For example, after generating a resumption consumption message instruction based on the currently running shard count, the apparatus further includes a first control module, a second control module, a third control module, and a fourth control module. The first control module controls the new shard to be consumed by the target consumption thread; the second control module controls the target consumption thread to submit the new shard to the execution thread pool queue in the execution thread pool; the third control module controls the execution thread pool to return the waiting execution instruction to the execution control unit while the new shard is waiting for execution in the execution thread pool queue; and the fourth control module controls the execution thread pool to return the execution success instruction to the execution control unit after the new shard has been executed in the execution thread pool queue. This can improve the resource utilization of the execution thread pool.
[0097] In one optional embodiment, the third control module includes a first control submodule, which is used to control the execution thread pool to send the waiting execution instruction to the target consumer thread while the new shard is waiting to be executed in the execution thread pool queue, so as to control the target consumer thread to send the waiting execution instruction to the execution control unit. The fourth control module includes a second control submodule, which is used to control the execution thread pool to send the execution success instruction to the target consumer thread after the new shard has been executed in the execution thread pool queue, so as to control the target consumer thread to send the execution success instruction to the execution control unit. This can improve the resource utilization of the execution thread pool and improve the execution efficiency of batch processing jobs.
[0098] In this embodiment, after controlling the target consumer thread to submit the new shard to the execution thread pool queue in the execution thread pool, the device further includes a fifth control module. This fifth control module controls the target consumer thread to return a successful consumption message to the message queue. This can improve the execution efficiency of batch processing jobs.
[0099] In one alternative approach, the multiple execution threads in the aforementioned execution thread pool are distributed across different execution machines. This multi-threaded approach can improve the execution efficiency of batch processing jobs.
[0100] As an optional solution, the aforementioned pause message consumption command is also used to control the message queue to pause forwarding new shards to the aforementioned execution thread pool, and the aforementioned resume message consumption command is also used to control the aforementioned message queue to resume forwarding new shards to the aforementioned execution thread pool. This can effectively prevent message consumption failures while resolving the consumption timeout issue.
[0101] The multi-threaded operation apparatus of this application includes: a construction unit for constructing an execution control unit, wherein the execution control unit maintains a count of running shards in the execution thread pool, the count of running shards including the number of shards being executed and the number of shards waiting to be executed in the execution thread pool; the count of running shards is incremented by one when a shard is successfully submitted to the execution thread pool, and decremented by one after a shard in the execution thread pool is completed; and a generation unit for generating a pause consumption message instruction and a resume consumption message instruction based on the count of running shards, wherein the pause consumption message instruction controls the execution threads in the execution thread pool to pause consuming new shards, and the resume consumption message instruction controls the execution threads in the execution thread pool to resume consuming new shards. This device implements an active feedback mechanism for the running status of the execution thread pool by introducing an execution control unit. Based on this mechanism, it performs pause and resume consumption operations in a timely manner, thereby solving the consumption timeout problem and effectively avoiding message consumption failures. This improves the resource utilization of the execution thread pool, thereby improving the execution efficiency of batch processing jobs and solving the problem of low resource utilization in the existing multi-threaded operation mode of sharding.
[0102] The aforementioned multi-threaded operation device includes a processor and a memory. The aforementioned building units are all stored as program units in the memory, and the processor executes these program units stored in the memory to achieve the corresponding functions. All of the aforementioned modules reside in the same processor; alternatively, the aforementioned modules may be located in different processors in any combination.
[0103] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and adjusting kernel parameters can address the low resource utilization issue of fragmented multithreaded execution in existing technologies.
[0104] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0105] This invention provides a computer-readable storage medium that includes a stored program, wherein the program, when running, controls the device containing the computer-readable storage medium to execute the multi-threaded operation method of the job.
[0106] Specifically, the methods for running jobs in a multi-threaded manner include:
[0107] Step S201: Construct an execution control unit. The execution control unit is used to maintain the running shard count value in the execution thread pool. The running shard count value includes the number of shards being executed and the number of shards waiting to be executed in the execution thread pool. When a shard is successfully submitted to the execution thread pool, the running shard count value is incremented by one. After a shard in the execution thread pool is completed, the running shard count value is decremented by one.
[0108] Specifically, by pausing and resuming consumption operations in a timely manner based on this mechanism, the problem of consumption timeout can be solved while effectively preventing message consumption failures.
[0109] Step S202: Based on the currently running shard count, generate a pause message consumption instruction and a resume message consumption instruction. The pause message consumption instruction controls the execution threads in the execution thread pool to pause consuming new shards, and the resume message consumption instruction controls the execution threads in the execution thread pool to resume consuming new shards. After pausing, the execution control unit will no longer consume new messages until it resumes consuming subsequent messages from the paused position.
[0110] Specifically, setting the above-mentioned pause threshold and resume threshold can effectively prevent message consumption failures while solving the consumption timeout problem.
[0111] Optionally, based on the running shard count value, a pause consumption message instruction is generated, including: determining a pause threshold, wherein the pause threshold is the product of the execution thread pool capacity and a first constant, and the execution thread pool capacity is the sum of the number of threads in the execution thread pool and the thread queue length; and generating the pause consumption message instruction if the running shard count value is greater than or equal to the pause threshold.
[0112] Optionally, based on the running shard count value, a recovery consumption message instruction is generated, including: determining a recovery threshold, wherein the recovery threshold is the product of the execution thread pool capacity and a second constant, and the execution thread pool capacity is the sum of the number of threads in the execution thread pool and the thread queue length; and generating the recovery consumption message instruction if the running shard count value is less than the recovery threshold.
[0113] Optionally, after generating a recovery consumption message instruction based on the running shard count, the method further includes: controlling the new shard to be consumed by the target consumption thread; controlling the target consumption thread to submit the new shard to the execution thread pool queue in the execution thread pool; controlling the execution thread pool to return the waiting execution instruction to the execution control unit while the new shard is waiting to be executed in the execution thread pool queue; and controlling the execution thread pool to return the execution success instruction to the execution control unit after the new shard has been executed in the execution thread pool queue.
[0114] Optionally, while the new shard is waiting to be executed in the execution thread pool queue, controlling the execution thread pool to return the waiting execution instruction to the execution control unit includes: while the new shard is waiting to be executed in the execution thread pool queue, controlling the execution thread pool to send the waiting execution instruction to the target consumer thread, so as to control the target consumer thread to send the waiting execution instruction to the execution control unit; after the new shard has been executed in the execution thread pool queue, controlling the execution thread pool to return the execution success instruction to the execution control unit includes: after the new shard has been executed in the execution thread pool queue, controlling the execution thread pool to send the execution success instruction to the target consumer thread, so as to control the target consumer thread to send the execution success instruction to the execution control unit.
[0115] Optionally, after controlling the target consumer thread to submit the new shard to the execution thread pool queue in the execution thread pool, the method further includes: controlling the target consumer thread to return the successful consumption message to the message queue.
[0116] Optionally, the multiple execution threads in the above execution thread pool are distributed across different execution machines.
[0117] Optionally, the above-mentioned pause message consumption instruction is also used to control the message queue to pause forwarding new shards to the above-mentioned execution thread pool, and the above-mentioned resume message consumption instruction is also used to control the above-mentioned message queue to resume forwarding new shards to the above-mentioned execution thread pool.
[0118] According to another aspect of this application, a multi-threaded job execution apparatus is provided, comprising: a construction unit for constructing an execution control unit, the execution control unit for maintaining a count of running shards in an execution thread pool, the count of running shards including the number of shards being executed and the number of shards waiting to be executed in the execution thread pool; incrementing the count of running shards by one when a shard is successfully submitted to the execution thread pool; and decrementing the count of running shards by one after a shard in the execution thread pool has been executed; and a generation unit for generating a pause consumption message instruction and a resume consumption message instruction based on the count of running shards, the pause consumption message instruction controlling the execution threads in the execution thread pool to pause consuming new shards, and the resume consumption message instruction controlling the execution threads in the execution thread pool to resume consuming new shards.
[0119] This invention provides a processor for running a program, wherein the program executes the multi-threaded job execution method during runtime.
[0120] Specifically, the methods for running jobs in a multi-threaded manner include:
[0121] Step S201: Construct an execution control unit. The execution control unit is used to maintain the running shard count value in the execution thread pool. The running shard count value includes the number of shards being executed and the number of shards waiting to be executed in the execution thread pool. When a shard is successfully submitted to the execution thread pool, the running shard count value is incremented by one. After a shard in the execution thread pool is completed, the running shard count value is decremented by one.
[0122] Specifically, by pausing and resuming consumption operations in a timely manner based on this mechanism, the problem of consumption timeout can be solved while effectively preventing message consumption failures.
[0123] Step S202: Based on the currently running shard count, generate a pause message consumption instruction and a resume message consumption instruction. The pause message consumption instruction controls the execution threads in the execution thread pool to pause consuming new shards, and the resume message consumption instruction controls the execution threads in the execution thread pool to resume consuming new shards. After pausing, the execution control unit will no longer consume new messages until it resumes consuming subsequent messages from the paused position.
[0124] Specifically, setting the above-mentioned pause threshold and resume threshold can effectively prevent message consumption failures while solving the consumption timeout problem.
[0125] Optionally, based on the running shard count value, a pause consumption message instruction is generated, including: determining a pause threshold, wherein the pause threshold is the product of the execution thread pool capacity and a first constant, and the execution thread pool capacity is the sum of the number of threads in the execution thread pool and the thread queue length; and generating the pause consumption message instruction if the running shard count value is greater than or equal to the pause threshold.
[0126] Optionally, based on the running shard count value, a recovery consumption message instruction is generated, including: determining a recovery threshold, wherein the recovery threshold is the product of the execution thread pool capacity and a second constant, and the execution thread pool capacity is the sum of the number of threads in the execution thread pool and the thread queue length; and generating the recovery consumption message instruction if the running shard count value is less than the recovery threshold.
[0127] Optionally, after generating a recovery consumption message instruction based on the running shard count, the method further includes: controlling the new shard to be consumed by the target consumption thread; controlling the target consumption thread to submit the new shard to the execution thread pool queue in the execution thread pool; controlling the execution thread pool to return the waiting execution instruction to the execution control unit while the new shard is waiting to be executed in the execution thread pool queue; and controlling the execution thread pool to return the execution success instruction to the execution control unit after the new shard has been executed in the execution thread pool queue.
[0128] Optionally, while the new shard is waiting to be executed in the execution thread pool queue, controlling the execution thread pool to return the waiting execution instruction to the execution control unit includes: while the new shard is waiting to be executed in the execution thread pool queue, controlling the execution thread pool to send the waiting execution instruction to the target consumer thread, so as to control the target consumer thread to send the waiting execution instruction to the execution control unit; after the new shard has been executed in the execution thread pool queue, controlling the execution thread pool to return the execution success instruction to the execution control unit includes: after the new shard has been executed in the execution thread pool queue, controlling the execution thread pool to send the execution success instruction to the target consumer thread, so as to control the target consumer thread to send the execution success instruction to the execution control unit.
[0129] Optionally, after controlling the target consumer thread to submit the new shard to the execution thread pool queue in the execution thread pool, the method further includes: controlling the target consumer thread to return the successful consumption message to the message queue.
[0130] Optionally, the multiple execution threads in the above execution thread pool are distributed across different execution machines.
[0131] Optionally, the above-mentioned pause message consumption instruction is also used to control the message queue to pause forwarding new shards to the above-mentioned execution thread pool, and the above-mentioned resume message consumption instruction is also used to control the above-mentioned message queue to resume forwarding new shards to the above-mentioned execution thread pool.
[0132] This invention provides a device including a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs at least the following steps:
[0133] Step S201: Construct an execution control unit. The execution control unit is used to maintain the running shard count value in the execution thread pool. The running shard count value includes the number of shards being executed and the number of shards waiting to be executed in the execution thread pool. When a shard is successfully submitted to the execution thread pool, the running shard count value is incremented by one. After a shard in the execution thread pool is completed, the running shard count value is decremented by one.
[0134] Step S202: Based on the currently running shard count, generate a pause message consumption instruction and a resume message consumption instruction. The pause message consumption instruction controls the execution threads in the execution thread pool to pause consuming new shards, and the resume message consumption instruction controls the execution threads in the execution thread pool to resume consuming new shards. After pausing, the execution control unit will no longer consume new messages until it resumes consuming subsequent messages from the paused position.
[0135] The devices mentioned in this article can be servers, PCs, tablets, mobile phones, etc.
[0136] Optionally, based on the running shard count value, a pause consumption message instruction is generated, including: determining a pause threshold, wherein the pause threshold is the product of the execution thread pool capacity and a first constant, and the execution thread pool capacity is the sum of the number of threads in the execution thread pool and the thread queue length; and generating the pause consumption message instruction if the running shard count value is greater than or equal to the pause threshold.
[0137] Optionally, based on the running shard count value, a recovery consumption message instruction is generated, including: determining a recovery threshold, wherein the recovery threshold is the product of the execution thread pool capacity and a second constant, and the execution thread pool capacity is the sum of the number of threads in the execution thread pool and the thread queue length; and generating the recovery consumption message instruction if the running shard count value is less than the recovery threshold.
[0138] Optionally, after generating a recovery consumption message instruction based on the running shard count, the method further includes: controlling the new shard to be consumed by the target consumption thread; controlling the target consumption thread to submit the new shard to the execution thread pool queue in the execution thread pool; controlling the execution thread pool to return the waiting execution instruction to the execution control unit while the new shard is waiting to be executed in the execution thread pool queue; and controlling the execution thread pool to return the execution success instruction to the execution control unit after the new shard has been executed in the execution thread pool queue.
[0139] Optionally, while the new shard is waiting to be executed in the execution thread pool queue, controlling the execution thread pool to return the waiting execution instruction to the execution control unit includes: while the new shard is waiting to be executed in the execution thread pool queue, controlling the execution thread pool to send the waiting execution instruction to the target consumer thread, so as to control the target consumer thread to send the waiting execution instruction to the execution control unit; after the new shard has been executed in the execution thread pool queue, controlling the execution thread pool to return the execution success instruction to the execution control unit includes: after the new shard has been executed in the execution thread pool queue, controlling the execution thread pool to send the execution success instruction to the target consumer thread, so as to control the target consumer thread to send the execution success instruction to the execution control unit.
[0140] Optionally, after controlling the target consumer thread to submit the new shard to the execution thread pool queue in the execution thread pool, the method further includes: controlling the target consumer thread to return the successful consumption message to the message queue.
[0141] Optionally, the multiple execution threads in the above execution thread pool are distributed across different execution machines.
[0142] Optionally, the above-mentioned pause message consumption instruction is also used to control the message queue to pause forwarding new shards to the above-mentioned execution thread pool, and the above-mentioned resume message consumption instruction is also used to control the above-mentioned message queue to resume forwarding new shards to the above-mentioned execution thread pool.
[0143] According to another aspect of this application, a multi-threaded job execution apparatus is provided, comprising: a construction unit for constructing an execution control unit, the execution control unit for maintaining a count of running shards in an execution thread pool, the count of running shards including the number of shards being executed and the number of shards waiting to be executed in the execution thread pool; incrementing the count of running shards by one when a shard is successfully submitted to the execution thread pool; and decrementing the count of running shards by one after a shard in the execution thread pool has been executed; and a generation unit for generating a pause consumption message instruction and a resume consumption message instruction based on the count of running shards, the pause consumption message instruction controlling the execution threads in the execution thread pool to pause consuming new shards, and the resume consumption message instruction controlling the execution threads in the execution thread pool to resume consuming new shards.
[0144] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having at least the following method steps:
[0145] Step S201: Construct an execution control unit. The execution control unit is used to maintain the running shard count value in the execution thread pool. The running shard count value includes the number of shards being executed and the number of shards waiting to be executed in the execution thread pool. When a shard is successfully submitted to the execution thread pool, the running shard count value is incremented by one. After a shard in the execution thread pool is completed, the running shard count value is decremented by one.
[0146] Step S202: Based on the currently running shard count, generate a pause message consumption instruction and a resume message consumption instruction. The pause message consumption instruction controls the execution threads in the execution thread pool to pause consuming new shards, and the resume message consumption instruction controls the execution threads in the execution thread pool to resume consuming new shards. After pausing, the execution control unit will no longer consume new messages until it resumes consuming subsequent messages from the paused position.
[0147] Optionally, based on the running shard count value, a pause consumption message instruction is generated, including: determining a pause threshold, wherein the pause threshold is the product of the execution thread pool capacity and a first constant, and the execution thread pool capacity is the sum of the number of threads in the execution thread pool and the thread queue length; and generating the pause consumption message instruction if the running shard count value is greater than or equal to the pause threshold.
[0148] Optionally, based on the running shard count value, a recovery consumption message instruction is generated, including: determining a recovery threshold, wherein the recovery threshold is the product of the execution thread pool capacity and a second constant, and the execution thread pool capacity is the sum of the number of threads in the execution thread pool and the thread queue length; and generating the recovery consumption message instruction if the running shard count value is less than the recovery threshold.
[0149] Optionally, after generating a recovery consumption message instruction based on the running shard count, the method further includes: controlling the new shard to be consumed by the target consumption thread; controlling the target consumption thread to submit the new shard to the execution thread pool queue in the execution thread pool; controlling the execution thread pool to return the waiting execution instruction to the execution control unit while the new shard is waiting to be executed in the execution thread pool queue; and controlling the execution thread pool to return the execution success instruction to the execution control unit after the new shard has been executed in the execution thread pool queue.
[0150] Optionally, while the new shard is waiting to be executed in the execution thread pool queue, controlling the execution thread pool to return the waiting execution instruction to the execution control unit includes: while the new shard is waiting to be executed in the execution thread pool queue, controlling the execution thread pool to send the waiting execution instruction to the target consumer thread, so as to control the target consumer thread to send the waiting execution instruction to the execution control unit; after the new shard has been executed in the execution thread pool queue, controlling the execution thread pool to return the execution success instruction to the execution control unit includes: after the new shard has been executed in the execution thread pool queue, controlling the execution thread pool to send the execution success instruction to the target consumer thread, so as to control the target consumer thread to send the execution success instruction to the execution control unit.
[0151] Optionally, after controlling the target consumer thread to submit the new shard to the execution thread pool queue in the execution thread pool, the method further includes: controlling the target consumer thread to return the successful consumption message to the message queue.
[0152] Optionally, the multiple execution threads in the above execution thread pool are distributed across different execution machines.
[0153] Optionally, the above-mentioned pause message consumption instruction is also used to control the message queue to pause forwarding new shards to the above-mentioned execution thread pool, and the above-mentioned resume message consumption instruction is also used to control the above-mentioned message queue to resume forwarding new shards to the above-mentioned execution thread pool.
[0154] According to another aspect of this application, a multi-threaded job execution apparatus is provided, comprising: a construction unit for constructing an execution control unit, the execution control unit for maintaining a count of running shards in an execution thread pool, the count of running shards including the number of shards being executed and the number of shards waiting to be executed in the execution thread pool; incrementing the count of running shards by one when a shard is successfully submitted to the execution thread pool; and decrementing the count of running shards by one after a shard in the execution thread pool has been executed; and a generation unit for generating a pause consumption message instruction and a resume consumption message instruction based on the count of running shards, the pause consumption message instruction controlling the execution threads in the execution thread pool to pause consuming new shards, and the resume consumption message instruction controlling the execution threads in the execution thread pool to resume consuming new shards.
[0155] It is obvious to those skilled in the art that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0156] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0157] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0158] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0159] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0160] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0161] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0162] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0163] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0164] As can be seen from the above description, the embodiments of this application achieve the following technical effects:
[0165] 1) The multi-threaded operation method of the above application first constructs an execution control unit, which is used to maintain the running shard count value in the execution thread pool. The running shard count value includes the number of shards being executed and the number of shards waiting to be executed in the execution thread pool. When a shard is successfully submitted to the execution thread pool, the running shard count value is incremented by one. After a shard in the execution thread pool is completed, the running shard count value is decremented by one. Then, based on the running shard count value, a pause consumption message instruction and a resume consumption message instruction are generated. The pause consumption message instruction is used to control the execution threads in the execution thread pool to pause consuming new shards, and the resume consumption message instruction is used to control the execution threads in the execution thread pool to resume consuming new shards. This method introduces an execution control unit to implement an active feedback mechanism for the running status of the execution thread pool. Based on this mechanism, it performs pause and resume consumption operations in a timely manner, thereby solving the consumption timeout problem and effectively avoiding message consumption failures. This improves the resource utilization of the execution thread pool, thereby improving the execution efficiency of batch processing jobs and solving the problem of low resource utilization in the existing multi-threaded operation mode of sharding.
[0166] 2) The multi-threaded operation apparatus of this application includes: a construction unit for constructing an execution control unit, wherein the execution control unit is used to maintain a count of running shards in the execution thread pool, the count of running shards including the number of shards being executed and the number of shards waiting to be executed in the execution thread pool; the count of running shards is incremented by one when a shard is successfully submitted to the execution thread pool, and decremented by one after a shard in the execution thread pool is completed; and a generation unit for generating a pause consumption message instruction and a resume consumption message instruction based on the count of running shards, wherein the pause consumption message instruction controls the execution threads in the execution thread pool to pause consuming new shards, and the resume consumption message instruction controls the execution threads in the execution thread pool to resume consuming new shards. This device implements an active feedback mechanism for the running status of the execution thread pool by introducing an execution control unit. Based on this mechanism, it performs pause and resume consumption operations in a timely manner, thereby solving the consumption timeout problem and effectively avoiding message consumption failures. This improves the resource utilization of the execution thread pool, thereby improving the execution efficiency of batch processing jobs and solving the problem of low resource utilization in the existing multi-threaded operation mode of sharding.
[0167] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for multi-threaded execution of a job, characterized in that, include: An execution control unit is constructed, which is used to maintain the running shard count value in the execution thread pool. The running shard count value includes the number of shards being executed and the number of shards waiting to be executed in the execution thread pool. When a shard is successfully submitted to the execution thread pool, the running shard count value is incremented by one, and after a shard in the execution thread pool is completed, the running shard count value is decremented by one. Based on the running shard count, a pause consumption message instruction and a resume consumption message instruction are generated. The pause consumption message instruction is used to control the execution threads in the execution thread pool to pause consuming new shards, and the resume consumption message instruction is used to control the execution threads in the execution thread pool to resume consuming new shards. Based on the running shard count, a pause consumption message instruction is generated, including: determining a pause threshold, wherein the pause threshold is the product of the execution thread pool capacity and a first constant, and the execution thread pool capacity is the sum of the number of threads in the execution thread pool and the thread queue length; and generating the pause consumption message instruction if the running shard count is greater than or equal to the pause threshold. Based on the currently running shard count, a recovery consumption message instruction is generated, including: determining a recovery threshold, wherein the recovery threshold is the product of the execution thread pool capacity and a second constant, and the execution thread pool capacity is the sum of the number of threads in the execution thread pool and the length of the thread queue; and generating the recovery consumption message instruction when the execution thread pool capacity is [value missing].
2. The method according to claim 1, characterized in that, After generating a resume consumption message instruction based on the currently running shard count, the method further includes: Control the new shards to be consumed by the target consumer thread; The target consumer thread is controlled to submit the new shard to the execution thread pool queue in the execution thread pool. While the new shard is waiting to be executed in the execution thread pool queue, the execution thread pool will return the waiting execution instruction to the execution control unit. After the new slice has been executed in the execution thread pool queue, the execution thread pool will return a success instruction to the execution control unit.
3. The method according to claim 2, characterized in that, While the new shard is waiting to be executed in the execution thread pool queue, controlling the execution thread pool to return the waiting execution instructions to the execution control unit includes: While the new shard is waiting to be executed in the execution thread pool queue, the execution thread pool is controlled to send the waiting execution instruction to the target consumer thread, so that the target consumer thread can send the waiting execution instruction to the execution control unit. After the new slice has been executed in the execution thread pool queue, the execution thread pool is controlled to return a success instruction to the execution control unit, including: After the new shard is executed in the execution thread pool queue, the execution thread pool is controlled to send the execution success instruction to the target consumer thread, so that the target consumer thread can send the execution success instruction to the execution control unit.
4. The method according to claim 2, characterized in that, After controlling the target consumer thread to submit the new shard to the execution thread pool queue in the execution thread pool, the method further includes: The target consumption thread is controlled to return a successful consumption message to the message queue.
5. The method according to any one of claims 1 to 4, characterized in that, The execution threads in the execution thread pool are distributed across different execution machines.
6. The method according to any one of claims 1 to 4, characterized in that, The pause message consumption instruction is also used to control the message queue to pause forwarding new shards to the execution thread pool, and the resume message consumption instruction is also used to control the message queue to resume forwarding new shards to the execution thread pool.
7. A multi-threaded operation device, characterized in that, include: A construction unit is used to construct an execution control unit. The execution control unit is used to maintain the running shard count value in the execution thread pool. The running shard count value includes the number of shards being executed and the number of shards waiting to be executed in the execution thread pool. When a shard is successfully submitted to the execution thread pool, the running shard count value is incremented by one. After a shard in the execution thread pool is completed, the running shard count value is decremented by one. The generation unit is used to generate a pause consumption message instruction and a resume consumption message instruction based on the running shard count value. The pause consumption message instruction is used to control the execution threads in the execution thread pool to pause consuming new shards, and the resume consumption message instruction is used to control the execution threads in the execution thread pool to resume consuming new shards. The generation unit includes a first determining module and a first generating module. The first determining module is used to determine a pause threshold, which is the product of the execution thread pool capacity and a first constant. The execution thread pool capacity is the sum of the number of threads in the execution thread pool and the length of the thread queue. The first generating module is used to generate the pause consumption message instruction when the count value of the currently running shard is greater than or equal to the pause threshold. The generation unit further includes a second determining module and a second generation module. The second determining module is used to determine a recovery threshold, which is the product of the execution thread pool capacity and a second constant. The execution thread pool capacity is the sum of the number of threads in the execution thread pool and the length of the thread queue. The second generation module is used to generate the recovery consumption message instruction when the execution thread pool capacity is zero.
8. An electronic device, characterized in that, include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including a job multithreading method for performing any one of claims 1 to 6.
Citation Information
Patent Citations
Message queue consumption speed control method and device, electronic equipment and medium
CN112527527A
Message consumption method and device, electronic equipment and computer readable medium
CN113760498A