[go: up one dir, main page]

CN100403739C - Interprocess Message Passing Method Based on Linked List - Google Patents

Interprocess Message Passing Method Based on Linked List Download PDF

Info

Publication number
CN100403739C
CN100403739C CNB2006100074871A CN200610007487A CN100403739C CN 100403739 C CN100403739 C CN 100403739C CN B2006100074871 A CNB2006100074871 A CN B2006100074871A CN 200610007487 A CN200610007487 A CN 200610007487A CN 100403739 C CN100403739 C CN 100403739C
Authority
CN
China
Prior art keywords
message
linked list
shared memory
processing
queue
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CNB2006100074871A
Other languages
Chinese (zh)
Other versions
CN1859325A (en
Inventor
孟庆光
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CNB2006100074871A priority Critical patent/CN100403739C/en
Publication of CN1859325A publication Critical patent/CN1859325A/en
Application granted granted Critical
Publication of CN100403739C publication Critical patent/CN100403739C/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Computer And Data Communications (AREA)

Abstract

本发明公开了一种基于链表的进程间消息传递方法,包括:主控进程创建消息队列,该消息队列包括已分配节点队列和空闲节点队列;第一处理进程接收来自外部的消息,从空闲节点消息队列中申请空闲节点,并将消息字段首尾链接成共享内存链表,然后发送该链表的头指针到第二处理进程;当收到第一处理进程传递的共享内存链表头指针后,第二处理进程将第一处理进程传递的指针转换为本进程地址空间内的内存地址。第二处理进程访问该内存地址中的共享内存链表,在完成处理后将结果更新到该链表中,然后将该链表的头指针发送到后续处理进程。采用基于共享内存指针的消息传递技术和共享内存链表的数据结构,有效提高了在流式服务处理框架下消息的传递效率。

The invention discloses an inter-process message transfer method based on a linked list, comprising: a main control process creates a message queue, and the message queue includes an allocated node queue and an idle node queue; Apply for an idle node in the message queue, and link the beginning and end of the message fields into a shared memory linked list, and then send the head pointer of the linked list to the second processing process; after receiving the shared memory linked list head pointer passed by the first processing process, the second processing The process converts the pointer passed by the first processing process into a memory address in the address space of the process. The second processing process accesses the shared memory linked list in the memory address, updates the result to the linked list after processing, and then sends the head pointer of the linked list to the subsequent processing process. The message delivery technology based on the shared memory pointer and the data structure of the shared memory linked list are adopted to effectively improve the efficiency of message delivery under the streaming service processing framework.

Description

基于链表的进程间消息传递方法 Interprocess Message Passing Method Based on Linked List

技术领域 technical field

本发明涉及进程间消息传递方法,尤其涉及一种基于链表的进程间消息传递方法。The invention relates to an inter-process message transmission method, in particular to an inter-process message transmission method based on a linked list.

背景技术 Background technique

在现有技术中,服务框架由服务组件和消息事件组成。其中,服务组件可以为独立的进程或者线程,每个服务组件通常包含一个输入消息队列和一个输出消息队列,并且每个服务组件知道其下一个服务名称,由此形成一个逻辑上首尾相接的服务链表。消息事件在流经每个服务组件后,会产生新的消息事件输入下个衔接的服务组件。In the prior art, the service framework is composed of service components and message events. Among them, the service components can be independent processes or threads, each service component usually includes an input message queue and an output message queue, and each service component knows its next service name, thus forming a logical end-to-end service list. After the message event flows through each service component, a new message event will be generated and input to the next connected service component.

“消息”是在计算机间传送的数据单位。消息可以非常简单,例如只包含文本字符串;也可以更复杂,可能包含嵌入对象。消息被发送到队列中。“消息队列”是在消息的传输过程中保存消息的容器。消息队列管理器在将消息从它的源中继到它的目标时充当中间人。队列的主要目的是提供路由并保证消息的传递;消息队列会保留消息,直到可以成功地传递它。A "message" is a unit of data transferred between computers. Messages can be as simple as just text strings, or more complex and may contain embedded objects. Messages are sent to the queue. A "message queue" is a container that holds messages during their transmission. A message queue manager acts as a middleman in relaying a message from its source to its destination. The main purpose of a queue is to provide routing and guarantee delivery of messages; a message queue holds a message until it can be delivered successfully.

在使用套接字SOCKET、管道(FIFO)等进程间通信(Inter-ProcessCommunication,IPC)机制传递消息时,消息需要在多个进程间传递,通常,每个处理进程都要完成下面的处理环节:从接收缓冲区中读取接收的消息,并解码成为内部数据结构;完成处理过程,保存处理结果;把处理后的结果编码成为消息流,写入发送缓冲区发送到对端进程。例如图1所示,处理进程1从接收缓冲区中拷贝消息数据,然后需要对消息数据进行解码,对解码后的数据进行相应的处理后,再对经过处理后的消息数据进行编码,并且拷贝到发送缓冲区,以便下一个进程(即处理进程2)能够接收消息数据。处理进程2、处理进程3都重复类似的步骤来对消息数据进行处理。When using Inter-Process Communication (IPC) mechanisms such as socket sockets and pipes (FIFO) to transmit messages, messages need to be transmitted between multiple processes. Usually, each processing process must complete the following processing steps: Read the received message from the receiving buffer and decode it into an internal data structure; complete the processing process and save the processing result; encode the processed result into a message stream, write it into the sending buffer and send it to the peer process. For example, as shown in Figure 1, the processing process 1 copies the message data from the receiving buffer, and then needs to decode the message data, perform corresponding processing on the decoded data, encode the processed message data, and copy to the send buffer so that the next process (i.e. process 2) can receive the message data. Both the processing process 2 and the processing process 3 repeat similar steps to process the message data.

在上述传统进程间消息传递机制中,消息在不同进程间传递时都要在缓冲区和内存之间被拷贝,并且消息事件字段的编码、解码,在消息并发数量和消息事件承载数据量较少的情况下,上述操作不会造成性能上的瓶颈,但是在消息并发数量较多或者消息事件承载数据量较多的应用中(如实时计费系统),上述操作频繁发生,会造成系统性能严重下降。In the above-mentioned traditional inter-process message passing mechanism, messages are copied between the buffer and the memory when they are passed between different processes, and the encoding and decoding of the message event fields are relatively small in terms of the number of concurrent messages and the amount of data carried by message events. Under certain circumstances, the above operations will not cause performance bottlenecks, but in applications with a large number of concurrent messages or a large amount of data carried by message events (such as a real-time billing system), the above operations occur frequently, which will cause serious system performance. decline.

根据上述描述,可以得出现有技术的技术方案存在下列缺点:消息在接收缓冲区、发送缓冲区以及内存之间多次拷贝,在大数据量的情况下数据传输效率低;每次消息传递都要完成编码或者解码的过程,消耗系统CPU资源;According to the above description, it can be concluded that the technical solution of the prior art has the following disadvantages: the message is copied multiple times between the receiving buffer, the sending buffer and the memory, and the data transmission efficiency is low in the case of a large amount of data; To complete the encoding or decoding process, consume system CPU resources;

发明内容 Contents of the invention

本发明解决的问题是现有技术中,进程间对消息传递的处理消耗了大量资源,导致系统性能下降的情况。本发明提供了一种能够提高消息传输效率的基于链表的进程间消息传递方法。The problem solved by the present invention is that in the prior art, the processing of message transfer between processes consumes a large amount of resources, resulting in a decrease in system performance. The invention provides a link list-based inter-process message transmission method capable of improving message transmission efficiency.

本发明提供的基于链表的进程间消息传递方法包括:The interprocess message transfer method based on linked list provided by the present invention includes:

a)主控进程创建共享内存区,所述共享内存区用于存放进程间通信的消息数据;a) The master control process creates a shared memory area, and the shared memory area is used to store message data for inter-process communication;

