Inter-process communication method, system, electronic device, storage medium and program product

By adopting client-server communication architecture and multi-channel mechanism in inter-process communication, the problem of insufficient flexibility and efficiency of inter-process communication in the prior art is solved, and communication effects with high concurrency, low latency and low resource consumption are achieved.

CN119782000APending Publication Date: 2025-04-08CHINA TELECOM ARTIFICIAL INTELLIGENCE TECHNOLOGY (BEIJING) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411805545.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-09
Publication Date
2025-04-08

AI Technical Summary

Technical Problem

The existing inter-process communication methods have shortcomings in terms of flexibility and efficiency. They usually require developers to have deep knowledge of system programming and have problems of resource consumption and performance bottlenecks.

Method used

The client-server communication architecture is adopted to realize inter-process communication through a multi-channel mechanism. The client components and server components configure write threads and read threads respectively, support full-duplex request-response mode, and multiplex communication channels during the communication process to improve resource utilization and concurrency capabilities.

Benefits of technology

It realizes inter-process communication with high concurrency, low latency and low resource consumption, reduces the communication coding complexity of applications, and improves the system's response speed and resource utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119782000A_ABST
    Figure CN119782000A_ABST
Patent Text Reader

Abstract

The present invention provides an inter-process communication method, system, electronic device, storage medium and program product, and relates to the field of information processing technology. In an embodiment of the present invention, multiple communication channels are created between two processes, and in subsequent communications, these channels are reused to support thread-safe data transmission and reception, and multiple communication channels do not affect each other. For a communication task, after the writing thread sends the data, it will not occupy the current communication channel all the time, but release the channel for other communication tasks to use. Correspondingly, after the reading thread receives the data, it will not occupy the communication channel all the time, thereby improving resource utilization and concurrency, and reducing the communication coding complexity of the application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of information processing technology, and in particular, to an inter-process communication method, system, electronic device, storage medium, and program product. Background Art

[0002] In computer systems, although inter-process communication (IPC) already has a wealth of technical means, whether it is the method natively supported by the underlying operating system or the advanced components built by upper-level users, they each demonstrate powerful functions in specific scenarios, but they are also accompanied by some disadvantages that cannot be ignored.

[0003] For IPC methods natively supported by the underlying operating system, such as shared memory, message queues, semaphores, and sockets, although they provide efficient communication mechanisms, they often require developers to have deep knowledge of system programming and a deep understanding of the underlying hardware resources. The flexibility and efficiency of these methods come at the expense of ease of use. Developers need to perform a lot of secondary development on these infrastructures to build communication scenarios that meet complex user needs. This not only increases development costs, but can also lead to challenges in system stability, as any improper modifications can introduce subtle errors.

[0004] The advanced communication components built by upper-level users, such as HTTP protocol, WebSocket, and RabbitMQ, provide richer and more flexible functions, but also bring problems of complexity and resource consumption. These mainstream components are often too comprehensive and include many features that users may not need. Therefore, when applied to general inter-process communication, they are too bloated and complex. This not only increases the system overhead, but also may introduce potential performance bottlenecks due to unnecessary complexity.

[0005] Among them, MQTT is a technology that adopts the subscription-publish communication model. Although it is very suitable for scenarios such as the Internet of Things that require broadcasting messages, in traditional inter-process communication, a separate message broker is required to forward messages between publishers and subscribers. This not only increases the complexity and resource consumption of the system, but may also reduce communication efficiency due to processing delays in the message broker. The HTTP protocol adopts a request-response communication model. Although it is simple and easy to understand and widely used in Web development, it does not have the characteristics of full-duplex. This means that during the communication process, the client and server need to send requests and responses in turn, which limits the concurrency and efficiency of communication.

[0006] In addition, some technologies may also use a timed polling method in the message receiving agent module to receive data. Although this method is simple and intuitive, it will lead to problems of reduced concurrency and reduced efficiency. Because timed polling needs to constantly check whether new messages have arrived, it not only wastes a lot of CPU resources, but may also introduce additional delays due to improper polling interval settings.

[0007] In summary, although the existing inter-process communication methods perform well in some aspects, they also have disadvantages that cannot be ignored. Therefore, a new inter-process communication method is urgently needed. Summary of the invention

