Concurrent processing event-driven management method, server and storage medium
By dynamically adjusting event priorities and optimizing buffer management, combined with zero-copy technology and coroutine processing, the problems of unreasonable event scheduling and resource waste in existing event-driven processing methods are solved, achieving efficient concurrent processing and data transmission.
Patent Information
- Application Number
- CN202510919177.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-04
- Publication Date
- 2025-11-21
AI Technical Summary
Existing event-driven processing methods suffer from problems such as unreasonable event priority scheduling, low data transmission efficiency, and improper resource management in concurrent connection requirements, resulting in slow system response speed, resource waste, and poor stability.
By dynamically adjusting event priorities, combining zero-copy technology and coroutine processing, optimizing buffer management, and utilizing asynchronous I/O libraries and micro-thread libraries, efficient event scheduling and resource utilization are achieved.
It improves system response speed and resource utilization, reduces the number of data copies and thread context switching overhead, and enhances data transmission efficiency and system stability.
Smart Images

Figure CN120994414A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer network communication, in particular to an event-driven management method for concurrent processing, a server and a storage medium. BACKGROUND
[0002] In today's computer network communication field, event-driven concurrent processing mechanisms are widely used in various network server programs to cope with the growing demand for concurrent connections. However, the existing event-driven processing methods have exposed many deficiencies in practical application, as follows: Unreasonable event priority scheduling: existing methods often use fixed event priority strategies and cannot dynamically adjust according to real-time system load. In high load, low priority events may occupy too many resources, causing critical read event processing delays and affecting system response speed; in low load, system resources cannot be fully utilized to prioritize batch-executable write events, resulting in resource waste.
[0003] Low data transmission efficiency: in traditional methods, data usually needs to be copied multiple times between kernel mode and user mode when processing events, increasing CPU overhead and processing delay. In high-concurrency scenarios, frequent data copying becomes a bottleneck for system performance, limiting system throughput.
[0004] Lack of effective resource management and scheduling strategies: for events of different priorities, existing methods lack targeted processing mechanisms. High-priority events may be blocked by low-priority events and cannot be processed in time; low-priority events may not be reasonably delayed in high load, affecting the overall stability and performance of the system. SUMMARY
[0005] The technical problem to be solved by the present application is to provide an event-driven management method for concurrent processing, a server and a storage medium to improve the efficiency of event processing.
[0006] To solve the above technical problems, the technical solution adopted by the present application is: An event-driven management method for concurrent processing, comprising the steps of: S1, initializing event priority and collecting device load data in real time to determine the current load status of the device; S2, adjusting the priority of event types according to the current load status of the device: If the device is currently in a high load state, events requested by the client are high priority, events operated on the client are medium priority, and abnormal events are low priority; if the device is currently in a low load state, events operated on the client are high priority, events requested by the client are medium priority, and abnormal events are low priority; S3, detecting an event trigger, reading data of a high-priority event directly from a kernel buffer through a zero-copy technology, dispatching to a coroutine for processing, and entering a buffer queue for medium-priority and low-priority events, and scheduling according to a delay strategy.
[0007] To solve the above technical problems, another technical solution adopted by the present application is: An event-driven management server for concurrent processing, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the event-driven management method for concurrent processing when executing the computer program.
[0008] To solve the above technical problems, another technical solution adopted by the present application is: A storage medium having a computer program stored thereon, wherein the computer program implements the steps of the event-driven management method for concurrent processing when executed.
[0009] The event-driven management method for concurrent processing, the server and the storage medium have the advantages that: the event priority is dynamically adjusted according to the real-time load status of the device, the timely processing of critical events is ensured in high load, the device resources are fully utilized in low load, the response speed and resource utilization of the system are improved, the high-priority event is read directly from the kernel buffer through the zero-copy technology, the number of data copying is reduced, the processing delay is reduced, and the data transmission efficiency is improved, the high-priority event is quickly processed by using the lightweight characteristics of the coroutine, the thread context switching overhead is reduced, and the efficiency of event processing is further improved. BRIEF DESCRIPTION OF DRAWINGS
[0010] Figure 1 The flowchart of the event-driven management method for concurrent processing of the embodiment of the present application is shown in the figure. Figure 2 The structure diagram of the event-driven management server for concurrent processing of the embodiment of the present application is shown in the figure. Label explanation: 1. An event-driven management server for concurrent processing; 2. A processor; 3. A memory. DETAILED DESCRIPTION
[0011] To explain the technical content, the achieved purposes and effects of the present application in detail, the following will be described in combination with the embodiments and the accompanying drawings.
[0012] Please refer to Figure 1 An event-driven management method for concurrent processing, comprising the steps of: S1, initialize event priority, and collect device load data in real time to determine the current load status of the device; S2, adjust the priority of the event type according to the current load status of the device: If the device is currently in a high load state, the event requested by the client is high priority, the event operated to the client is medium priority, and the abnormal event is low priority; if the device is currently in a low load state, the event operated to the client is high priority, the event requested by the client is medium priority, and the abnormal event is low priority; S3, when an event trigger is detected, the high-priority event is read directly from the kernel buffer through zero-copy technology and dispatched to the coroutine for processing; the medium-priority and low-priority events enter the buffer queue and are scheduled according to the delay strategy.
[0013] As can be seen from the above description, the event-driven management method for concurrent processing of the application can dynamically adjust the event priority according to the real-time load status of the device, can ensure timely processing of critical events in high load, can fully utilize device resources in low load, and can improve the response speed and resource utilization of the system; the high-priority event is read directly from the kernel buffer through zero-copy technology, the number of data copying is reduced, the processing delay is reduced, and the data transmission efficiency is improved; at the same time, the high-priority event is quickly processed by using the lightweight characteristics of the coroutine, the thread context switching overhead is reduced, and the efficiency of event processing is further improved.
[0014] Further, step S1 further comprises the steps of: configuring initial parameters of the connection pool; In step S3, available connections are allocated by the connection pool during event processing.
[0015] As can be seen from the above description, the available connections are allocated by the connection pool, the overhead caused by frequent creation and destruction of connections can be avoided, the reusability of the connections is improved, the available connections can be quickly obtained during event processing, the resource consumption is reduced, and the overall performance of the system is improved.
[0016] Further, it further comprises the step of: S4, periodically scanning the connection pool, removing abnormal / idle connections, and dynamically adjusting the size of the connection pool according to the device load and connection state.
[0017] As can be seen from the above description, the connection pool is periodically scanned, the abnormal and idle connections are removed, and the size is dynamically adjusted, which can ensure the effectiveness and availability of the connections in the connection pool. Invalid connections can be avoided to occupy resources, the number of connections can be flexibly adjusted according to the load, and the connection resources can be efficiently utilized by the system under different loads.
[0018] Further, the step S4 specifically uses a heartbeat mechanism to detect and remove abnormal / idle connections, including steps of: sending a heartbeat packet to the client periodically to detect the active state of the connection; if no confirmation packet returned by the client is received within a preset time, it is considered that the connection with the client has been disconnected, and it is removed from the connection pool.
[0019] As can be seen from the above description, using the heartbeat mechanism to detect and remove abnormal / idle connections can timely discover disconnected connections and remove them from the connection pool, ensuring the reliability of the connections in the connection pool. It prevents invalid connections from affecting the event processing flow and improves the stability and resource utilization of the system.
[0020] Further, the step S1 further includes steps of: establishing a primary buffer for receiving network data in the kernel state, and establishing a secondary buffer for temporarily storing network data in the user state; directly reading data from the kernel buffer through zero-copy technology, specifically: after receiving target data in the kernel buffer, using the sendfile system call of the Linux system to send the target data to the target file descriptor.
[0021] As can be seen from the above description, buffers are established in the kernel state and the user state respectively, and zero-copy data transmission is realized by combining the sendfile system call, which reduces the number of data copying between the user space and the kernel space, reduces data transmission delay, improves data transmission efficiency, and enhances the timeliness of event processing.
[0022] Further, the step S1 further includes steps of: initializing the asynchronous I / O library and the micro-thread library, creating an event loop and a coroutine scheduler; The step S3 of dispatching to the coroutine for processing specifically includes: creating an event loop using the asynchronous I / O library, registering I / O events, and dispatching events to the coroutine for processing through a lightweight coroutine scheduler.
[0023] As can be seen from the above description, initializing the asynchronous I / O library and the micro-thread library, creating an event loop and a coroutine scheduler, and using coroutines to process events can reduce thread context switching overhead. Lightweight coroutine scheduling makes event processing more efficient, enabling more concurrent events to be processed within a single thread and improving system concurrent processing capability.
[0024] Further, the step S3 of scheduling according to a delay strategy includes steps of: calculating an adjustment coefficient according to current load data of the device, the adjustment coefficient being proportional to the load data; The processing delay time of different priority events is dynamically adjusted according to the adjustment coefficient.
[0025] As can be seen from the above description, the adjustment coefficient is calculated according to the device load, and the processing delay time of different priority events is dynamically adjusted, so that the event processing strategy is more flexible. When the load is high, the delay of high-priority events is reduced to ensure that critical events are processed in time. When the load is low, the delay is reasonably allocated to fully utilize system resources.
[0026] Further, the load data includes CPU load data, memory load data and network load data.
[0027] As can be seen from the above description, the load data covers CPU, memory and network load data, which can more comprehensively and accurately reflect the load condition of the device. Based on these data, the event priority and processing strategy are adjusted, so that the system can efficiently operate in a complex load environment, and the overall performance is not affected by the local high load.
[0028] Please refer to Figure 2 An event-driven management server for concurrent processing 1, comprising a processor 2, a memory 3, and a computer program stored in the memory 3 and executable on the processor 2, wherein the processor 2 executes the computer program to implement the steps of the event-driven management method for concurrent processing described above.
[0029] A storage medium having a computer program stored thereon, wherein the computer program is executed to implement the steps of the event-driven management method for concurrent processing described above.
[0030] As can be seen from the above description, the event-driven management server and storage medium for concurrent processing of the present application dynamically adjust the event priority according to the real-time load condition of the device, which can ensure the timely processing of critical events when the load is high, and fully utilize the device resources when the load is low, thereby improving the response speed and resource utilization of the system. High-priority events use zero-copy technology to read data directly from the kernel buffer, reducing the number of data copies, reducing processing delay and improving data transmission efficiency. At the same time, the lightweight characteristics of coroutines are used to quickly process high-priority events, reducing the thread context switching overhead and further improving the efficiency of event processing.
[0031] The event-driven management method, server and storage medium for concurrent processing of the present application are suitable for Socket event-driven of devices, especially for efficient Linux Socket event-driven.
[0032] Please refer to Figure 1 The embodiment one of the present application is: A concurrent event-driven management method, comprising the steps of: S1, initializing event priority and collecting device load data in real time to determine the current load status of the device; Step S1 further comprises the steps of: configuring initial parameters of the connection pool; establishing a primary buffer for receiving network data in the kernel state, and a secondary buffer for temporarily storing network data in the user state; Initialize the asynchronous I / O library and micro-thread library, create event loop and coroutine scheduler.
[0033] The load data includes CPU load data, memory load data and network load data.
[0034] In this embodiment, when initializing the event priority, different priorities are assigned according to different types of events (read, write, exception). The read event is a high-priority event, usually a client request, which needs to be processed as soon as possible; the write event is a medium-priority event, involving sending data to the client; and other events are low-priority events, which usually do not affect the operation of the system.
[0035] The current CPU usage, memory occupancy and network bandwidth usage are obtained through system API to monitor the CPU, memory and network load of the system in real time. At the same time, the initial capacity, maximum number of connections, minimum number of connections and other parameters of the connection pool are set.
[0036] A multi-level buffer is established between the kernel state and the user state for data transmission of high-priority events. Specifically, a primary buffer of appropriate size is created in the kernel state, and a corresponding secondary buffer is created in the user state.
[0037] Select appropriate asynchronous I / O library (such as libuv) and micro-thread library (such as libco) for initialization, and create event loop and coroutine scheduler.
[0038] S2, according to the current load status of the device, adjust the priority of the event type: If the device is currently in a high-load state, the event of the client request is high-priority, the event of the client operation is medium-priority, and the exception event is low-priority; if the device is currently in a low-load state, the event of the client operation is high-priority, the event of the client request is medium-priority, and the exception event is low-priority.
[0039] In this embodiment, the priority of the event is dynamically adjusted according to the load status during the operation of the system. In the case of heavy load of the system, the priority of the event with low system load can be relatively increased to relieve the system load.
[0040] In high load situations: Prioritize initial high priority events (e.g. read events); Initial medium priority events (e.g. write events) are next; Initial low priority events (e.g. exception events) are last.
[0041] In low load situations: Prioritize initial medium priority events (e.g. write events); Initial high priority events (e.g. write events) are next; Initial low priority events (e.g. exception events) are last.
[0042] S3, detect event trigger, read data from kernel buffer directly through zero-copy technology, dispatch high priority events to coroutine for processing; medium and low priority events enter buffer queue and are scheduled according to delay strategy; In step S3, when processing events, available connections are allocated by the connection pool; In step S3, dispatching to coroutine for processing specifically includes: Creating an event loop using an asynchronous I / O library, registering I / O events, and dispatching events to coroutines for processing through a lightweight coroutine scheduler; Directly reading data from the kernel buffer through zero-copy technology specifically includes: After receiving the target data in the kernel buffer, using the sendfile system call of the Linux system to send the target data to the target file descriptor.
[0043] In this embodiment, the sendfile system call of Linux is used to implement zero-copy data transmission. The zero-copy technology enables data to be transmitted between the kernel mode and the user mode without passing through the user mode buffer, thereby reducing data duplication. After the kernel buffer receives the data, it directly sends the data to the target file descriptor through the sendfile system call without passing through the user mode. The combination of the zero-copy technology and the multi-level buffer ensures that the data does not need to be duplicated multiple times during transmission, thereby improving the data transmission efficiency.
[0044] Optimize buffer management strategy Optimize buffer management strategy to reduce data duplication and memory consumption. The specific optimization measures are as follows: Before optimization: Each connection has an independent buffer, resulting in large memory consumption and frequent data duplication.
[0045] After optimization: Shared buffer pool is introduced, and multiple connections can reuse buffers to reduce memory consumption.
[0046] Optimization strategy: Implement buffer pool management, dynamically allocate and release buffers.
[0047] Adjust the buffer size dynamically according to data traffic, avoid memory waste.
[0048] Use reference counting mechanism, ensure that the buffer is released when there is no connection.
[0049] In this embodiment, the intelligent connection pool management strategy is developed, which can automatically identify and close idle or abnormal connections, dynamically adjust the size of the connection pool, and avoid resource waste. When handling high-priority events, intelligent connection management can ensure timely allocation and release of connection resources, and improve the response speed of the system. When the system load is low, intelligent connection management can still optimize the resource allocation of the connection pool, and improve the overall efficiency of the system.
[0050] When handling high-priority events, the fusion of asynchronous I / O and microthreads can reduce blocking and thread context switching overhead, and improve the response speed of the system. Introduce lightweight microthread libco to realize coroutine scheduling: initialize the microthread library and create a coroutine scheduler; handle I / O events in the coroutine, and each coroutine handles one or more I / O events.
[0051] Handle I / O events in the coroutine to reduce thread context switching and improve processing efficiency: when an asynchronous I / O event is triggered, dispatch the event to the corresponding coroutine for processing; the coroutine handles the I / O event and returns to the event loop after completion, waiting for the next event; through the lightweight context switching of the coroutine, the context switching overhead in the traditional thread model is reduced, and the overall performance of the system is improved.
[0052] The step S3 of scheduling according to the delay strategy includes the steps of: According to the current load data of the device, calculate the adjustment coefficient, which is proportional to the load data; According to the adjustment coefficient, dynamically adjust the processing delay time of different priority events.
[0053] In this embodiment, the delay time parameter is defined: the initial processing delay time of high, medium and low priority events is defined, for example, the high priority event is 0 microseconds, the medium priority event is 100 microseconds, and the low priority event is 200 microseconds. According to the current load of the system, calculate the adjustment coefficient, for example, the higher the system load, the larger the adjustment coefficient. According to the adjustment coefficient, dynamically adjust the processing delay time of different priority events. When the system load is high, reduce the processing delay time of high priority events and increase the processing delay time of low priority events. Optimize event processing, prioritize high priority events in the event queue to ensure that critical events are processed in a timely manner.
[0054] Meanwhile, in the embodiment, when the system load is low, the medium and low priority events (such as write events and abnormal events) need to be properly handled, and the multi-level buffering and zero-copy technology can still improve the data transmission efficiency.
[0055] S4, periodically scan the connection pool, remove abnormal / idle connections, and dynamically adjust the size of the connection pool according to the device load and connection state; In step S4, the heartbeat mechanism is used to detect and remove abnormal / idle connections, including the following steps: Periodically send a heartbeat packet to the client to detect the active state of the connection; If no confirmation packet returned by the client is received within a predetermined time, it is considered that the connection with the client has been disconnected, and it is removed from the connection pool.
[0056] In the embodiment, (1) periodically scan the connection pool, identify idle or abnormal connections, and ensure that high priority events can be processed in time. The specific steps are as follows: Step 1: Periodically check the status of each connection, including the last active time, data transmission, etc.
[0057] Step 2: Mark the connection that has not been active for a long time as an idle connection, and mark the connection that has abnormal data transmission as an abnormal connection.
[0058] (2) Dynamically adjust the size of the connection pool, dynamically adjust the size of the connection pool according to the system load and connection state, release unnecessary resources, and ensure that high priority event connection resources are allocated preferentially.
[0059] According to the connection state, the size of the connection pool is dynamically adjusted to release unnecessary resources. The specific implementation is as follows: Step 1: Dynamically adjust the size of the connection pool according to the number of idle and abnormal connections.
[0060] Step 2: Release the resources occupied by idle and abnormal connections and remove them from the connection pool.
[0061] Step 3: When a new connection request arrives, if the connection pool is full, use the released connection resources preferentially.
[0062] (3) Use the heartbeat mechanism to detect the connection state Use the heartbeat mechanism to detect the connection state to ensure that the connections in the connection pool are valid. The specific steps are as follows: Step 1: The server periodically sends a heartbeat packet to the client to detect the active state of the connection.
[0063] Step 2: After receiving the heartbeat packet, the client immediately returns an acknowledgement packet indicating that the connection is normal.
[0064] Step 3: If the server does not receive an acknowledgement packet within a certain time, it considers the connection to be disconnected and removes it from the connection pool.
[0065] Please refer to Figure 2 Embodiment two of the present application is: An event-driven management server for concurrent processing 1, comprising a processor 2, a memory 3, and a computer program stored in the memory 3 and executable on the processor 2, the processor 2 executes the computer program to realize the steps in the event-driven management method for concurrent processing in the above embodiment one.
[0066] Embodiment three of the present application is: A storage medium having a computer program stored thereon, the computer program being executed to realize the steps in the event-driven management method for concurrent processing in the above embodiment one.
[0067] In summary, the present application provides an event-driven management method for concurrent processing, a server and a storage medium, which dynamically adjusts the event priority according to the real-time load status of the device, can ensure timely processing of critical events at high load, fully utilizes device resources at low load, improves the response speed and resource utilization of the system; high priority events use zero-copy technology to read data directly from the kernel buffer, reducing the number of data copies, reducing processing delay and improving data transmission efficiency; at the same time, the light weight of coroutine is used to quickly process high priority events, reducing the thread context switching overhead, further improving the efficiency of event processing.
[0068] The present application optimizes the trigger logic of epoll or similar mechanisms to ensure that critical events are processed in a timely manner. The various improvements are connected through a main trunk, and through the running steps of the event-driven framework, it shows how the various improvements work together to form a complete event-driven framework.
[0069] Define event priority, assign different priorities according to different types of events (read, write, exception). Read events are high priority events, usually client requests that need to be processed as soon as possible; write events are medium priority events, involving sending data to the client; other events are low priority events, which usually do not affect the operation of the system.
[0070] Monitor system load, get current CPU usage through system API to monitor CPU, memory, network and other load conditions in real time.
[0071] At least the following beneficial effects are achieved: (1) High system throughput: through adaptive event scheduling algorithm and multi-level buffer and zero-copy technology, the system throughput is significantly improved, and the data processing delay is reduced.
[0072] (2) Reduce resource consumption: Intelligent connection management strategy effectively reduces resource waste, optimizes connection pool size, and reduces system memory and CPU consumption.
[0073] (3) Improve concurrent processing capability: Fusion asynchronous I / O model and micro-thread technology, while maintaining high concurrency, reduce thread context switching overhead, and improve single-thread processing capability.
[0074] (4) Enhance system stability: Optimize event-driven model and data processing flow to improve system stability and scalability in high-concurrency scenarios.
[0075] The above is only an embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent transformation or direct or indirect application in related technical fields using the content of the present application specification and drawings is also included in the patent protection scope of the present application.
Claims
1. An event-driven management method for concurrent processing, characterized in that, Including the following steps: S1. Initialize event priorities and collect device load data in real time to determine the current load status of the device; S2. Adjust the priority of the event types according to the current load status of the device: If the device is currently under high load, events requested by the client will have high priority, events that operate on the client will have medium priority, and abnormal events will have low priority. If the device is currently under low load, events that operate on the client are given high priority, events that request the client are given medium priority, and abnormal events are given low priority. S3. When an event is detected, high-priority events are read directly from the kernel buffer using zero-copy technology and dispatched to a coroutine for processing; medium-priority and low-priority events are placed in a buffer queue and scheduled according to a delay strategy.
2. The event-driven management method for concurrent processing according to claim 1, characterized in that, Step S1 also includes the following steps: Configure the initial parameters of the connection pool; In step S3, during event processing, the connection pool allocates available connections.
3. The event-driven management method for concurrent processing according to claim 2, characterized in that, It also includes the following steps: S4. Periodically scan the connection pool, remove abnormal / idle connections, and dynamically adjust the size of the connection pool based on device load and connection status.
4. The event-driven management method for concurrent processing according to claim 3, characterized in that, Step S4 specifically involves using a heartbeat mechanism to detect and remove abnormal / idle connections, including the following steps: Periodically send heartbeat packets to the client to check the connection's activity status; If no acknowledgment packet is received from the client within a preset time, the connection with the client is considered to be broken, and the client is removed from the connection pool.
5. The event-driven management method for concurrent processing according to claim 1, characterized in that, Step S1 also includes the following steps: A primary buffer for receiving network data is established in kernel mode, and a secondary buffer for temporarily storing network data is established in user mode. Reading data directly from the kernel buffer using zero-copy technology specifically involves: After receiving the target data in the kernel-mode buffer, the Linux system's sendfile system call is used to send the target data to the target file descriptor.
6. The event-driven management method for concurrent processing according to claim 1, characterized in that, Step S1 also includes the following steps: Initialize the asynchronous I / O library and microthread library, and create the event loop and coroutine scheduler; The specific steps in step S3, where the task is assigned to a coroutine for processing, are as follows: Create an event loop using an asynchronous I / O library, register I / O events, and dispatch events to coroutines for processing using a lightweight coroutine scheduler.
7. The event-driven management method for concurrent processing according to claim 1, characterized in that, Step S3, scheduling according to the delay policy, includes the following steps: Based on the current load data of the equipment, an adjustment coefficient is calculated, and the adjustment coefficient is proportional to the load data. The processing delay time for events of different priorities is dynamically adjusted based on the adjustment coefficient.
8. The event-driven management method for concurrent processing according to claim 1, characterized in that, The load data includes CPU load data, memory load data, and network load data.
9. A concurrent event-driven management server, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the event-driven management method for concurrent processing as described in any one of claims 1-8.
10. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed, it implements the steps of the event-driven management method for concurrent processing as described in any one of claims 1-8.