主控进程创建消息队列,所述消息队列包括已分配节点队列和空闲节点队列;The main control process creates a message queue, and the message queue includes an allocated node queue and an idle node queue;

b)第一处理进程接收来自外部的消息,从消息队列中申请空闲节点,并将消息字段首尾链接成共享内存链表,然后发送该链表的头指针到第二处理进程;b) The first processing process receives an external message, applies for an idle node from the message queue, and links the message fields head to tail to form a shared memory linked list, and then sends the head pointer of the linked list to the second processing process;

c)当收到第一处理进程传递的共享内存链表头指针后,第二处理进程将第一处理进程传递的指针转换为地址空间内的内存地址;c) After receiving the head pointer of the shared memory linked list delivered by the first processing process, the second processing process converts the pointer delivered by the first processing process into a memory address in the address space;

d)第二处理进程访问所述内存地址中的共享内存链表,在完成处理后将结果更新到该链表中,然后将该链表的头指针发送到后续处理进程。d) The second processing process accesses the shared memory linked list in the memory address, updates the result to the linked list after processing, and then sends the head pointer of the linked list to the subsequent processing process.

根据上述进程间消息传递方法,所述共享内存区为消息的每个字段分配预定长度的内存块,According to the above inter-process message passing method, the shared memory area allocates a memory block of predetermined length for each field of the message,

根据上述进程间消息传递方法,有多个处理进程对外部的消息进行处理。According to the above inter-process message transfer method, there are multiple processing processes for processing external messages.

根据上述进程间消息传递方法,所述处理进程中的最后一个处理进程将处理完的消息节点被释放到空闲节点队列中去。According to the above inter-process message transfer method, the last processing process in the processing processes releases the processed message node to the idle node queue.

根据上述进程间消息传递方法,节点包括:消息队列大小、消息队列空闲节点链表头指针和消息队列已分配节点链表头指针。According to the above inter-process message transfer method, the nodes include: the size of the message queue, the head pointer of the linked list of idle nodes of the message queue and the head pointer of the linked list of allocated nodes of the message queue.

根据上述进程间消息传递方法,在处理进程间采用先入先出FIFO机制发送共享内存链表的头指针。According to the above inter-process message transfer method, the first-in-first-out FIFO mechanism is used to send the head pointer of the shared memory linked list between processing processes.

根据上述进程间消息传递方法,消息队列节点数据包括:共享内存链表的头指针、共享内存链表的尾指针和消息数据字段个数的至少一个。According to the above inter-process message transfer method, the message queue node data includes: at least one of the head pointer of the shared memory linked list, the tail pointer of the shared memory linked list and the number of message data fields.

特别地,本发明还提供了一种基于链表的计费系统进程间消息传递方法,包括:In particular, the present invention also provides a method for passing messages between processes in a billing system based on a linked list, including:

a)主控进程创建共享内存区,所述共享内存区用于存放进程间通信的消息数据;主控进程创建消息队列,所述消息队列包括已分配节点队列和空闲节点队列;A) the master control process creates a shared memory area, and the shared memory area is used to store message data for inter-process communication; the master control process creates a message queue, and the message queue includes an allocated node queue and an idle node queue;

b)鉴权进程接收来自外部进程的消息,并且从消息队列中申请空闲节点,并将消息字段首尾链接成共享内存链表,然后发送该链表的头指针到计费进程;b) The authentication process receives a message from an external process, and applies for an idle node from the message queue, and links the message fields head to tail into a shared memory linked list, and then sends the head pointer of the linked list to the billing process;

c)当收到鉴权进程传递的共享内存链表头指针后,计费进程将鉴权进程传递的指针转换为地址空间内的内存地址;c) After receiving the shared memory linked list head pointer passed by the authentication process, the billing process converts the pointer passed by the authentication process into a memory address in the address space;

d)计费进程访问所述内存地址中的共享内存链表,在完成处理后把处理后的结果更新到该链表中,然后发送该链表的头指针到记账进程;d) The billing process accesses the shared memory linked list in the memory address, updates the processed result to the linked list after completing the processing, and then sends the head pointer of the linked list to the accounting process;

e)记账进程指针转换为地址空间内的内存地址,访问所述内存地址中的共享内存链表。e) The bookkeeping process pointer is converted into a memory address in the address space, and the shared memory linked list in the memory address is accessed.

