High-speed inter-process communication system and method supporting dynamic process management and load balancing
By using the SDK module and the command channel and data channel connection of the background service process in the inter-process communication system, combined with shared memory and CPU cache line optimization technology, combined with the load balancing algorithm and polling method, the low communication efficiency in the existing technology is solved. It solves the problem of inflexible channel management and achieves high-speed, flexible and stable inter-process communication.
Patent Information
- Application Number
- CN202411026771.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-10-08
AI Technical Summary
When existing technology implements high-speed inter-process communication, the communication efficiency is low and the management of multi-process communication channels is not flexible enough. Especially when processes are frequently created and accessed, the flow control of the data path is unbalanced and some process data Accumulated and unable to be processed in time.
Use SDK modules and background service processes to connect through command channels and data channels, use pipes or Domain Sockets to implement command channels, use shared memory lock-free ring queues and CPU cache line optimization to implement data channels, and combine load balancing algorithms and polling methods. Data distribution and management.
It realizes dynamic process management and load balancing, improves the efficiency of inter-process communication and the flexibility and stability of the system, avoids the problem of long-term occupation of hardware resources by a single process under certain circumstances, and ensures the stability of the data rate when multi-user processes are concurrent. sex.
Smart Images

Figure CN118747124A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data transmission, and in particular to a high-speed inter-process communication system and method supporting dynamic process management and load balancing. Background Art
[0002] In the current password card system, the PCIe 2.0 XDMA IP core can support up to two DMA channels, but it faces the need for multiple applications to access the encryption and decryption resources of the password card together. In order to meet this need, it is necessary to cooperate with each other in multiple aspects such as message design and inter-process communication to realize multi-user access support for the password card. Among them, the design of the inter-process communication system is an important component of the above-mentioned password card system.
[0003] Similar products on the market currently use the following solutions to meet the above requirements. First, the inter-process communication system is completed by using the pipes, message queues, sockets and other methods provided by the system. The advantages of this solution are that the inter-process communication method is provided by the system, mature, stable, flexible in the number of concurrent processes, and sufficient to meet the needs of multi-process communication. However, its communication efficiency is low and cannot meet the core demand of high-speed inter-process communication. Second, the communication is carried out by using shared memory or message queues and lock-free queues based on shared memory. A certain number of inter-process communication channels are created when the system is initialized, and an idle channel is allocated to it for data transmission when a new application is connected. This solution achieves high-speed communication, but its management of multi-process communication channels is not flexible enough, especially when processes are frequently created and connected. At the same time, in order to ensure high-speed communication, this solution often uses polling to send and receive data, which easily leads to unbalanced data path flow control. For example, when there is continuous high concurrent data in a channel, the background server process has been processing data on this channel and cannot be released, so that other process data accumulates at the same time and cannot be processed in time. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a high-speed inter-process communication system and method, which realizes a high-speed inter-process communication system that supports dynamic process management and load balancing.
[0005] In order to solve the technical problem, the technical solution adopted by the present invention is: a high-speed inter-process communication system supporting dynamic process management and load balancing, including an SDK module and a background service process, the SDK module and the background service process are connected through a command channel and a data channel; The SDK module is used by user applications to call. Each user process corresponds to an SDK module. The SDK module is used to establish a command channel and a data channel with the background service process. The command channel is used to transmit command and control information, and the data channel is used to transmit the user process's encryption and decryption requests, data, and encryption and decryption results; The background service process is used to implement channel management of command channels and data channels, process command messages of command channels, receive encryption and decryption requests and data of data channels, distribute them to designated queues through load balancing algorithms, and send the information to be encrypted and decrypted to the DPDK driver of the encryption card; The command channel is implemented by pipeline or Domain Socket, which is responsible for the transmission of control data between processes; The data channel is implemented using a lock-free circular queue based on shared memory and is used for inter-process data transmission.
[0006] Furthermore, the control data transmitted by the command channel includes a data channel creation command, a data channel deletion command, and heartbeat maintenance data.
[0007] Furthermore, the data channel uses a ring queue for message management.
[0008] Furthermore, the data channel uses memory fences to implement lock-free data transmission and reception in a single-producer-single-consumer mode.
[0009] Furthermore, the data channel uses CPU cache line optimization to improve data transmission performance.
[0010] The present invention also discloses a high-speed inter-process communication method supporting dynamic process management and load balancing. The method is implemented based on the above communication system and includes the following steps: S01), the background service process starts up when the device to which the cryptographic card belongs is powered on, creates a command channel monitoring and management thread, is responsible for receiving the connection of the user process, and establishes a connection with the cryptographic card device; S02), the user process calls the SDK module to initiate a command channel connection request to the background service process; S03), the background service process receives the user process connection, establishes a command channel between the two parties, and adds the created command channel to the command channel management queue; S04) After the command channel is connected, the SDK module sends heartbeat data packets regularly to maintain the current command channel; S05), the user process calls the SDK module and sends a data channel creation command through the command channel established with the background service process; S06), after receiving the data channel creation command, the background service process dynamically creates a data channel with the user process; S07), the data to be encrypted / decrypted of the user process is sent to the background service process through the data channel, and the background service process sends the data to be encrypted / decrypted to the password card. At the same time, the background service process reads the encrypted / decrypted data from the password card DPDK driver, parses the data packet, and sends it to the corresponding user process through the specified data channel; S08), the background service process uses a load balancing algorithm to perform load balancing processing on each data channel; S09), the data receiving thread of the background service process receives data. If no data arrives within the specified time, the thread enters a waiting state; S10), the user process sends a data channel destruction command, and the background service process destroys the data channel; S11), the user process closes the command channel, and the background service process cleans up the corresponding command channel resources.
[0011] Furthermore, the background service process uses polling to perform load balancing, and the polling method evenly sends encryption and decryption requests to each hardware encryption and decryption channel.
[0012] Furthermore, the background service process uses a weighted round-robin method for load balancing. The weighted round-robin method configures weights based on the performance of the underlying encryption and decryption channels, and the weights are positively correlated with the performance.
[0013] Furthermore, the data receiving thread of the background service process receives data by using a polling plus event notification method, activating the waiting thread before the data arrives, and then entering the polling state.
[0014] Beneficial effects of the present invention: The present invention adopts the pipeline (window system) / Domain Socket (linux system) mode to create a command channel, and performs dynamic management operations on the creation, maintenance, and deletion of data channels, making the system more flexible; for data channels, the inter-process lockless data channel is realized based on shared memory and circular queues, and the CPU cache line optimization technology is adopted for optimization, so that high-speed data transmission can be performed between processes; at the same time, the background service process adopts a load balancing strategy to perform balanced management on the data transmission and reception of multiple data channels, ensuring the stability of data rates of different data channels when multiple user processes are concurrent, and eliminating the situation in which the PCIE password card hardware resources are occupied by a single process for a long time under specific circumstances. The flexibility and stability of the entire password card system are improved while taking into account high performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 This is a functional block diagram of the system described in Example 1. DETAILED DESCRIPTION
[0016] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments.
[0017] Example 1 This embodiment discloses a high-speed inter-process communication system that supports dynamic process management and load balancing. Figure 1 As shown, the system includes two parts: SDK module and background service process. The SDK module and the background service process are connected through a command channel and a high-speed data channel.
[0018] The SDK module is used by user applications. Each user process corresponds to an SDK module. The SDK module is responsible for establishing command channels and data channels with the background service. Relevant commands and control information are transmitted through the command channel. The high-speed data channel is responsible for sending the encryption and decryption requests and data of the user process to the background service process, and processing the encryption and decryption results returned by the background service process and returning them to the user process.
[0019] The main functions of the background service process include channel management of command channels and high-speed data channels; corresponding processing of command messages of command channels; receiving encryption and decryption requests and data of data channels, and distributing them to designated queues through load balancing algorithms; sending messages to be encrypted and decrypted to the DPDK driver of the PCIE encryption board, etc.
[0020] The command channel is implemented in the form of pipe (window system) / Domain Socket (linux system). It is mainly responsible for the transmission of control data between processes, including but not limited to data channel creation commands, data channel deletion commands, heartbeat maintenance data, etc., to achieve more flexible dynamic process management functions.
[0021] The data channel is implemented using a lock-free circular queue based on shared memory, which is used for high-speed data transmission between processes. It adopts technologies such as circular queues, memory fences, and CPU cache line optimization. The circular queue is used for message management to avoid dynamic memory allocation; the memory fence is used to realize lock-free data transmission and reception in a single-producer and single-consumer mode to improve transmission efficiency; the CPU cache line optimization is used to improve the CPU CACHE hit rate and improve data processing efficiency.
[0022] In this embodiment, the data channel uses a message queue implemented by a lock-free circular queue based on shared memory. The message queue is a common component for communication between processes and systems. Applications communicate by reading and writing messages in and out of the queue to achieve asynchronous communication and simplify system design; the message queue can also be used as a cache to improve system throughput. The circular queue is a commonly used data structure. This structure ensures that data is operated according to the "first in, first out" principle, that is, the first element in is also the first element out. The circular queue is a special queue structure that ensures that the elements are also first in, but the difference from the general queue is that they are circular, that is, the previous element at the head of the queue is the tail of the queue, usually a closed loop with a fixed number of elements.
[0023] The inter-process communication mechanisms provided by the operating system include files, sockets, message queues, pipes, shared memory, etc. Among them, shared memory is the fastest IPC mechanism. After the shared memory is mapped to the process space, data can be read and written directly from the shared memory without executing a system call to transfer data. Therefore, the user mode / kernel mode switching and data copying between user space and kernel space required by other inter-process communication mechanisms are avoided. Since the message queue does not need to support cross-host communication, shared memory can be used for inter-process communication.
[0024] Lock-free is an optimistic strategy that assumes that there will be no conflicts when threads access shared resources, so there is no need to lock. Therefore, threads will continue to execute without stopping. Once a conflict occurs, the current operation will be retried until there is no conflict. The lock-free strategy uses a technique called CAS Compare And Swap to identify thread conflicts. Once a conflict is detected, the current operation will be retried until there is no conflict.
[0025] Cache Line is the basic unit for storing data in the cache. In order to improve the cache hit rate, the size of the data structure is set to an integer multiple of the cache line, thereby achieving cache line alignment. In this way, when the CPU accesses a certain data, the adjacent data can also be loaded into the cache at the same time, thereby improving cache utilization.
[0026] Example 2 This embodiment discloses a high-speed inter-process communication method supporting dynamic process management and load balancing, comprising the following steps: 1. The background service process starts with the power on of the device to which the PCIE cryptographic card belongs, and creates a command channel monitoring and management thread, which is responsible for receiving the connection of the user process and establishing a connection with the PCIE cryptographic card device.
[0027] 2. The user process calls the SDK module and initiates a command channel connection request to the background service process.
[0028] 3. The background service process receives the user process connection, establishes a command channel between the two parties, and adds the created command channel to the command channel management queue.
[0029] 4. After the command channel is connected, the SDK module sends heartbeat data packets regularly to maintain the current command channel to prevent the user process from exiting unexpectedly, which may cause the related communication channels in the background service process to fail to close normally and in time.
[0030] 5. The user process calls the SDK module and sends a data channel creation command through the command channel established with the background service process.
[0031] 6. After receiving the data channel creation command, the background service process dynamically creates a data channel with the user process.
[0032] 7. The data to be encrypted / decrypted of the user process is sent to the background service process through the data channel, and the background service process sends the data to the password card; at the same time, the background service process reads the encrypted / decrypted data from the password card DPDK driver, parses the data packet, and sends it to the corresponding user process through the specified data channel.
[0033] 8. The background service process uses the existing commonly used load balancing algorithms for each data channel to perform load balancing processing to prevent a data channel from taking up too much hardware time, resulting in the data channels of other user processes not being processed in a timely manner. The optional load balancing algorithms include polling and weighted polling. The polling method sends encryption and decryption requests evenly to each hardware encryption and decryption channel. The weighted polling method configures weights according to the performance of the underlying encryption and decryption channel. The weight is positively correlated with the performance, so that the channel with high performance undertakes more encryption and decryption tasks.
[0034] 9. The data receiving thread of the background service process uses polling plus event notification to receive data. When no data arrives within the specified time, the thread enters the waiting state to avoid the CPU still running at high load when there is no data. Before the data arrives, the waiting thread will be activated and then enter the polling state, ensuring high-speed data transmission between processes.
[0035] 10. The user process sends a data channel destruction command, and the background service process destroys the data channel.
[0036] 11. The user process closes the command channel, and the background service process cleans up the corresponding command channel resources.
[0037] Therefore, dynamic process management is performed through the command channel, high-speed decryption and decryption data transmission between processes is performed through a high-speed data channel implemented by technologies such as circular queues, memory fences, and CPU cache line optimization, and load balancing of encryption and decryption requests is achieved through polling and weighted polling, thereby realizing a high-speed inter-process communication system that supports dynamic process management and load balancing.
[0038] The above description is only the basic principle and preferred embodiments of the present invention. Improvements and substitutions made by those skilled in the art based on the present invention belong to the protection scope of the present invention.
Claims
1. A high-speed inter-process communication system that supports dynamic process management and load balancing, Features: It includes SDK module and background service process, and the SDK module and background service process are connected through command channel and data channel; The SDK module is used by user applications to call. Each user process corresponds to an SDK module. The SDK module is used to establish a command channel and a data channel with the background service process. The command channel is used to transmit command and control information, and the data channel is used to transmit the user process's encryption and decryption requests, data, and encryption and decryption results; The background service process is used to implement channel management of command channels and data channels, process command messages of command channels, receive encryption and decryption requests and data of data channels, distribute them to designated queues through load balancing algorithms, and send the information to be encrypted and decrypted to the DPDK driver of the encryption card; The command channel is implemented by pipeline or Domain Socket, which is responsible for the transmission of control data between processes; The data channel is implemented using a lock-free circular queue based on shared memory and is used for inter-process data transmission.
2. The high-speed inter-process communication system supporting dynamic process management and load balancing according to claim 1, Features: The control data transmitted by the command channel includes data channel creation command, data channel deletion command, and heartbeat maintenance data.
3. The high-speed inter-process communication system supporting dynamic process management and load balancing according to claim 1, Features: The data channel uses a circular queue for message management.
4. The high-speed inter-process communication system supporting dynamic process management and load balancing according to claim 1, Features: The data channel uses memory fences to implement lock-free data transmission and reception in a single-producer single-consumer mode.
5. The high-speed inter-process communication system supporting dynamic process management and load balancing according to claim 1, Features: The data channel uses CPU cache line optimization to improve data transfer performance.
6. A high-speed inter-process communication method that supports dynamic process management and load balancing, Features: The method is implemented based on the system described in claim 1, and comprises the following steps: S01), the background service process starts up when the device to which the cryptographic card belongs is powered on, creates a command channel monitoring and management thread, is responsible for receiving the connection of the user process, and establishes a connection with the cryptographic card device; S02), the user process calls the SDK module to initiate a command channel connection request to the background service process; S03), the background service process receives the user process connection, establishes a command channel between the two parties, and adds the created command channel to the command channel management queue; S04) After the command channel is connected, the SDK module sends heartbeat data packets regularly to maintain the current command channel; S05), the user process calls the SDK module and sends a data channel creation command through the command channel established with the background service process; S06), after receiving the data channel creation command, the background service process dynamically creates a data channel with the user process; S07), the data to be encrypted / decrypted of the user process is sent to the background service process through the data channel, and the background service process sends the data to be encrypted / decrypted to the password card. At the same time, the background service process reads the encrypted / decrypted data from the password card DPDK driver, parses the data packet, and sends it to the corresponding user process through the specified data channel; S08), the background service process uses a load balancing algorithm to perform load balancing processing on each data channel; S09), the data receiving thread of the background service process receives data. If no data arrives within the specified time, the thread enters a waiting state; S10), the user process sends a data channel destruction command, and the background service process destroys the data channel; S11), the user process closes the command channel, and the background service process cleans up the corresponding command channel resources.
7. The high-speed inter-process communication method supporting dynamic process management and load balancing according to claim 6, Features: The background service process uses polling to perform load balancing, which evenly sends encryption and decryption requests to each hardware encryption and decryption channel.
8. The high-speed inter-process communication method supporting dynamic process management and load balancing according to claim 6, Features: The background service process uses a weighted round-robin method for load balancing. The weighted round-robin method configures weights based on the performance of the underlying encryption and decryption channels, and the weights are positively correlated with the performance.
9. The high-speed inter-process communication method supporting dynamic process management and load balancing according to claim 6, Features: The data receiving thread of the background service process uses polling plus event notification to receive data. Before the data arrives, the waiting thread is activated and then enters the polling state.
