Communication method and device, electronic equipment, storage medium and program product

By expanding the shared memory when sending messages, the problem of zero-copy communication for variable-length messages is solved, enabling flexible inter-process communication suitable for sending both variable-length and fixed-length messages.

CN121967359APending Publication Date: 2026-05-01HUIZHOU DESAY SV AUTOMOTIVE
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HUIZHOU DESAY SV AUTOMOTIVE
Filing Date
2024-10-30
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

In existing technologies, variable-length messages cannot use shared memory for zero-copy inter-process communication, which limits the flexibility of message types.

Method used

If the length of the message to be sent is greater than the estimated memory size, the shared memory is expanded, the size of the expanded shared memory is determined, and new shared memory is requested for message sending.

Benefits of technology

It enables zero-copy communication between processes for variable-length messages via shared memory, applicable to both variable-length and fixed-length messages, offering flexibility and avoiding the need for precise pre-estimation of message length.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121967359A_ABST
    Figure CN121967359A_ABST
Patent Text Reader

Abstract

The invention discloses a communication method and device, electronic equipment, a storage medium and a program product. The method comprises the following steps: acquiring a to-be-sent message, and determining the message length of the to-be-sent message; if the message length is greater than the estimated memory size, expanding the shared memory according to the message length, determining the size of the expanded shared memory, and determining the size of the shared memory according to the estimated memory size; and applying for a new shared memory according to the size of the expanded shared memory, and sending the to-be-sent message according to the new shared memory, thereby solving the problem that the variable-length message cannot use the shared memory to perform inter-process zero-copy communication, performing expansion when the estimated memory size is smaller than the message length in the message sending process, and improving the message sending efficiency. Zero-copy communication between processes of the variable-length message through the shared memory is realized, and the length of the to-be-sent message does not need to be accurately pre-estimated in advance; the method is suitable for sending variable-length messages and fixed-length messages, message types are not limited, and the use process is flexible and changeable.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a communication method, apparatus, electronic device, storage medium, and program product. Background Technology

[0002] In publish-subscribe mechanisms, zero-copy communication using shared memory between processes is generally limited to fixed-length messages. Shared memory is an efficient inter-process communication method. To facilitate information exchange between multiple processes, a memory region is reserved in the kernel space. This region can be mapped to the private address space of each process. Processes can directly read and write to this memory region without copying data between process space and kernel space, thus improving communication efficiency.

[0003] The sending and receiving processes calculate the required shared memory size based on the message length and the number of requests set by the user, and map the requested shared memory into the process space. The processes then directly read and write this memory area for communication.

[0004] Because the allocation of shared memory requires calculation based on the message length, only fixed-length message types can accurately calculate the length and perform shared memory allocation and mapping. Therefore, this method of zero-copy communication is limited to fixed-length message types, restricting the message types and preventing the use of shared memory for zero-copy communication between processes with variable-length messages. Summary of the Invention

[0005] This invention provides a communication method, apparatus, electronic device, storage medium, and program product to solve the problem that variable-length messages cannot use shared memory for zero-copy inter-process communication.

[0006] According to one aspect of the present invention, a communication method is provided, comprising:

[0007] Obtain the message to be sent and determine the message length of the message to be sent;

[0008] If the message length is greater than the estimated memory size, the shared memory is expanded according to the message length, and the size of the expanded shared memory is determined based on the estimated memory size.

[0009] Request new shared memory based on the expanded shared memory size, and send the message to be sent based on the new shared memory.

[0010] According to another aspect of the present invention, a communication device is provided, comprising:

[0011] The message to be sent acquisition module is used to acquire the message to be sent and determine the message length of the message to be sent.

[0012] The expansion module is used to expand the shared memory according to the message length if the message length is greater than the estimated memory size, and to determine the size of the expanded shared memory, wherein the size of the shared memory is determined according to the estimated memory size;

[0013] The message sending module is used to request new shared memory based on the expanded size of the shared memory, and send the message to be sent based on the new shared memory.

[0014] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:

[0015] At least one processor, and a memory communicatively connected to said at least one processor;