由于本发明采用基于共享内存的消息传递技术和共享内存链表的数据结构,有效地提高了在流式服务处理框架下消息的传递效率。Since the present invention adopts the message transmission technology based on the shared memory and the data structure of the shared memory linked list, the efficiency of message transmission under the streaming service processing framework is effectively improved.

在本发明中,由于传递的数据只是链表的指针,因此减轻了进程间数据传输的负荷,提高了传输效率。并且由于链表本身具有插入、删除节点速度较快且灵活的特性,以及采用动态内存链表作为消息的数据结构,因此能够解决因消息字段数据动态更改引起的性能问题。使用链表结构可以充分利用计算机内存空间,实现灵活的内存动态管理。In the present invention, since the transmitted data is only the pointer of the linked list, the load of inter-process data transmission is reduced and the transmission efficiency is improved. And because the linked list itself has the characteristics of fast and flexible insertion and deletion of nodes, and uses a dynamic memory linked list as the data structure of the message, it can solve the performance problem caused by the dynamic change of the message field data. Using the linked list structure can make full use of the computer memory space and realize flexible memory dynamic management.

附图说明 Description of drawings

图1是现有技术中IPC机制消息传递示意图;FIG. 1 is a schematic diagram of IPC mechanism message delivery in the prior art;

图2是本发明实例原型系统示意图;Fig. 2 is the schematic diagram of the example prototype system of the present invention;

图3是本发明实例的基于链表的进程间消息传递方法的流程图;Fig. 3 is the flow chart of the interprocess message transmission method based on linked list of the example of the present invention;

图4是本发明实例采用的内存池机制示意图;Fig. 4 is a schematic diagram of a memory pool mechanism adopted by an example of the present invention;

图5是根据本发明实例的计费系统处理框架示意图;Fig. 5 is a schematic diagram of a billing system processing framework according to an example of the present invention;

图6是本发明实例在计费系统中的应用示意图;Fig. 6 is a schematic diagram of the application of the example of the present invention in the billing system;

图7是本发明在计费系统中消息传递方法的流程图。Fig. 7 is a flow chart of the message delivery method in the billing system of the present invention.

具体实施方式 Detailed ways

图2是本发明原型系统示意图。如图所示,所述原型系统包括主控进程、处理进程和外部进程。其中,主控进程负责创建消息队列,同时主控进程还对各处理进程进行控制。Fig. 2 is a schematic diagram of the prototype system of the present invention. As shown in the figure, the prototype system includes a main control process, a processing process and an external process. Wherein, the main control process is responsible for creating the message queue, and at the same time, the main control process also controls each processing process.

外部进程将消息事件输入到处理进程中,并由主控进程和处理进程在共享内存中维护该消息队列的数据结构。所述消息队列的数据结构包括:消息队列大小、消息队列空闲节点链表头指针、消息队列已分配节点链表头指针。The external process inputs the message event into the processing process, and the data structure of the message queue is maintained in the shared memory by the main control process and the processing process. The data structure of the message queue includes: the size of the message queue, the head pointer of the idle node list of the message queue, and the head pointer of the allocated node list of the message queue.

在本实施例中,为了方便描述,只涉及三个处理进程:进程1、进程2和进程3。这三个处理进程可以进行相应的消息处理,关于消息处理的具体过程根据不同的应用有所不同。例如,三个消息处理进程可以是通信计费系统中的“识别鉴权”、“计费”、“记账”等等处理进程。从外部进程输入的消息在三个处理进程之间“流转”并得到处理。在实际应用中,系统可以包括更多的处理进程。In this embodiment, for convenience of description, only three processing processes are involved: process 1 , process 2 and process 3 . These three processing processes can perform corresponding message processing, and the specific process of message processing is different according to different applications. For example, the three message processing processes may be processing processes such as "identification and authentication", "billing", and "accounting" in the communication billing system. Incoming messages from external processes "flow" among the three processing processes and are processed. In practical applications, the system may include more processing processes.

图3是本发明实施例的基于共享内存链表的进程间消息传递方法的流程图。在步骤301,主控进程创建一个共享内存区。系统启动时,首先由主控进程创建一个全局的共享内存区,共享内存的大小根据系统的处理能力计算获得,也可以通过动态增加的方法进行调整。FIG. 3 is a flowchart of a method for passing messages between processes based on a shared memory linked list according to an embodiment of the present invention. In step 301, the master control process creates a shared memory area. When the system is started, a global shared memory area is firstly created by the main control process. The size of the shared memory is calculated according to the processing capability of the system, and can also be adjusted through a dynamic increase method.

为了提高内存的分配效率,本系统采用了共享内存池机制以实现共享内存的分配和回收管理。如图4所示,共享内存链表是本发明为了解决消息动态更改采用的数据结构。消息数据由若干个字段组成,在共享内存中为每个消息数据的字段分配固定长度的内存块,并把这些字段首尾链接在一起,就形成了共享内存链表,每个已分配节点存放指向共享内存链表的头指针。为了避免在分配较小内存块时造成的内存碎片,本发明采用了内存池技术。在内存池中,具有多个内存块,在各内存块中具有预定长度的存储单元,如16字节的内存块、32字节长度的内存块、4k字节长度的内存块等等。具有不同长度的消息数据的字段分别存储在相应长度的内存块中。In order to improve the efficiency of memory allocation, this system adopts the shared memory pool mechanism to realize the allocation and recovery management of shared memory. As shown in FIG. 4 , the shared memory linked list is a data structure adopted by the present invention to solve the dynamic change of messages. The message data consists of several fields. A fixed-length memory block is allocated for each message data field in the shared memory, and these fields are linked end to end to form a shared memory linked list. Each allocated node stores pointers to the shared The head pointer of the memory linked list. In order to avoid memory fragmentation caused when small memory blocks are allocated, the present invention adopts memory pool technology. In the memory pool, there are multiple memory blocks, and each memory block has a storage unit of a predetermined length, such as a 16-byte memory block, a 32-byte memory block, a 4k-byte memory block, and the like. Fields with message data of different lengths are stored in memory blocks of corresponding lengths respectively.

