CN114371945A - Message transmission method and device, electronic equipment and computer storage medium - Google Patents

Message transmission method and device, electronic equipment and computer storage medium Download PDF

Info

Publication number
CN114371945A
CN114371945A CN202210022366.3A CN202210022366A CN114371945A CN 114371945 A CN114371945 A CN 114371945A CN 202210022366 A CN202210022366 A CN 202210022366A CN 114371945 A CN114371945 A CN 114371945A
Authority
CN
China
Prior art keywords
message
shared memory
threshold value
subdata
larger
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.)
Pending
Application number
CN202210022366.3A
Other languages
Chinese (zh)
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.)
China Travelsky Technology Co Ltd
Original Assignee
China Travelsky Technology 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 China Travelsky Technology Co Ltd filed Critical China Travelsky Technology Co Ltd
Priority to CN202210022366.3A priority Critical patent/CN114371945A/en
Publication of CN114371945A publication Critical patent/CN114371945A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer And Data Communications (AREA)

Abstract

The application provides a message transmission method, a message transmission device, electronic equipment and a computer storage medium, wherein the method comprises the following steps: when the message is sent, judging whether the byte number of the message is larger than a first threshold value or not; if the byte number of the message is not larger than the first threshold value, directly storing the message into a SysV message queue of an operating system; if the byte number of the message is larger than the first threshold value, storing the message header of the message into an operation system SysV message queue, and storing the message body of the message into a shared memory. Therefore, when a message body of a message with the byte number larger than the first threshold value is required to be used, the message body can be extracted from the shared memory through the identification of the message, and the purpose of efficiently transmitting a large message is further achieved. And finally, the shared memory distributes the message body of the message through a preset shared memory distribution mechanism, so that a shared memory distribution/recovery mechanism based on the offset is realized, and the utilization rate of the shared memory is effectively improved.

Description

