Controllable multi-level concurrent model construction method and system based on channels
Through the multi-level concurrency model based on the channel, the problems of low concurrency logic control accuracy and unbalanced processing pressure are solved, and efficient concurrent task execution and system reliability are achieved.
Patent Information
- Application Number
- CN202411126249.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-16
- Publication Date
- 2025-01-03
AI Technical Summary
The control accuracy of concurrent logic is not high, and communication between threads and child threads is difficult, resulting in low system operation reliability and uneven concurrent processing pressure.
Adopting a channel-based controllable multi-level concurrency model, the parallel execution and pressure balance of tasks are achieved by creating concurrent controllers, task executors and data channels, and leveraging the multi-core performance of the server.
It realizes efficient concurrent task execution, ensures consistency in task creation and execution sequence, reduces the processing pressure of bottleneck business links, and improves the reliability and efficiency of the system.
Smart Images

Figure CN119248469A_ABST
Abstract
Description
Background Art
[0002] Concurrency is generally implemented through threads. There are difficulties in communication between threads and between parent threads and child threads. The control accuracy of concurrent logic is not high, which may lead to unpredictable business processing results due to uncontrollable thread running status, resulting in low system operation reliability. Summary of the invention
[0003] The present application provides a channel-based controllable multi-level concurrent model construction method and system, which is used to utilize the multi-core performance of the server through concurrency, reduce the processing pressure of bottleneck business links, and achieve a balance between efficiency and pressure.
[0004] In a first aspect, a method for constructing a controllable multi-level concurrent model based on a channel is provided, comprising the following steps:
[0005] Create concurrent controllers;
[0006] Create a task executor;
[0007] Create a channel with a data area capacity equal to the number of concurrent connections and a buffer capacity equal to the number of caches;
[0008] Create a task and store it at the end of the channel;
[0009] Execute tasks;
[0010] Close the concurrent controller.
[0011] In the above technical scheme, by creating a concurrent controller; creating a task executor; creating a channel with a data area capacity equal to the number of concurrency and a buffer capacity equal to the number of caches; creating a task and storing it at the end of the channel; executing the task; and closing the concurrent controller, the construction of a controllable multi-level concurrent model based on a channel is realized. By concurrently utilizing the multi-core performance of the server, the processing pressure of the bottleneck business link can be reduced, thereby achieving a balance between efficiency and pressure.
[0012] In a specific embodiment, it also includes:
[0013] When there are multiple layers of tasks, create a sub-concurrent executor in the task, set parameters, create sub-tasks, and execute sub-tasks.
[0014] In a specific implementation scheme, the concurrency controller includes a concurrency number, a buffer number, whether it is necessary to wait for the execution result of the child thread, a receiver of the task execution result, and the task executor.
[0015] In a specific implementation scheme, the task executor includes the channel and a daemon thread that takes tasks from the channel for execution.
[0016] In a specific implementation scheme, writing data to the channel and retrieving data from the channel are performed independently, and the actions of data entering and exiting the channel do not need to wait for each other.
[0017] In a specific implementation scheme, the steps of performing the task are as follows:
[0018] The task executor takes out tasks from the head of the channel and executes them, and takes out concurrent tasks from the channel and executes them simultaneously;
[0019] After the task execution is completed, the task executor continues to take out tasks from the channel head for execution until the data in the channel is empty.
[0020] In a specific implementation scheme, the step of shutting down the concurrent controller is specifically as follows:
[0021] After receiving the completion status of all tasks, the shutdown action is executed to destroy the channels and waiting threads created during the task execution.
[0022] In a second aspect, a channel-based controllable multi-level concurrent model building system is provided, comprising:
[0023] Concurrent controller creation module, used to create concurrent controllers;
[0024] Task executor creation module, used to create task executors;
[0025] A channel creation module is used to create a channel whose data area capacity is the number of concurrent connections and whose buffer area capacity is the number of caches;
[0026] A task creation module, used for creating tasks and storing them at the end of the channel;
[0027] A task execution module, used to execute tasks;
[0028] The concurrent controller shutdown module is used to shut down the concurrent controller.
[0029] In the above technical scheme, by creating a concurrent controller; creating a task executor; creating a channel with a data area capacity equal to the number of concurrency and a buffer capacity equal to the number of caches; creating a task and storing it at the end of the channel; executing the task; and closing the concurrent controller, the construction of a controllable multi-level concurrent model based on a channel is realized. By concurrently utilizing the multi-core performance of the server, the processing pressure of the bottleneck business link can be reduced, thereby achieving a balance between efficiency and pressure.
[0030] In a specific embodiment, it also includes:
[0031] The sub-concurrent controller creation module is used to create sub-concurrent executors in tasks when there are multi-level tasks, and to set parameters, create sub-tasks, and execute sub-tasks.
[0032] In a specific implementation scheme, the sub-concurrent controller creation module includes:
[0033] A sub-concurrent controller creation unit, used to create a sub-concurrent controller;
[0034] A subtask executor creation unit, used to create a subtask executor;
[0035] A subchannel creation unit, used to create a subchannel whose data area capacity is the number of concurrent connections and whose buffer area capacity is the number of caches;
[0036] A subtask creation unit, used for creating a subtask and storing it at the end of the subchannel;
[0037] A subtask execution unit, used for executing subtasks;
[0038] The sub-concurrent controller closing unit is used to close the sub-concurrent controller. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 A flowchart of a controllable multi-level concurrent model building method based on a channel provided in an embodiment of the present application;
[0040] Figure 2 A schematic diagram of the channel data structure and data input and output method provided in an embodiment of the present application;
[0041] Figure 3 Create a graph for the concurrent model provided in the embodiment of the present application;
[0042] Figure 4 A multi-level concurrent task execution process diagram provided for an embodiment of the present application;
[0043] Figure 5 A structural block diagram of a channel-based controllable multi-level concurrent model building system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0044] The present application is further described in detail below through the accompanying drawings and embodiments. Through these descriptions, the characteristics and advantages of the present application will become clearer and more specific.
[0045] The word "exemplary" is used exclusively herein to mean "serving as an example, embodiment, or illustration." Any embodiment described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments. Although various aspects of the embodiments are shown in the drawings, the drawings are not necessarily drawn to scale unless otherwise noted.
[0046] In addition, the technical features involved in different embodiments of the present application described below can be combined with each other as long as they do not conflict with each other.
[0047] To facilitate understanding of the controllable multi-level concurrent model construction method and system based on channels provided by the embodiment of the present application, its application scenario is first explained. The controllable multi-level concurrent model construction method based on channels provided by the embodiment of the present application is used to utilize the multi-core performance of the server through concurrency, and can also reduce the processing pressure of the bottleneck business link, and achieve a balance between efficiency and pressure. Concurrency is generally implemented through threads. There are difficulties in communication between threads and threads, and between parent threads and child threads. The control accuracy of concurrent logic is not high, and it is easy to cause the business processing results to be unpredictable due to the uncontrollable running state of the threads, resulting in a situation where the reliability of the system operation is not high. For this reason, the embodiment of the present application provides a controllable multi-level concurrent model construction method and system based on channels, so as to utilize the multi-core performance of the server through concurrency, and can also reduce the processing pressure of the bottleneck business link, and achieve a balance between efficiency and pressure. The following is a detailed description of it with embodiments in conjunction with specific drawings.
[0048] refer to Figures 1 to 5 , Figure 1 A flowchart of a controllable multi-level concurrent model building method based on a channel provided in an embodiment of the present application; Figure 2 A schematic diagram of the channel data structure and data input and output method provided in an embodiment of the present application; Figure 3 Create a graph for the concurrent model provided in the embodiment of the present application; Figure 4 A multi-level concurrent task execution process diagram provided for an embodiment of the present application; Figure 5 A structural block diagram of a channel-based controllable multi-level concurrent model building system provided in an embodiment of the present application.
[0049] exist Figure 1 In the embodiment of the present application, a method for constructing a controllable multi-level concurrent model based on a channel is provided, comprising the following steps:
[0050] Create concurrent controllers;
[0051] Create a task executor;
[0052] Create a channel with a data area capacity equal to the number of concurrent connections and a buffer capacity equal to the number of caches;
[0053] Create a task and store it at the end of the channel;
[0054] Execute tasks;
[0055] Close the concurrent controller.
[0056] In the above technical scheme, by creating a concurrent controller; creating a task executor; creating a channel with a data area capacity equal to the number of concurrency and a buffer capacity equal to the number of caches; creating a task and storing it at the end of the channel; executing the task; and closing the concurrent controller, the construction of a controllable multi-level concurrent model based on a channel is realized. By concurrently utilizing the multi-core performance of the server, the processing pressure of the bottleneck business link can be reduced, thereby achieving a balance between efficiency and pressure.
[0057] In a specific embodiment, it also includes:
[0058] When there are multiple layers of tasks, create a sub-concurrent executor in the task, set parameters, create sub-tasks, and execute sub-tasks.
[0059] In a specific implementation scheme, the concurrency controller includes a concurrency number, a buffer number, whether it is necessary to wait for the execution result of the child thread, a receiver of the task execution result, and the task executor.
[0060] In a specific implementation scheme, the task executor includes the channel and a daemon thread that takes tasks from the channel for execution.
[0061] In a specific implementation scheme, writing data to the channel and retrieving data from the channel are performed independently, and the actions of data entering and exiting the channel do not need to wait for each other.
[0062] In a specific implementation scheme, the steps of performing the task are as follows:
[0063] The task executor takes out tasks from the head of the channel and executes them, and takes out concurrent tasks from the channel and executes them simultaneously;
[0064] After the task execution is completed, the task executor continues to take out tasks from the channel head for execution until the data in the channel is empty.
[0065] In a specific implementation scheme, the step of shutting down the concurrent controller is specifically as follows:
[0066] After receiving the completion status of all tasks, the shutdown action is executed to destroy the channels and waiting threads created during the task execution.
[0067] Specifically, refer to Figures 2 to 4 The specific process of the channel-based controllable multi-level concurrent model construction method is as follows:
[0068] 1. Create a concurrent controller. The concurrent controller includes the number of concurrency, the number of caches, whether to wait for the child thread execution result, the task execution result receiver, and the task execution executor. The various elements of the concurrent controller are encapsulated into a TaskController object, which is created and initialized by the main thread.
[0069] 2. Create a task executor. The task executor contains a channel and a waiting thread that takes tasks from the channel for execution. The various elements of the task executor are encapsulated into a TaskExecutor object, which is created and initialized by the concurrent controller.
[0070] 3. Create a channel (Channel) with a data area capacity equal to the number of concurrent connections and a buffer capacity equal to the number of caches. The channel is a linear storage area with a first-in-first-out feature. After the data is taken out from the head of the channel, the remaining data in the channel moves forward logically in sequence. After the channel capacity is filled with data, no more data can be stored in the channel. Writing data to the channel and getting data from the channel run independently, and the actions of data entering and leaving the channel do not need to wait for each other. The channel is created by the task executor. See the channel data structure. Figure 2 .
[0071] 4. Create tasks and store them at the end of the channel. The number of tasks that the task executor can receive is the channel capacity. When the channel capacity is full, the task creation thread enters the waiting state. After the task processing in the waiting channel is taken out and executed by the task executor, the task creation thread stores the created tasks at the end of the channel. See the concurrent model creation process for details. Figure 3 .
[0072] 5. Execute the task. The task executor takes out the task from the head of the channel and executes it. It takes out the concurrent number of tasks from the channel and executes them at the same time. After the task execution is completed, the task executor continues to take out tasks from the head of the channel and execute them until the data in the channel is empty.
[0073] 6. Close the parallel controller. After receiving the end status of all tasks, execute the closing action and destroy the channels, waiting threads and other objects created during the task execution.
[0074] 7. When there are multi-level tasks, create a child concurrent executor in the task, and set relevant parameters, create tasks, and execute tasks. After the multi-level parallel model is created and run, all levels can run in parallel at the same time. The parent thread can execute subsequent logic only after all levels have finished running. The parent level can perform logical processing based on the running status of the child level and the returned exceptions. See the multi-level concurrent task execution process for details. Figure 4 .
[0075] In the above technical solution, the tree-type concurrency model is a multi-level concurrent processing model including branches and leaves. This embodiment designs a model based on channels to support multi-level concurrency and accurately control concurrent tasks at each level based on the basic concurrency semantics of the development language. It can not only utilize the multi-core performance of the server through concurrency, but also reduce the processing pressure of bottleneck business links, thereby achieving a balance between efficiency and pressure.
[0076] In the above technical scheme, the technical scheme of the present application has the following advantages: 1. The channel has the characteristics of a queue, which can ensure that the order of task creation is the same as the order of execution. 2. Data entering and leaving the channel are processed in parallel without the need for additional lock overhead, and data movement in the channel has high performance. 3. The concurrent controller can fully obtain the execution results of the task, and can accurately control and track the execution of parallel tasks. 4. It can create multi-level and parallel tasks at the same time, which can fully utilize the performance of multi-core CPUs, reduce the processing pressure of bottleneck business links, and achieve a balance between efficiency and pressure.
[0077] exist Figure 5 In the embodiment of the present application, a controllable multi-level concurrent model building system based on a channel is provided, including:
[0078] Concurrent controller creation module, used to create concurrent controllers;
[0079] Task executor creation module, used to create task executors;
[0080] A channel creation module is used to create a channel whose data area capacity is the number of concurrent connections and whose buffer area capacity is the number of caches;
[0081] A task creation module, used for creating tasks and storing them at the end of the channel;
[0082] A task execution module, used to execute tasks;
[0083] The concurrent controller shutdown module is used to shut down the concurrent controller.
[0084] In the above technical scheme, by creating a concurrent controller; creating a task executor; creating a channel with a data area capacity equal to the number of concurrency and a buffer capacity equal to the number of caches; creating a task and storing it at the end of the channel; executing the task; and closing the concurrent controller, the construction of a controllable multi-level concurrent model based on a channel is realized. By concurrently utilizing the multi-core performance of the server, the processing pressure of the bottleneck business link can be reduced, thereby achieving a balance between efficiency and pressure.
[0085] In a specific embodiment, it also includes:
[0086] The sub-concurrent controller creation module is used to create sub-concurrent executors in tasks when there are multi-level tasks, and to set parameters, create sub-tasks, and execute sub-tasks.
[0087] In a specific implementation scheme, the sub-concurrent controller creation module includes:
[0088] A sub-concurrent controller creation unit, used to create a sub-concurrent controller;
[0089] A subtask executor creation unit, used to create a subtask executor;
[0090] A subchannel creation unit, used to create a subchannel whose data area capacity is the number of concurrent connections and whose buffer area capacity is the number of caches;
[0091] A subtask creation unit, used for creating a subtask and storing it at the end of the subchannel;
[0092] A subtask execution unit, used for executing subtasks;
[0093] The sub-concurrent controller closing unit is used to close the sub-concurrent controller.
[0094] In the above technical scheme, the technical scheme of the present application has the following advantages: 1. The channel has the characteristics of a queue, which can ensure that the order of task creation is the same as the order of execution. 2. Data entering and leaving the channel are processed in parallel without the need for additional lock overhead, and data movement in the channel has high performance. 3. The concurrent controller can fully obtain the execution results of the task, and can accurately control and track the execution of parallel tasks. 4. It can create multi-level and parallel tasks at the same time, which can fully utilize the performance of multi-core CPUs, reduce the processing pressure of bottleneck business links, and achieve a balance between efficiency and pressure.
[0095] Those skilled in the art will appreciate that the present application may be implemented as a system, method or computer program product.
[0096] Therefore, the present disclosure may be specifically implemented in the following forms, namely: it may be completely hardware, it may be completely software (including firmware, resident software, microcode, etc.), or it may be a combination of hardware and software, generally referred to herein as a "circuit", "module" or "system". In addition, in some embodiments, the present application may also be implemented in the form of a computer program product in one or more computer-readable media, and the computer-readable medium may contain computer-readable program code.
[0097] Any combination of one or more computer-readable media can be used. Computer-readable media can be computer-readable signal media or computer-readable storage media. Computer-readable storage media can be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or devices, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: electrical connections with one or more wires, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In this document, computer-readable storage media can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0098] Although the embodiments of the present application have been shown and described above, it is understood that the above embodiments are exemplary and cannot be understood as limiting the present application. A person of ordinary skill in the art can change, modify, replace and modify the above embodiments within the scope of the present application. On this basis, a variety of replacements and improvements can be made to the present application, all of which fall within the scope of protection of the present application.
Claims
1. A controllable multi-level concurrent model construction method based on channels, characterized in that: The following steps are involved: Create concurrent controllers; Create a task executor; Create a channel with a data area capacity equal to the number of concurrent connections and a buffer capacity equal to the number of caches; Create a task and store it at the end of the channel; Execute tasks; Close the concurrent controller.
2. The channel-based controllable multi-level concurrent model construction method according to claim 1 is characterized in that: Also includes: When there are multiple layers of tasks, create a sub-concurrent executor in the task, set parameters, create sub-tasks, and execute sub-tasks.
3. The channel-based controllable multi-level concurrent model construction method according to claim 2 is characterized in that: The concurrency controller includes the concurrency number, the buffer number, whether it is necessary to wait for the sub-thread execution result, the receiver of the task execution result and the task executor.
4. The channel-based controllable multi-level concurrent model construction method according to claim 3 is characterized in that: The task executor includes the channel and a waiting thread for taking tasks from the channel for execution.
5. The channel-based controllable multi-level concurrent model construction method according to claim 4 is characterized in that: Writing data to the channel and fetching data from the channel are performed independently, and the actions of data entering and exiting the channel do not need to wait for each other.
6. The channel-based controllable multi-level concurrent model construction method according to claim 5, characterized in that: The steps to perform the task are as follows: The task executor takes out tasks from the head of the channel and executes them, and takes out concurrent tasks from the channel and executes them simultaneously; After the task execution is completed, the task executor continues to take out tasks from the channel head for execution until the data in the channel is empty.
7. The channel-based controllable multi-level concurrent model construction method according to claim 6, characterized in that: The steps of closing the concurrent controller are specifically as follows: After receiving the completion status of all tasks, the shutdown action is executed to destroy the channels and waiting threads created during the task execution.
8. A controllable multi-level concurrent model building system based on channels, characterized in that: include: Concurrent controller creation module, used to create concurrent controllers; Task executor creation module, used to create task executors; A channel creation module is used to create a channel whose data area capacity is the number of concurrent connections and whose buffer area capacity is the number of caches; A task creation module, used for creating tasks and storing them at the end of the channel; A task execution module, used to execute tasks; The concurrent controller shutdown module is used to shut down the concurrent controller.
9. The channel-based controllable multi-level concurrent model construction method according to claim 8, characterized in that: Also includes: The sub-concurrent controller creation module is used to create sub-concurrent executors in tasks when there are multi-level tasks, and to set parameters, create sub-tasks, and execute sub-tasks.
10. The channel-based controllable multi-level concurrent model construction method according to claim 9, characterized in that: The sub-concurrent controller creation module includes: A sub-concurrent controller creation unit, used to create a sub-concurrent controller; A subtask executor creation unit, used to create a subtask executor; A subchannel creation unit, used to create a subchannel whose data area capacity is the number of concurrent connections and whose buffer area capacity is the number of caches; A subtask creation unit, used for creating a subtask and storing it at the end of the subchannel; A subtask execution unit, used for executing subtasks; The sub-concurrent controller closing unit is used to close the sub-concurrent controller.