在步骤302,主控进程创建消息队列。创建消息队列提供了可与各个处理进程交互的资源。消息队列是由多个共享内存链表组成,其中包括已分配节点链表和空闲节点链表。In step 302, the master control process creates a message queue. Creating a message queue provides resources that can interact with individual processing processes. The message queue is composed of multiple shared memory linked lists, including the allocated node linked list and the free node linked list.

在步骤303,处理进程1接收来自外部的消息,并且从所述消息队列中申请空闲节点。进程1通过SOCKET或者FIFO等IPC机制接收来自外部进程传递的消息,并且从消息队列中申请一个空闲节点。消息队列节点数据结构中包括下列信息:共享内存链表的头指针;共享内存链表的尾指针;消息数据字段个数。申请空闲的消息队列节点是为处理后的消息申请内存块。In step 303, processing process 1 receives an external message, and applies for an idle node from the message queue. Process 1 receives messages from external processes through IPC mechanisms such as SOCKET or FIFO, and applies for an idle node from the message queue. The message queue node data structure includes the following information: the head pointer of the shared memory linked list; the tail pointer of the shared memory linked list; the number of message data fields. Applying for an idle message queue node is to apply for a memory block for the processed message.

在步骤304,进程1对从外部进程所接收的消息进行处理。进程1以及后面提到的进程2、进程3是处理进程。对消息的处理过程根据不同的应用有所不同。例如,三个消息处理进程可以是通信计费系统中的“鉴权”、“计费”、“记账”等等处理进程。In step 304, process 1 processes the message received from the external process. Process 1 and process 2 and process 3 mentioned later are processing processes. The processing of the message is different according to different applications. For example, the three message processing processes may be processing processes such as "authentication", "billing", and "accounting" in the communication billing system.

在步骤305,进程1将处理后的消息的字段首尾链接成共享内存链表,然后发送该链表的头指针到处理进程2。再参考图4,字段1、字段2、字段3、字段4是四个经过进程1处理后的字段,其中字段1、字段3、字段4的长度均为32字节,字段2的长度为64字节,因此四个字段分别存储在32字节和64字节长的内存块里。进程1将四个字段首尾链接,形成共享内存链表,然后采用IPC机制(例如,FIFO机制)发送该链表的头指针(即消息队列节点的指针)到进程2。该链表的头指针即进程1所申请的空闲节点的共享内存链表的头指针,由于存放了指向共享内存链表的头指针,该节点成为已分配节点。In step 305, process 1 links the fields of the processed message into a shared memory linked list, and then sends the head pointer of the linked list to processing process 2. Referring to Figure 4 again, field 1, field 2, field 3, and field 4 are four fields processed by process 1, wherein the length of field 1, field 3, and field 4 is 32 bytes, and the length of field 2 is 64 bytes. bytes, so the four fields are stored in 32-byte and 64-byte long memory blocks, respectively. Process 1 links the four fields end to end to form a shared memory linked list, and then uses an IPC mechanism (eg, FIFO mechanism) to send the head pointer of the linked list (ie, the pointer to the message queue node) to process 2. The head pointer of the linked list is the head pointer of the shared memory linked list of the idle node applied for by process 1. Since the head pointer pointing to the shared memory linked list is stored, this node becomes an allocated node.

在步骤306,当收到进程1传递的共享内存链表头指针后,进程2将进程1传递的指针转换为地址空间内的内存地址。进程2将指针数据转换为地址空间内的内存地址。进程2通过访问所述内存地址即可获取存储在相关地址中的消息数据,以便作进一步的处理,这样避免了对消息数据的拷贝,节约了系统资源。In step 306, after receiving the head pointer of the shared memory linked list passed by process 1, process 2 converts the pointer passed by process 1 into a memory address in the address space. Process 2 converts the pointer data to a memory address within the address space. Process 2 can obtain the message data stored in the relevant address by accessing the memory address for further processing, thus avoiding copying of the message data and saving system resources.

在步骤307,处理进程2访问所述内存地址中的共享内存链表,对消息数据进行相应的处理,在完成处理后,将处理后的字段结果更新到该链表中,然后将该链表的头指针发送到处理进程3。In step 307, the processing process 2 accesses the shared memory linked list in the memory address, performs corresponding processing on the message data, and after completing the processing, updates the processed field results into the linked list, and then the head pointer of the linked list Sent to process 3.

在步骤308,进程3通过对链表指针所映射的内存地址的访问来获取共享内存链表。In step 308, process 3 obtains the shared memory linked list by accessing the memory address mapped by the linked list pointer.

在步骤309,进程3将处理完的消息节点释放到空闲节点队列中去。在本实施例中,进程3是最后一个处理进程,在消息数据进行处理完成后,可以将已经申请的消息队列节点释放到空闲节点队列中去。In step 309, process 3 releases the processed message nodes to the idle node queue. In this embodiment, process 3 is the last processing process. After the message data is processed, the message queue nodes that have been applied for can be released to the idle node queue.

计费系统就是本发明一种典型的应用案例,为了使计费系统有较好的处理性能,需要把数据和处理进程绑定在同一个物理主机上进行处理,以方便数据就近读取,提高数据读取效率。The billing system is a typical application case of the present invention. In order to make the billing system have better processing performance, it is necessary to bind the data and the processing process on the same physical host for processing, so as to facilitate the nearby reading of data and improve the performance of the billing system. Data read efficiency.

由于通常计费事件中会包含几十个甚至几百个计费特征字段,在进程间传递这些数据时,如果采用数据拷贝的方法,会导致系统性能的急剧下降。而且计费系统的每个处理进程在处理过程中都需要不断的修改计费事件消息的数据结构并传递给下一个处理进程,例如从原始计费消息中识别出计费特征字段(如主叫位置、被叫位置、亲情号码标志等),因此在计费系统更适合采用本发明的指针直接引用的方法。Since billing events usually contain dozens or even hundreds of billing feature fields, if the data copy method is used to transfer these data between processes, the system performance will drop sharply. Moreover, each processing process of the billing system needs to constantly modify the data structure of the billing event message and pass it to the next processing process during the processing process, such as identifying the billing feature field (such as the calling party) from the original billing message. location, called location, family number sign, etc.), so the method for directly quoting the pointer of the present invention is more suitable for use in the billing system.