[0008] Embodiments of the present invention provide an inter-process communication method, system, electronic device, storage medium and program product to at least partially solve the above problems.

[0009] A first aspect of an embodiment of the present invention provides an inter-process communication method, the method comprising:

[0010] The first process sends first communication data to the client component;

[0011] The client writing thread of the client component receives the first communication data sent by the first process;

[0012] The client writing thread sends the communication data to the second process based on the first communication channel in the communication channel queue;

[0013] The client writing thread releases the first communication channel;

[0014] The first process and the second process are a client-server communication architecture, the first process is configured with a client component, and the second process is configured with a server component.

[0015] Optionally, the method further comprises:

[0016] The client reading thread of the client component receives second communication data sent by the second process based on the second communication channel, where the second communication data is sent by the second process through the server writing thread of the server component;

[0017] The client reading thread saves the second communication data to a data queue;

[0018] The client reading thread releases the second communication channel;

[0019] The first process reads the second communication data from the data queue.

[0020] Optionally, before the client reading thread receives the second communication data sent by the second process based on the second communication channel, the method further includes:

[0021] When the client read monitoring thread of the client component monitors the second communication data sent by the second process through the second communication channel, the second communication channel is distributed to the client read thread.

[0022] Optionally, after the client read thread releases the second communication channel, the method further includes:

[0023] The client read thread writes wake-up data into the listening file descriptor to wake up the client read listening thread;

[0024] The client read monitoring thread updates the communication channel monitoring list and adds the second communication channel to the current communication channel monitoring list.

[0025] Optionally, the method further comprises:

[0026] Sending connection request information to the server component through the client component;

[0027] The request connection information is received by the server component, and based on the request connection information, a plurality of communication channels are established between the server component and the client component.

[0028] A second aspect of an embodiment of the present invention provides an inter-process communication method, the method comprising:

[0029] The second process sends second communication data to the server component;

[0030] The server write thread of the server component receives the second communication data sent by the second process;

[0031] The server writing thread sends the second communication data to the first process based on the third communication channel in the communication channel queue;

[0032] The server write thread releases the third communication channel;

[0033] The first process and the second process are a client-server communication architecture, the first process is configured with a client component, and the second process is configured with a server component.

[0034] A third aspect of an embodiment of the present invention provides an inter-process communication system, the inter-process communication system comprising:

[0035] A first process is used to send first communication data to a client component; the client component includes a client write thread;

[0036] The client writing thread is used to receive first communication data sent by the first process; send the communication data to the second process based on the first communication channel in the communication channel queue; and release the first communication channel;

[0037] A second process is used to send second communication data to a server component; the server component includes a server write thread;

[0038] The server write thread is used to receive the second communication data sent by the second process; based on the third communication channel in the communication channel queue, send the second communication data to the first process; release the third communication channel;

[0039] The first process and the second process are a client-server communication architecture, the first process is configured with a client component, and the second process is configured with a server component.

[0040] Optionally, the client component further includes a client reading thread;

[0041] The client read thread is used to receive the second communication data sent by the second process based on the second communication channel; save the second communication data to the data queue; release the second communication channel; the second communication data is sent by the second process through the server write thread of the server component;

[0042] The first process is further used to read the second communication data from the data queue.

[0043] Optionally, the client component also includes a client read listening thread:

[0044] The client read monitoring thread is used to distribute the second communication channel to the client read thread when monitoring the second communication data sent by the second process through the second communication channel.

[0045] Optionally, the client read thread is further used to write wake-up data into the listening file descriptor to wake up the client read listening thread;

[0046] The client read monitoring thread is further used to update the communication channel monitoring list and add the second communication channel to the current communication channel monitoring list.

[0047] A fourth aspect of an embodiment of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executed, implements the inter-process communication method as described in the first aspect of the present invention.

[0048] A fifth aspect of an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the inter-process communication method as described in the first aspect of the present invention.

[0049] A sixth aspect of an embodiment of the present invention provides a computer program product, including a computer program / instruction, which is implemented by a processor to implement the steps of the inter-process communication method as described in the first aspect of the present invention.

[0050] In the embodiment of the present invention, a request-response mode is adopted. Different from the request-response mode of traditional web applications, the embodiment of the present invention can realize full-duplex request-response, that is, it can realize that the client initiates a request to the server and the server passively responds, and it can also realize that the server actively pushes data to the client. A process is either a client or a server, and the role does not change.

[0051] In an embodiment of the present invention, multiple communication channels are created between two processes, and these channels are reused in subsequent communications to support thread-safe data transmission and reception. The multiple communication channels do not affect each other. For a communication task, after the write thread sends the data, it will not occupy the current communication channel all the time, but release the channel for use by other communication tasks. Correspondingly, after the read thread receives the data, it will not occupy the communication channel all the time, thereby improving resource utilization and concurrency capabilities, and reducing the communication coding complexity of the application. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.

[0053] Figure 1 is a flowchart of the steps of the inter-process communication method provided by an embodiment of the present invention;

[0054] Figure 2 It is a schematic diagram of the overall flow of the inter-process communication method provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0055] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0056] First, some terms involved in the embodiments of the present invention are explained:

[0057] http (HyperText Transfer Protocol): is an application layer protocol used for distributed, collaborative, hypermedia information systems.

[0058] Socket: In computer networks, it is a technology that allows communication between nodes. It is an abstract representation in network communication and can be used for process communication between one device or multiple devices.

[0059] Unix domain socket: It is a special socket on Unix-like operating systems that only allows communication between processes on one device.

[0060] IPC (Inter Process Communication): inter-process communication.

[0061] Batch: A batch can contain only one transaction or multiple transactions. For example, a communication request can contain only one message or multiple messages.

[0062] fd (filedescriptor): file descriptor. In the field of software engineering, it is an abstraction of a file, through which you can monitor, read and write actual files.

[0063] The embodiment of the present invention proposes an inter-process communication method that combines the high efficiency of the underlying native method and the ease of use of the upper-level components, realizes the characteristics of high concurrency, low latency and low resource consumption through a multi-channel mechanism, and provides a new solution for inter-process communication.

[0064] Specifically, an embodiment of the present invention provides an inter-process communication method, such as Figure 1 As shown, it shows a flowchart of the steps of the inter-process communication method provided by an embodiment of the present invention. Specifically, the method includes the following steps:

[0065] S101: A first process sends first communication data to a client component.

[0066] S102: A client writing thread of a client component receives first communication data sent by a first process.

[0067] S103: The client write thread sends the communication data to the second process based on the first communication channel in the communication channel queue.

[0068] S104: The client writing thread releases the first communication channel.

[0069] The first process and the second process are a client-server communication architecture, the first process is configured with a client component, and the second process is configured with a server component.

[0070] The inter-process communication method provided in the embodiment of the present invention is applied to a scenario where two processes communicate with each other.

[0071] In the embodiment of the present invention, when two processes communicate on the same computer, Unix domain socket can be used to complete the communication to avoid network transmission overhead. When communicating on different computers, ordinary sockets are used for network communication.

[0072] The communication architecture adopted in the embodiment of the present invention is a client-server (CS) architecture, which adopts a request-response mode. Different from the request-response mode of traditional web applications, the embodiment of the present invention allows full-duplex request-response, that is, it allows both client->server and client<-server. A process is either a client or a server, and the role does not change.

[0073] In the embodiment of the present invention, the two processes can communicate with each other through the client component and the server component, and the client component and the server component can be deployed in the two processes respectively. Specifically, in the embodiment of the present invention, the first process is configured with a client component or a server component, and the second process is configured with a client component or a server component corresponding to the first process.

[0074] The CS architecture is a distributed computing model in which the client and the server communicate through a network. The client is responsible for sending requests to the server and receiving responses from the server. The server is responsible for processing the client's request and returning the corresponding results. In this architecture, the roles of the client and the server are fixed. A process is either a client or a server, and the role does not change. Traditional Web applications usually adopt a one-way request-response mode, that is, the client actively initiates a request and the server passively responds. However, an embodiment of the present invention allows a full-duplex request-response mode, which means that not only can the client send a request to the server, but the server can also actively push data to the client. Full-duplex communication allows data to be transmitted in both directions at the same time. Therefore, full-duplex communication is a combination of two simplex communication modes, which requires that both the sending device and the receiving device have independent receiving and sending capabilities.