[0016] The memory stores a computer program that can be executed by the at least one processor, which is then executed by the at least one processor to enable the at least one processor to perform the communication method described in any embodiment of the present invention.

[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the communication method described in any embodiment of the present invention.

[0018] According to another aspect of the present invention, a computer program product is provided, the computer program product comprising a computer program that, when executed by a processor, implements the communication method described in any embodiment of the present invention.

[0019] The technical solution of this invention addresses the problem that variable-length messages cannot use shared memory for zero-copy inter-process communication. First, the message length is determined, and then compared with the estimated memory size. If the message length is greater than the estimated memory size, the shared memory is expanded based on the message length, and the expanded shared memory size is determined. Then, new shared memory is requested based on the expanded shared memory size, and the message to be sent is sent using the new shared memory. This solves the problem that variable-length messages cannot use shared memory for zero-copy inter-process communication. The method first determines the message length, compares it with the estimated memory size, and if the message length is greater than the estimated memory size, expands the shared memory based on the message length, determines the expanded shared memory size, and then requests new shared memory to send the message to be sent. During message sending, expansion can be performed when the estimated memory size is less than the message length, enabling zero-copy inter-process communication of variable-length messages using shared memory without the need for precise pre-estimation of the message length. The method of this application can be applied to sending both variable-length and fixed-length messages, without limiting the message type, and its use is flexible and adaptable.

[0020] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description

[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 This is a flowchart of a communication method provided according to Embodiment 1 of the present invention;

[0023] Figure 2 This is a flowchart of a communication method provided according to Embodiment 2 of the present invention;

[0024] Figure 3 This is a schematic diagram of the initial value of the size of shared memory according to Embodiment 2 of the present invention;

[0025] Figure 4 This is a schematic diagram of message transmission via shared memory according to Embodiment 2 of the present invention;

[0026] Figure 5 This is a schematic diagram of the size of the expanded shared memory according to Embodiment 2 of the present invention;

[0027] Figure 6 This is a schematic diagram of the structure of a communication device according to Embodiment 3 of the present invention;

[0028] Figure 7 This is a schematic diagram of the structure of an electronic device that implements the communication method of the present invention. Detailed Implementation

[0029] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0030] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0031] Example 1

[0032] Figure 1 This is a flowchart of a communication method provided in Embodiment 1 of the present invention. This embodiment is applicable to zero-copy inter-process communication using shared memory for variable-length messages. The method can be executed by a communication device, which can be implemented in hardware and / or software and can be configured in an electronic device. Figure 1 As shown, the method includes:

[0033] S101. Obtain the message to be sent and determine the message length of the message to be sent.

[0034] In this embodiment, the message to be sent can be understood as a message that needs to be sent from one process to another. The process that sends the message is the sending process, and the process that receives the message is the receiving process.

[0035] The method provided in this application can be executed by a sending process. The sending process obtains the message to be sent, and can communicate with other software or hardware with data processing capabilities to obtain the message. The message to be sent is parsed, and the message length is determined according to the data structure of the message. For example, the message to be sent consists of two parts: a constant length and a variable length. The constant length can be used to store some data of fixed length, and the variable length can be used to store data of non-fixed length.

[0036] S102. If the message length is greater than the estimated memory size, expand the shared memory according to the message length, and determine the size of the expanded shared memory. The size of the shared memory is determined based on the estimated memory size.

[0037] Shared memory is pre-allocated. The size of the shared memory can change during communication, for example, by expanding its capacity. The current estimated memory size is determined; this estimated size is related to the total shared memory size, and the final size of the shared memory can be determined based on the estimated size. The message length is compared with the estimated memory size. If the message length is greater than the estimated memory size, the shared memory is too small to transmit the message directly. The required size of shared memory is determined based on the message length, and the shared memory is expanded to determine the expanded size. For example, the message length can be used as the expanded shared memory size; or, the message length can be increased by a preset length as the expanded shared memory size; or, the message length can be used as the estimated expanded memory size, and the final size of the expanded shared memory can be determined based on the estimated expanded memory size, and so on.