在如图5所示的计费系统中,包括了三个处理进程,即鉴权进程、计费进程、记账进程。三个进程都受到动态规则引擎的控制,在本实施例中,动态规则引擎是系统的主控进程。在实际计费系统中,会有多个处理进程进行消息数据处理。为了便于描述,在本实施例中,只对上述鉴权、计费、记账进程进行说明。In the billing system shown in FIG. 5 , three processing processes are included, namely, authentication process, billing process, and accounting process. All three processes are controlled by the dynamic rule engine, and in this embodiment, the dynamic rule engine is the main control process of the system. In the actual billing system, there will be multiple processing processes for message data processing. For ease of description, in this embodiment, only the above authentication, charging, and accounting processes are described.

首先,将标准话单的消息数据输入到鉴权进程,所述标准话单消息数据中包括了话务的类型、主体、对象、通话开始时间、通话位置、业务量等特征字段,鉴权进程在对该消息数据进行处理后,处理后所得的结果,例如,产品ID等特征字段被添加到共享内存链表中,并且将该链表的指针发送到计费进程。计费进程在获取链表指针所映射的内存地址中的内容后,类似地,在对消息数据字段进行进一步处理后,将在该步骤产生的结果(例如,费用项、费用)添加到共享内存链表中,并且将该链表的指针发送到下一个处理进程(即记账进程)进行处理。First, the message data of the standard call list is input into the authentication process. The standard call list message data includes characteristic fields such as the type of traffic, the subject, the object, the call start time, the call location, and the traffic volume. After the message data is processed, the processed results, such as characteristic fields such as product ID, are added to the shared memory linked list, and the pointer of the linked list is sent to the billing process. After the billing process obtains the content in the memory address mapped by the linked list pointer, similarly, after further processing the message data field, the result generated in this step (for example, cost item, cost) is added to the shared memory linked list , and send the pointer of the linked list to the next processing process (that is, the accounting process) for processing.

图7是本发明在计费系统中消息传递方法的流程图。其中:Fig. 7 is a flow chart of the message delivery method in the billing system of the present invention. in:

在步骤701,主控进程创建一个共享内存区。共享内存的大小根据系统的处理能力计算获得,也可以通过动态增加的方法进行调整。In step 701, the master control process creates a shared memory area. The size of the shared memory is calculated according to the processing capability of the system, and can also be adjusted dynamically.

如图6所示,为了避免在分配较小内存块时造成的内存碎片,本发明采用了内存池技术,在内存池中,具有多个内存块,在各内存块中具有预定长度的存储单元,具有不同长度的计费系统的各种消息数据的字段分别存储在相应长度的内存块中。As shown in Figure 6, in order to avoid memory fragmentation caused when allocating smaller memory blocks, the present invention adopts the memory pool technology, in the memory pool, there are a plurality of memory blocks, each memory block has a storage unit of predetermined length , the fields of various message data of the billing system with different lengths are respectively stored in memory blocks of corresponding lengths.

在步骤702,主控进程创建消息队列。创建消息队列提供了可与各个处理进程交互的资源。消息队列是由多个共享内存链表组成,其中包括已分配节点链表和空闲节点链表。In step 702, the master control process creates a message queue. Creating a message queue provides resources that can interact with individual processing processes. The message queue is composed of multiple shared memory linked lists, including the allocated node linked list and the free node linked list.

在步骤703,鉴权进程接收来自外部进程的标准话单消息数据,并且从所述消息队列中申请空闲节点。所述标准话单消息数据中包括了话务的类型、主体、对象、通话开始时间、通话位置、业务量等特征字段。鉴权进程通过SOCKET或者FIFO等IPC机制接收来自外部进程传递的标准话单消息,从消息队列中申请一个空闲节点,消息队列节点数据结构中通常包括下列信息:共享内存链表的头指针;共享内存链表的尾指针;消息数据字段个数。申请空闲的消息队列节点是为处理后的消息申请内存块。In step 703, the authentication process receives the standard bill message data from the external process, and applies for an idle node from the message queue. The standard bill message data includes characteristic fields such as the type of traffic, subject, object, call start time, call location, and traffic volume. The authentication process receives the standard bill message from the external process through the IPC mechanism such as SOCKET or FIFO, and applies for an idle node from the message queue. The data structure of the message queue node usually includes the following information: the head pointer of the shared memory linked list; The tail pointer of the linked list; the number of message data fields. Applying for an idle message queue node is to apply for a memory block for the processed message.

在步骤704,鉴权进程对从外部进程所接收的消息进行处理。鉴权进程对所输入的标准话单的消息数据进行识别鉴权处理,处理后生成了新的特征字段(如产品ID)。In step 704, the authentication process processes the message received from the external process. The authentication process performs identification and authentication processing on the message data of the input standard bill, and a new characteristic field (such as product ID) is generated after processing.

在步骤705,鉴权进程将处理后的消息字段(包括处理后产生的特征字段以及原先输入的标准话单消息字段)首尾链接成共享内存链表,然后发送该链表的头指针到计费进程。鉴权进程采用IPC机制(例如,FIFO机制)将该链表的头指针(即消息队列节点的指针)发送到计费进程。该链表的头指针即鉴权进程所申请的空闲节点的共享内存链表的头指针,由于存放了指向共享内存链表的头指针,该节点成为已分配节点。In step 705, the authentication process links the processed message fields (including the processed feature fields and the original input standard bill message fields) end-to-end into a shared memory linked list, and then sends the head pointer of the linked list to the billing process. The authentication process uses the IPC mechanism (eg, FIFO mechanism) to send the head pointer of the linked list (ie, the pointer of the message queue node) to the accounting process. The head pointer of the linked list is the head pointer of the shared memory linked list of the idle node applied for by the authentication process. Since the head pointer pointing to the shared memory linked list is stored, the node becomes an allocated node.