[0075] Specifically, in the embodiment of the present invention, the client component is configured with a client write thread, a client read thread and a client read listener thread, and the server component is configured with a server write thread, a server read thread and a server read listener thread. Thus, both the client component and the server component can complete independent data transmission and data reception based on multiple communication channels based on the write thread, read thread and read listener thread configured by themselves.

[0076] In the embodiment of the present invention, different from the traditional HTTP protocol, the Socket protocol is used for information exchange. Socket is the underlying implementation of TCP / IP inter-process communication, allowing the server and the client to send data freely at any time, and can be applied to full-duplex communication.

[0077] In an optional embodiment, the method further comprises the following steps:

[0078] S11, sending connection request information to the server component through the client component.

[0079] S12, receiving the request connection information through the server component, and establishing multiple communication channels between the server component and the client component based on the request connection information.

[0080] In the embodiment of the present invention, the first process is configured with a client component, and the second process is configured with a server component. Specifically, the second process can start the server component according to the configuration file, and complete the configuration of the server address (usually the IP address and port number) and the client key allowed to access. Specifically, the server needs to be bound to a specific address and port so that the client can connect to the server. The client key is used to verify the identity of the client, ensuring that only the client with the correct key can connect to the server. After the configuration is completed, the second process starts the server component, listens to the specified address and port, and waits for the client's connection request.

[0081] Accordingly, the first process starts the client component according to the configuration file and initiates a connection to the server component using the agreed key. Specifically, the client component uses the key specified in the configuration file to initiate a connection request to the server component. The connection request contains the client's authentication information (key) to ensure that the server can recognize and accept the connection.

[0082] After receiving the connection request, the server verifies the key contained in the request. If the key is correct, the server will accept the connection request, and the communication connection between the client and the server is established.

[0083] In the embodiment of the present invention, the server component can receive connection requests from multiple client components, allowing a server to communicate with multiple clients simultaneously without the need for additional business logic.

[0084] In the embodiment of the present invention, multiple communication channels can be established between the server component and the client component to facilitate the execution of subsequent communication tasks. Specifically, the server component creates a listening socket and waits for the client component to access, and then the server and client components send and receive messages on these established communication channels.

[0085] In an embodiment of the present invention, multiple communication channels can be created between two processes, and these channels can be reused in subsequent communications. It supports thread-safe data transmission and reception, and multiple communication channels do not affect each other. For a communication task, after the client sends the data, it will not occupy the current communication channel all the time, but release the channel for other communication tasks to use. Correspondingly, after the server receives the data, it will not occupy the communication channel all the time, thereby improving resource utilization and concurrency capabilities, and reducing the communication coding complexity of the application.

[0086] Specifically, in the embodiment of the present invention, the communication channel, communication data, and communication initiator are managed and tracked within the component. The initiation of a communication task is identified by a globally unique ID, and the channel is released when the initiator completes sending the data. The underlying layer uses thread pool technology to execute data sending / receiving tasks. Each time data is sent / received, batches are dynamically formed to send as much data as possible, thereby improving concurrency and reducing resource consumption.

[0087] In the embodiment of the present invention, based on multiple independent communication channels, data can be sent and received in a batch manner, and multiple messages can be written or read at one time, thereby reducing the number of system calls and improving efficiency.

[0088] In the embodiment of the present invention, the first process is configured with a client component and the second process is configured with a server component. In step S101, the first process writes data to the client component. The data includes a fixed-length message header and a non-fixed-length message body. The message header records the message type, message body length, and the global unique ID of this communication task. The message body can contain any information. The data is distributed to the thread of the write thread pool in the client component. The thread gets the available communication channel from the communication channel queue to complete the data transmission.

[0089] In the embodiment of the present invention, a globally unique ID is used to identify each communication task, and the ID is tracked internally by the component. The client component and the server component can use the ID to clearly identify the message, thereby determining whether the message is related to themselves.

[0090] Specifically, the communication channel queue may be a write fd queue, and the communication channel executes the communication task in the form of fd.