Message transmission method and device, electronic equipment and computer storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for transmitting a packet, an electronic device, and a computer storage medium.
Background
At present, the same machine inter-process communication mode generally uses SysV message queues for communication, which can meet the 'contention' mechanism of multiple producers/multiple consumers, does not need to provide inter-process communication lock and notification mechanism, and does not have the problem that the socket of pipeline, TCP and Domain needs to be applied to solve the problem of packet sticking.
However, the SysV message queue has an important parameter limit: large message size (max size of message), i.e. the maximum number of bytes of a single packet (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 more than 65535bytes, we need to be able to "correctly evaluate" the largest possible message and modify the system parameters. However, this value is often difficult to determine "correctly" and can severely impact performance if set too large.
Disclosure of Invention
In view of this, the present application provides a method and an apparatus for transmitting a message, an electronic device, and a computer storage medium, which are used for efficiently transmitting a message.
A first aspect of the present application provides a method for transmitting a packet, including:
when a message is sent, judging whether the byte number of a message of the message is larger than a first threshold value or not;
if the byte number of the message is judged to be not larger than the first threshold value, the message is directly stored in an operation system SysV message queue;
if the byte number of the message is judged to be larger than a first threshold value, storing a message header of the message into an operation system SysV message queue, and storing a message body of the message into a shared memory; wherein the message header includes an identification of the message;
and the shared memory distributes the message body of the message through a preset shared memory distribution mechanism.
Optionally, the allocating, by the shared memory through a preset shared memory allocation mechanism, the message body of the message includes:
judging whether the size of the subdata is larger than a second threshold value or not aiming at each subdata in the message body;
if the size of the subdata is judged to be not larger than a second threshold value, the subdata is distributed in a first distribution mode;
and if the size of the subdata is judged to be larger than a second threshold value, distributing the subdata by adopting a second distribution mode.
Optionally, the allocating the sub data by using the first allocation manner includes:
determining the actual distribution size of the subdata;
determining the distributable number according to the size of the subdata, and distributing according to the distribution number.
Optionally, the allocating the sub data by using the second allocation manner includes:
starting from a sentinel on an idle page, a continuous space is selected for allocation.
Optionally, the method for transmitting a packet further includes:
when memory recovery is carried out, adding a target page into a position information linked list; the target page is a page with data in the page and a memory released;
and releasing the target page when all the data in the target page are released.
Optionally, the method for transmitting a packet further includes:
when the target page is released, if the front page and the back page of the target page are free spaces, three sections of spaces need to be combined into a continuous memory.
A second aspect of the present application provides a message transmission apparatus, including:
the first judging unit is used for judging whether the byte number of a message of the message is larger than a first threshold value or not when the message is sent;
the storage unit is used for directly storing the message to an operating system SysV message queue if the first judgment unit judges that the byte number of the message is not greater than a first threshold value;
the storage unit is further configured to store a message header of the message into an operating system SysV message queue and store a message body of the message into a shared memory if the first determination unit determines that the number of bytes of the message is greater than a first threshold value; wherein the message header includes an identification of the message;
and the shared memory unit is used for distributing the message body of the message through a preset shared memory distribution mechanism.
Optionally, the shared memory unit includes:
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;
a first allocation unit, configured to allocate the sub-data in a first allocation manner if the size of the sub-data is not greater than a second threshold value as determined by the second determination unit;
and the second distributing unit is used for distributing the subdata by adopting a second distributing mode if the size of the subdata is larger than a second threshold value judged by the second judging unit.
Optionally, the first allocation unit includes:
a determining unit, configured to determine an actual allocation size of the sub data;
and the first allocation subunit is used for determining the allocable number according to the size of the sub-data and allocating according to the allocation number.
Optionally, the second allocating unit includes:
and the second distribution subunit is used for selecting a continuous space for distribution from the sentinels on the idle pages.
Optionally, the apparatus for transmitting a packet further includes:
the recovery unit is used for adding the target page into the position information linked list when the memory is recovered; the target page is a page with data in the page and a memory released;
and the releasing unit is used for releasing the target page when all the data in the target page are released.
Optionally, the apparatus for transmitting a packet further includes:
and the synthesis unit is used for synthesizing three sections of spaces into a continuous memory if the front page and the rear page of the target page are free spaces.
A third aspect of the present application provides an electronic device comprising:
one or more processors;
a storage device having one or more programs stored thereon;
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method for transmitting a message according to any one of the first aspects.
A fourth aspect of the present application provides a computer storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method for transmitting a packet according to any one of the first aspects.
According to the above scheme, the present application provides a message transmission method, an apparatus, an electronic device, and a computer storage medium, where the message transmission method includes: firstly, when a message is sent, judging whether the byte number of a message of the message is greater than a first threshold value; if the byte number of the message is judged to be not larger than the first threshold value, the message is directly stored in an operation system SysV message queue; if the byte number of the message is judged to be larger than a first threshold value, storing a message header of the message into an operation system SysV message queue, and storing a message body of the message into a shared memory; wherein the message header includes an identification of the message. Therefore, when a message body of a message with the byte number larger than the first threshold value is required to be used, the message body can be extracted from the shared memory through the identification of the message, so that the limitation of the SysV message queue of the operating system on the size of the message is broken through, and the purpose of efficiently transmitting a large message is realized on the basis of the message queue. And finally, the shared memory distributes the message body of the message through a preset shared memory distribution mechanism, so that a shared memory distribution/recovery mechanism based on the offset is realized, and the utilization rate of the shared memory is effectively improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, it is obvious that the drawings in the following description are only embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
Fig. 1 is a detailed flowchart of a message transmission method according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a system configuration according to another embodiment of the present application;
fig. 3 is a schematic diagram of a shared memory structure according to another embodiment of the present application;
fig. 4 is a flowchart illustrating storing a message body of a message in a shared memory according to another embodiment of the present application;
fig. 5 is a schematic diagram of an nginnx slab memory layout according to another embodiment of the present application;
fig. 6 is a schematic diagram of a first allocation manner (block allocation) according to another embodiment of the present application;
FIG. 7 is a diagram illustrating a second allocation (page allocation) according to another embodiment of the present application;
fig. 8 is a schematic diagram of a message transmission apparatus according to another embodiment of the present application;
fig. 9 is a schematic view of an electronic device implementing a message transmission method according to another embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The term "include" and variations thereof as used herein are open-ended, i.e., "including but not limited to". The term "based on" is "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". Relevant definitions for other terms will be given in the following description.
It should be noted that the terms "first", "second", and the like in the present application are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence relationship of the functions performed by the devices, modules or units.
It is noted that references to "a", "an", and "the" modifications in this application are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that reference to "one or more" unless the context clearly dictates otherwise.
The embodiment of the present application provides a method for transmitting a packet, which specifically includes the following steps, as shown in fig. 1:
s101, when the message is sent, judging whether the byte number of the message is larger than a first threshold value.
In practical applications, the first threshold is determined according to system IPC resource parameters, generally speaking, 65535bytes by default, and is not limited herein.
Specifically, if the byte number of the message is not greater than the first threshold value, step S102 is executed; if the byte number of the packet is greater than the first threshold, step S103 is executed.
S102, directly storing the message into a SysV message queue of an operating system.
S103, storing the message header of the message into an operation system SysV message queue, and storing the message body of the message into a shared memory.
And S104, distributing the message body of the message by the shared memory through a preset shared memory distribution mechanism.
Wherein the message header includes an identification of the message. Shared memory is the fastest IPC method, and is specially designed for the low operating efficiency of other interprocess communication methods. It is often used in conjunction with other communication mechanisms, such as semaphores, to achieve synchronization and communication between processes.
Therefore, when a message body of the message with the byte number larger than the first threshold value is required to be used, the message body can be extracted from the shared memory through the identification of the message.
It can be seen that the scheme of the present application is composed of four parts: resource creation components, producers, consumers, and system resources; the system resources include a SysV process communication message queue (Ipcq), a SysV process communication shared memory (Shm), and a SysV process communication semaphore (Sem). System V Interface Definition (SVID) is a standard Definition of how System V works.
Fig. 2 is a schematic diagram of the system of the present application.
The sys manager is responsible for creating system resources, and the creation of Ipcq, Shm and sim is performed through the resource creation component.
The producer is the producer, which is used to generate messages. For small messages, directly putting the complete message into an ipcq message queue; for large messages, the body of the message is stored in Shm, and the header of the message is placed in Ipcq.
Consumer is a Consumer that blocks messages from getting on Ipcq. If the length of the received message is equal to the header + body, the message is a small message; and if not, acquiring the body from the shm according to the message identifier of the message.
The data structure of the messages in the present application may be as follows:
Figure BDA0003462900980000061
Figure BDA0003462900980000071
because the data structure is based on long memory alignment, it can be directly used on memory allocation:
(Msg*)malloc(sizeof(long)+sizeof(MsgHeader)+bodylen);
suppose that the system IPC resource parameters are: maximum byte number of a single message: kernel. msgmax 65535; the maximum byte number of the message queue is as follows: msgmnb 655350.
Then, for small messages, sizeof (msgheader) + body ═ kernel.msgmax (65535), the entire message is written directly to ipcq; for large messages, sizeof (MsgHeader) + body > kernel, msgmax (65535), then only MsgHeader is put into ipcq, and the body part is put into shared memory.
Fig. 3 is a schematic diagram of a shared memory structure. The shared memory is uniformly controlled by using sysv shm + sysv sem. The whole shared memory consists of two parts: a continuous fixed Hash bucket space; and a continuous space is followed, and the dynamic memory allocation of the PkyKey and the PkgData is uniformly allocated by a slab algorithm.
Wherein, Group refers to the lock granularity control unit. Granularity is controlled by allocating N semaphores out of sem, suggesting that system default configurations are not exceeded (up to 250 signals per semaphore).
The Hash bucket, which is typically sized to a larger prime number, e.g., 9973; each element in the bucket is a PkgHead (sentinel of the linked list) followed by a PkgKey linked list structure.
PkgKey refers to the stored message id and an offset to PkgData.
PkgData refers to the data length and continuous data content.
It can be understood that, because a shared memory mode is adopted to support multi-process large message transmission, the memory cannot be managed by using the malloc/free mode. Therefore, an effective memory management mechanism needs to be introduced to realize a "malloc/free" mechanism based on a shared memory, so that the memory is reasonably utilized to the maximum extent.
Therefore, in another embodiment of the present application, an implementation of step S104, as shown in fig. 4, includes:
s401, judging whether the size of the subdata is larger than a second threshold value or not aiming at each subdata in the message body.
Specifically, the Nginx Slab memory allocation principle is a power of 2. Wherein, those less than 2048 (i.e., the second threshold) bytes are called "block allocation", i.e., the first allocation; larger than 2048 bytes, a "page allocation" and a second allocation are used.
It should be noted that if the size of the subdata is 1-8 bytes, 8 bytes of memory are actually allocated to the subdata; if the size of the subdata is 1-8 bytes, actually allocating 8 bytes of memory for the subdata; if the size of the subdata is 9-16 bytes, actually allocating 16 bytes of memory for the subdata; if the size of the subdata is 17-32 bytes, actually allocating 32 bytes of memory for the subdata; if the size of the subdata is 33-64 bytes, actually allocating 64 bytes of memory for the subdata; if the size of the subdata is 65-128 bytes, a 128-byte memory is actually allocated to the subdata; if the size of the subdata is 129-256 bytes, 256 bytes of memory are actually allocated to the subdata; if the size of the subdata is 257-512 bytes, a 512-byte memory is actually allocated to the subdata; if the size of the subdata is 513-1024 bytes, actually distributing 1024 bytes of memory for the subdata; if the size of the subdata is 1025-2048 bytes, 2048 bytes of memory is actually allocated to the subdata; if the size of the subdata is larger than 2048 bytes, a memory of 4kpage is actually allocated to the subdata.
FIG. 5 is a schematic diagram of a Nginx slab memory layout.
In the Nginx Slab algorithm, the size of Page is 4K, and the whole memory area can be divided into 6 parts.
(1) Control information: memory starting address, total Pages, remaining Pages. The latter two items of data are statistical information and are supplementary to the Nginx Slab algorithm.
(2) SpageFree: the idle Pages sentinels are doubly linked lists. The present application is directed to a way to revise prev, next to an offset for shared memory.
(3) Slot [0-8] is the Page sentinel that allocates less than 2048 bytes of memory.
(4) Align mem is 4K aligned, unused space.
(5) Pages 0-N) is true physical memory.
(6) unused is unused memory less than 4 k.
Specifically, if it is determined that the size of the sub-data is not greater than the second threshold, step S402 is executed; if the size of the sub-data is greater than the second threshold, step S403 is executed.
S402, distributing the subdata by adopting a first distribution formula.
Optionally, in another embodiment of the present application, an implementation manner of step S402 includes:
determining the actual distribution size of the subdata; and determining the distributable number according to the size of the subdata and distributing according to the distribution number.
Fig. 6 is a schematic diagram of a first allocation manner (block allocation).
The block allocation is relatively complex, and for example, 8 bytes, the allocable number 4096/8 is 512 blocks. But requires a reserved space for marking which block of memory is used, and to introduce the bitmap concept, 8 bytes in the page are used by every 1 bit, and 512/8-64 bytes are needed in total. Then within page 1, the allocable 8-byte blocks are 512-64/8-504 blocks.
And S403, distributing the sub-data by adopting a second distribution mode.
Fig. 7 is a schematic diagram of the second allocation manner (page allocation).
Optionally, in another embodiment of the present application, an implementation manner in memory recovery includes:
when memory recovery is carried out, adding a target page into a position information linked list; the target page is a page with data in the page and a memory released;
and releasing the target page when all the data in the target page are released.
Optionally, in another embodiment of the present application, if the front page and the back page of the target page are free spaces, three sections of spaces need to be combined into a continuous memory.
According to the above scheme, the present application provides a method for transmitting a packet: firstly, when a message is sent, judging whether the byte number of a message of the message is larger than a first threshold value or not; if the byte number of the message is judged to be not larger than the first threshold value, the message is directly stored in a SysV message queue of the operating system; if the byte number of the message is judged to be larger than the first threshold value, storing the message header of the message into an operation system SysV message queue, and storing the message body of the message into a shared memory; wherein the message header includes an identification of the message. Therefore, when a message body of a message with the byte number larger than the first threshold value is required to be used, the message body can be extracted from the shared memory through the identification of the message, so that the limitation of the SysV message queue of the operating system on the size of the message is broken through, and the purpose of efficiently transmitting a large message is realized on the basis of the message queue. And finally, the shared memory distributes the message body of the message through a preset shared memory distribution mechanism, so that a shared memory distribution/recovery mechanism based on the offset is realized, and the utilization rate of the shared memory is effectively improved.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The names of messages or information exchanged between a plurality of devices in the embodiments of the present application are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
Computer program code for carrying out operations for aspects of the present application may be written in any combination of one or more programming languages, including but not limited to an object oriented programming language such as Python, Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
Another embodiment of the present application provides a message transmission apparatus, as shown in fig. 8, specifically including:
a first determining unit 801, configured to determine, when a message is received, whether a byte number of a message of the message is greater than a first threshold.
The storing unit 802 is configured to, if the first determining unit 801 determines that the number of bytes of the message is not greater than the first threshold, directly store the message in the SysV message queue of the operating system.
The storing unit 802 is further configured to store the message header of the message into the SysV message queue of the operating system and store the message body of the message into the shared memory if the first determining unit 801 determines that the byte number of the message is greater than the first threshold.
Wherein the message header includes an identification of the message.
A shared memory unit 803, configured to allocate a message body of the message through a preset shared memory allocation mechanism.
For a specific working process of the unit disclosed in the above embodiment of the present application, reference may be made to the content of the corresponding method embodiment, as shown in fig. 1, which is not described herein again.
Optionally, in another embodiment of the present application, an implementation manner of the shared memory unit 803 includes:
and the second judging unit is used for judging whether the size of the subdata is larger than a second threshold value or not aiming at each subdata in the message body.
The first distribution unit is used for distributing the subdata by adopting a first distribution formula if the second judgment unit judges that the size of the subdata is not larger than a second threshold value;
and the second distributing unit is used for distributing the sub-data in a second distributing mode if the second judging unit judges that the size of the sub-data is larger than a second threshold value.
For a specific working process of the unit disclosed in the above embodiment of the present application, reference may be made to the content of the corresponding method embodiment, as shown in fig. 4, which is not described herein again.
Optionally, in another embodiment of the present application, an implementation manner of the first distribution unit includes:
a determining unit for determining an actual allocation size of the sub data.
And the first allocation subunit is used for determining the allocable number according to the size of the sub-data and allocating according to the allocation number.
For specific working processes of the units disclosed in the above embodiments of the present application, reference may be made to the contents of the corresponding method embodiments, which are not described herein again.
Optionally, in another embodiment of the present application, an implementation manner of the second allocating unit includes:
and the second distribution subunit is used for selecting a continuous space for distribution from the sentinels on the idle pages.
For specific working processes of the units disclosed in the above embodiments of the present application, reference may be made to the contents of the corresponding method embodiments, which are not described herein again.
Optionally, in another embodiment of the present application, an implementation manner of the message transmission apparatus further includes:
the recovery unit is used for adding the target page into the position information linked list when the memory is recovered; the target page is a page with data in the page and a memory released;
and the releasing unit is used for releasing the target page when all the data in the target page are released.
For specific working processes of the units disclosed in the above embodiments of the present application, reference may be made to the contents of the corresponding method embodiments, which are not described herein again.
Optionally, in another embodiment of the present application, an implementation manner of the message transmission apparatus further includes:
and the synthesis unit is used for synthesizing three sections of spaces into a continuous memory if the front page and the rear page of the target page are free spaces.
For specific working processes of the units disclosed in the above embodiments of the present application, reference may be made to the contents of the corresponding method embodiments, which are not described herein again.
According to the above scheme, the present application provides a transmission apparatus for a packet: first, when receiving a message, the first determining unit 801 determines whether the number of bytes of a message of the message is greater than a first threshold; if the first determining unit 801 determines that the number of bytes of the message is not greater than the first threshold, the storing unit 802 directly stores the message in the SysV message queue of the operating system; if the first determining unit 801 determines that the byte number of the message is greater than the first threshold, the storing unit 802 stores the message header of the message into the SysV message queue of the operating system, and stores the message body of the message into the shared memory; wherein the message header includes an identification of the message. Therefore, when a message body of a message with the byte number larger than the first threshold value is required to be used, the message body can be extracted from the shared memory through the identification of the message, so that the limitation of the SysV message queue of the operating system on the size of the message is broken through, and the purpose of efficiently transmitting a large message is realized 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, so that a shared memory allocation/recovery mechanism based on the offset is realized, and the utilization rate of the shared memory is effectively improved.
The functions described herein above 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 a chip (SOCs), Complex Programmable Logic Devices (CPLDs), and the like.
Another embodiment of the present application provides an electronic device, as shown in fig. 9, including:
one or more processors 901.
Storage 902 having one or more programs stored thereon.
The one or more programs, when executed by the one or more processors 901, cause the one or more processors 901 to implement the method for transmitting a message as in any one of the above embodiments.
Another embodiment of the present application provides a computer storage medium, on which a computer program is stored, wherein when being executed by a processor, the computer program implements the message transmission method according to any one of the above embodiments.
In the context of this application, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The 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, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
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 two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present application, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
Another embodiment of the present application provides a computer program product for performing the method of transmitting a message according to any one of the above when the computer program product is executed.
In particular, according to embodiments of the application, the processes described above with reference to the flow diagrams may be implemented as computer software programs. For example, embodiments of the present application include a computer program product comprising a computer program carried on a non-transitory computer readable medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means, or installed from a storage means, or installed from a ROM. The computer program, when executed by a processing device, performs the above-described functions defined in the method of the embodiments of the present application.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.
While several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the application. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
The above description is only a preferred embodiment of the application and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the application referred to in the present application is not limited to the embodiments with a particular combination of the above-mentioned features, but also encompasses other embodiments with any combination of the above-mentioned features or their equivalents without departing from the scope of the application. For example, the above features may be replaced with (but not limited to) features having similar functions as those described in this application.