在步骤706,当收到鉴权进程传递的共享内存链表头指针后,计费进程将鉴权进程传递的指针转换为地址空间内的内存地址。计费进程将指针数据转换为地址空间内的内存地址,使得计费进程可以通过访问所述内存地址获取存储在相关地址中的标准话单消息数据以及鉴权进程处理后生成的字段,以便作进一步的处理,这样避免了对消息数据的拷贝,节约了系统资源。In step 706, after receiving the head pointer of the shared memory linked list passed by the authentication process, the accounting process converts the pointer passed by the authentication process into a memory address in the address space. The billing process converts the pointer data into a memory address in the address space, so that the billing process can obtain the standard bill message data stored in the relevant address and the fields generated by the authentication process by accessing the memory address, so as to make Further processing avoids copying of message data and saves system resources.

在步骤707,计费进程访问所述内存地址中的共享内存链表,对消息数据进行相应的处理,在完成处理后,将处理后生成的字段结果(例如费用项、费用等字段)以及原先从鉴权进程输入的消息数据字段更新到该链表中,然后将该链表的头指针发送到记账进程。In step 707, the billing process accesses the shared memory linked list in the memory address, and processes the message data accordingly. The message data field input by the authentication process is updated into the linked list, and then the head pointer of the linked list is sent to the accounting process.

在步骤708,记账进程通过对链表指针所映射的内存地址的访问来获取共享内存链表,并且进行相应处理,生成例如账目、金额、累计项、累计值等字段。通过相关的输出进程将处理结果输出。In step 708, the accounting process obtains the shared memory linked list by accessing the memory address mapped by the linked list pointer, and performs corresponding processing to generate fields such as account, amount, accumulated item, accumulated value, and the like. The resulting output will be processed through the associated output process.

在步骤709,在完成处理后,记账进程将处理完的消息节点释放到空闲节点队列中去。作为最后一个处理进程,记账进程在处理完成后需要释放已经申请的消息队列节点到空闲节点队列中去可以进一步系统的利用效率。In step 709, after the processing is completed, the accounting process releases the processed message nodes to the idle node queue. As the last processing process, the accounting process needs to release the applied message queue node to the idle node queue after the processing is completed to further improve the utilization efficiency of the system.

虽然本发明公开了上述实施例,但具体实施例并不是用来限定本发明的,任何本领域技术人员,在不脱离本发明的精神和范围内,可以作出一些修改和润饰,因此本发明的保护范围应当以所附的权利要求书界定的范围为准。Although the present invention discloses the above-mentioned embodiments, the specific embodiments are not used to limit the present invention, and any skilled person can make some modifications and modifications without departing from the spirit and scope of the present invention, so the present invention The scope of protection should be determined by the scope defined in the appended claims.

Claims (13)