[0091] In the embodiment of the present invention, the client component is responsible for processing data sending and receiving in the first process. It usually includes multiple submodules, such as connection management, data processing, thread pool management, etc. The write thread pool is a module in the client component, which consists of multiple threads. These threads are responsible for the data sending operation. Using a thread pool can improve performance, and the thread pool allows the reuse of existing threads to process tasks.

[0092] When data needs to be sent, the communication data sent by the first process will be distributed to the threads in the write thread pool. In the embodiment of the present invention, the specific distribution mechanism is not limited, and can be based on load balancing, polling, random selection and other strategies to ensure that the threads in the thread pool are evenly loaded.

[0093] In the embodiment of the present invention, the write fd queue is a data structure for storing file descriptors (fd) that can be used for write operations. A file descriptor is an integer used by the operating system to identify an open file or socket. In network programming, a file descriptor is typically used to identify a socket connection.

[0094] In the embodiment of the present invention, the fds in the write fd queue are all available fds, specifically those file descriptors that are ready for write operations, which usually means that the corresponding socket connection has been established and data can be sent safely.

[0095] In the embodiment of the present invention, after a thread obtains an available fd, it can use the fd to send data. The sending operation usually involves calling a write operation function (such as write() or send()) provided by the operating system to send the data to a server or other client through a socket.

[0096] Different from the traditional request-response mode, in the embodiment of the present invention, the request and response actions will not be executed sequentially on the same fd. After sending the request data, the present invention immediately releases the communication channel, and the reception of the response data may be completed on another communication channel, thereby decoupling the request and response processes and realizing asynchronous calls. Specifically, in the embodiment of the present invention, after the data is sent, the write thread will release the first communication channel, that is, the fd will be put back into the write fd queue so that other write threads can use it for subsequent write operations. This ensures the reuse of fd and improves resource utilization. Therefore, in the embodiment of the present invention, the data sending operation is managed and scheduled through the thread pool and the fd queue to realize an efficient client data sending mechanism. It improves the performance and response speed of the client, and can be applied to scenarios that need to handle a large number of concurrent connections and data sending.

[0097] In the embodiment of the present invention, after step S103, the method further includes the following steps: calling a callback function to write a data sending success parameter; and the callback function sends a data sending success message to the first process based on the data sending success parameter.

[0098] In the embodiment of the present invention, the first communication data sent by the first process may include a callback function, and the callback function is used to notify the first process that the sending is complete. The writing thread completes the sending of the data and finally calls the callback function to notify the first process that the sending is complete.

[0099] The callback function is a function body implemented by the first process. The embodiment of the present invention does not make specific requirements and restrictions on its implementation method, and only focuses on the role of implementing the callback function: after the data is sent, it is called by the client component to notify the first process whether the data is correctly sent to the second process.

[0100] In the embodiment of the present invention, if the first process does not care whether the communication data has been sent completely, then the callback function may not be set.

[0101] In an embodiment of the present invention, the method further comprises the following steps:

[0102] S201, a client reading thread of a client component receives second communication data sent by a second process based on a second communication channel, where the second communication data is sent by the second process through a server writing thread of a server component.

[0103] S202: The client read thread saves the second communication data to a data queue.

[0104] S203: The client reading thread releases the second communication channel.

[0105] S204: The first process reads the second communication data from the data queue.

[0106] In the embodiment of the present invention, the client component is further provided with a client reading thread, which can receive the second communication data sent by the second process based on the second communication channel. In the embodiment of the present invention, the second communication channel can be the same as the first communication channel or different from the first communication channel.

[0107] In the embodiment of the present invention, before step S201, the method further includes:

[0108] S200: When a client read monitoring thread of a client component monitors second communication data sent by a second process through a second communication channel, the client read monitoring thread distributes the second communication channel to the client read thread.

[0109] In the embodiment of the present invention, a client read monitoring thread is also provided in the client component, and the client read monitoring thread is responsible for monitoring whether each communication channel receives communication data.

[0110] When communication data is sent from the second process through a communication channel, the read listening thread in the client component immediately distributes the communication channel for receiving the data to the thread in the read thread pool. The thread completes the reception of the data, puts it in the data queue, and then releases the communication channel.

[0111] Specifically, in the embodiment of the present invention, the read monitoring thread is responsible for monitoring read fd, which is used for receiving data from the communication channel, and read fd corresponds to the communication channel. When data is sent from the second process, the read monitoring thread immediately distributes readfd to the thread of the read thread pool.