[0038] S103. Request new shared memory based on the expanded size of the shared memory, and send the message to be sent based on the new shared memory.

[0039] Based on the expanded shared memory size, new shared memory is requested. At this time, the size of the requested shared memory is larger than the message to be sent, so the message to be sent can be sent normally. The message to be sent is sent based on the new shared memory.

[0040] After expanding the shared memory, the sending process can notify the receiving process that it has re-allocated the new shared memory, and the sending and receiving processes will communicate using the newly allocated shared memory.

[0041] The communication method provided in this invention solves the problem that variable-length messages cannot use shared memory for zero-copy inter-process communication. First, the message length of the message to be sent is determined. The message length is compared with the estimated memory size. If the message length is greater than the estimated memory size, the shared memory is expanded according to the message length. The size of the expanded shared memory is determined, and new shared memory is requested to send the message. During message sending, expansion can be performed when the estimated memory size is less than the message length, enabling zero-copy inter-process communication of variable-length messages via shared memory without the need for precise pre-estimation of the message length. The method in this application can be applied to sending both variable-length and fixed-length messages, without limiting the message type, and its use is flexible and adaptable.

[0042] Example 2

[0043] Figure 2 This is a flowchart of a communication method provided in Embodiment 2 of the present invention. This embodiment is a refinement based on the above embodiments. Figure 2 As shown, the method includes:

[0044] S201. Obtain the message to be sent and determine the message length of the message to be sent;

[0045] S202. Determine if the message length is greater than the estimated memory size. If yes, proceed to S203; otherwise, proceed to S206.

[0046] Optionally, the steps for determining the initial value of the estimated memory size include:

[0047] A1. Obtain the variable-length message type transmitted in shared memory.

[0048] Each shared memory instance transmits one type of message; therefore, different shared memory instances can transmit different types of messages. The message type transmitted by each shared memory instance is predetermined. When transmitting variable-length messages through shared memory, the variable-length message type transmitted by the shared memory is predetermined. The variable-length message type can be the message's business type, such as name, gender, age, etc., or it can be a character type, such as string.

[0049] A2. Determine the number of elements that can be stored based on the variable-length message type.

[0050] In this embodiment, storable element data can be understood as the number of elements that may be stored within a message, such as 10, 15, etc. The number of storable elements may differ for different types of messages. The number of storable elements is pre-determined for each variable-length message type, and when requesting shared memory, the corresponding number of storable elements is determined based on the variable-length message type.

[0051] A3. Determine the initial value of the estimated memory size based on the number of storable elements and the predetermined fixed-length message.

[0052] In this embodiment, the fixed-length message length can be understood as the size of the fixed-length field in the message used for transmitting data.

[0053] The fixed-length message is predetermined. This length can be determined based on the message type, as different message types carry different data, thus their fixed-length messages may vary. The sum of the number of storable elements and the fixed-length message is calculated. This sum can be used directly as the estimated memory size, or a preset value can be added to the sum, with the sum serving as the initial estimated memory size. The initial estimated memory size should be greater than the sum of the number of storable elements and the fixed-length message. The estimated memory size calculated in this step is the initial estimated memory size, which can be adjusted during subsequent message transmissions to achieve capacity expansion.

[0054] Optionally, the initial value of the shared memory size is the estimated memory length; the steps for determining the estimated memory length include: determining the estimated memory length based on the product of the initial value of the estimated memory size and the pre-configured queue depth.

[0055] In this embodiment, the estimated memory length can be understood as the pre-estimated memory size. The queue depth can be pre-configured by the user and can be set according to the business scenario.

[0056] Different queue depths can store different numbers of messages. The number of messages that can be stored is determined based on the queue depth. The total length required to store the messages is determined based on the estimated memory size for each message and the number of messages that can be stored. This is achieved by calculating the product of the initial estimated memory size and the queue depth; this product is the total length required to store the messages. The estimated memory length can be determined as the initial value of the shared memory size, or a value greater than this product can be used as the estimated memory length. The estimated memory length calculated in this step is the initial value of the shared memory size. The size of the shared memory can be changed by expanding it during subsequent message transmission.