1.一种基于链表的进程间消息传递方法,其特征在于,包括:1. A linked list-based interprocess message delivery method, characterized in that, comprising: a)主控进程创建共享内存区,所述共享内存区用于存放进程间通信的消息数据;a) The master control process creates a shared memory area, and the shared memory area is used to store message data for inter-process communication; 主控进程创建消息队列,所述消息队列包括已分配节点队列和空闲节点队列;The main control process creates a message queue, and the message queue includes an allocated node queue and an idle node queue; b)第一处理进程接收来自外部的消息,从消息队列中申请空闲节点,并将消息字段首尾链接成共享内存链表,然后发送该链表的头指针到第二处理进程;b) The first processing process receives an external message, applies for an idle node from the message queue, and links the message fields head to tail to form a shared memory linked list, and then sends the head pointer of the linked list to the second processing process; c)当收到第一处理进程传递的共享内存链表头指针后,第二处理进程将第一处理进程传递的指针转换为地址空间内的内存地址;c) After receiving the head pointer of the shared memory linked list delivered by the first processing process, the second processing process converts the pointer delivered by the first processing process into a memory address in the address space; d)第二处理进程访问所述内存地址中的共享内存链表,在完成处理后将结果更新到该链表中,然后将该链表的头指针发送到后续处理进程。d) The second processing process accesses the shared memory linked list in the memory address, updates the result to the linked list after processing, and then sends the head pointer of the linked list to the subsequent processing process. 2.根据权利要求1所述的进程间消息传递方法,其特征在于,所述共享内存区为消息的每个字段分配预定长度的内存块。2. The inter-process message transfer method according to claim 1, wherein the shared memory area allocates a memory block of a predetermined length for each field of the message. 3.根据权利要求1所述的进程间消息传递方法,其特征在于,有多个处理进程对外部的消息进行处理。3. The inter-process message transfer method according to claim 1, characterized in that there are multiple processing processes for processing external messages. 4.根据权利要求1所述的进程间消息传递方法,其特征在于,所述处理进程中的最后一个处理进程将处理完的消息节点释放到空闲节点队列中。4. The inter-process message transfer method according to claim 1, wherein the last processing process in the processing processes releases the processed message node into the idle node queue. 5.根据权利要求1所述的进程间消息传递方法,其特征在于,节点包括:消息队列大小、消息队列空闲节点链表头指针和消息队列已分配节点链表头指针。5 . The inter-process message transfer method according to claim 1 , wherein the nodes include: the size of the message queue, the head pointer of the linked list of idle nodes of the message queue, and the head pointer of the linked list of assigned nodes of the message queue. 6.根据权利要求1所述的进程间消息传递方法,其特征在于,在处理进程间采用先入先出FIFO或者其他进程间通信IPC机制发送共享内存链表的头指针。6. The inter-process message transfer method according to claim 1, characterized in that FIFO or other inter-process communication IPC mechanisms are used between processing processes to send the head pointer of the shared memory linked list. 7.根据权利要求1所述的进程间消息传递方法,其特征在于,消息队列节点数据包括:共享内存链表的头指针、共享内存链表的尾指针和消息数据字段个数中的至少一个。7. The inter-process message transfer method according to claim 1, wherein the message queue node data comprises: at least one of a head pointer of a shared memory linked list, a tail pointer of a shared memory linked list, and the number of message data fields. 8.一种基于链表的计费系统进程间消息传递方法,其特征在于,包括:8. A linked list-based billing system inter-process message delivery method, characterized in that it comprises: a)主控进程创建共享内存区,所述共享内存区用于存放进程间通信的消息数据;a) The master control process creates a shared memory area, and the shared memory area is used to store message data for inter-process communication; 主控进程创建消息队列,所述消息队列包括已分配节点队列和空闲节点队列;The main control process creates a message queue, and the message queue includes an allocated node queue and an idle node queue; b)鉴权进程接收来自外部进程的消息,并且从消息队列中申请空闲节点,并将消息字段首尾链接成共享内存链表,然后发送该链表的头指针到计费进程;b) The authentication process receives a message from an external process, and applies for an idle node from the message queue, and links the message fields head to tail into a shared memory linked list, and then sends the head pointer of the linked list to the billing process; c)当收到鉴权进程传递的共享内存链表头指针后,计费进程将鉴权进程传递的指针转换为本进程地址空间内的内存地址;c) After receiving the shared memory linked list head pointer passed by the authentication process, the billing process converts the pointer passed by the authentication process into a memory address in the address space of the process; d)计费进程访问所述内存地址中的共享内存链表,在完成处理后把处理后的结果更新到该链表中,然后发送该链表的头指针到记账进程;d) The billing process accesses the shared memory linked list in the memory address, updates the processed result to the linked list after completing the processing, and then sends the head pointer of the linked list to the accounting process; e)记账进程指针转换为本进程地址空间内的内存地址,访问所述内存地址中的共享内存链表。e) The bookkeeping process pointer is converted into a memory address in the address space of the process, and the shared memory linked list in the memory address is accessed. 9.根据权利要求8所述的进程间消息传递方法,其特征在于,所述共享内存区为消息的每个字段分配预定长度的内存块。9. The inter-process message transfer method according to claim 8, wherein the shared memory area allocates a memory block of a predetermined length for each field of the message. 10.根据权利要求8所述的进程间消息传递方法,其特征在于,所述处理进程中的最后一个处理进程将处理完的消息节点释放到空闲节点队列中。10. The inter-process message delivery method according to claim 8, wherein the last processing process in the processing processes releases the processed message node to the idle node queue. 11.根据权利要求8所述的进程间消息传递方法,其特征在于,节点包括:消息队列大小、消息队列空闲节点链表头指针和消息队列已分配节点链表头指针。11. The inter-process message transfer method according to claim 8, wherein the node comprises: the size of the message queue, the head pointer of the linked list of idle nodes of the message queue, and the head pointer of the linked list of assigned nodes of the message queue. 12.根据权利要求8所述的进程间消息传递方法,其特征在于,在各进程间采用先入先出FIFO或者其他进程间通信IPC机制发送共享内存链表的头指针。12. The inter-process message transfer method according to claim 8, characterized in that FIFO or other inter-process communication IPC mechanisms are used between each process to send the head pointer of the shared memory linked list. 13.根据权利要求8所述的进程间消息传递方法,其特征在于,消息队列节点数据包括:共享内存链表的头指针、共享内存链表的尾指针和消息数据字段个数中的至少一个。13. The inter-process message transfer method according to claim 8, wherein the message queue node data comprises: at least one of a head pointer of a shared memory linked list, a tail pointer of a shared memory linked list, and the number of message data fields.
CNB2006100074871A 2006-02-14 2006-02-14 Interprocess Message Passing Method Based on Linked List Expired - Fee Related CN100403739C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2006100074871A CN100403739C (en) 2006-02-14 2006-02-14 Interprocess Message Passing Method Based on Linked List

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2006100074871A CN100403739C (en) 2006-02-14 2006-02-14 Interprocess Message Passing Method Based on Linked List

Publications (2)

Publication Number Publication Date
CN1859325A CN1859325A (en) 2006-11-08
CN100403739C true CN100403739C (en) 2008-07-16

Family

ID=37298188

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2006100074871A Expired - Fee Related CN100403739C (en) 2006-02-14 2006-02-14 Interprocess Message Passing Method Based on Linked List

Country Status (1)