Claims (10)

1. A method for transmitting a message is characterized by comprising the following steps:
when a message is sent, judging whether the byte number of a message of the message is larger than a first threshold value or not;
if the byte number of the message is judged to be not larger than the first threshold value, the message is directly stored in an operation system SysV message queue;
if the byte number of the message is judged to be larger than a first threshold value, storing a message header of the message into an operation system SysV message queue, and storing a message body of the message into a shared memory; wherein the message header includes an identification of the message;
and the shared memory distributes the message body of the message through a preset shared memory distribution mechanism.
2. The transmission method according to claim 1, wherein the allocating, by the shared memory through a preset shared memory allocation mechanism, the message body of the message includes:
judging whether the size of the subdata is larger than a second threshold value or not aiming at each subdata in the message body;
if the size of the subdata is judged to be not larger than a second threshold value, the subdata is distributed in a first distribution mode;
and if the size of the subdata is judged to be larger than a second threshold value, distributing the subdata by adopting a second distribution mode.
3. The transmission method according to claim 2, wherein the allocating the sub-data in the first allocation manner includes:
determining the actual distribution size of the subdata;
determining the distributable number according to the size of the subdata, and distributing according to the distribution number.
4. The transmission method according to claim 2, wherein the allocating the sub-data by the second allocation method includes:
starting from a sentinel on an idle page, a continuous space is selected for allocation.
5. The transmission method according to claim 2, further comprising:
when memory recovery is carried out, adding a target page into a position information linked list; the target page is a page with data in the page and a memory released;
and releasing the target page when all the data in the target page are released.
6. The transmission method according to claim 5, further comprising:
if the front page and the back page of the target page are free spaces, three sections of spaces need to be combined into a continuous memory.
7. A message transmission apparatus, comprising:
the first judging unit is used for judging whether the byte number of a message of the message is larger than a first threshold value or not when the message is sent;
the storage unit is used for directly storing the message to an operating system SysV message queue if the first judgment unit judges that the byte number of the message is not greater than a first threshold value;
the storage unit is further configured to store a message header of the message into an operating system SysV message queue and store a message body of the message into a shared memory if the first determination unit determines that the number of bytes of the message is greater than a first threshold value; wherein the message header includes an identification of the message;
and the shared memory unit is used for distributing the message body of the message through a preset shared memory distribution mechanism.
8. The transmission apparatus as claimed in claim 7, wherein the shared memory unit comprises:
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;
a first allocation unit, configured to allocate the sub-data in a first allocation manner if the size of the sub-data is not greater than a second threshold value as determined by the second determination unit;
and the second distributing unit is used for distributing the subdata by adopting a second distributing mode if the size of the subdata is larger than a second threshold value judged by the second judging unit.
9. An electronic device, comprising:
one or more processors;
a storage device having one or more programs stored thereon;
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method of transmission of a message as claimed in any one of claims 1 to 6.
10. A computer storage medium, having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method of transmission of a message according to any one of claims 1 to 6.
CN202210022366.3A 2022-01-10 2022-01-10 Message transmission method and device, electronic equipment and computer storage medium Pending CN114371945A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210022366.3A CN114371945A (en) 2022-01-10 2022-01-10 Message transmission method and device, electronic equipment and computer storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210022366.3A CN114371945A (en) 2022-01-10 2022-01-10 Message transmission method and device, electronic equipment and computer storage medium