[0057] S203. Determine the estimated memory size after expansion based on the product of the message length and the preset parameters. The preset parameters are determined based on the data structure of the memory.

[0058] In this embodiment, the preset parameter is determined based on the data structure of the memory. For example, since data is usually stored in binary, the preset parameter can be a power of 2 such as 2, 4, or 8, i.e., the preset parameter is 2. n n is an integer greater than or equal to 1.

[0059] Preset preset parameters. The preset parameters can be set to fixed values ​​or set according to the business type. Different business types can set the same or different preset parameters. Calculate the product of the message length and the preset parameters, and use this product as the estimated memory size after expansion, or use a value greater than this product as the estimated memory size after expansion.

[0060] S204. Determine the size of the expanded shared memory based on the product of the estimated memory size and the queue depth.

[0061] Calculate the product of the estimated memory size after expansion and the queue depth, and use this product as the size of the expanded shared memory, or use a value greater than this product as the size of the expanded shared memory.

[0062] S205. Request new shared memory based on the expanded shared memory size, and send the message to be sent based on the new shared memory.

[0063] S206. Send the message to be sent based on shared memory.

[0064] The communication process in this embodiment can be described as follows: The sending process predetermines an initial value for the estimated memory size, determines an initial value for the shared memory size based on the initial value of the estimated memory size, and requests shared memory based on this initial value. After the shared memory is requested, the sending process sends the message to be sent through the shared memory. Since the number of messages sent by the sending process is usually multiple, for example, the first message to be sent is sent first, and then the second message to be sent is sent. The sending process sends message 1 to be sent at time t1, determines the message length of message 1 to be sent, and assumes that the message length of message 1 to be sent is not greater than the estimated memory size M1 (at this time, the estimated memory size M1 is the initial value), and directly sends this message to be sent through this shared memory. At time t2, the sending process sends message 2 to be sent. The message length of message 2 is greater than the estimated memory size (which is still M1 at this time). The shared memory is expanded according to the message length, and the estimated memory size after expansion is determined to be M2. The size of the expanded shared memory is determined according to the estimated memory size M2. New shared memory is requested according to the size of the expanded shared memory, and message 2 to be sent is sent according to the new shared memory. At time t3, the sending process sends message 3 to be sent. The message length of message 3 is not greater than the estimated memory size M2. Message 3 to be sent is sent through the shared memory at this time, and so on.

[0065] For example, Figure 3 A schematic diagram is provided for the initial value of the shared memory size, where the initial value of the shared memory size = the initial value of the estimated memory size * the queue depth; Figure 4A schematic diagram is provided for transmitting messages via shared memory. The sizes of messages 1 to 3 are all smaller than the estimated memory size, so they can be transmitted normally via shared memory. The length of message 4 is larger than the estimated memory size, so it cannot be transmitted normally and therefore needs to be expanded. Figure 5 A schematic diagram of the expanded shared memory size is provided. The estimated memory size after expansion is obtained by multiplying the message length of message 4 by 2 (i.e., the preset parameter is 2). The product of the estimated memory size after expansion and the queue depth is calculated to obtain the size of the expanded shared memory.

[0066] Optionally, the method further includes: reducing the size of the shared memory when a shrinkage condition is detected.

[0067] In this embodiment, the scaling-down condition can be understood as a condition used to determine whether to scale down the shared memory. For example, receiving a scaling-down instruction or operation, or sending a message with a length less than a certain threshold. The scaling-down condition is preset, and it is checked in real time whether the condition is met. When the condition is met, the size of the shared memory is scaled down to save resources. Scaling down the shared memory size can be done by reducing the original memory size by a preset value, or by reducing it to a preset value, etc.

[0068] Optionally, the volume reduction conditions include at least one of the following:

[0069] The length of messages sent within the preset time is less than the current length threshold;

[0070] The length of a preset number of consecutively sent messages is less than the current length threshold;

[0071] The current length threshold is determined based on the current size of the shared memory.