Country Link
CN (1) CN100403739C (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP4060497A1 (en) * 2021-03-19 2022-09-21 Beijing Tusen Zhitu Technology Co., Ltd. Method for inter-process communication, related computing device and storage medium

Families Citing this family (27)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100444120C (en) * 2006-11-30 2008-12-17 南京联创科技股份有限公司 Mass data transmission method based on message queue between pipelined multi-processes
CN101141742B (en) * 2007-10-12 2011-08-10 中兴通讯股份有限公司 Application communication method of terminal
CN101458650B (en) * 2007-12-13 2010-12-15 华为技术有限公司 Apparatus and method for detecting internal memory transfer abnormity in multi-core system
CN101763289B (en) * 2009-09-25 2013-11-20 中国人民解放军国防科学技术大学 Message passing method based on shared memory
CN102906706A (en) * 2010-05-24 2013-01-30 索尼电脑娱乐公司 Information processing device and information processing method
CN102004675A (en) * 2010-11-11 2011-04-06 福建星网锐捷网络有限公司 Cross-process data transmission method, device and network equipment
CN102479106A (en) * 2010-11-23 2012-05-30 金蝶软件(中国)有限公司 Method and system for acquiring messages from multi-queue nodes
BR112014014414A2 (en) * 2011-12-14 2017-06-13 Optis Cellular Tech Llc Temporary storage resource management method and telecommunication equipment
CN103197979B (en) * 2012-01-04 2017-05-03 阿里巴巴集团控股有限公司 Method and device for realizing data interaction access among processes
CN103365705B (en) * 2012-03-27 2016-02-24 腾讯科技(深圳)有限公司 Message queue disposal route and device
CN102880507A (en) * 2012-09-12 2013-01-16 科立讯通信股份有限公司 Method for applying and distributing chain structure message
CN103543988B (en) * 2013-10-23 2017-05-10 华为终端有限公司 Method for processing array information, method and device of controlling information to enter arrays
CN104536704A (en) * 2015-01-12 2015-04-22 浪潮(北京)电子信息产业有限公司 Dual-controller communication method, transmitting end controller and receiving end controller
CN105988876B (en) * 2015-03-27 2019-09-17 杭州迪普科技股份有限公司 Memory allocation method and device
CN106338931A (en) * 2015-07-06 2017-01-18 天津九洲云物联科技有限公司 Central control information scheduling algorithm
CN105045660A (en) * 2015-07-27 2015-11-11 汉柏科技有限公司 Dynamic resource recovery method and system
CN106201742B (en) * 2016-07-04 2019-09-20 东软医疗系统股份有限公司 A shared memory management method, device and system
CN106681847B (en) * 2016-12-30 2020-08-11 深圳Tcl数字技术有限公司 Message processing method and device based on Android system
CN107995006A (en) * 2017-12-01 2018-05-04 天津麒麟信息技术有限公司 Real-time Billing System based on message trigger under a kind of cloud environment
CN108595282A (en) * 2018-05-02 2018-09-28 广州市巨硅信息科技有限公司 A kind of implementation method of high concurrent message queue
CN110737536B (en) * 2019-09-19 2024-03-12 亚信创新技术(南京)有限公司 Message storage method and message reading method based on shared memory
CN110750372B (en) * 2019-10-16 2024-05-14 深圳技威时代科技有限公司 Log system and log management method based on shared memory
CN111158927B (en) * 2019-12-17 2023-10-24 科大讯飞股份有限公司 Inter-process communication method, inter-process communication device and storage medium
CN111459417B (en) * 2020-04-26 2023-08-18 中国人民解放军国防科技大学 A lock-free transmission method and system for NVMeoF storage network
CN115686875A (en) * 2021-07-22 2023-02-03 伊姆西Ip控股有限责任公司 Method, apparatus and program product for transferring data between multiple processes
CN114979270B (en) * 2022-05-25 2023-08-25 上海交通大学 Message publishing method and system suitable for RDMA network
CN120371570A (en) * 2025-06-26 2025-07-25 北京华环电子股份有限公司 Inter-process communication method and device

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1490724A (en) * 2002-10-18 2004-04-21 上海贝尔有限公司 Virtual machine for embedded systemic software development
CN1501277A (en) * 2002-11-19 2004-06-02 宝山钢铁股份有限公司 Bus type inter-process communication method
WO2004061687A1 (en) * 2002-12-19 2004-07-22 Emulex Design & Manufacturing Corporation Direct memory access controller system
US6847991B1 (en) * 2000-09-06 2005-01-25 Cisco Technology, Inc. Data communication among processes of a network component
US20050044551A1 (en) * 2003-08-19 2005-02-24 Sodhi Ajit S. System and method for shared memory based IPC queue template having event based notification
CN1713151A (en) * 2004-06-22 2005-12-28 国际商业机器公司 Method and system for facilitating communication in a shared memory environment

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6847991B1 (en) * 2000-09-06 2005-01-25 Cisco Technology, Inc. Data communication among processes of a network component
CN1490724A (en) * 2002-10-18 2004-04-21 上海贝尔有限公司 Virtual machine for embedded systemic software development
CN1501277A (en) * 2002-11-19 2004-06-02 宝山钢铁股份有限公司 Bus type inter-process communication method
WO2004061687A1 (en) * 2002-12-19 2004-07-22 Emulex Design & Manufacturing Corporation Direct memory access controller system
US20050044551A1 (en) * 2003-08-19 2005-02-24 Sodhi Ajit S. System and method for shared memory based IPC queue template having event based notification
CN1713151A (en) * 2004-06-22 2005-12-28 国际商业机器公司 Method and system for facilitating communication in a shared memory environment

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP4060497A1 (en) * 2021-03-19 2022-09-21 Beijing Tusen Zhitu Technology Co., Ltd. Method for inter-process communication, related computing device and storage medium

Also Published As

Publication number Publication date
CN1859325A (en) 2006-11-08

Similar Documents

Publication Publication Date Title
CN100403739C (en) Interprocess Message Passing Method Based on Linked List
US7320041B2 (en) Controlling flow of data between data processing systems via a memory
US8407707B2 (en) Task queuing in a network communications processor architecture
US7409468B2 (en) Controlling flow of data between data processing systems via a memory
US7694310B2 (en) Method for implementing MPI-2 one sided communication
CN101539902B (en) DMA Equipment and Communication Method for Nodes in Multicomputer System
CN105978985A (en) Memory management method of user-state RPC over RDMA
US10146468B2 (en) Addressless merge command with data item identifier
CN114896189B (en) Cache method, device, equipment and storage medium for high-speed bus data
CN112486702B (en) Global message queue implementation method based on multi-core multi-processor parallel system
CN106873915A (en) A kind of data transmission method and device based on RDMA registers memory blocks
CN116204487A (en) Remote data access method and device
US9311044B2 (en) System and method for supporting efficient buffer usage with a single external memory interface
US7552232B2 (en) Speculative method and system for rapid data communications
CN113127139A (en) Memory allocation method and device based on data plane development kit DPDK
CN114186163B (en) A method for caching application layer network data
US10489322B2 (en) Apparatus and method to improve performance in DMA transfer of data
CN118152154A (en) Communication control method, system and readable storage medium based on shared memory development
US20160085701A1 (en) Chained cpp command
US9990307B1 (en) Split packet transmission DMA engine
US6766358B1 (en) Exchanging messages between computer systems communicatively coupled in a computer system network
US8898353B1 (en) System and method for supporting virtual host bus adaptor (VHBA) over infiniband (IB) using a single external memory interface
CN102098221A (en) Message query method and device
CN104468417A (en) Stacking switch message transmission method and system and stacking switch
CN115933973A (en) Method for updating data remotely, RDMA system and storage medium

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
C17 Cessation of patent right
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20080716

Termination date: 20130214