[0112] In an embodiment of the present invention, a read listening thread (read listening thread) is a thread responsible for monitoring data reception. Its task is to monitor multiple file descriptors (fd) so as to process data from other processes (such as the second process) in a timely manner. When the second process sends data to the first process, the data arrives at the corresponding read fd through the communication channel. The read listening thread detects that data has arrived on the read fd and immediately distributes the read fd to a thread in the read thread pool for processing. The threads in the read thread pool receive the distributed read fd and read data from the fd. The read data is placed in a data queue for subsequent processing. Once the data is successfully read and placed in the queue, the thread releases the read fd. This means that the fd can be reused to receive new data.

[0113] In the embodiment of the present invention, after step S203, the method further includes:

[0114] S205, the client read thread writes wake-up data to the listening file descriptor to wake up the client read listening thread;

[0115] S206: The client read monitoring thread updates the communication channel monitoring list and adds the second communication channel to the current communication channel monitoring list.

[0116] In an embodiment of the present invention, a listening text descriptor (for example, trigger fd) is also provided in the listening list of the client read listening thread, and trigger fd is used to trigger the listening thread to update the listening list immediately. In an embodiment of the present invention, after processing the data, the client read thread releases the communication channel and writes a data to the trigger fd. This operation is used to notify the read listening thread that it needs to update its listening list. This mechanism allows the listening thread to quickly respond to changes in the fd state, ensuring that no opportunity to receive data is missed.

[0117] In an embodiment of the present invention, the receiver of the communication task uses IO multiplexing technology, and the read listening thread monitors all communication channels, transfers the readable channels to the read thread pool for processing, and the thread pool reads the data. After the read thread reads the data, the communication channel is released and returned to the read listening thread.

[0118] In the embodiment of the present invention, considering that the returned communication channel cannot usually be captured by the listening thread immediately, the conventional solution is that the listening thread periodically updates the listening list, but whether this cycle is set to be long or short, there are problems. If the cycle is too long, it will cause a large data reception delay, and if the cycle is too short, the thread polling listening list frequency is too high, wasting CPU resources. The embodiment of the present invention proposes a new and efficient method, which adds an additional fd (file descriptor) to the listening list of the read listening thread. When the reading thread pool returns the communication channel, a data is written into the fd at the same time. At this time, the operating system immediately wakes up the reading listening thread, so that the reading listening thread can immediately capture the communication channel.

[0119] Therefore, the technical solution provided by the embodiment of the present invention improves the response speed of the system and reduces resource consumption.

[0120] Through the above description, it can be seen that in the embodiment of the present invention, a multi-channel multiplexing method is used. When each communication task ends, the communication channel will be quickly released and then used by the next communication task, thereby improving efficiency, reducing resource occupation, and enhancing concurrency. In addition, the use of trigger fd avoids the delay caused by the regular update of the monitoring list and improves the response speed of the system. The use of the globally unique communication task ID separates the sending and receiving tasks, and the fixed mode of request-response becomes request, request, response, response, or only request, only response mode, that is, the response can be received at any time, meeting the communication requirements of full-duplex.

[0121] In the embodiment of the present invention, the content of the communication message body is not limited, and it can be binary data or data of the http protocol, and the communication protocol can be customized according to the usage scenario.

[0122] In the embodiment of the present invention, the client component and the server component can provide standardized and limited calling methods, which greatly simplifies the workload of application development and can be flexibly applied to all scenarios of communication between two processes, with a wide range of applications.

[0123] In summary, the embodiments of the present invention can greatly reduce the workload of application development, reduce the complexity of software, and have flexible use and reliable performance.

[0124] In the embodiment of the present invention, for the receiver of the communication task, when sending a response message, the server component can select a writable channel from all communication channels, attach the unique ID of the initiator of the communication task to the message, and write it into the channel. The sender of the communication task reads the response message in a similar manner to the receiver receiving the message.

[0125] Correspondingly, in an embodiment of the present invention, a method for inter-process communication is also provided, the method comprising:

[0126] S301: The second process sends second communication data to the server component.

[0127] S302, the server write thread of the server component receives second communication data sent by the second process;

[0128] S303: The server write thread sends the second communication data to the first process based on the third communication channel in the communication channel queue.

[0129] S304: The server write thread releases the third communication channel.

[0130] In an embodiment of the present invention, the method further includes:

[0131] The server reading thread of the server component receives first communication data sent by the first process based on the fourth communication channel, where the first communication data is sent by the first process through the client writing thread of the client component;

[0132] The server read thread saves the first communication data to a data queue;

[0133] The server read thread releases the fourth communication channel;

[0134] The second process reads the first communication data from the data queue.

[0135] In the embodiment of the present invention, before the server reading thread receives the first communication data sent by the first process based on the fourth communication channel, the method further includes:

[0136] When the server read listening thread of the server component monitors the first communication data sent by the first process through the first communication channel, the server read listening thread distributes the first communication channel to the server read thread.

[0137] In the embodiment of the present invention, after the server read thread releases the fourth communication channel, the method further includes:

[0138] The server read thread writes wake-up data into the listening file descriptor to wake up the server read listening thread;

[0139] The server read monitoring thread updates the communication channel monitoring list and adds the fourth communication channel to the current communication channel monitoring list.

[0140] The first process and the second process are a client-server communication architecture, the first process is configured with a client component, and the second process is configured with a server component.

[0141] The aforementioned embodiment describes the communication process from the client to the server. The embodiment of the present invention provides a full-duplex communication architecture. The communication process from the server to the client is similar to the former, and the embodiment of the present invention will not be repeated here.

[0142] In summary, the efficient, flexible and easy-to-implement multi-channel inter-process communication method provided by the present invention is based on client and server components, which solves the problems of poor usability and complex implementation of the current inter-process communication method, and achieves the technical effects of reducing coding complexity, improving communication efficiency, optimizing resource utilization and enhancing concurrent processing capabilities.

[0143] For ease of understanding, the following combination Figure 2 The inter-process communication method provided by the embodiment of the present invention is further explained:

[0144] exist Figure 2 In the example, process A is configured with a client component, and process B is configured with a server component. Specifically, the application layer of process A puts data into the data queue through the send operation. The data in the data queue is taken out by the thread in the thread pool and is ready to be sent. The thread can request a file descriptor (fd) from the write fd queue for the write operation. After the write operation is completed, the data is sent. After the send operation is completed, the thread will notify the application layer to wait done through the callback function, release the used fd, and put the requested fd into the write fd queue. The read listener thread is responsible for listening to the read fd queue and preparing to receive data from process B. When process B sends data, the read listener thread in the client component immediately distributes the corresponding read fd to the thread in the read thread pool. The thread completes the data reception, puts it into the data queue, then releases the read fd, and writes a data to the triggerfd. In this way, the listener list of the read listener thread can be quickly updated. The application layer takes data out of the data queue through the read operation. For process B, its data sending and receiving process is similar to that of process A, which will not be repeated here.

[0145] In an embodiment of the present invention, the communication data between two processes is carried out through multiple communication channels. These channels allow data to flow between the client and server components of the two processes. The client component and the server component have their own thread pools to handle the sending and receiving of data, and read listening threads to listen and receive data. Data is transmitted in the communication channel through a file descriptor (fd), and the threads in the thread pool are responsible for obtaining data from the application layer, sending it through fd, and receiving data from the other process and putting it into a data queue for the application layer to read. This communication system allows efficient data exchange between two processes.

[0146] Based on the same inventive concept, an embodiment of the present invention further provides an inter-process communication system, the inter-process communication system comprising:

[0147] A first process is used to send first communication data to a client component; the client component includes a client write thread;

[0148] The client writing thread is used to receive first communication data sent by the first process; send the communication data to the second process based on the first communication channel in the communication channel queue; and release the first communication channel;

[0149] A second process is used to send second communication data to a server component; the server component includes a server write thread;

[0150] The server write thread is used to receive the second communication data sent by the second process; based on the third communication channel in the communication channel queue, send the second communication data to the first process; release the third communication channel;

[0151] The first process and the second process are a client-server communication architecture, the first process is configured with a client component, and the second process is configured with a server component.

[0152] Optionally, the client component further includes a client reading thread;