[0072] In this embodiment, the current length threshold can be understood as the threshold of the message length at the current moment, which can be determined based on the current size of the shared memory. For example, if the current size of the shared memory is N and the queue depth is Q, the current length threshold = N / Q. Alternatively, if the estimated memory size corresponding to the current shared memory is N1, the current length threshold is N1 / 2, and so on. The preset time can be understood as a pre-set period of time, such as 5 minutes, 10 minutes, etc. The preset quantity can be pre-set, for example, the message transmission speed is determined according to the service type, and the preset quantity is determined according to the message transmission speed.

[0073] The current length threshold can also be preset to a fixed value. For example, it can be set according to the business type, or the current length threshold can be the same as the initial value of the estimated memory size, and so on.

[0074] Retrieve messages sent within a preset time period and determine their lengths. If the length of each message is less than the current length threshold, the scaling-down condition is met. Retrieving messages sent within the preset time period can be done by starting from the current time and moving backwards by a preset time period, retrieving the information transmitted within the time interval formed by the start and end points. Retrieve a preset number of consecutively sent messages and determine their lengths. If the length of each message is less than the current length threshold, the scaling-down condition is met. Retrieving the preset number of consecutively sent messages can be done by starting from the most recently transmitted message and moving backwards by a preset number of consecutive messages. Alternatively, both of the above conditions must be met to determine that the scaling-down condition is met.

[0075] Optionally, the volume reduction conditions may also include at least one of the following:

[0076] The number of messages whose length is less than the current length threshold sent within a preset time is greater than the first preset number threshold.

[0077] The number of messages with a length shorter than the current length threshold among the preset number of messages sent continuously exceeds the second preset number threshold.

[0078] The system retrieves messages sent within a preset time period, determines the message length, and counts the number of messages with a length less than the current length threshold. If the number of such messages exceeds a preset threshold, the system is deemed to meet the scaling-down condition. The first preset threshold can be determined based on the number of messages sent within the preset time period. For example, the first preset threshold is equal to 90% of the number of messages sent within the preset time period. For instance, if 20 messages sent within 5 minutes have a length greater than the current length threshold, the scaling-down condition is met. The system also retrieves a preset number of consecutively sent messages, determines the message length, and counts the number of messages with a length less than the current length threshold. If the number of such messages exceeds a second preset threshold, the system is deemed to meet the scaling-down condition. For instance, if 15 out of 20 consecutive messages have a length greater than the current length threshold, the scaling-down condition is met.

[0079] Optionally, the size of the shared memory can be reduced, including:

[0080] B1. Get the set of sent messages.

[0081] In this embodiment, the sent message set can be understood as the collection of messages that have been sent. Starting from the current time, messages sent before the current time are retrieved, i.e., sent messages, to obtain the sent message set. For example, a certain number of sent messages can be retrieved to form the sent message set, or sent messages within a certain period of time can be retrieved to form the sent message set, and so on.

[0082] B2. Determine the size of the shared memory after scaling down based on the message length of the sent messages in the sent message set, and then scale down the shared memory according to the size of the scaled-down shared memory.

[0083] The system analyzes the sent messages in the sent message set to determine the message length of each message. Based on these lengths, it performs analytical calculations, such as calculating the average, maximum, minimum, and median. The size of the shared memory after scaling down is determined based on the calculation results. For example, the result can be used directly as the new shared memory size, or the system can determine if the result is a power of 2. If it is, the result is used as the new shared memory size; otherwise, the system identifies the smallest difference between the new and the new shared memory, which is greater than the power of 2 of the original result, and uses this value as the new shared memory size. The shared memory is then scaled down based on this new size, and new shared memory is allocated to facilitate message transmission, avoiding resource waste caused by excessive memory usage and conserving resources.

[0084] When the set of sent messages is empty, it can be reduced in size according to a preset value or a preset multiple.

[0085] After shrinking the shared memory, the sending process can notify the receiving process that it has re-allocated the shared memory, and the sending and receiving processes will communicate using the newly allocated shared memory. If the shared memory remains unchanged, the sending and receiving processes will communicate using the originally allocated shared memory.

[0086] The communication method provided in this invention solves the problem that variable-length messages cannot use shared memory for zero-copy inter-process communication. When sending a message, if the message length is greater than the estimated memory size, the shared memory is expanded according to the message length, the size of the expanded shared memory is determined, and new shared memory is requested to send the message. During message sending, expansion can be performed when the estimated memory size is less than the message length, enabling zero-copy inter-process communication of variable-length messages through shared memory without the need for precise pre-estimation of the message length. When the shrinkage condition is met, the shared memory is shrunk, avoiding resource waste and saving resources. The method in this application can be applied to sending both variable-length and fixed-length messages, without limiting the message type, and its use is flexible and adaptable.

[0087] Example 3

[0088] Figure 6 This is a schematic diagram of a communication device provided in Embodiment 3 of the present invention. Figure 6 As shown, the device includes: a message acquisition module 31 to be sent, a capacity expansion module 32, and a message sending module 33.

[0089] The message to be sent acquisition module 31 is used to acquire the message to be sent and determine the message length of the message to be sent.

[0090] The expansion module 32 is used to expand the shared memory according to the message length if the message length is greater than the estimated memory size, and to determine the size of the expanded shared memory, wherein the size of the shared memory is determined according to the estimated memory size.

[0091] The message sending module 33 is used to request new shared memory based on the expanded size of the shared memory, and send the message to be sent based on the new shared memory.

[0092] The communication device provided in this invention solves the problem that variable-length messages cannot use shared memory for zero-copy inter-process communication. First, the message length of the message to be sent is determined. The message length is compared with the estimated memory size. If the message length is greater than the estimated memory size, the shared memory is expanded according to the message length. The size of the expanded shared memory is determined, and new shared memory is requested to send the message. During message sending, expansion can be performed when the estimated memory size is less than the message length, enabling zero-copy inter-process communication of variable-length messages through shared memory without the need for precise pre-estimation of the message length. The method in this application can be applied to sending both variable-length and fixed-length messages, without limiting the message type, and its use is flexible and adaptable.

[0093] Optionally, the device may also include:

[0094] The estimated initial memory value determination module is used to determine the initial value of the estimated memory size;

[0095] Optionally, the estimated initial memory value determination module is specifically used for: obtaining the variable-length message type transmitted by the shared memory; determining the number of storable elements based on the variable-length message type; and determining the initial value of the estimated memory size based on the number of storable elements and the predetermined fixed-length message length.

[0096] Optionally, the initial value of the size of the shared memory is the estimated memory length;

[0097] The device also includes an estimated memory length determination module, used to determine the estimated memory length based on the product of the initial value of the estimated memory size and the pre-configured queue depth.

[0098] Optional, expansion module 32 includes:

[0099] The expansion size determination unit is used to determine the estimated memory size after expansion based on the product of the message length and a preset parameter, wherein the preset parameter is determined according to the data structure of the memory;

[0100] The memory expansion determination unit is used to determine the size of the expanded shared memory based on the product of the estimated expanded memory size and the queue depth.

[0101] Optionally, the device may also include:

[0102] The shrinking module is used to shrink the size of the shared memory when it is detected that the shrinking condition is met.

[0103] Optionally, the volume reduction conditions include at least one of the following:

[0104] The length of messages sent within the preset time is less than the current length threshold;

[0105] The length of a preset number of consecutively sent messages is less than the current length threshold;

[0106] The current length threshold is determined based on the current size of the shared memory.

[0107] Optional, the shrinkage module includes:

[0108] The message set acquisition unit is used to acquire the set of sent messages;

[0109] The shrinking unit is used to determine the size of the shrunken shared memory based on the message length of the sent messages in the sent message set, and to shrink the shared memory according to the size of the shrunken shared memory.

[0110] The communication device provided in the embodiments of the present invention can execute the communication method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of executing the method.

[0111] Example 4

[0112] Figure 7 A schematic diagram of an electronic device 40 that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.

