Communication method, device, electronic device and storage medium
By determining an alternative storage area among multiple storage areas and selecting a target storage area with faster processing speed to save messages, the problem of CPU waiting in RDMA communication is solved, and cache utilization and communication efficiency are improved.
Patent Information
- Application Number
- CN202411858510.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-16
- Publication Date
- 2025-04-08
AI Technical Summary
When using the RDMA network protocol for communication, after the CPU processes messages in a small part of the storage area through cache, it needs to wait for the CPU to process messages in other storage areas through memory, resulting in low cache utilization and reducing communication efficiency.
By receiving messages sent by the peer, the message processing status of multiple storage areas is obtained, the unprocessed alternative storage areas are determined, and the message is saved to the target storage area with a faster processing speed, thereby avoiding the phenomenon of CPU waiting.
Improve cache utilization, reduce CPU waiting time, and improve communication efficiency.
Smart Images

Figure CN119781971A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a communication method, device, electronic device and storage medium. Background Art
[0002] With the rapid development of computer technology, Remote Direct Memory Access (RDMA) network protocol has become a more commonly used communication method due to its advantages of high bandwidth, low latency, and low central processing unit (CPU) consumption.
[0003] Typically, when communicating using the RDMA network protocol, the sender and receiver can send messages to the queue of the other end for processing. A small portion of the storage area is processed by the CPU through the cache at a faster speed, while most of the storage area is processed by the CPU through the memory at a slower speed.
[0004] In the related art, each time a message is transmitted to the other end, the message is saved in the storage area in the queue in turn. After the CPU processes the messages in a small part of the storage area through the cache, it takes a lot of time to wait for the CPU to process the messages in other storage areas through the memory before it can process the corresponding messages through the cache again, resulting in low cache utilization and reduced communication efficiency. Summary of the invention
[0005] In order to solve the problems in the above-mentioned prior art, the example of the present application provides a communication method, device, electronic device and storage medium, which can timely allocate the storage area for message storage according to the message processing status, increase the cache utilization rate, and improve the efficiency of communication.
[0006] In a first aspect, an embodiment of the present application provides a communication method, including:
[0007] Receive messages sent by the peer end;
[0008] Acquire a message processing status of each storage area in a plurality of storage areas, and determine a candidate storage area in which a message processing status is unprocessed among the plurality of storage areas based on the message processing status; wherein the message processing status indicates whether a message is stored in the storage area;
[0009] The message is saved in a target storage area among the candidate storage areas, wherein a processing speed for the message in the target storage area is faster than a processing speed for the message in at least one non-target storage area among the candidate storage areas.
[0010] By first determining the alternative storage area in multiple storage areas and then selecting the target storage area with a faster message processing speed from the alternative storage area, it is possible to avoid the problem that after the CPU completes processing the messages in a small part of the storage area through the cache, it takes a lot of time to wait for the CPU to process the messages in other storage areas through the memory. The target storage area selected each time must be faster than the storage area processed by the CPU through the memory, which increases the cache utilization and improves the communication efficiency.
[0011] In a possible implementation manner, before receiving the message sent by the peer end, the method further includes:
[0012] According to the capacity of the storage area and the remaining capacity of the storage space, a plurality of storage areas are sequentially divided in the storage space, wherein the capacity of the storage area is determined based on information input by a user and / or for different message processing speeds in the storage space.
[0013] Compared with the prior art in which the maximum message length is set as the storage space size, resulting in a reduction in the amount of storage space that a cache of the same size can accommodate, the present application can use the above method to set different storage space sizes according to different situations, thereby improving the utilization of the cache space and improving the efficiency of communication.
[0014] In a possible implementation manner, the step of saving the message to a target storage area in the candidate storage area includes:
[0015] Determine a field of the target storage area based on an offset of the target storage area and a field of a first storage area of the plurality of storage areas;
[0016] The message is saved according to the field of the target storage area.
[0017] Through the above method, messages no longer need to be saved in sequence. Instead, after the target storage area is determined, the specific location of the target storage area can be determined according to the relevant information of the target storage area, and the message can be saved. Compared with the existing technology, it is more flexible and can save the message to any storage area as needed.
[0018] In a possible implementation, the saving of the message according to the field of the target storage area includes:
[0019] If the length of the message is less than or equal to the remaining capacity of the target storage area, the message is saved in the target storage area.
[0020] Through the above method, it can be determined whether the message can be saved in the corresponding target storage area according to the remaining capacity of the target storage area and the length of the message, and at the same time, it can be prepared for the situation where the message cannot be saved later.
[0021] In a possible implementation, the method further includes:
[0022] If the length of the message is greater than the remaining capacity of the target storage area, determining a target number of the additional storage blocks based on the length of the message and the size of the additional storage blocks;
[0023] Determine the corresponding additional storage area according to the target number of the additional storage blocks, and save the fields of the additional storage area into the target storage area; the additional storage area and the target storage area are located in different storage spaces;
[0024] The message is saved in the additional storage area.
[0025] If the message length is too long and is stored in the target storage area, the process of the CPU confirming whether there is a message in each storage area each time will become cumbersome, and the CPU needs to traverse the messages in each storage area. Messages that are too large will cause the CPU processing performance to decrease. By setting an additional storage area, once the CPU determines that the target storage area contains relevant information of the additional storage area by reading the target storage area, it can be determined that there is a message in the target storage area, which can reduce the burden on the CPU in confirming the target storage area.
[0026] In a possible implementation manner, determining the corresponding additional storage area according to the target number of additional storage blocks includes:
[0027] determining a maximum number of consecutive additional storage blocks that do not store messages from the plurality of additional storage blocks;
[0028] If the maximum number is greater than or equal to the target number, the target number of additional storage blocks are divided into additional storage areas corresponding to the target storage area.
[0029] The additional storage area corresponding to the target storage area in the plurality of additional storage blocks may be determined in the above manner, and after the additional storage area is determined, the message may be saved in the corresponding additional storage area.
[0030] In a possible implementation manner, after the message is saved in the additional storage area corresponding to the target storage area, the method further includes:
[0031] In response to an access request to the target storage area, read the target data stored in the target storage area;
[0032] If the target data includes a message identifier, transmitting the message corresponding to the message identifier to the device that sent the access request;
[0033] If the target data includes the field of the additional storage area, the message stored in the additional storage area corresponding to the field of the additional storage area is transmitted to the device that sends the access request.
[0034] Through the above method, different operations can be performed to determine whether data or related information of the corresponding additional storage area is stored in the target storage area, so that the device sending the access request can receive the required message.
[0035] In a second aspect, an embodiment of the present application provides a communication device, including:
[0036] The candidate storage area determination unit is configured to receive a message sent by a peer end; obtain a message processing status of each storage area in a plurality of storage areas, and determine a candidate storage area in which a message processing status of the plurality of storage areas is unprocessed based on the message processing status; wherein the message processing status indicates whether a message is stored in the storage area;
[0037] The message saving unit is used to save the message to a target storage area in the candidate storage areas, wherein a processing speed for the message in the target storage area is faster than a processing speed for the message in at least one non-target storage area in the candidate storage areas.
[0038] In a third aspect, an embodiment of the present application provides an electronic device, including:
[0039] A memory for storing program instructions;
[0040] The processor is used to call the program instructions stored in the memory and execute the steps included in the method described in the first aspect according to the obtained program instructions.
[0041] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in any one of the first aspects is implemented.
[0042] The present application example provides a communication method, device, electronic device and storage medium, which can receive messages sent by the other party, obtain the message processing status of each storage area in multiple storage areas, and determine the alternative storage area with the message processing status as unprocessed in the multiple storage areas based on the message processing status. Finally, the message can be saved to the target storage area in the alternative storage area, wherein the processing speed of the message in the target storage area is faster than the processing speed of the message in at least one non-target storage area in the alternative storage area. Through the communication method provided by the present application, the target storage area can be judged after each message sent by the other party is received, instead of simply saving the message in multiple storage areas in sequence. This can avoid the situation where the CPU needs to wait a lot of time to wait for the CPU to process the messages in other storage areas through the memory after completing the processing of the messages in a small part of the storage areas through the cache before processing the corresponding messages again through the cache. The storage area for saving the message can be allocated in time according to the message processing status, thereby increasing the cache utilization rate and improving the communication efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0044] Figure 1 A schematic diagram of an application scenario of a communication method provided in an embodiment of the present application;
[0045] Figure 2 A flow chart of a communication method provided in an embodiment of the present application;
[0046] Figure 3 A schematic diagram of a queue provided in an embodiment of the present application;
[0047] Figure 4 A schematic diagram of an additional storage area provided in an embodiment of the present application;
[0048] Figure 5 A schematic diagram of another additional storage area provided in an embodiment of the present application;
[0049] Figure 6 A schematic diagram of another additional storage area provided in an embodiment of the present application;
[0050] Figure 7 A specific flow chart of a communication method provided in an embodiment of the present application;
[0051] Figure 8A structural block diagram of a communication device provided in an embodiment of the present application;
[0052] Fig. 9 A structural block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0053] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Among them, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0054] In the description of the embodiments of the present application, unless otherwise specified, "and" means or. For example, A / B can mean A or B. The "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0055] Specifically, in the description of the present application, it needs to be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", "clockwise", "counterclockwise" and the like indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the referred device or element must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present application, and, unless otherwise specified, the "connection" and "connection" mentioned in the present application include direct and indirect connections (connections).
[0056] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0057] The present application is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0058] In one possible embodiment, Figure 1 A schematic diagram of an application scenario of a communication method provided in an embodiment of the present application is shown. Figure 1 As shown, Figure 1 The system includes a message sending end 100 and a message receiving end 200. The message sending end 100 is connected to a queue 110, and the queue 110 includes multiple storage areas. Similarly, the message receiving end 200 is connected to a queue 210, and the queue 210 includes multiple storage areas. The queue 210 connected to the message receiving end 200 can receive messages sent by the message sending end 100, and the queue 110 connected to the message sending end 100 can also receive messages sent by the message receiving end 200. For example, the message sending end 100 can write a request message into the queue 210 of the message receiving end 200 through a write operation in the RDMA protocol, and the message receiving end 200 can extract the received message for processing by querying the queue 210 in a round-robin manner, and then write a response message into the queue 110 of the message sending end 100 through a write operation in the RDMA protocol, and the message sending end 100 can extract the received message for processing by querying the queue 110 in a round-robin manner.
[0059] Among them, the message sending end 100 and the message receiving end 200 can both be mobile phones, tablet computers, and portable wearable devices, etc. Among them, the portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. It should be noted that the number of message sending ends 100 and message receiving ends 200 is not limited in this application. There can be multiple message sending ends 100 sending messages to the message receiving end 200, and there can be multiple message receiving ends 200 receiving messages sent by the message sending end 100. The same is that before the message reaches the corresponding device, it must be sent to the queue before the device. Therefore, the communication method provided in the embodiment of the present application can be applied to both the message sending end 100 and the message receiving end 200.
[0060] Figure 1 The application scenario is only an example of an application scenario for implementing the embodiment of the present application. The embodiment of the present application is not limited to the above Figure 1 The application scenarios described. The fault testing method provided by the exemplary embodiment of the present application is described below with reference to the accompanying drawings in combination with the application scenarios described above. It should be noted that the application scenarios described above are only shown to facilitate understanding of the spirit and principles of the present application, and the implementation of the present application is not limited in this respect.
[0061] Figure 2 A flow chart of a communication method provided in an embodiment of the present application is shown. Figure 2 As shown, the method may include the following steps:
[0062] Step S201, receiving a message sent by a peer end, and obtaining a message processing status of each storage area in a plurality of storage areas.
[0063] In a possible embodiment, if the present application is applied to a message receiving end, the opposite end is a message sending end; if the present application is applied to a message sending end, the opposite end is a message receiving end. The following description is based on the application to the message receiving end and the opposite end is a message sending end. Before the communication starts, that is, before the message receiving end receives the message sent by the message sending end, the creation of the queue corresponding to the message receiving end can be realized in the following manner: according to the capacity of the storage area and the remaining capacity of the storage space, a plurality of storage areas are divided in sequence in the storage space. Among them, the storage space is divided out in advance from the computing device of the receiving end, and different sizes can be selected as needed, which can be 2MB or 3MB and other values, which are not limited in this application. Subsequently, the remaining capacity of the storage space is determined in the divided storage space, thereby completing the sequential division of the storage area. Similarly, the storage area can also select different sizes as needed, which can be 10KB or 15KB and other values, which are not limited in this application.
[0064] In a possible embodiment, among the multiple storage areas divided, the messages stored in a part of the storage areas are processed by the CPU through the cache at a faster speed, and this part of the storage area can be called the first storage area; the other part of the storage area is processed by the CPU through the memory at a slower speed, and this part of the storage area can be called the second storage area. Generally speaking, the first storage area is much smaller than the second storage area, but the message processing speed in the first storage area is much faster than the message processing speed in the second storage area. Generally, the storage area with a faster message processing speed is closer to the front. It should be noted that it is also possible that multiple storage areas can be divided into more parts according to different message processing speeds, and this application is not limited here. It should be noted that it can be considered that the storage area that takes a shorter time to process messages of the same length has a faster message processing speed. For example, for a 10KB message, the processing speed of storage area 1 is 1ms, and the processing speed of storage area 2 is 2ms, then it can be considered that the processing speed of the message in storage area 1 is faster than the processing speed of the message in storage area 2.
[0065] The purpose of the present application is to improve the utilization rate of the first storage area. Therefore, the size of the storage area can be determined based on the message processing speed in the first storage area and the message processing speed in the second storage area. For example, if the message processing speed in the first storage area is significantly different from the message processing speed in the second storage area, the storage area can be divided into a smaller size. Similarly, if the message processing speed in the first storage area is slightly different from the message processing speed in the second storage area, the storage area can be divided into a larger size. In addition to determining the size of the storage area based on the message processing speed in the first storage area and the message processing speed in the second storage area, the user's input can also be directly received. For example, the user knows that during the communication process, the maximum length of the message is 10KB and the minimum is 2KB, then 6KB can be entered as the size of the storage area. The above two methods can be combined or executed separately, and the present application does not limit this.
[0066] In one possible embodiment, Figure 3 A schematic diagram of a queue provided in an embodiment of the present application is shown, such as Figure 3 As shown, in Figure 3 There are four storage areas, storage area 1, storage area 2, storage area 3 and storage area 4, each of which contains two storage blocks, which are used to store message content and message information respectively. For example, storage area 1 contains a storage block for storing message 1, and another storage block for storing information 1. Storage area 2 contains a storage block for storing message 2, and another storage block for storing information 2, etc. Among them, the message information may include a check value for determining whether to store a message, a storage area field for storing the current message, and a storage area field for storing the next message. For example, when traversing to the storage block for storing information 1, the CPU can confirm based on the information stored in the storage block that the message has been stored in storage area 1, the storage area field for storing the current message is AAA, and the storage area corresponding to AAA is storage area 1; the storage area field for storing the next message is BBB, and the storage area corresponding to BBB is storage area 2.
[0067] In a possible embodiment, after the storage space is divided, step S201 can be continued. After receiving the message sent by the message sending end, the message receiving end needs to save the message to the storage space of the queue corresponding to the message receiving end. Before saving, each storage area can be traversed to determine whether there is a message stored in each storage area, that is, the message processing status of each storage area in multiple storage areas is obtained. Among them, the message processing status can be processing or unprocessed. If there is a message in any storage space, the message processing status of the storage space can be set to processing; if there is no message in any storage space, the message processing status of the storage space can be set to unprocessed.
[0068] Step S202: determining, based on the message processing status, a candidate storage area whose message processing status is unprocessed among multiple storage areas.
[0069] In a possible embodiment, a storage area with a message processing status of unprocessed can be used as an alternative storage area. For example, the storage area with a message processing status of unprocessed includes storage area 1, storage area 2, and storage area 4, then storage area 1, storage area 2, and storage area 4 can all be used as alternative storage areas.
[0070] Step S203: save the message to a target storage area in the candidate storage areas.
[0071] In a possible embodiment, a target storage area can be selected from the candidate storage areas, wherein the processing speed of messages in the target storage area should be faster than the processing speed of messages in at least one non-target storage area in the candidate storage area. For example, the processing speed of messages in storage area 1 is faster than the processing speed of messages in storage area 2, the processing speed of messages in storage area 2 is faster than the processing speed of messages in storage area 3, and the processing speed of messages in storage area 3 is faster than the processing speed of messages in storage area 4. If the four storage areas in storage area 1-storage area 4 are all candidate areas, any one storage area can be selected from storage area 1-storage area 3 as the target storage area; if the three storage areas in storage area 1-storage area 3 are all candidate areas, any one storage area can be selected from storage area 1-storage area 2 as the target storage area; if storage area 1 and storage area 2 are both candidate areas, storage area 1 can be selected as the target storage area. That is to say, except for the slowest alternative area, the target storage area can be any other alternative area, or the target storage area can be set to a storage area with the fastest message processing speed among the alternative areas, or a storage area with a speed greater than a set threshold as needed. The present application does not make any limitation here. Compared with the related art, the changes in the target storage area selection process of the present application have greatly improved the utilization of the cache.
[0072] In another possible embodiment, if the order of the storage areas in the multiple storage areas is sorted according to the processing speed of the messages in each storage area, a bitmap can be used to manage the queue. In the bitmap, the same number of storage blocks as the storage areas is stored, and each storage block is in a one-to-one correspondence with the storage area. The first storage area corresponds to the first storage block in the bitmap, and the second storage area corresponds to the second storage block in the bitmap. In addition, two numbers 0 or 1 are stored in each storage block of the bitmap. The storage block with the stored number 0 is used to indicate that no message is stored in the corresponding storage area, and the storage block with the stored number 1 is used to indicate that a message is stored in the corresponding storage area. If there is no message stored in the storage area corresponding to a storage block, when a message is stored in the storage area corresponding to the storage block, the number stored in the storage block can be set from 0 to 1; if there is a message stored in the storage area corresponding to a storage block, when the message is processed by the CPU and released, the number stored in the storage block can be set from 1 to 0. After each message is received, it can be traversed from the first storage block in the bitmap until the first storage block storing the number 0 is determined, and the storage area corresponding to the storage block is the target storage area.
[0073] In a possible embodiment, after the target storage area is determined, the message can be saved according to the field of the target storage area. Specifically, the remaining capacity of the target storage area, that is, the capacity without storing any message or data, can be determined, and the remaining capacity can be compared with the length of the message. According to the result of the comparison, it is determined how to save the message.
[0074] If the length of the message is less than or equal to the remaining capacity of the target storage area, the message can be saved in the target storage area. For example, if the length of the message is 10KB, the capacity of the target storage area is 15KB, of which 2KB is occupied by other data, the remaining capacity is 13KB, which is greater than 10KB, so the message can be directly saved in the target storage area.
[0075] If the length of the message is greater than the remaining capacity of the target storage area, the number of additional storage blocks can be determined based on the length of the message and the size of the additional storage block, the corresponding additional storage area can be determined according to the target number of additional storage blocks, and the fields of the additional storage area are saved in the target storage area. Among them, the additional storage area and the target storage area are located in different storage spaces, so the body of the message written to the target storage area is not the same as the body of the message written to the additional storage area. If the length of the message is 14KB and the size of the additional storage block is 5KB, it can be determined that the number of additional storage blocks is 3. Under normal circumstances, the message will not be continued to be saved in the additional storage block where part of the message is stored. It is also necessary to save the fields of the additional storage area in the target storage area. When the CPU traverses to the target storage area, the corresponding additional storage area field can be read to determine which additional storage area the message is specifically saved in, and a message acquisition request can be issued to the additional storage area. The additional storage area can send the message to the CPU after receiving the message acquisition request.
[0076] In one possible embodiment, Figure 4 A schematic diagram of an additional storage area provided in an embodiment of the present application is shown. Figure 4 As shown, the extra storage area is divided into three rows. The first row is a number used to identify the location of each extra storage block. The second row is the size, which needs to be confirmed together with the status of the third row. The size in the second row refers to the number of adjacent extra storage blocks in the same state, which can be obtained from Figure 4 It can be concluded that the first additional storage block numbered 0 is occupied and has a size of 1, the second additional storage block numbered 1 is not occupied, and the 128th additional storage block numbered 127 is not occupied. Therefore, the size corresponding to the additional storage block numbered 1 is 127, the sizes corresponding to the additional storage blocks numbered 2 to 126 can be left blank, and the size corresponding to the additional storage block numbered 127 is 127. In this way, the size corresponding to the additional storage block can be determined by the value corresponding to the size in the first additional storage block and the value corresponding to the size in the last additional storage block.
[0077] In a possible embodiment, in the case of saving messages in an additional storage area, it is also necessary to determine the maximum number of continuous additional storage blocks that do not save messages before saving. If the maximum number is greater than or equal to the target number of required additional storage blocks, the target number of additional storage blocks can be divided into additional storage areas corresponding to the target storage area. For example, the maximum number of continuous additional storage blocks that do not save messages is 20, the target number of required additional storage blocks is 5, and 20 is greater than 5, so 5 additional storage blocks can be used as additional storage areas for saving messages. If the maximum number is less than the target number of required additional storage blocks, after the messages are processed in the additional storage blocks of other saved messages, it is possible to return to determine the maximum number of continuous additional storage blocks that do not save messages again until the messages are saved in the additional storage blocks.
[0078] It should be noted that after saving the message to the extra storage area, the state and size of the extra storage block need to be changed. Figure 5 A schematic diagram showing another additional storage area provided in an embodiment of the present application is shown. Figure 5 As shown, Figure 5 is Figure 4 Based on the data, 4 additional storage blocks are applied for storing messages, so Figure 5 and Figure 4 The difference is that Figure 5 The additional storage blocks numbered 1 to 4 are the 4 additional storage blocks applied for, so the status of the additional storage blocks numbered 1 to 4 is changed to occupied, wherein the sizes corresponding to the additional storage blocks numbered 1 and 4 can be changed to 4, and the sizes corresponding to the additional storage blocks numbered 2 and 3 can be left blank; the sizes corresponding to the additional storage blocks numbered 5 and 127 can be changed to 123, and the sizes corresponding to the additional storage blocks numbered 6 to 126 can be left blank.
[0079] In a possible embodiment, after the message processing is completed in the additional storage area, the state and size of the additional storage block also need to be changed. Figure 6 A schematic diagram showing another additional storage area provided in an embodiment of the present application is shown. Figure 6As shown, the additional storage block numbered 0 is occupied, the additional storage blocks numbered 1 and 2 are not occupied, the additional storage blocks numbered 3 and 4 are occupied by a message, and the additional storage blocks numbered 5-127 are occupied by another message. If the messages stored in the additional storage blocks numbered 3 and 4 are processed, the messages stored in the additional storage blocks numbered 3 and 4 can be released. After the release, the status of the additional storage blocks numbered 3 and 4 is not occupied, which is the same as the status of the additional storage blocks numbered 1 and 2, that is, they are all not occupied. Therefore, the additional storage blocks numbered 1-4 can be merged to form Figure 5 The additional storage area shown. It should be noted that applying for additional storage blocks of different sizes in the additional storage area to save messages will cause memory fragmentation problems during long-term operation. You can use multiple additional storage blocks of different sizes to form different additional storage areas.
[0080] By saving the message in the additional storage area, it is possible to avoid reading too much data in the process of determining the target storage area. For example, if there is a message of 2GB in size, which is saved in the first storage area among multiple storage areas, each time the target storage area corresponding to other messages is determined, it is necessary to determine which specific storage area does not store the message. In the process of determining whether the message is saved in the storage area, it is necessary to read whether the message is saved in the storage area, so it is necessary to read the 2GB message saved in the first storage area. However, the 2GB message is saved in the additional storage area, and the fields of the additional storage area are saved in the target storage area. Then, in the process of the CPU traversing the storage area, it only needs to read the fields of a few KB saved in the target storage area to determine whether the message is saved in the storage area, thereby avoiding the disadvantage of reading too much data in the process of determining the target storage area.
[0081] In a possible embodiment, in response to an access request for a target storage area, target data stored in the target storage area is read; if the target data contains a message identifier, that means the message corresponding to the message identifier is stored in the target storage area, and the message corresponding to the message identifier can be transmitted to the device that sends the access request; if the target data contains a field of an additional storage area, that means the message corresponding to the message identifier is stored in the additional storage area, and the field of the additional storage area is stored in the target storage area, and the message stored in the additional storage area corresponding to the field of the additional storage area can be transmitted to the device that sends the access request.
[0082] The present application example provides a communication method, device, electronic device and storage medium, which can receive messages sent by the other party, obtain the message processing status of each storage area in multiple storage areas, and determine the alternative storage area with the message processing status as unprocessed in the multiple storage areas based on the message processing status. Finally, the message can be saved to the target storage area in the alternative storage area, wherein the processing speed of the message in the target storage area is faster than the processing speed of the message in at least one non-target storage area in the alternative storage area. Through the communication method provided by the present application, the target storage area can be judged after each message sent by the other party is received, instead of simply saving the message in multiple storage areas in sequence. This can avoid the situation where the CPU needs to wait a lot of time to wait for the CPU to process the messages in other storage areas through the memory after completing the processing of the messages in a small part of the storage areas through the cache before processing the corresponding messages again through the cache. The storage area for saving the message can be allocated in time according to the message processing status, thereby increasing the cache utilization rate and improving the communication efficiency.
[0083] In one possible embodiment, Figure 7 A specific flow chart of a communication method provided in an embodiment of the present application is shown, such as Figure 7 As shown, the method comprises the following steps:
[0084] Step S701, dividing a plurality of storage areas in order in the storage space according to the capacity of the storage area and the remaining capacity of the storage space.
[0085] Step S702: Receive a message sent by the opposite end, and obtain a message processing status of each storage area in a plurality of storage areas.
[0086] Step S703: determining, based on the message processing status, a candidate storage area whose message processing status is unprocessed among the multiple storage areas.
[0087] Step S704: Select a target storage area from the candidate storage areas.
[0088] In a possible embodiment, a processing speed of messages in the target storage area is faster than a processing speed of messages in at least one non-target storage area in the candidate storage area.
[0089] Step S705, determining whether the message length is greater than the remaining capacity of the target storage area, if not, executing step S706; if yes, executing step S707.
[0090] Step S706: Save the message to the target storage area.
[0091] Step S707 , determining a target number of additional storage blocks based on the length of the message and the size of the additional storage blocks, and determining a maximum number of continuous additional storage blocks that do not store the message from the multiple additional storage blocks.
[0092] Step S708, determine whether the maximum number is less than the target number, if not, execute step S709; if yes, execute step S710.
[0093] Step S709: Divide the target number of extra storage blocks into extra storage areas corresponding to the target storage area. Then, step S711 is executed.
[0094] Step S710, wait for the message processing in any additional storage block to be completed, and return to step S707.
[0095] Step S711, saving the message into the additional storage area, and saving the fields in the additional storage area into the target storage area.
[0096] Based on the same inventive concept, Figure 8 A structural block diagram of a communication device provided in an embodiment of the present application, such as Figure 8 As shown, the communication device 800 may include:
[0097] The candidate storage area determination unit 801 is configured to receive a message sent by a peer end; obtain a message processing status of each storage area in a plurality of storage areas, and determine a candidate storage area in which a message processing status of the plurality of storage areas is unprocessed based on the message processing status; wherein the message processing status indicates whether a message is stored in the storage area;
[0098] The message saving unit 802 is configured to save the message to a target storage area in the candidate storage areas, wherein a processing speed for the message in the target storage area is faster than a processing speed for the message in at least one non-target storage area in the candidate storage areas.
[0099] In a possible implementation, the alternative storage area determination unit 801 is also used to divide a plurality of storage areas in sequence in the storage space according to the capacity of the storage area and the remaining capacity of the storage space, wherein the capacity of the storage area is determined based on information input by the user and / or for different message processing speeds in the storage space.
[0100] In a possible implementation, the message storage unit 802 is specifically configured to determine the field of the target storage area based on the offset of the target storage area and the field of the first storage area of the multiple storage areas;
[0101] The message is saved according to the field of the target storage area.
[0102] In a possible implementation, the message saving unit 802 is specifically configured to save the message in the target storage area if the length of the message is less than or equal to the remaining capacity of the target storage area.
[0103] In a possible implementation, the message storage unit 802 is further configured to determine the number of the additional storage blocks based on the length of the message and the size of the additional storage blocks if the length of the message is greater than the remaining capacity of the target storage area;
[0104] Determine the corresponding additional storage area according to the target number of the additional storage blocks, and save the fields of the additional storage area into the target storage area; the additional storage area and the target storage area are located in different storage spaces;
[0105] The message is saved in the additional storage area.
[0106] In a possible implementation, the message storage unit 802 is further configured to determine a maximum number of continuous additional storage blocks that do not store messages from the plurality of additional storage blocks;
[0107] If the maximum number is greater than or equal to the target number, the target number of additional storage blocks are divided into additional storage areas corresponding to the target storage area.
[0108] In a possible implementation manner, the message storage unit 802 is further configured to respond to an access request to the target storage area and read target data stored in the target storage area;
[0109] If the target data includes a message identifier, transmitting the message corresponding to the message identifier to the device that sent the access request;
[0110] If the target data includes the field of the additional storage area, the message stored in the additional storage area corresponding to the field of the additional storage area is transmitted to the device that sends the access request.
[0111] Based on the same inventive concept, the embodiment of the present application provides an electronic device, which can implement the functions of the communication method discussed above, please refer to Fig. 9 The electronic device 900 includes a memory 901, a processor 902 and a bus 903.
[0112] The memory 901 is used to store computer programs executed by the processor 902. The memory 901 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and programs required for running the instant messaging function, etc.; the data storage area may store various instant messaging information and operation instruction sets, etc.
[0113] The memory 901 may be a volatile memory, such as a random-access memory (RAM); the memory 901 may also be a non-volatile memory, such as a read-only memory, a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), or the memory 901 may be any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 901 may be a combination of the above memories.
[0114] The processor 902 may include one or more central processing units (CPU) or a digital processing unit, etc. The processor 902 is used to implement the communication method in the above embodiment when calling the computer program stored in the memory 901 .
[0115] The specific connection medium between the memory 901 and the processor 902 is not limited in the embodiment of the present application. Fig. 9 In the embodiment, the memory 901 and the processor 902 are connected via a bus 903. The bus 903 is connected to the processor 902 via a bus 903. Fig. 9 The connections between other components are shown in bold lines, which are only for illustration and are not intended to be limiting. Bus 903 can be divided into address bus, data bus, control bus, etc. For ease of illustration, Fig. 9 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0116] Based on the same inventive concept, the embodiment of the present application provides a computer-readable storage medium, and the computer program product includes: computer program code, when the computer program code is executed on a computer, the computer executes any of the communication methods discussed above. Since the principle of solving the problem by the above-mentioned computer-readable storage medium is similar to that of the communication method, the implementation of the above-mentioned computer-readable storage medium can refer to the implementation of the method, and the repeated parts will not be repeated.
[0117] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0118] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0119] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0120] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0121] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A communication method, characterized in that: include: Receive messages sent by the peer end; Acquire a message processing status of each storage area in a plurality of storage areas, and determine, based on the message processing status, a candidate storage area in which the message processing status of the plurality of storage areas is unprocessed; The message processing state indicates whether there is a message stored in the storage area; The message is saved in a target storage area among the candidate storage areas, wherein a processing speed for the message in the target storage area is faster than a processing speed for the message in at least one non-target storage area among the candidate storage areas.
2. The method according to claim 1, characterized in that Before receiving the message sent by the opposite end, the method further includes: According to the capacity of the storage area and the remaining capacity of the storage space, a plurality of storage areas are sequentially divided in the storage space, wherein the capacity of the storage area is determined based on information input by a user and / or for different message processing speeds in the storage space.
3. The method according to claim 1, characterized in that The step of saving the message to a target storage area in the candidate storage area includes: Determine a field of the target storage area based on an offset of the target storage area and a field of a first storage area of the plurality of storage areas; The message is saved according to the field of the target storage area.
4. The method according to any one of claims 1 to 3, characterized in that: The step of saving the message according to the field of the target storage area includes: If the length of the message is less than or equal to the remaining capacity of the target storage area, the message is saved in the target storage area.
5. The method according to claim 4, characterized in that The method further comprises: If the length of the message is greater than the remaining capacity of the target storage area, determining a target number of the additional storage blocks based on the length of the message and the size of the additional storage blocks; Determine the corresponding additional storage area according to the target number of the additional storage blocks, and save the fields of the additional storage area into the target storage area; the additional storage area and the target storage area are located in different storage spaces; The message is saved in the additional storage area.
6. The method according to claim 5, characterized in that The determining the corresponding additional storage area according to the target number of additional storage blocks includes: determining a maximum number of consecutive additional storage blocks that do not store messages from the plurality of additional storage blocks; If the maximum number is greater than or equal to the target number, the target number of additional storage blocks are divided into additional storage areas corresponding to the target storage area.
7. The method according to claim 5, characterized in that After the message is saved in the additional storage area corresponding to the target storage area, the method further includes: In response to an access request to the target storage area, read the target data stored in the target storage area; If the target data includes a message identifier, transmitting the message corresponding to the message identifier to the device that sent the access request; If the target data includes the field of the additional storage area, the message stored in the additional storage area corresponding to the field of the additional storage area is transmitted to the device that sends the access request.
8. A communication device, characterized in that: include: A candidate storage area determination unit, configured to receive a message sent by a peer end; Acquire a message processing status of each storage area in a plurality of storage areas, and determine, based on the message processing status, a candidate storage area in which the message processing status of the plurality of storage areas is unprocessed; The message processing state indicates whether there is a message stored in the storage area; The message saving unit is used to save the message to a target storage area in the candidate storage area, wherein a processing speed for the message in the target storage area is faster than a processing speed for the message in at least one non-target storage area in the candidate storage area.
9. An electronic device, characterized in that: include: A memory for storing program instructions; A processor is used to call the program instructions stored in the memory, and execute the steps included in any one of claims 1-7 according to the obtained program instructions.
10. A computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.