[0153] The client read thread is used to receive the second communication data sent by the second process based on the second communication channel; save the second communication data to the data queue; release the second communication channel; the second communication data is sent by the second process through the server write thread of the server component;

[0154] The first process is further used to read the second communication data from the data queue.

[0155] Optionally, the client component also includes a client read listening thread:

[0156] The client read monitoring thread is used to distribute the second communication channel to the client read thread when monitoring the second communication data sent by the second process through the second communication channel.

[0157] Optionally, the client read thread is further used to write wake-up data into the listening file descriptor to wake up the client read listening thread;

[0158] The client read monitoring thread is further used to update the communication channel monitoring list and add the second communication channel to the current communication channel monitoring list.

[0159] Based on the same inventive concept, an embodiment of the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes, the steps in the inter-process communication method described in any of the above embodiments are implemented.

[0160] Based on the same inventive concept, an embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps of the inter-process communication method described in any of the above embodiments are implemented.

[0161] Based on the same inventive concept, an embodiment of the present invention provides a computer program product, including a computer program / instruction, which implements the steps of the inter-process communication method described in any of the above embodiments when executed by a processor.

[0162] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0163] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0164] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (apparatus), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0165] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0166] These computer program instructions can also be loaded onto a computer or other programmable terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0167] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0168] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0169] The above is a detailed introduction to an inter-process communication method provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. An inter-process communication method, characterized in that: The method comprises: The first process sends first communication data to the client component; The client writing thread of the client component receives the first communication data sent by the first process; The client writing thread sends the communication data to the second process based on the first communication channel in the communication channel queue; The client writing thread releases the first communication channel; The first process and the second process are a client-server communication architecture, the first process is configured with a client component, and the second process is configured with a server component.

2. The inter-process communication method according to claim 1, characterized in that: The method further comprises: The client reading thread of the client component receives second communication data sent by the second process based on the second communication channel, where the second communication data is sent by the second process through the server writing thread of the server component; The client reading thread saves the second communication data to a data queue; The client reading thread releases the second communication channel; The first process reads the second communication data from the data queue.

3. The inter-process communication method according to claim 2, characterized in that: Before the client reading thread receives the second communication data sent by the second process based on the second communication channel, the method further includes: When the client read monitoring thread of the client component monitors the second communication data sent by the second process through the second communication channel, the second communication channel is distributed to the client read thread.

4. The inter-process communication method according to claim 3, characterized in that: After the client read thread releases the second communication channel, the method further includes: The client read thread writes wake-up data into the listening file descriptor to wake up the client read listening thread; The client read monitoring thread updates the communication channel monitoring list and adds the second communication channel to the current communication channel monitoring list.

5. The inter-process communication method according to any one of claims 1 to 4, characterized in that: The method further comprises: Sending connection request information to the server component through the client component; The server component receives the connection request information, and based on the connection request information, establishes a plurality of communication channels between the server component and the client component.

6. An inter-process communication method, characterized in that: The method comprises: The second process sends second communication data to the server component; The server write thread of the server component receives the second communication data sent by the second process; The server writing thread sends the second communication data to the first process based on the third communication channel in the communication channel queue; The server write thread releases the third communication channel; The first process and the second process are a client-server communication architecture, the first process is configured with a client component, and the second process is configured with a server component.

7. An inter-process communication system, characterized in that: The inter-process communication system comprises: A first process is used to send first communication data to a client component; the client component includes a client write thread; The client writing thread is used to receive first communication data sent by the first process; send the communication data to the second process based on the first communication channel in the communication channel queue; and release the first communication channel; A second process is used to send second communication data to a server component; the server component includes a server write thread; The server write thread is used to receive the second communication data sent by the second process; based on the third communication channel in the communication channel queue, send the second communication data to the first process; release the third communication channel; The first process and the second process are a client-server communication architecture, the first process is configured with a client component, and the second process is configured with a server component.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the inter-process communication method according to any one of claims 1 to 5 or the inter-process communication method according to claim 6 is implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the inter-process communication method according to any one of claims 1 to 5 or the inter-process communication method according to claim 6 is implemented.

10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the steps in the inter-process communication method according to any one of claims 1 to 5 or the inter-process communication method according to claim 6 are implemented.