[0113] like Figure 7As shown, the electronic device 40 includes at least one processor 41 and a memory, such as a read-only memory (ROM) 42 or a random access memory (RAM) 43, communicatively connected to the at least one processor 41. The memory stores computer programs executable by the at least one processor. The processor 41 can perform various appropriate actions and processes based on the computer program stored in the ROM 42 or loaded into the RAM 43 from storage unit 48. The RAM 43 may also store various programs and data required for the operation of the electronic device 40. The processor 41, ROM 42, and RAM 43 are interconnected via a bus 44. An input / output (I / O) interface 45 is also connected to the bus 44.

[0114] Multiple components in electronic device 40 are connected to I / O interface 45, including: input unit 46, such as keyboard, mouse, etc.; output unit 47, such as various types of monitors, speakers, etc.; storage unit 48, such as disk, optical disk, etc.; and communication unit 49, such as network card, modem, wireless transceiver, etc. Communication unit 49 allows electronic device 40 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0115] Processor 41 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 41 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 41 performs the various methods and processes described above, such as communication methods.

[0116] In some embodiments, the communication method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 48. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 40 via ROM 42 and / or communication unit 49. When the computer program is loaded into RAM 43 and executed by processor 41, one or more steps of the communication method described above may be performed. Alternatively, in other embodiments, processor 41 may be configured to perform the communication method by any other suitable means (e.g., by means of firmware).

[0117] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0118] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0119] This invention provides a computer program product, which includes a computer program that, when executed by a processor, implements the communication method described in any embodiment of this invention.

[0120] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0121] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0122] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.

[0123] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.

[0124] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.

[0125] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A communication method, characterized in that, include: Obtain the message to be sent and determine the message length of the message to be sent; If the message length is greater than the estimated memory size, the shared memory is expanded according to the message length, and the size of the expanded shared memory is determined based on the estimated memory size. Request new shared memory based on the expanded shared memory size, and send the message to be sent based on the new shared memory.

2. The method according to claim 1, characterized in that, The steps for determining the initial value of the estimated memory size include: Get the type of variable-length message transmitted in shared memory; The number of elements that can be stored is determined based on the variable-length message type; The initial value of the estimated memory size is determined based on the number of storable elements and the predetermined fixed-length message.

3. The method according to claim 2, characterized in that, The initial value of the shared memory size is the estimated memory length, and the steps for determining the estimated memory length include: The estimated memory length is determined by multiplying the initial value of the estimated memory size by the pre-configured queue depth.

4. The method according to claim 1, characterized in that, The step of expanding the shared memory according to the message length and determining the size of the expanded shared memory includes: The estimated memory size after expansion is determined by multiplying the message length by a preset parameter, wherein the preset parameter is determined based on the memory's data structure. The size of the expanded shared memory is determined by multiplying the estimated expanded memory size by the queue depth.

5. The method according to any one of claims 1-4, characterized in that, Also includes: When the shrinkage condition is detected, the size of the shared memory is shrunk.

6. The method according to claim 5, characterized in that, The volume reduction conditions include at least one of the following: The length of messages sent within the preset time is less than the current length threshold; The length of a preset number of consecutively sent messages is less than the current length threshold; The current length threshold is determined based on the current size of the shared memory.

7. The method according to claim 5, characterized in that, The reduction of the size of the shared memory includes: Get the collection of sent messages; The size of the scaled-down shared memory is determined based on the message length of the sent messages in the sent message set, and the scaled-down shared memory is then scaled down based on the size of the scaled-down shared memory.

8. A communication device, characterized in that, include: The message to be sent acquisition module is used to acquire the message to be sent and determine the message length of the message to be sent. The expansion module is used to expand the shared memory according to the message length if the message length is greater than the estimated memory size, and to determine the size of the expanded shared memory, wherein the size of the shared memory is determined according to the estimated memory size; The message sending module is used to request new shared memory based on the expanded size of the shared memory, and send the message to be sent based on the new shared memory.

9. An electronic device, characterized in that, The electronic device includes: At least one processor, and a memory communicatively connected to said at least one processor; The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the communication method according to any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that are used to cause a processor to execute the communication method according to any one of claims 1-7.

11. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the communication method according to any one of claims 1-7.