Publications (1)

Publication Number Publication Date
CN114371945A true CN114371945A (en) 2022-04-19

Family

ID=81143197

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210022366.3A Pending CN114371945A (en) 2022-01-10 2022-01-10 Message transmission method and device, electronic equipment and computer storage medium

Country Status (1)

Country Link
CN (1) CN114371945A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115580587A (en) * 2022-12-06 2023-01-06 北京云脉芯联科技有限公司 Message information processing method and device, computer equipment and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115580587A (en) * 2022-12-06 2023-01-06 北京云脉芯联科技有限公司 Message information processing method and device, computer equipment and storage medium
CN115580587B (en) * 2022-12-06 2023-03-14 北京云脉芯联科技有限公司 Message information processing method and device, computer equipment and storage medium

Similar Documents

Publication Publication Date Title
EP3417569B1 (en) System and method for quantum key distribution
US9396030B2 (en) Quota-based adaptive resource balancing in a scalable heap allocator for multithreaded applications
CN106844041B (en) Memory management method and memory management system
US8504744B2 (en) Lock-less buffer management scheme for telecommunication network applications
CN112667414A (en) Message queue-based message consumption method and device, computer equipment and medium
CN112905342B (en) Resource scheduling method, device, equipment and computer readable storage medium
US11201836B2 (en) Method and device for managing stateful application on server
CN109074281B (en) Method and device for distributing graphics processor tasks
CN110704214B (en) Inter-process communication method and device
CN112953757B (en) Data distribution method, system and computer equipment
EP3644182A1 (en) Container isolation method and device for netlink resource
CN111221638A (en) Scheduling processing method, device, equipment and medium for concurrent tasks
CN105094981A (en) Method and device for processing data
CN111290979B (en) Data transmission method, device and system
CN114155026A (en) Resource allocation method, device, server and storage medium
CN114371945A (en) Message transmission method and device, electronic equipment and computer storage medium
CN104780118B (en) A kind of flow control method and device based on token
US20140089624A1 (en) Cooperation of hoarding memory allocators in a multi-process system
CN115237589A (en) SR-IOV-based virtualization method, device and equipment
CN113381889B (en) Network slice determination method and device, electronic equipment and storage medium
US9268621B2 (en) Reducing latency in multicast traffic reception
CN112260962B (en) Bandwidth control method and device
CN108139969B (en) Memory configuration method, device and system
CN116841720A (en) Resource allocation method, apparatus, computer device, storage medium and program product
CN114860390B (en) Container data management method, device, program product, medium and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination