Message Transmission Method, Apparatus, Electronic Device, and Computer Storage Medium

By judging the packet size in the SysV message queue and storing the message body of the large message in the shared memory, the limit on the packet size of the SysV message queue is solved, and efficient transmission of large messages and efficient utilization of shared memory is achieved.

CN114371945BActive Publication Date: 2025-05-27TRAVELSKY TECHNOLOGY LIMITED
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210022366.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-10
Publication Date
2025-05-27
Estimated Expiration
2042-01-10

AI Technical Summary

Technical Problem

The SysV message queue has a maximum limit on the packet size (65535 bytes). When the packet exceeds this size, it cannot be stored, and it is difficult to correctly evaluate and adjust the system parameters to support large packet transmission, which affects performance.

Method used

By determining whether the number of bytes of the message is greater than the first threshold (65535 bytes), if it is greater, the message header is stored in the SysV message queue, the message body is stored in the shared memory, and allocated through the preset shared memory allocation mechanism.

Benefits of technology

It breaks through the SysV message queue's limit on message size, realizes efficient transmission of large messages, and improves the utilization rate of shared memory.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114371945B_ABST
    Figure CN114371945B_ABST
Patent Text Reader

Abstract

The present application provides a method, apparatus, electronic device, and computer storage medium for transmitting messages. The method includes: when sending a message, determining whether the number of bytes of the message packet is greater than a first threshold; if the number of bytes of the packet is not greater than the first threshold, directly storing the packet in the operating system SysV message queue; if the number of bytes of the packet is greater than the first threshold, storing the message header of the packet in the operating system SysV message queue and storing the message body of the packet in the shared memory. Thus, when wanting to use the message body of a packet with the number of bytes greater than the first threshold, it can be extracted from the shared memory through the identifier of the message, thereby achieving the purpose of efficiently transmitting large packets. Finally, the shared memory allocates the message body of the packet through a preset shared memory allocation mechanism, implementing a shared memory allocation / reclamation mechanism based on offsets, effectively improving the utilization rate of the shared memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a message transmission method, device, electronic device and computer storage medium. Background Art

[0002] Currently, inter-process communication on the same machine usually uses SysV message queues, which can meet the multi-producer / multi-consumer "competition" mechanism. There is no need for applications to provide inter-process communication locks and notification mechanisms, and there are no pipes, TCP, or Domain sockets that require applications to solve the problem of sticky packets.

[0003] However, SysV message queues have an important parameter limitation: the maximum message size (max size of message), which is the maximum number of bytes of a single message (default: 65535 bytes). If the message exceeds this size, it cannot be stored in the queue. In actual production, 90% of messages do not exceed 65535 bytes. If we want to support messages larger than 65535 bytes, we need to be able to "correctly evaluate" the possible maximum message and modify the system parameters. However, this value is often difficult to "correctly" determine. If it is set too large, it will seriously affect performance. Summary of the invention

[0004] In view of this, the present application provides a message transmission method, device, electronic device and computer storage medium for efficiently transmitting messages.

[0005] The first aspect of the present application provides a method for transmitting a message, including:

[0006] When sending a message, determining whether the number of bytes of the message is greater than a first threshold;

[0007] If it is determined that the number of bytes of the message is not greater than the first threshold, directly storing the message in the operating system SysV message queue;

[0008] If it is determined that the number of bytes of the message is greater than the first threshold, the message header of the message is stored in the operating system SysV message queue, and the message body of the message is stored in the shared memory; wherein the message header includes an identifier of the message;

[0009] The shared memory allocates the message body of the message through a preset shared memory allocation mechanism.

[0010] Optionally, the shared memory allocates the message body of the message through a preset shared memory allocation mechanism, including:

[0011] For each sub-data in the message body, determining whether the size of the sub-data is greater than a second threshold;

[0012] If it is determined that the size of the sub-data is not greater than the second threshold, the sub-data is allocated using a first allocation method;

[0013] If it is determined that the size of the sub-data is greater than the second threshold, the sub-data is allocated in a second allocation manner.

[0014] Optionally, distributing the sub-data in a first distribution manner includes:

[0015] Determining the actual allocation size of the sub-data;

[0016] The allocatable quantity is determined according to the size of the sub-data, and allocation is performed according to the allocated quantity.

[0017] Optionally, distributing the sub-data in a second distribution manner includes:

[0018] Starting from the sentinel of the free page, a continuous space is selected for allocation.

[0019] Optionally, the message transmission method further includes:

[0020] When performing memory recycling, the target page is added to the location information linked list; wherein the target page is a page in which a piece of memory is released by data;

[0021] When all data in the target page are released, the target page is released.

[0022] Optionally, the message transmission method further includes:

[0023] When releasing the target page, if the previous page and the next page of the target page are free spaces, the three spaces need to be combined into a continuous memory.

[0024] A second aspect of the present application provides a message transmission device, including:

[0025] A first judgment unit, used to judge whether the number of bytes of the message body of the message is greater than a first threshold when sending the message;

[0026] a storage unit, configured to directly store the message into a SysV message queue of an operating system if the first determination unit determines that the number of bytes of the message is not greater than a first threshold;

[0027] The storage unit is further configured to store a message header of the message into a SysV message queue of an operating system and a message body of the message into a shared memory if the first judgment unit determines that the number of bytes of the message is greater than a first threshold; wherein the message header includes an identifier of the message;

[0028] The shared memory unit is used to allocate the message body of the message through a preset shared memory allocation mechanism.

[0029] Optionally, the shared memory unit includes:

[0030] A second judging unit, configured to judge, for each sub-data in the message body, whether the size of the sub-data is greater than a second threshold;

[0031] a first allocating unit, configured to allocate the sub-data in a first allocation manner if the second determining unit determines that the size of the sub-data is not greater than a second threshold;

[0032] The second allocating unit is configured to allocate the sub-data in a second allocation manner if the second determining unit determines that the size of the sub-data is greater than a second threshold.

[0033] Optionally, the first allocation unit includes:

[0034] A determination unit, used to determine the actual allocation size of the sub-data;

[0035] The first allocation subunit is used to determine the allocatable quantity according to the size of the sub-data, and allocate according to the allocated quantity.

[0036] Optionally, the second allocation unit includes:

[0037] The second allocation subunit is used to select a continuous space from the sentinel of the free page for allocation.

[0038] Optionally, the message transmission device further includes:

[0039] A recycling unit, used for adding a target page to a location information linked list when performing memory recycling; wherein the target page is a page in which a block of memory is released by data;

[0040] The releasing unit is used to release the target page when all data in the target page are released.

[0041] Optionally, the message transmission device further includes:

[0042] The synthesis unit is used for synthesizing the three segments of space into a continuous memory if the front page and the back page of the target page are free spaces.

[0043] A third aspect of the present application provides an electronic device, including:

[0044] one or more processors;

[0045] a storage device having one or more programs stored thereon;

[0046] When the one or more programs are executed by the one or more processors, the one or more processors implement the message transmission method as described in any one of the first aspects.

[0047] A fourth aspect of the present application provides a computer storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the method for transmitting a message as described in any one of the first aspects is implemented.

[0048] As can be seen from the above scheme, the present application provides a message transmission method, device, electronic device and computer storage medium, the message transmission method comprising: first, when sending a message, judging whether the number of bytes of the message is greater than a first threshold; if it is judged that the number of bytes of the message is not greater than the first threshold, directly storing the message in the operating system SysV message queue; if it is judged that the number of bytes of the message is greater than the first threshold, storing the message header of the message in the operating system SysV message queue, and storing the message body of the message in the shared memory; wherein the message header includes the identifier of the message. Thus, when you want to use the message body of a message with a byte number greater than the first threshold, you can extract it from the shared memory through the identifier of the message, thereby breaking through the limitation of the message size of the operating system SysV message queue, and realizing the purpose of efficient transmission of large messages on the basis of the message queue. Finally, the shared memory allocates the message body of the message through a preset shared memory allocation mechanism, realizes a shared memory allocation / recycling mechanism based on an offset, and effectively improves the utilization rate of the shared memory. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0050] Figure 1 A specific flow chart of a message transmission method provided in an embodiment of the present application;

[0051] Figure 2 A schematic diagram of a system composition provided in another embodiment of the present application;

[0052] Figure 3 A schematic diagram of a shared memory structure provided in another embodiment of the present application;

[0053] Figure 4 A flowchart of storing a message body of a message into a shared memory is provided for another embodiment of the present application;

[0054] Figure 5 A schematic diagram of an Nginx slab memory layout provided for another embodiment of the present application;

[0055] Figure 6 A schematic diagram of a first allocation method (block allocation) provided in another embodiment of the present application;

[0056] Figure 7 A schematic diagram of a second allocation method (page allocation) provided in another embodiment of the present application;

[0057] Figure 8 A schematic diagram of a message transmission device provided in another embodiment of the present application;

[0058] Fig. 9 A schematic diagram of an electronic device for implementing a message transmission method provided in another embodiment of the present application. DETAILED DESCRIPTION

[0059] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0060] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.

[0061] It should be noted that the concepts such as "first" and "second" mentioned in this application are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0062] It should be noted that the modifications of "one" and "plurality" mentioned in the present application are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0063] The present application embodiment provides a method for transmitting a message, such as Figure 1 As shown, the specific steps include:

[0064] S101. When sending a message, determine whether the number of bytes of the message is greater than a first threshold.

[0065] The first threshold is determined in actual applications according to system IPC resource parameters, and is generally 65535 bytes by default, which is not limited here.

[0066] Specifically, if it is determined that the number of bytes of the message is not greater than the first threshold, step S102 is executed; if it is determined that the number of bytes of the message is greater than the first threshold, step S103 is executed.

[0067] S102. directly store the message into the operating system SysV message queue.

[0068] S103, storing the message header of the message in the operating system SysV message queue, and storing the message body of the message in the shared memory.

[0069] S104. The shared memory allocates the message body of the message through a preset shared memory allocation mechanism.

[0070] The message header includes the message identifier. Shared memory is the fastest IPC method, which is specially designed to address the low efficiency of other inter-process communication methods. It is often used in conjunction with other communication mechanisms, such as semaphores, to achieve synchronization and communication between processes.

[0071] Therefore, when one wants to use the message body of a message whose byte number is greater than the first threshold, it can be extracted from the shared memory through the identifier of the message.

[0072] It can be seen that the solution of this application is composed of four parts: resource creation components, producers, consumers and system resources; among which, system resources include SysV process communication message queue (Ipcq), SysV process communication shared memory (Shm) and SysV process communication semaphore (Sem). System V Interface Definition (SVID) is a standard definition of how System V works.

[0073] like Figure 2 As shown, it is a schematic diagram of the system composition of this application.

[0074] Among them, sys manager is responsible for the creation of system resources, and creates Ipcq, Shm and Sem through resource creation components.

[0075] Producer is a producer that generates messages. For small messages, the complete message is directly put into the ipcq message queue; for large messages, the message body is stored in Shm, and then the message header is put into Ipcq.

[0076] Consumer is a consumer, which is used to block and obtain messages on Ipcq. If the length of the received message is equal to header+body, it is a small message; if not equal, the body is obtained from shm according to the message identifier of the message.

[0077] The data structure of the message in this application can be as follows:

[0078]

[0079]

[0080] Since the data structure is based on long memory alignment, the following can be used directly for memory allocation:

[0081] (Msg*)malloc(sizeof(long)+sizeof(MsgHeader)+bodylen);

[0082] Assume that the system IPC resource parameters are: the maximum number of bytes of a single message: kernel.msgmax = 65535; the maximum number of bytes of a message queue is: kernel.msgmnb = 655350.

[0083] Then, for small messages, sizeof(MsgHeader)+bodylen<=kernel.msgmax(65535), the entire message is directly written into ipcq; for large messages, sizeof(MsgHeader)+bodylen>kernel.msgmax(65535), then only MsgHeader is put into ipcq, and the body part is put into shared memory.

[0084] like Figure 3 The following is a schematic diagram of the shared memory structure. The shared memory is uniformly controlled by sysv shm+sysv sem. The entire shared memory consists of two parts: a continuous fixed hash bucket space; followed by a continuous space, where PkyKey and PkgData dynamic memory allocation are uniformly allocated by the slab algorithm.

[0085] Group refers to the lock granularity control unit. N semaphores are allocated through sem to control the granularity. It is recommended not to exceed the system default configuration (each semaphore has a maximum of 250 semaphores).

[0086] The size of a hash bucket is usually a large prime number, such as 9973; each element in the bucket is a PkgHead (the sentinel of the linked list), followed by a PkgKey linked list structure.

[0087] PkgKey refers to the storage message id and the offset pointing to PkgData.

[0088] PkgData refers to the data length and continuous data content.

[0089] It is understandable that since shared memory is used to support multi-process large message transmission, we cannot use "malloc / free" to manage memory. Therefore, we need to introduce an effective memory management mechanism to implement the shared memory "malloc / free" mechanism to maximize the reasonable use of memory.

[0090] Therefore, in another embodiment of the present application, an implementation of step S104 is as follows: Figure 4 As shown, including:

[0091] S401. For each sub-data in a message body, determine whether the size of the sub-data is greater than a second threshold.

[0092] Specifically, the Nginx Slab memory allocation principle is a power of 2. Among them, less than or equal to 2048 (i.e., the second threshold) bytes are called "block allocation", i.e., the first allocation method; more than 2048 bytes are called "page allocation", i.e., the second allocation method.

[0093] It should be noted that if the size of the sub-data is 1 to 8 bytes, 8 bytes of memory are actually allocated to it; if the size of the sub-data is 1 to 8 bytes, 8 bytes of memory are actually allocated to it; if the size of the sub-data is 9 to 16 bytes, 16 bytes of memory are actually allocated to it; if the size of the sub-data is 17 to 32 bytes, 32 bytes of memory are actually allocated to it; if the size of the sub-data is 33 to 64 bytes, 64 bytes of memory are actually allocated to it; if the size of the sub-data is 65 to 128 bytes, 12 bytes of memory are actually allocated to it 8 bytes of memory; if the size of the sub-data is 129-256 bytes, 256 bytes of memory are actually allocated to it; if the size of the sub-data is 257-512 bytes, 512 bytes of memory are actually allocated to it; if the size of the sub-data is 513-1024 bytes, 1024 bytes of memory are actually allocated to it; if the size of the sub-data is 1025-2048 bytes, 2048 bytes of memory are actually allocated to it; if the size of the sub-data is greater than 2048 bytes, 4kpage of memory is actually allocated to it.

[0094] See also Figure 5 , which is a schematic diagram of the Nginx slab memory layout.

[0095] In the Nginx Slab algorithm, the Page size is 4K and the entire memory area can be divided into 6 parts.

[0096] (1) Control information: memory start address, total pages, and remaining pages. The latter two items are statistical information, which are supplementary to the Nginx Slab algorithm.

[0097] (2) SpageFree: Free Pages sentinel, which is a doubly linked list. This application modifies prev and next into offsets for shared memory.

[0098] (3) Slot[0-8] is the page sentinel for memory allocation less than 2048 bytes.

[0099] (4) Alignmem is the unused space after 4K alignment.

[0100] (5)Pages[0-N) is the real physical memory.

[0101] (6) unused is unused memory less than 4k.

[0102] Specifically, if it is determined that the size of the sub-data is not greater than the second threshold, step S402 is executed; if it is determined that the size of the sub-data is greater than the second threshold, step S403 is executed.

[0103] S402: Distribute the sub-data in a first distribution manner.

[0104] Optionally, in another embodiment of the present application, an implementation of step S402 includes:

[0105] Determine the actual allocation size of the sub-data; then determine the allocatable quantity based on the size of the sub-data, and allocate according to the allocated quantity.

[0106] like Figure 6 Shown is a schematic diagram of the first allocation method (block allocation).

[0107] Block allocation is relatively complex. Taking 8 bytes as an example, the number of allocable blocks is 4096 / 8 = 512. However, space needs to be reserved to mark which memory block is used. For this purpose, the concept of bitmap is introduced. Each bit indicates that 8 bytes in the page are used, and a total of 512 / 8 = 64 bytes are required. Therefore, within 1 page, the number of allocable 8-byte blocks is 512-64 / 8 = 504.

[0108] S403: Distribute the sub-data using a second distribution method.

[0109] like Figure 7 The figure shows a schematic diagram of the second allocation method (page allocation).

[0110] Optionally, in another embodiment of the present application, an implementation method for performing memory recycling includes:

[0111] When performing memory recycling, the target page is added to the location information linked list; wherein the target page is a page in which a piece of memory is released by data;

[0112] When all data in the target page are released, the target page is released.

[0113] Optionally, in another embodiment of the present application, if the front page and the back page of the target page are free spaces, the three segments of space need to be combined into a continuous memory.

[0114] It can be seen from the above scheme that the present application provides a method for transmitting a message: first, when sending a message, determine whether the number of bytes of the message is greater than a first threshold; if it is determined that the number of bytes of the message is not greater than the first threshold, the message is directly stored in the operating system SysV message queue; if it is determined that the number of bytes of the message is greater than the first threshold, the message header of the message is stored in the operating system SysV message queue, and the message body of the message is stored in the shared memory; wherein the message header includes the identifier of the message. Thus, when you want to use the message body of a message whose number of bytes is greater than the first threshold, you can extract it from the shared memory through the identifier of the message, thereby breaking through the limitation of the message size of the operating system SysV message queue, and achieving the purpose of efficient transmission of large messages on the basis of the message queue. Finally, the shared memory allocates the message body of the message through a preset shared memory allocation mechanism, realizes a shared memory allocation / recycling mechanism based on an offset, and effectively improves the utilization rate of the shared memory.

[0115] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0116] The names of the messages or information exchanged between multiple devices in the embodiments of the present application are only used for illustrative purposes and are not used to limit the scope of these messages or information.

[0117] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including, but not limited to, object-oriented programming languages, such as Python, Java, C++, etc., and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0118] Another embodiment of the present application provides a message transmission device, such as Figure 8 As shown, specifically including:

[0119] The first judgment unit 801 is used to judge whether the number of bytes of the message body is greater than a first threshold when a message is received.

[0120] The storage unit 802 is used to directly store the message into the operating system SysV message queue if the first judgment unit 801 judges that the number of bytes of the message is not greater than the first threshold.

[0121] The storage unit 802 is also used to store the message header of the message in the operating system SysV message queue and the message body of the message in the shared memory if the first judgment unit 801 judges that the number of bytes of the message is greater than the first threshold.

[0122] The message header includes the identifier of the message.

[0123] The shared memory unit 803 is used to allocate the message body of the message through a preset shared memory allocation mechanism.

[0124] For the specific working process of the units disclosed in the above embodiments of the present application, please refer to the corresponding method embodiments, such as Figure 1 As shown, no further description is given here.

[0125] Optionally, in another embodiment of the present application, an implementation of the shared memory unit 803 includes:

[0126] The second judging unit is used to judge, for each sub-data in the message body, whether the size of the sub-data is greater than a second threshold.

[0127] A first allocation unit, configured to allocate the sub-data using a first allocation method if the second determination unit determines that the size of the sub-data is not greater than a second threshold;

[0128] The second allocating unit is configured to allocate the sub-data in a second allocation manner if the second determining unit determines that the size of the sub-data is greater than a second threshold.

[0129] For the specific working process of the units disclosed in the above embodiments of the present application, please refer to the corresponding method embodiments, such as Figure 4 As shown, no further description is given here.

[0130] Optionally, in another embodiment of the present application, an implementation of the first allocation unit includes:

[0131] Determines the unit used to determine the actual allocation size of the child data.

[0132] The first allocation subunit is used to determine the allocatable quantity according to the size of the sub-data and to allocate according to the allocated quantity.

[0133] The specific working process of the units disclosed in the above embodiments of the present application can be found in the corresponding method embodiments, which will not be repeated here.

[0134] Optionally, in another embodiment of the present application, an implementation of the second allocation unit includes:

[0135] The second allocation subunit is used to select a continuous space from the sentinel of the free page for allocation.

[0136] The specific working process of the units disclosed in the above embodiments of the present application can be found in the corresponding method embodiments, which will not be repeated here.

[0137] Optionally, in another embodiment of the present application, an implementation of the message transmission device further includes:

[0138] A recycling unit, used for adding a target page to a location information linked list when performing memory recycling; wherein the target page is a page in which a block of memory is released by data;

[0139] The releasing unit is used to release the target page when all data in the target page are released.

[0140] The specific working process of the units disclosed in the above embodiments of the present application can be found in the corresponding method embodiments, which will not be repeated here.

[0141] Optionally, in another embodiment of the present application, an implementation of the message transmission device further includes:

[0142] The synthesis unit is used for synthesizing the three segments of space into a continuous memory if the front page and the back page of the target page are free spaces.

[0143] The specific working process of the units disclosed in the above embodiments of the present application can be found in the corresponding method embodiments, which will not be repeated here.

[0144] As can be seen from the above scheme, the present application provides a message transmission device: first, when the first judgment unit 801 receives a message, it determines whether the number of bytes of the message is greater than the first threshold; if the first judgment unit 801 determines that the number of bytes of the message is not greater than the first threshold, the storage unit 802 directly stores the message in the operating system SysV message queue; if the first judgment unit 801 determines that the number of bytes of the message is greater than the first threshold, the storage unit 802 stores the message header of the message in the operating system SysV message queue, and stores the message body of the message in the shared memory; wherein the message header includes the identifier of the message. Thus, when you want to use the message body of a message with a byte number greater than the first threshold, you can extract it from the shared memory through the identifier of the message, thereby breaking through the limitation of the message size of the operating system SysV message queue, and realizing the purpose of efficient transmission of large messages on the basis of the message queue. Finally, the shared memory unit 803 allocates the message body of the message through a preset shared memory allocation mechanism, realizes a shared memory allocation / recycling mechanism based on an offset, and effectively improves the utilization rate of the shared memory.

[0145] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.

[0146] Another embodiment of the present application provides an electronic device, such as Fig. 9 As shown, including:

[0147] One or more processors 901.

[0148] The storage device 902 stores one or more programs.

[0149] When one or more programs are executed by one or more processors 901, the one or more processors 901 implement the message transmission method as described in any one of the above embodiments.

[0150] Another embodiment of the present application provides a computer storage medium on which a computer program is stored, wherein when the computer program is executed by a processor, a method for transmitting a message as described in any one of the above embodiments is implemented.

[0151] In the context of the present application, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0152] It should be noted that the computer-readable medium mentioned above in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0153] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0154] Another embodiment of the present application provides a computer program product. When the computer program product is executed, it is used to execute any of the above-mentioned message transmission methods.

[0155] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device, or installed from a ROM. When the computer program is executed by a processing device, the above-mentioned functions defined in the method of the embodiment of the present application are executed.

[0156] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.

[0157] Although several specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present application. Certain features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination.

[0158] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of application involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above application concept. For example, the above features are replaced with (but not limited to) technical features with similar functions applied in the present application.

Claims

1. A method for transmitting a message, characterized in that, it includes: When sending a message, determine whether the number of bytes of the message packet is greater than a first threshold; If it is determined that the number of bytes of the packet is not greater than the first threshold, directly store the packet in the operating system SysV message queue; If it is determined that the number of bytes of the packet is greater than the first threshold, store the message header of the packet in the operating system SysV message queue, and store the message body of the packet in the shared memory; wherein, the message header includes the identifier of the message; The shared memory allocates the message body of the packet through a preset shared memory allocation mechanism, which includes: for each sub-data in the message body, determine whether the size of the sub-data is greater than a second threshold; if it is determined that the size of the sub-data is not greater than the second threshold, allocate the sub-data using a first allocation method; if it is determined that the size of the sub-data is greater than the second threshold, allocate the sub-data using a second allocation method; When performing memory recovery, add the target page to the position information linked list; wherein, the target page is a page in which a piece of memory has been released in the page; When all the data in the target page have been released, release the target page; Among them, the shared memory is uniformly controlled by SysV process communication shared memory and SysV process communication semaphore. The shared memory consists of two parts: a continuous and fixed Hash bucket space, and a continuous space after the Hash bucket space. The dynamic memory allocation of PkyKey and PkgData is uniformly allocated by the slab algorithm. PkgKey refers to storing the message id and the offset pointing to PkgData, and PkgData refers to the data length and continuous data content. The slab algorithm divides the memory area into control information, SpageFree, Slot[0-8], Alignmem, Pages[0-N), and unused. The control information includes the starting address of the memory, the total number of Pages, and the remaining number of Pages. SpageFree is the sentinel of free Pages, and SpageFree is a doubly linked list. Slot[0-8] is the sentinel of Pages for memory allocation less than 2048 bytes. Alignmem is the unused space after 4K alignment. Pages[0-N) is the real physical memory, and unused is the unused memory less than 4k.

2. The transmission method according to claim 1, characterized in that, the step of allocating the sub-data using the first allocation method includes: Determine the actual allocation size of the sub-data; Determine the allocable quantity according to the size of the sub-data, and allocate according to the allocable quantity.

3. The transmission method according to claim 1, characterized in that, the step of allocating the sub-data using the second allocation method includes: Starting from the sentinel of the free page, select a continuous space for allocation.

4. The transmission method according to claim 1, characterized in that, it further includes: If the front page and the back page of the target page are free space, it is necessary to combine the three segments of space into a continuous piece of memory.

5. A transmission device for a message, characterized in that, it includes: A first judgment unit, used to judge whether the number of bytes of the message of the message is greater than a first threshold when sending the message; A storage unit, used to directly store the message into the operating system SysV message queue if the first judgment unit judges that the number of bytes of the message is not greater than the first threshold; The storage unit is also used to store the message header of the message into the operating system SysV message queue and store the message body of the message into the shared memory if the first judgment unit judges that the number of bytes of the message is greater than the first threshold; wherein, the message header includes the identifier of the message; A shared memory unit, used to allocate the message body of the message through a preset shared memory allocation mechanism; A recycling unit, used to add the target page to the position information linked list when performing memory recycling; wherein, the target page is a page in which a piece of memory has been released in the page; A release unit, used to release the target page when all the data in the target page has been released; Among them, the shared memory is uniformly controlled by SysV process communication shared memory and SysV process communication semaphore. The shared memory consists of two parts: a continuous and fixed Hash bucket space, and a continuous space after the Hash bucket space. The dynamic memory allocation of PkyKey and PkgData is uniformly allocated by the slab algorithm. PkgKey refers to storing the message id and the offset pointing to PkgData, and PkgData refers to the data length and continuous data content. The slab algorithm divides the memory area into control information, SpageFree, Slot[0-8], Alignmem, Pages[0-N), and unused. The control information includes the starting address of the memory, the total number of Pages, and the remaining Pages. SpageFree is the sentinel of free Pages. SpageFree is a doubly linked list. Slot[0-8] is the sentinel of Pages for memory allocation less than 2048 bytes. Alignmem is the unused space after 4K alignment. Pages[0-N) is the real physical memory, and unused is the unused memory less than 4k; Among them, the shared memory unit includes: A second judgment unit, used to judge whether the size of each sub-data in the message body is greater than a second threshold; A first allocation unit, used to allocate the sub-data in a first allocation manner if the second judgment unit judges that the size of the sub-data is not greater than the second threshold; A second allocation unit, used to allocate the sub-data in a second allocation manner if the second judgment unit judges that the size of the sub-data is greater than the second threshold.

6. An electronic device, characterized in that, it includes: One or more processors; A storage device, on which one or more programs are stored; When the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the method for transmitting a message as described in any one of claims 1 to 4.

7. A computer storage medium, characterized in that, a computer program is stored thereon, wherein when the computer program is executed by a processor, the method for transmitting a message as described in any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Communication method based on shared memory and apparatus thereof

    CN102023961A

  • Cluster fine-grained memory management method

    CN103914265A