Message sending method, device, equipment and readable storage medium

By obtaining and adjusting the CPU's message sending queue and target interval, the problem of packet loss caused by the high CPU sending frequency in DPDK technology is solved, and efficient and stable message sending is achieved.

CN116233039BActive Publication Date: 2024-09-17BEIJING XINERTEL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310077361.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-01-13
Publication Date
2024-09-17
Estimated Expiration
2043-01-13

AI Technical Summary

Technical Problem

In DPDK technology, when the CPU transmission frequency of the high-performance tester is greater than the hardware port frequency, it causes packet loss problems, which is difficult to effectively solve with existing technology.

Method used

By obtaining the number of messages in the queue to be sent and the CPU and the target sending interval, the CPU clock accuracy and the preset sending interval are used to adjust the message sending frequency to ensure that no packets are lost, and to adapt to the sending intervals of different message lengths. Improve efficiency.

Benefits of technology

It effectively reduces the probability of packet loss during message sending, improves message sending efficiency and stability, and adapts to the sending needs of different message lengths.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116233039B
    Figure CN116233039B
Patent Text Reader

Abstract

The present application relates to the field of data transmission, especially to a method, device, equipment and readable storage medium for sending messages, and the method includes: obtaining a queue to be sent, the number of messages sent by the CPU each time, and a target message sending interval; sending messages to be sent according to the number of messages and the target message sending interval; the process of obtaining the target message sending interval includes: obtaining the CPU clock accuracy, a preset CPU message sending interval and multiple simulated messages; based on the number of messages and the preset CPU message sending interval, sending to determine whether all simulated messages are successfully sent; if so, using the preset CPU message sending interval as the target message sending interval; if not, obtaining a new CPU message sending interval according to the CPU clock accuracy and the preset CPU message sending interval and using it as the preset CPU message sending interval, until all simulated messages are successfully sent, and obtaining the target message sending interval. The present application has the effect of reducing the number of packet losses.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of data transmission, and in particular to a message sending method, apparatus, device and readable storage medium. Background Art

[0002] Generally, in DPDK technology (Intel Data Plane Development Kit), the CPU in a high-performance tester sends multiple messages to a hardware port, and then the hardware port forwards the multiple messages to the network to test the network speed.

[0003] However, when a hardware port fails, the high-performance tester needs to replace the hardware port, and the CPU's sending frequency may be greater than the hardware port's sending frequency, resulting in packet loss.

[0004] Therefore, how to provide a solution to the above technical problems is a problem that those skilled in the art need to solve at present. Summary of the invention

[0005] In order to reduce the number of packet losses, the present application provides a message sending method, apparatus, device and readable storage medium.

[0006] In a first aspect, the present application provides a method for sending a message, which adopts the following technical solution:

[0007] A message sending method, comprising:

[0008] Obtain a queue to be sent, where the queue to be sent includes multiple messages to be sent;

[0009] Get the number of messages sent by the CPU each time and the target message sending interval of the CPU;

[0010] According to the number of messages sent by the CPU each time and the target message sending interval, multiple messages to be sent in the waiting-to-send queue are sent;

[0011] The process of obtaining the target message sending interval of the CPU includes:

[0012] Get CPU clock accuracy, preset CPU message sending interval and multiple simulated messages;

[0013] Based on the number of messages sent by the CPU each time and the preset CPU message sending interval, sending the multiple simulation messages, and determining whether all the multiple simulation messages are sent successfully;

[0014] If yes, the preset CPU message sending interval is used as the target message sending interval of the CPU;

[0015] If not, obtaining a new CPU message sending interval according to the CPU clock accuracy and the preset CPU message sending interval;

[0016] The new CPU message sending interval is used as the preset CPU message sending interval, and based on the preset CPU message sending interval and the number of messages sent by the CPU each time, the multiple simulated messages are sent, and it is determined whether all the simulated messages are sent successfully, until all the multiple simulated messages are sent successfully, so as to obtain the target message sending interval of the CPU.

[0017] By adopting the above technical solution, after obtaining the queue to be sent, the number of messages sent by the CPU each time and the target message sending interval of the CPU that can ensure that no packet loss occurs during the message sending process are obtained. Based on the CPU clock accuracy, the number of messages sent by the CPU each time and the preset CPU message sending interval, multiple simulated messages are sent, and it is determined whether all the multiple simulated messages are sent successfully; if so, it is determined that no packet loss occurs, and the preset CPU message sending interval can be used as the target message sending interval of the CPU; if not, it indicates that packet loss still occurs, and based on the CPU clock accuracy, the preset CPU message sending interval The scheme uses the CPU clock accuracy and the preset CPU message sending interval to adjust the sending interval, which can reduce the number of packet losses caused by the CPU clock accuracy being less than the hardware port clock accuracy; until multiple simulated messages are all sent successfully to obtain the CPU's target message sending interval; and then according to the number of messages sent by the CPU each time and the target message sending interval, multiple messages to be sent in the queue to be sent are sent, which can reduce the probability of packet loss during message sending, and realizes a message sending method that reduces the probability of packet loss by adjusting the sending interval and indirectly adjusting the sending frequency.

[0018] In a preferred example, the present application can be further configured as follows:

[0019] After obtaining the queue to be sent, it also includes:

[0020] Acquire multiple message length ranges, wherein the number of message lengths included in each message length range is the same;

[0021] Obtaining the message lengths corresponding to each of the multiple messages to be sent;

[0022] Determine a number of messages to be sent corresponding to each message length range according to the message lengths corresponding to each of the multiple messages to be sent and the multiple message lengths included in each message length range;

[0023] The target message sending interval of the CPU includes the target message sending intervals corresponding to each of the plurality of message length ranges, and the target message sending interval corresponding to each message length range is obtained through the acquisition process of the target message sending interval of the CPU;

[0024] Accordingly, the number of messages sent by the CPU each time and the target message sending interval of the CPU are obtained, and multiple messages to be sent in the to-be-sent queue are sent according to the number of messages and the target message sending interval, including:

[0025] The number of messages sent by the CPU each time and the target message sending interval of the CPU corresponding to each message length range are obtained, wherein the message length of the simulated message used in each process of obtaining the target message sending interval includes all message lengths corresponding to each message length range;

[0026] For each message length range, a number of to-be-sent messages corresponding to the message length range are sent according to the number of messages and the target message sending interval corresponding to the message length range.

[0027] By adopting the above technical scheme, multiple message length ranges are obtained, different message lengths are segmented, and the message lengths corresponding to each of the multiple messages to be sent are obtained; according to the message lengths corresponding to each of the multiple messages to be sent and the multiple message lengths included in each message length range, a number of messages to be sent corresponding to each message length range are determined, and the corresponding message length range is determined for each message to be sent; the number of messages sent by the CPU each time is obtained, and the corresponding target message sending interval is obtained for each message length range, so that the target message sending interval can be flexibly adapted to messages of different message lengths, and the target message sending interval is obtained for each message length range instead of for each different message length, which can reduce the time wasted in matching the corresponding sending interval when sending; finally, for each message length range, according to the number of messages sent by the CPU each time and the target message sending interval corresponding to the message length range, a number of messages to be sent corresponding to the message length range are sent to improve the message sending efficiency.

[0028] In a preferred example, the present application can be further configured as follows:

[0029] After obtaining the multiple message length ranges, the method further includes:

[0030] Sorting all message length ranges according to the left endpoints or right endpoints corresponding to each of the message length ranges to obtain a plurality of message length ranges in order, wherein each message length range includes a unique left endpoint and a unique right endpoint;

[0031] Accordingly, the target message sending interval of the CPU corresponding to each message length range is obtained, including:

[0032] Based on the order of the multiple message length ranges, a target message sending interval is determined for each message length range in turn.

[0033] By adopting the above technical solution, all message length ranges are sorted according to their corresponding left endpoints or right endpoints to obtain multiple ordered message length ranges. Then, based on the order of the multiple message length ranges, the target message sending interval is determined for each message length range in turn. Compared with obtaining all target message sending intervals at the same time, repeated acquisition or erroneous acquisition may occur. The present application improves the accuracy and effectiveness of the acquisition process by obtaining in sequence.

[0034] In a preferred example, the present application can be further configured as follows:

[0035] The step of determining the target message sending interval for each message length range in turn based on the order of the multiple message length ranges includes:

[0036] Based on the order of multiple message length ranges, in the process of determining the target message sending interval corresponding to each message length range in turn, the target message sending interval determined for the previous message length range is used as the preset CPU message sending interval for the current message length range.

[0037] By adopting the above technical solution, in the process of determining the target message sending interval corresponding to each message length range in sequence based on the order of multiple message length ranges, by using the target message sending interval determined by the previous message length range as the preset CPU message sending interval of the current message length range, the time for obtaining the target message sending interval corresponding to the current message length range is shortened, thereby improving the efficiency of obtaining the target message sending interval.

[0038] In a preferred example, the present application can be further configured as follows:

[0039] After obtaining the queue to be sent, it also includes:

[0040] Obtaining a message type of each message to be sent, wherein the message type includes at least a command message and a non-command message;

[0041] For each message to be sent, determine whether the message type is a command message;

[0042] For each message to be sent, if yes, obtain the message sending interval corresponding to the instruction message, and use the message sending interval corresponding to the instruction message as the target message sending interval of the message to be sent, wherein the message sending interval corresponding to the instruction message is greater than the target message sending interval of any non-instruction message.

[0043] By adopting the above technical solution, after obtaining the message type of each message to be sent, for each message to be sent, it is determined whether the message type is an instruction message; if it is an instruction message, the message sending interval corresponding to the instruction message is obtained, and the message sending interval corresponding to the instruction message is used as the target message sending interval of the message to be sent. By making the message sending interval corresponding to the instruction message greater than the target message sending interval of any non-instruction message to be sent, the probability of the instruction message being lost during the sending process is reduced, thereby improving the stability of the instruction message triggering process.

[0044] In a preferred example, the present application can be further configured as follows:

[0045] After obtaining the queue to be sent, it also includes:

[0046] Get the preset maximum message length;

[0047] Based on the preset maximum message length, all the messages to be sent in the to-be-sent queue are screened to obtain a plurality of screened messages to be sent, wherein the message length of each screened message to be sent is not greater than the preset maximum message length;

[0048] Accordingly, according to the number of messages sent by the CPU each time and the target message sending interval, multiple messages to be sent in the waiting-to-send queue are sent, including:

[0049] According to the number of messages sent by the CPU each time and the target message sending interval, multiple filtered messages to be sent in the to-be-sent queue are sent.

[0050] By adopting the above technical solution, after obtaining the preset maximum value of the message length, all the messages to be sent in the queue to be sent are screened based on the preset maximum value of the message length to obtain a plurality of screened messages to be sent; then, according to the number of messages sent by the CPU each time and the target message sending interval, the plurality of screened messages to be sent in the queue to be sent are sent, and by screening the message length, a plurality of messages to be sent with a lower probability of being erroneously transmitted are obtained, and the plurality of screened messages to be sent are sent, thereby improving the stability of the message sending process.

[0051] In a preferred example, the present application can be further configured as follows:

[0052] The filtering of all the to-be-sent messages in the to-be-sent queue based on the preset maximum message length includes:

[0053] Based on the preset maximum message length, all the messages to be sent in the to-be-sent queue are screened to obtain a plurality of filtered messages to be sent, wherein the message length of each filtered message to be sent is greater than the preset maximum message length;

[0054] According to the plurality of filtered messages to be sent, compressing to obtain a plurality of compressed filtered messages to be sent;

[0055] Accordingly, according to the number of messages sent by the CPU each time and the target message sending interval, multiple filtered messages to be sent in the to-be-sent queue are sent, including:

[0056] According to the number of messages sent by the CPU each time and the target message sending interval, the compressed and filtered messages to be sent in the to-be-sent queue are sent.

[0057] By adopting the above technical solution, based on the preset maximum message length, all the messages to be sent in the queue to be sent are screened to obtain multiple filtered messages to be sent, and then, based on the multiple filtered messages to be sent, compression is performed to obtain compressed multiple filtered messages to be sent, which can reduce the probability of the filtered messages to be sent being erroneously transmitted due to the large message length; finally, according to the number of messages sent by the CPU each time and the target message sending interval, the compressed multiple filtered messages to be sent in the queue to be sent are sent, thereby improving the stability of message sending.

[0058] In a second aspect, the present application provides a message sending device, which adopts the following technical solution:

[0059] A message sending device, comprising:

[0060] A message acquisition module, used to acquire a queue to be sent, wherein the queue to be sent includes a plurality of messages to be sent;

[0061] The data preparation module is used to obtain the number of messages sent by the CPU each time and the target message sending interval of the CPU;

[0062] A message sending module, used for sending a plurality of messages to be sent in a waiting-to-send queue according to the number of messages sent by the CPU each time and a target message sending interval;

[0063] The data preparation module is used to:

[0064] Get CPU clock accuracy, preset CPU message sending interval and multiple simulated messages;

[0065] Based on the number of messages sent by the CPU each time and the preset CPU message sending interval, sending the multiple simulation messages, and determining whether all the multiple simulation messages are sent successfully;

[0066] If yes, the preset CPU message sending interval is used as the target message sending interval of the CPU;

[0067] If not, obtaining a new CPU message sending interval according to the CPU clock accuracy and the preset CPU message sending interval;

[0068] The new CPU message sending interval is used as the preset CPU message sending interval, and based on the preset CPU message sending interval and the number of messages sent by the CPU each time, the multiple simulated messages are sent, and it is determined whether all the simulated messages are sent successfully, until all the multiple simulated messages are sent successfully, so as to obtain the target message sending interval of the CPU.

[0069] In a third aspect, the present application provides an electronic device, which adopts the following technical solution:

[0070] at least one processor;

[0071] Memory;

[0072] At least one application, wherein the at least one application is stored in a memory and configured to be executed by at least one processor, and the at least one application is configured to: execute any one of the methods 1 to 7 above.

[0073] In a fourth aspect, the present application provides a computer-readable storage medium, which adopts the following technical solution:

[0074] A computer-readable storage medium stores a computer program, which, when executed in a computer, causes the computer to execute any one of methods 1 to 7 above.

[0075] In summary, the present application includes at least one of the following beneficial technical effects:

[0076] 1. After obtaining the queue to be sent, obtain the number of messages sent by the CPU each time and the target message sending interval of the CPU that can ensure that no packet loss occurs during the message sending process. Based on the CPU clock accuracy, the number of messages sent by the CPU each time and the preset CPU message sending interval, send multiple simulated messages and determine whether all the multiple simulated messages are sent successfully; if so, it is determined that no packet loss occurs, and the preset CPU message sending interval can be used as the target message sending interval of the CPU; if not, it indicates that packet loss still occurs. According to the CPU clock accuracy and the preset CPU message sending interval, the target message sending interval is obtained. New message sending interval, this scheme uses the CPU clock accuracy and the preset CPU message sending interval to adjust the sending interval, which can reduce the number of packet losses caused by the CPU clock accuracy being less than the hardware port clock accuracy; until multiple simulated messages are all sent successfully to obtain the CPU's target message sending interval; and then according to the number of messages sent by the CPU each time and the target message sending interval, multiple messages to be sent in the waiting queue are sent, which can reduce the probability of packet loss during message sending, and realizes a message sending method that reduces the probability of packet loss by adjusting the sending interval and indirectly adjusting the sending frequency;

[0077] 2. By obtaining multiple message length ranges, different message lengths are segmented, and the message lengths corresponding to each of the multiple messages to be sent are obtained; according to the message lengths corresponding to the multiple messages to be sent and the multiple message lengths included in each message length range, a number of messages to be sent corresponding to each message length range are determined, and the corresponding message length range is determined for each message to be sent; the number of messages sent by the CPU each time is obtained, and the corresponding target message sending interval is obtained for each message length range, so that the target message sending interval can be flexibly adapted to messages of different message lengths, and the target message sending interval is obtained for each message length range instead of for each different message length, which can reduce the time wasted in matching the corresponding sending interval when sending; finally, for each message length range, according to the number of messages sent by the CPU each time and the target message sending interval corresponding to the message length range, a number of messages to be sent corresponding to the message length range are sent to improve the message sending efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0078] Figure 1 It is a structural schematic diagram of a high-performance tester provided for an embodiment of the present application.

[0079] Figure 2 It is a flow chart of a message sending method provided for an embodiment of the present application.

[0080] Figure 3 It is a flow chart of a method for obtaining a target message sending interval provided for an embodiment of the present application.

[0081] Figure 4 It is a structural diagram of a message sending device provided for an embodiment of the present application.

[0082] Figure 5 It is a structural schematic diagram of an electronic device provided for an embodiment of the present application. DETAILED DESCRIPTION

[0083] The present application is further described in detail below in conjunction with the accompanying drawings.

[0084] This specific embodiment is merely an explanation of the present application and is not a limitation of the present application. After reading this specification, a person skilled in the art may make non-creative modifications to the present embodiment as needed, but such modifications are protected by the patent law as long as they are within the scope of the present application.

[0085] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application are clearly and completely described. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0086] In addition, the term "and / or" in this article 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 represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article, unless otherwise specified, generally means that the associated objects before and after are in an "or" relationship.

[0087] High-performance tester, an electronic device used to test Ethernet speed, with DPDK technology as a typical application scenario.

[0088] DPDK is a technology that uses a library and driver set for fast data packet processing. It can improve data processing performance and throughput, and the efficiency of data plane applications. It is often used for message transmission, where message transmission includes receiving messages and sending messages. When transmitting messages, it is mainly determined whether to process the message by using a polling mechanism rather than an interrupt mechanism.

[0089] When the high-performance tester uses DPDK technology to transmit messages: the hardware port overloaded by DPDK directly stores the message into the memory, and the application layer software is directly processed through the interface provided by DPDK to realize message reception; Figure 1As shown in the structural diagram of a high-performance tester, the CPU sends the message in the memory to the network through the hardware port to realize the message sending. In the process of sending the message, the sending speed of the CPU may be higher than the sending speed of the hardware port, resulting in packet loss.

[0090] Generally, for the packet loss problem caused by different sending speeds, the number of packets to be sent can be controlled each time, and the difference between the sending speed of the CPU and the sending speed of the hardware port can be shortened to reduce the number of packet losses. However, when the number of packets to be sent increases suddenly, there is still a packet loss problem caused by the sending frequency of the CPU being greater than the sending frequency of the hardware port.

[0091] In response to the above-mentioned packet loss problem caused by different sending frequencies, the inventors found that the probability of packet loss can be reduced by obtaining the queue to be sent, the number of messages sent by the CPU each time, and the target message sending interval of the CPU; according to the number of messages sent by the CPU each time and the target message sending interval, multiple messages to be sent in the queue to be sent are sent, thereby achieving the purpose of reducing the probability of packet loss. Among them, the process of obtaining the target message sending interval of the CPU includes: obtaining the CPU clock accuracy, the preset CPU message sending interval and multiple simulated messages; sending multiple simulated messages based on the number of messages sent by the CPU each time and the preset CPU message sending interval, and judging whether all the multiple simulated messages are sent successfully; if so, taking the preset CPU message sending interval as the target message sending interval of the CPU; if not, obtaining a new CPU message sending interval according to the CPU clock accuracy and the preset CPU message sending interval; taking the new CPU message sending interval as the preset CPU message sending interval, executing based on the preset CPU message sending interval and the number of messages sent by the CPU each time, sending multiple simulated messages, and judging whether all the simulated messages are sent successfully, until all the multiple simulated messages are sent successfully, so as to obtain the target message sending interval of the CPU.

[0092] The embodiments of the present application are further described in detail below in conjunction with the drawings in the specification.

[0093] The embodiment of the present application provides a message sending method, which is executed by an electronic device, which can be a server or a terminal device, wherein the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services. The terminal device can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited thereto. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiment of the present application. Figure 2As shown in a flow chart of a message sending method, the method includes step S101, step S102 and step S103, wherein:

[0094] Step S101: Obtain a queue to be sent, wherein the queue to be sent includes a plurality of messages to be sent.

[0095] In DPDK technology, mainstream hardware platforms can be roughly divided into three types: hardware accelerators, network processors, and multi-core processors. In order to process multi-threaded tasks simultaneously, the embodiment of the present application adopts a multi-core processor to process data, wherein each CPU in the multi-core processor corresponds to a unique queue to be sent, and the queues to be sent send messages asynchronously.

[0096] There may be one or more queues to be sent. When only one CPU in a multi-core processor is in working state, there is one queue to be sent. When multiple CPUs in a multi-core processor are in working state, there are multiple queues to be sent. It can be understood that the working principle of each CPU sending a message to be sent is the same. The embodiment of the present application takes one CPU as an example to illustrate this solution, and multiple CPUs are no longer explained one by one.

[0097] Specifically, through the polling mode, it is determined whether there are messages to be sent; if there are messages to be sent, the CPU obtains multiple messages to be sent from the memory database and puts the multiple messages to be sent into the queue to be sent and wait for sending; if there are no messages to be sent, the polling mode is continued until there are messages to be sent.

[0098] Step S102: Acquire the number of messages sent by the CPU each time and the target message sending interval of the CPU.

[0099] Specifically, obtain the maximum number of messages sent each time by the hardware port and the maximum number of messages sent each time by the CPU, and determine whether the maximum number of messages sent each time by the CPU is greater than the maximum number of messages sent each time by the hardware port; if greater, use the maximum number of messages sent each time by the hardware port as the number of messages sent each time by the CPU; if not greater, directly use the maximum number of messages sent each time by the CPU as the number of messages sent each time by the CPU.

[0100] It is understandable that when sending messages to be sent, if the number of messages sent by the CPU each time is greater than the number of messages sent by the hardware port each time, packet loss will occur. Therefore, when the number of messages sent by the CPU is greater than the number of messages sent by the hardware port each time, the number of messages sent by the hardware port each time can be used as the number of messages sent by the CPU each time. The message sending process should not only minimize the occurrence of packet loss problems, but also pay attention to the message sending efficiency. Therefore, the maximum number of messages sent each time is selected for assignment, that is, the maximum number of messages sent by the hardware port each time is compared with the maximum number of messages sent by the CPU each time.

[0101] In one possible implementation, Figure 3 As shown in a flow chart of a method for acquiring a target message sending interval, the process of acquiring the target message sending interval of the CPU may specifically include step S1021, step S1022, step S1023, step S1024 and step S1025, wherein:

[0102] Step S1021: Acquire CPU clock accuracy, a preset CPU message sending interval, and multiple simulation messages.

[0103] Specifically, the CPU processing frequency is obtained, wherein the CPU processing frequency is a sending frequency preset by the CPU for sending messages, which is determined by the CPU structure; according to the CPU processing frequency, the CPU minimum clock accuracy is obtained through calculation; the CPU target clock accuracy is obtained, wherein the CPU target clock accuracy is manually set; it is determined whether the CPU target clock accuracy is less than the CPU minimum clock accuracy; if it is less than, the CPU minimum clock accuracy is used as the CPU clock accuracy; if it is not less than, the CPU target clock accuracy is used as the CPU clock accuracy; the preset CPU message sending interval is set to 0; multiple simulation messages are obtained, wherein the message length of the simulation message includes all message lengths of the messages to be sent.

[0104] The CPU clock accuracy, the preset CPU message sending interval and multiple simulation messages can be obtained sequentially, simultaneously or two at the same time. The specific acquisition method is no longer limited in the embodiments of the present application, as long as the purpose of the embodiments of the present application can be achieved.

[0105] It is understandable that the time required to send messages of different message lengths is different, so the message length of the simulated message can be set to the message length of the message to be sent to ensure that the sending interval obtained by the simulated message can still reduce the packet loss probability of the message to be sent when sending the message to be sent. For the preset message sending interval, when the CPU clock accuracy is the same as the hardware port clock accuracy, if the sending interval is greater than 0, the CPU may generate unnecessary waiting time, reducing the message sending efficiency, so the preset CPU message sending interval can be set to 0.

[0106] Step S1022: Based on the number of messages sent by the CPU each time and a preset CPU message sending interval, multiple simulation messages are sent, and it is determined whether all the multiple simulation messages are sent successfully.

[0107] Specifically, a first quantity is obtained, wherein the first quantity is the total number of multiple simulated messages; the CPU clock accuracy is used as the sending frequency, the number of messages sent by the CPU each time is used as the number sent in each batch, and the simulated messages in the queue to be sent are sent in batches until all simulated messages are sent, wherein the time interval between each batch of sending is the preset CPU message sending interval; a second quantity is obtained, wherein the second quantity is the number of simulated messages successfully sent by the CPU; it is determined whether the first quantity is equal to the second quantity, and whether multiple simulated messages are all sent successfully, wherein, if they are equal, it is determined that multiple simulated messages are all sent successfully, indicating that no packet loss occurs, and the sending interval is appropriate and no adjustment is required; if they are not equal, it is determined that multiple simulated messages fail to be sent, indicating that packet loss still exists, and the sending interval is not appropriate and still needs to be adjusted.

[0108] Step S1023: If yes, the preset CPU message sending interval is used as the target message sending interval of the CPU.

[0109] Step S1024: If not, a new CPU message sending interval is obtained according to the CPU clock accuracy and the preset CPU message sending interval.

[0110] Specifically, if multiple simulated message sending fails, the new CPU message sending interval is calculated according to the CPU clock accuracy and the preset CPU message sending interval by using the calculation formula of the new CPU message sending interval, where the calculation formula of the new CPU message sending interval can be: new CPU message sending interval = preset CPU message sending interval + CPU clock accuracy.

[0111] It is understandable that, in general, the hardware port clock accuracy is greater than the CPU clock accuracy, which may cause the CPU sending frequency to be greater than the hardware port sending frequency, resulting in the hardware port being unable to receive some batches of messages sent by the CPU when the CPU sends messages in batches, thereby causing packet loss; therefore, the number of packet loss situations can be reduced by adjusting the message sending interval based on the CPU clock accuracy, reducing the CPU sending frequency and reducing the number of times the hardware port is unable to receive some batches of messages sent by the CPU.

[0112] Step S1025: Use the new CPU message sending interval as the preset CPU message sending interval, execute based on the preset CPU message sending interval and the number of messages sent by the CPU each time, send multiple simulated messages, and determine whether all simulated messages are sent successfully, until all multiple simulated messages are sent successfully, so as to obtain the target message sending interval of the CPU.

[0113] Specifically, the new CPU message sending interval is used as the preset CPU message sending interval; the number of messages sent by the CPU each time is used as the number of messages sent in each batch, and the simulated messages in the queue to be sent are sent in batches until all simulated messages are sent, wherein the time of the sending interval of each batch is the preset CPU message sending interval; the first number and the second number are reacquired, and based on the first number and the second number, it is determined whether all simulated messages are sent successfully, wherein if the first number is equal to the second number, the sending is successful, and it is determined that the sending interval is appropriate, and the sending interval is no longer adjusted, and the preset CPU message sending interval is used as the target message sending interval; otherwise, the sending fails, and the preset message sending interval, CPU clock accuracy and the calculation formula of the new CPU message sending interval are used to recalculate the new CPU message sending interval, until all simulated messages are sent successfully, and the target message sending interval of the CPU is obtained.

[0114] It can be understood that the new message sending interval is used as the preset message sending interval, and whether all simulated messages are sent successfully is tested to determine whether the new message sending interval can ensure that there is no packet loss. This solution chooses to use the CPU clock accuracy as an increment to calculate the new message sending interval, aiming to accurately adjust the new message sending interval and reduce the packet loss problem caused by the CPU clock accuracy being greater than the hardware port clock accuracy, when the frequency of the CPU sending messages is greater than the frequency of the hardware port sending messages, and the frequency of the CPU sending messages is greater than the frequency of the hardware port receiving messages from the CPU.

[0115] Step S103: sending a plurality of to-be-sent messages in the to-be-sent queue according to the number of messages sent by the CPU each time and the target message sending interval.

[0116] Specifically, the number of messages sent by the CPU each time is the number of messages sent in each batch, and the messages to be sent in the queue to be sent are sent in batches until all the messages to be sent are sent, wherein the time interval between sending each batch is the target message sending interval of the CPU.

[0117] It can be understood that the multiple messages to be sent in the queue to be sent may be sent once or multiple times; when the number of messages to be sent is not greater than the number of messages sent by the CPU each time, all the messages to be sent can be sent at one time, wherein the number of messages to be sent sent at one time is equal to the number of all messages to be sent; when the number of messages to be sent is greater than the number of messages sent by the CPU each time, it takes multiple times to send all the messages to be sent, wherein when the number of all messages to be sent is an integer multiple of the number of messages sent by the CPU each time, the number of messages sent each time is equal to the number of messages sent by the CPU each time, and when the number of all messages to be sent is not an integer multiple of the number of messages sent by the CPU each time, except for the last time when the number of messages to be sent is a remainder, the number of messages sent each time is equal to the number of messages sent by the CPU each time, and the remainder is the remainder of "the number of all messages to be sent ÷ the number of messages sent by the CPU each time".

[0118] After obtaining the queue to be sent, this scheme obtains the number of messages sent by the CPU each time and the target message sending interval of the CPU that can ensure that no packet loss occurs during the message sending process. Based on the CPU clock accuracy, the number of messages sent by the CPU each time and the preset CPU message sending interval, multiple simulated messages are sent, and it is determined whether all the multiple simulated messages are sent successfully; if so, it is determined that no packet loss occurs, and the preset CPU message sending interval can be used as the target message sending interval of the CPU; if not, it indicates that packet loss still occurs, and a new message sending interval is obtained according to the CPU clock accuracy and the preset CPU message sending interval. This scheme uses the CPU clock accuracy and the preset CPU message sending interval to adjust the sending interval, which can reduce the number of packet losses caused by the CPU clock accuracy being less than the hardware port clock accuracy; until all multiple simulated messages are sent successfully to obtain the target message sending interval of the CPU; and then according to the number of messages sent by the CPU each time and the target message sending interval, multiple messages to be sent in the queue to be sent are sent, which can reduce the probability of packet loss during message sending, and realizes a message sending method that reduces the probability of packet loss by adjusting the sending interval and indirectly adjusting the sending frequency.

[0119] For messages of different lengths, the time required to send is also different. If the sending interval is set to be small when the CPU is sending messages to be sent from the waiting queue to the hardware port, it may happen that when the CPU sends the next batch of messages to be sent to the hardware port, the hardware port is still occupied, which causes the next batch of messages to be sent to be lost. In order to reduce the probability of packet loss caused by too small a sending interval, the message sending interval can be obtained based on the message to be sent with the largest message length among all the messages to be sent. However, a lot of waiting time will occur when sending all the messages to be sent, reducing the message sending efficiency. The waiting time is the idle time of the CPU in the message sending interval time period after the current batch of messages to be sent are successfully sent.

[0120] Therefore, by setting different sending intervals for messages of different message lengths to be sent, a large amount of waiting time can be reduced, and the message sending efficiency can be improved under the premise of reducing the probability of packet loss. Further, the inventors found that when the message length difference is small, the difference in time required to send messages of different message lengths is much smaller than the CPU clock accuracy. Therefore, the message length can be divided into multiple ranges, and the corresponding message sending length can be configured for each range, which can further improve the message sending efficiency.

[0121] Specifically, in a possible implementation manner of the embodiment of the present application, after step S101, the method may further include step S1011 (not shown in the figure), step S1012 (not shown in the figure), and step S1013 (not shown in the figure), wherein:

[0122] Step S1011: Acquire multiple message length ranges, wherein the number of message lengths included in each message length range is the same.

[0123] Specifically, the minimum message length is obtained, wherein the minimum message length represents the minimum message length allowed by the application network of the message sending method, and the application network may be a limited local area network or a wireless local area network. When the application network is a limited local area network, the minimum message length is 60 bytes, and when the application network is a wireless local area network, the minimum message length is 30 bytes; the maximum sending speed of the hardware port is obtained, so that the hardware port sends multiple simulated messages of the minimum message length at the maximum sending speed, and determines whether all simulated messages of the minimum message length are sent successfully;

[0124] If the sending is successful, the message length of the simulated message is increased by 1 byte increments to obtain a changed simulated message, and all the changed simulated messages are sent until the sending fails, and the message length of the current simulated message is obtained, wherein the sending success indicates that no packet loss occurs, and the sending failure indicates that packet loss occurs;

[0125] According to the message length of the current simulated message and the minimum message length, the message length increment is obtained by subtracting, wherein the message length increment = the message length of the current simulated message - the minimum message length, in bytes; taking the message length increment as the length of the range and the minimum message length as the left endpoint of the first message length range, multiple message length ranges are obtained, wherein each message length range is a closed interval with no overlapping endpoints, for example: when the message length increment is L and the minimum message length is 60, the first message length range is [60,60+L-1],…, the Nth message length range is [60+(N-1)*L,60+N*L-1].

[0126] Step S1012: Obtain the message lengths corresponding to each of the multiple messages to be sent.

[0127] Step S1013: according to the message lengths corresponding to the multiple messages to be sent and the multiple message lengths included in each message length range, determine a number of messages to be sent corresponding to each message length range.

[0128] Specifically, for each message length range, according to the message length range and the message lengths of all messages to be sent, a number of messages to be sent corresponding to the message length range are screened out, wherein the message lengths of the number of messages to be sent are all within the corresponding message length range, and a number of messages to be sent corresponding to each of the multiple message length ranges are determined. This can be determined in sequence for each message length range, or all message length ranges can be determined simultaneously. The specific determination method is no longer limited in the embodiments of the present application, as long as it can achieve the purpose of the embodiments of the present application.

[0129] It is understandable that when the number of messages to be sent suddenly increases, the number of messages in the queue to be sent is multiple, but the message lengths of the messages to be sent may not be evenly distributed, and it cannot be guaranteed that the number of messages to be sent corresponding to each message length range is multiple, and may also be 0 or one. Therefore, the number of messages to be sent corresponding to each message length range is several.

[0130] Correspondingly, the target message sending interval of the CPU includes target message sending intervals corresponding to multiple message length ranges, and the target message sending interval corresponding to each message length range is obtained through the acquisition process of the target message sending interval of the CPU; step S102 and step S103 may further include step S102-0 (not shown in the figure) and step S103-0 (not shown in the figure), wherein:

[0131] Step S102-0: Obtain the number of messages sent by the CPU each time and the target message sending interval of the CPU corresponding to each message length range, wherein the message length of the simulated message used in each process of obtaining the target message sending interval includes all message lengths corresponding to each message length range.

[0132] Specifically, for each message length range, according to a number of messages to be sent corresponding to the message length range and the message lengths corresponding to each of the messages to be sent, multiple simulated messages are obtained, wherein the message length of the simulated message may include the message lengths corresponding to each of the messages to be sent corresponding to the message length range; the maximum number of messages sent by the hardware port each time and the maximum number of messages sent by the CPU each time are obtained, and according to the maximum number of messages sent by the hardware port each time and the maximum number of messages sent by the CPU each time, the number of messages sent by the CPU each time is obtained, wherein the specific method for obtaining the number of messages sent by the CPU each time can refer to the relevant limitations of step S102; the CPU clock accuracy is obtained; according to a plurality of simulated messages, the number of messages sent by the CPU each time, and the CPU clock accuracy, steps S1021 to S1025 are used to obtain the target message sending interval of the message length range, wherein all target sending intervals may include simultaneous acquisition or sequential acquisition, and the specific acquisition method is no longer limited in the embodiments of the present application, as long as it can achieve the purpose of the embodiments of the present application.

[0133] It is understandable that when obtaining the target message sending interval for each message length range, the message length of the simulated message used is set to the message length included in the message length range to ensure that the target message sending interval is applicable to the corresponding message length range. For different message lengths, the time consumed when sending a message is also different. On the basis of ensuring a small probability of packet loss, in order to reduce the probability of low message sending efficiency caused by a long sending interval, different target message sending intervals can be set for messages of different message lengths; since the difference between the target message sending intervals corresponding to messages with small message length differences is much smaller than the CPU clock accuracy, the message length can be segmented, and the target message sending interval can be obtained for each message length range, so that the target message sending interval can be flexibly adapted to messages of different message lengths, and the target message sending interval can be obtained for each message length range instead of for each different message length, which can reduce the time wasted in matching the corresponding sending interval during sending and improve the message sending efficiency.

[0134] Step S103-0: For each message length range, according to the number of messages and the target message sending interval corresponding to the message length range, a number of to-be-sent messages corresponding to the message length range are sent.

[0135] Specifically, for each message length range, the number of messages sent by the CPU each time is taken as the number of messages sent in each batch, and several to-be-sent messages corresponding to the message length range in the to-be-sent queue are sent in batches until all the to-be-sent messages are sent, wherein the time interval between each batch of sending is the target message sending interval corresponding to the message length range.

[0136] In an embodiment of the present application, multiple message length ranges are obtained, different message lengths are segmented, and the message lengths corresponding to each of the multiple messages to be sent are obtained; according to the message lengths corresponding to each of the multiple messages to be sent and the multiple message lengths included in each message length range, a number of messages to be sent corresponding to each message length range are determined, and the corresponding message length range is determined for each message to be sent; the number of messages sent by the CPU each time is obtained, and the corresponding target message sending interval is obtained for each message length range, so that the target message sending interval can be flexibly adapted to messages of different message lengths, and the target message sending interval is obtained for each message length range instead of for each different message length, which can reduce the time wasted in matching the corresponding sending interval when sending; finally, for each message length range, according to the number of messages sent by the CPU each time and the target message sending interval corresponding to the message length range, a number of messages to be sent corresponding to the message length range are sent, thereby improving the message sending efficiency.

[0137] A possible implementation of the embodiment of the present application may further include, after step S1011, the following steps:

[0138] All message length ranges are sorted according to their corresponding left endpoints or right endpoints to obtain a plurality of ordered message length ranges, wherein each message length range includes a unique left endpoint and a unique right endpoint.

[0139] Specifically, the sorting method for sorting all message length ranges may include using left endpoint sorting, or using right endpoint sorting; in one possible implementation method, the correspondence between the message length ranges and their respective corresponding left endpoints, and the left endpoints corresponding to all message length ranges are obtained, and all left endpoints are sorted in ascending order to obtain a sorted left endpoint set, and according to the sorted left endpoint set and the correspondence between the message length ranges and their respective corresponding left endpoints, a plurality of ordered message length ranges are obtained; in another possible implementation method, the correspondence between the message length ranges and their respective corresponding right endpoints, and the right endpoints corresponding to all message length ranges are obtained, and all right endpoints are sorted in ascending order to obtain a sorted right endpoint set, and according to the sorted right endpoint set and the correspondence between the message length ranges and their respective corresponding right endpoints, a plurality of ordered message length ranges are obtained.

[0140] Accordingly, when executing step S102-0 to obtain the target message sending interval of the CPU corresponding to each message length range, the following steps may be included:

[0141] Based on the order of the multiple message length ranges, a target message sending interval is determined for each message length range in turn.

[0142] Preferably, this scheme sorts all message length ranges according to their corresponding left endpoints or right endpoints, and after obtaining multiple ordered message length ranges, determines the target message sending interval for each message length range in turn based on the order of the multiple message length ranges. Compared with obtaining all target message sending intervals at the same time, repeated acquisition or erroneous acquisition may occur. This application improves the accuracy and effectiveness of the acquisition process by acquiring in sequence.

[0143] A possible implementation of the embodiment of the present application is to determine the target message sending interval for each message length range in turn based on the order of multiple message length ranges, which may specifically include:

[0144] Based on the order of multiple message length ranges, in the process of determining the target message sending interval corresponding to each message length range in turn, the target message sending interval determined for the previous message length range is used as the preset CPU message sending interval for the current message length range.

[0145] Specifically, in the process of determining the target message sending interval for each message length range, the target message sending interval determined for the previous message length range is used as the preset CPU message sending interval for the current message length range; multiple simulated messages corresponding to the current CPU clock accuracy and the previous message length range are obtained; based on the CPU clock accuracy, the preset CPU message sending interval of the current message length range, and the multiple simulated messages corresponding to the previous message length range, the target message sending interval corresponding to the current message length range is obtained.

[0146] It can be understood that in order to reduce the probability of packet loss, the longer the message length, the larger the target message sending interval corresponding to the message. The message lengths of several messages to be sent corresponding to the previous message length range are all smaller than the message lengths of several messages to be sent corresponding to the current message length range. Therefore, the target message sending interval corresponding to the previous message length range is smaller than the target message sending interval corresponding to the current message length range. The target message sending interval corresponding to the previous message length range can be used as the preset CPU message sending interval for the current message length range to shorten the time for obtaining the target message sending interval corresponding to the current message length range, thereby improving the efficiency of obtaining the target message sending interval.

[0147] In the process of determining the target message sending interval corresponding to each message length range in sequence based on multiple message length ranges, this scheme shortens the time for obtaining the target message sending interval corresponding to the current message length range by using the target message sending interval determined by the previous message length range as the preset CPU message sending interval of the current message length range, thereby improving the efficiency of obtaining the target message sending interval.

[0148] In a possible implementation manner of the embodiment of the present application, after step S101, the following steps may further include SA1 to SA3 (not shown in the figure), wherein:

[0149] SA1: Obtain the message type of each message to be sent, wherein the message type includes at least a command message and a non-command message, and the command message is used to trigger a process.

[0150] Specifically, the message type may be determined by an identifier carried in the message to be sent.

[0151] SA2: For each message to be sent, determine whether the message type is a command message.

[0152] Among them, if it is an instruction message, it means that the current message to be sent is used to trigger the process. When the current message to be sent is lost, in addition to packet loss, some processes may not be able to run normally. If it is not an instruction message, it means that the current message to be sent is the data to be transmitted. When the current message to be sent is lost, it is only packet loss, but it will not affect the normal operation of any process.

[0153] SA3: For each message to be sent, if yes, obtain the message sending interval corresponding to the instruction message, and use the message sending interval corresponding to the instruction message as the target message sending interval of the message to be sent, wherein the message sending interval corresponding to the instruction message is greater than the target message sending interval of any non-instruction message.

[0154] It can be understood that in order to ensure that instruction messages are not lost and the process corresponding to the instruction messages can run normally, the message sending interval corresponding to the instruction messages can be made greater than the target message sending interval of any non-instruction message to be sent, wherein the message sending interval corresponding to the instruction messages is a message sending interval that ensures that the instruction messages with the largest message length among the common instruction messages are not lost when sent.

[0155] In an embodiment of the present application, after obtaining the message type of each message to be sent, for each message to be sent, it is determined whether the message type is an instruction type message; if it is an instruction type message, the message sending interval corresponding to the instruction type message is obtained, and the message sending interval corresponding to the instruction type message is used as the target message sending interval of the message to be sent. By making the message sending interval corresponding to the instruction type message greater than the target message sending interval of any non-instruction type message to be sent, the probability of the instruction type message being lost during the sending process is reduced, and the stability of the instruction type message triggering process is improved.

[0156] In a possible implementation manner of the embodiment of the present application, after step S101, the following steps may further include SB1 (not shown in the figure) and SB2 (not shown in the figure), wherein:

[0157] SB1: Get the preset maximum message length.

[0158] Specifically, based on the database, the message length corresponding to each erroneously transmitted message is obtained from the log records about data error transmission, wherein the error transmission may include message loss, message transmission time being too long, and message transmission being stuck; according to the message lengths corresponding to each of all erroneously transmitted messages, the minimum message length among the message lengths corresponding to each of the erroneously transmitted messages is obtained, and the minimum message length minus 1 byte is used as the preset maximum message length.

[0159] It can be understood that the probability of a message less than the minimum message length being lost is much lower than the probability of a message greater than or equal to the minimum message length being lost. The minimum message length minus 1 byte can be used as the preset maximum message length to reduce the probability of a message to be sent being lost.

[0160] SB2: Based on a preset maximum message length, all the messages to be sent in the queue to be sent are screened to obtain a plurality of screened messages to be sent, wherein the message length of each screened message to be sent is not greater than the preset maximum message length.

[0161] Accordingly, according to the number of messages sent by the CPU each time and the target message sending interval, sending multiple messages to be sent in the to-be-sent queue may specifically include:

[0162] According to the number of messages sent by the CPU each time and the target message sending interval, multiple filtered messages to be sent in the to-be-sent queue are sent.

[0163] It can be understood that sending a plurality of filtered messages to be sent reduces the probability of erroneous transmission of messages due to a long message length, and improves the stability of the message sending process.

[0164] In an embodiment of the present application, after obtaining a preset maximum message length, all messages to be sent in a queue to be sent are screened based on the preset maximum message length to obtain a plurality of screened messages to be sent; then, based on the number of messages sent by the CPU each time and the target message sending interval, the plurality of screened messages to be sent in the queue to be sent are sent, and by screening the message length, a plurality of messages to be sent with a lower probability of being erroneously transmitted are obtained, and the plurality of screened messages to be sent are sent, thereby improving the stability of the message sending process.

[0165] Further, in a possible implementation manner of the embodiment of the present application, when step SB2 performs screening of all the to-be-sent messages in the to-be-sent queue based on the preset maximum message length, it may specifically include SB2-1 (not shown in the figure) and SB2-2 (not shown in the figure), wherein:

[0166] SB2-1: Based on a preset maximum message length, all messages to be sent in the queue to be sent are screened to obtain a plurality of filtered messages to be sent, wherein the message length of each filtered message to be sent is greater than the preset maximum message length.

[0167] It can be understood that each filtered message to be sent is a message with a high probability of being erroneously transmitted.

[0168] SB2-2: According to the multiple filtered messages to be sent, multiple compressed filtered messages to be sent are obtained by compression.

[0169] By compressing each filtered message to be sent and reducing the time required to send each filtered message to be sent, the probability of each filtered message to be sent being erroneously transmitted is reduced, wherein the compression process may include compressing all filtered messages to be sent at the same time, or grouping them.

[0170] Preferably, the implementation process of group compression may specifically include: grouping all filtered messages to be sent according to different message lengths to obtain multiple groups of filtered messages to be sent; for each group of messages to be sent, obtaining the compression level corresponding to the current group of messages to be sent according to the correspondence between the group and the compression level, and compressing the current group of messages to be sent according to the compression level to obtain compressed filtered messages to be sent, wherein the correspondence between the group and the compression level may be set artificially, the larger the average message length corresponding to each group of filtered messages to be sent, the higher the corresponding compression level, and the greater the degree of compression of the messages to be sent, and the message lengths corresponding to each compressed group of filtered messages to be sent may be the same or different.

[0171] It is understandable that, by configuring different compression levels according to different message lengths, the probability of the filtered message to be sent being erroneously transmitted due to excessive length after being compressed can be reduced.

[0172] Accordingly, according to the number of messages sent by the CPU each time and the target message sending interval, sending a plurality of filtered messages to be sent in the to-be-sent queue may specifically include:

[0173] According to the number of messages sent by the CPU each time and the target message sending interval, the compressed and filtered messages to be sent in the to-be-sent queue are sent.

[0174] In an embodiment of the present application, based on a preset maximum message length, by screening all the messages to be sent in the queue to be sent, a plurality of filtered messages to be sent are obtained, and then, based on the plurality of filtered messages to be sent, compression is performed to obtain a plurality of compressed filtered messages to be sent, thereby reducing the probability of the filtered messages to be sent being erroneously transmitted due to the large message length; finally, based on the number of messages sent by the CPU each time and the target message sending interval, the plurality of compressed filtered messages to be sent in the queue to be sent are sent, thereby improving the stability of message sending.

[0175] The above embodiment introduces a message sending method from the perspective of method flow, and the following embodiment introduces a message sending device from the perspective of a virtual module or a virtual unit. Please refer to the following embodiment for details.

[0176] The present application embodiment provides a message sending device, such as Figure 4 As shown in a structural diagram of a message sending device, the message sending device may specifically include:

[0177] The message acquisition module 401 is used to acquire a queue to be sent, wherein the queue to be sent includes a plurality of messages to be sent;

[0178] The data preparation module 402 is used to obtain the number of messages sent by the CPU each time and the target message sending interval of the CPU;

[0179] The message sending module 403 is used to send a plurality of messages to be sent in the to-be-sent queue according to the number of messages sent by the CPU each time and the target message sending interval;

[0180] Wherein, when executing to obtain the target message sending interval of the CPU, the data preparation module 402 is used to:

[0181] Get the CPU clock accuracy, the preset CPU message sending interval, and multiple simulated messages;

[0182] Based on the number of messages sent by the CPU each time and the preset CPU message sending interval, multiple simulation messages are sent, and it is determined whether all the multiple simulation messages are sent successfully;

[0183] If yes, the preset CPU message sending interval is used as the target message sending interval of the CPU;

[0184] If not, a new CPU message sending interval is obtained according to the CPU clock accuracy and the preset CPU message sending interval;

[0185] The new CPU message sending interval is used as the preset CPU message sending interval, and multiple simulation messages are sent based on the preset CPU message sending interval and the number of messages sent by the CPU each time, and it is determined whether all the simulation messages are sent successfully, until all the multiple simulation messages are sent successfully, so as to obtain the target message sending interval of the CPU.

[0186] For the embodiment of the present application, after obtaining the queue to be sent, the number of messages sent by the CPU each time and the target message sending interval of the CPU that can ensure that no packet loss occurs during the message sending process are obtained. Based on the CPU clock accuracy, the number of messages sent by the CPU each time and the preset CPU message sending interval, multiple simulated messages are sent, and it is determined whether all the multiple simulated messages are sent successfully; if so, it is determined that no packet loss occurs, and the preset CPU message sending interval can be used as the target message sending interval of the CPU; if not, it indicates that packet loss still occurs, and based on the CPU clock accuracy, the preset CPU message sending interval interval, and obtain a new message sending interval. This scheme uses the CPU clock accuracy and the preset CPU message sending interval to adjust the sending interval, which can reduce the number of packet losses caused by the CPU clock accuracy being less than the hardware port clock accuracy; until multiple simulated messages are all sent successfully to obtain the CPU's target message sending interval; and then according to the number of messages sent by the CPU each time and the target message sending interval, multiple messages to be sent in the queue to be sent are sent, which can reduce the probability of packet loss during message sending, and realizes a message sending method that reduces the probability of packet loss by adjusting the sending interval and indirectly adjusting the sending frequency.

[0187] In a possible implementation manner of the embodiment of the present application, the message sending device may further include:

[0188] Message length grouping module, used for:

[0189] Acquire multiple message length ranges, wherein the number of message lengths included in each message length range is the same;

[0190] Obtain the message lengths corresponding to each of the multiple messages to be sent;

[0191] Determine a number of messages to be sent corresponding to each message length range according to the message lengths corresponding to each of the multiple messages to be sent and the multiple message lengths included in each message length range;

[0192] The target message sending interval of the CPU includes target message sending intervals corresponding to a plurality of message length ranges, and the target message sending interval corresponding to each message length range is obtained through an acquisition process of the target message sending interval of the CPU;

[0193] Accordingly, the data preparation module 402, when executing to obtain the number of messages sent by the CPU each time and the target message sending interval of the CPU, is used to:

[0194] The number of messages sent by the CPU each time and the target message sending interval of the CPU corresponding to each message length range are obtained, wherein the message length of the simulated message used in each process of obtaining the target message sending interval includes all message lengths corresponding to each message length range;

[0195] Accordingly, the message sending module 403, when executing to send a plurality of to-be-sent messages in the to-be-sent queue according to the number of messages and the target message sending interval, is used to:

[0196] For each message length range, a number of to-be-sent messages corresponding to the message length range are sent according to the number of messages and the target message sending interval corresponding to the message length range.

[0197] In a possible implementation manner of the embodiment of the present application, the message sending device may further include:

[0198] The message length range sorting module is used to:

[0199] Sorting all message length ranges according to the left endpoints or right endpoints corresponding to each of the message length ranges to obtain a plurality of message length ranges in order, wherein each message length range includes a unique left endpoint and a unique right endpoint;

[0200] Accordingly, the message length grouping module, when executing to obtain the target message sending interval of the CPU corresponding to each message length range, is used to:

[0201] Based on the order of the multiple message length ranges, a target message sending interval is determined for each message length range in turn.

[0202] In a possible implementation manner of the embodiment of the present application, the message length range sorting module, when executing an order based on multiple message length ranges and determining a target message sending interval for each message length range in turn, is used to:

[0203] Based on the order of multiple message length ranges, in the process of determining the target message sending interval corresponding to each message length range in turn, the target message sending interval determined for the previous message length range is used as the preset CPU message sending interval for the current message length range.

[0204] In a possible implementation manner of the embodiment of the present application, the message sending device may further include:

[0205] Command message processing module, used for:

[0206] Obtaining a message type of each message to be sent, wherein the message type includes at least a command message and a non-command message;

[0207] For each message to be sent, determine whether the message type is a command message;

[0208] For each message to be sent, if yes, obtain the message sending interval corresponding to the instruction message, and use the message sending interval corresponding to the instruction message as the target message sending interval of the message to be sent, wherein the message sending interval corresponding to the instruction message is greater than the target message sending interval of any non-instruction message.

[0209] In a possible implementation manner of the embodiment of the present application, the message sending device may further include:

[0210] Message filtering module, used to:

[0211] Get the preset maximum message length;

[0212] Based on a preset maximum message length, all the messages to be sent in the to-be-sent queue are screened to obtain a plurality of screened messages to be sent, wherein the message length of each screened message to be sent is not greater than the preset maximum message length;

[0213] Accordingly, the message sending device, when executing to send a plurality of to-be-sent messages in the to-be-sent queue according to the number of messages sent each time by the CPU and the target message sending interval, is used to:

[0214] According to the number of messages sent by the CPU each time and the target message sending interval, multiple filtered messages to be sent in the to-be-sent queue are sent.

[0215] In a possible implementation of the embodiment of the present application, the message screening module, when screening all the to-be-sent messages in the to-be-sent queue based on a preset maximum message length, is used to:

[0216] Based on a preset maximum message length, all messages to be sent in the to-be-sent queue are screened to obtain a plurality of filtered messages to be sent, wherein the message length of each filtered message to be sent is greater than the preset maximum message length;

[0217] According to the multiple filtered messages to be sent, a compressed multiple filtered messages to be sent are obtained by compression;

[0218] Accordingly, the message sending module 403, when executing to send a plurality of filtered to-be-sent messages in the to-be-sent queue according to the number of messages sent each time by the CPU and the target message sending interval, is used to:

[0219] According to the number of messages sent by the CPU each time and the target message sending interval, the compressed and filtered messages to be sent in the to-be-sent queue are sent.

[0220] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the message sending device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0221] An electronic device is provided in an embodiment of the present application, such as Figure 5 As shown, Figure 5 The electronic device shown includes: a processor 301 and a memory 303. The processor 301 and the memory 303 are connected, such as through a bus 302. Optionally, the electronic device may further include a transceiver 304. It should be noted that in actual applications, the transceiver 304 is not limited to one, and the structure of the electronic device does not constitute a limitation on the embodiments of the present application.

[0222] The processor 301 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. The processor 301 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0223] The bus 302 may include a path to transmit information between the above components. The bus 302 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 302 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but it does not mean that there is only one bus or only one type of bus.

[0224] The memory 303 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or 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.

[0225] The memory 303 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 301. The processor 301 is used to execute the application code stored in the memory 303 to implement the contents shown in the above method embodiment.

[0226] The electronic devices include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), and fixed terminals such as digital TVs, desktop computers, etc. It can also be a server, etc. Figure 5 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0227] The embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer-readable storage medium is run on a computer, the computer can execute the corresponding content in the aforementioned method embodiment. Compared with the related art, the embodiment of the present application obtains the number of messages sent by the CPU each time after obtaining the queue to be sent, and the target message sending interval of the CPU that can ensure that there is no packet loss in the message sending process. Based on the CPU clock accuracy, the number of messages sent by the CPU each time and the preset CPU message sending interval, multiple simulated messages are sent, and it is determined whether all multiple simulated messages are sent successfully; if so, it is determined that no packet loss occurs, and the preset CPU message sending interval can be used as the target message sending interval of the CPU; if not, it indicates that there is still packet loss, and according to the CPU clock accuracy, the preset CPU message sending interval, the target message sending interval of the CPU can be used. The scheme uses the CPU clock accuracy and the preset CPU message sending interval to adjust the sending interval, which can reduce the number of packet losses caused by the CPU clock accuracy being less than the hardware port clock accuracy; until multiple simulated messages are all sent successfully to obtain the CPU's target message sending interval; and then according to the number of messages sent by the CPU each time and the target message sending interval, multiple messages to be sent in the queue to be sent are sent, which can reduce the probability of packet loss during message sending, and realizes a message sending method that reduces the probability of packet loss by adjusting the sending interval and indirectly adjusting the sending frequency.

[0228] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0229] The above are only some implementation methods of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A message sending method, characterized in that: include: Obtain a queue to be sent, where the queue to be sent includes multiple messages to be sent; Get the number of messages sent by the CPU each time and the target message sending interval of the CPU; According to the number of messages sent by the CPU each time and the target message sending interval, multiple messages to be sent in the waiting-to-send queue are sent; The process of obtaining the target message sending interval of the CPU includes: Get CPU clock accuracy, preset CPU message sending interval and multiple simulated messages; Based on the number of messages sent by the CPU each time and the preset CPU message sending interval, sending the multiple simulation messages, and determining whether all the multiple simulation messages are sent successfully; If yes, the preset CPU message sending interval is used as the target message sending interval of the CPU; If not, obtaining a new CPU message sending interval according to the CPU clock accuracy and the preset CPU message sending interval; The new CPU message sending interval is used as the preset CPU message sending interval, and based on the preset CPU message sending interval and the number of messages sent by the CPU each time, the multiple simulated messages are sent, and it is determined whether all the simulated messages are sent successfully, until all the multiple simulated messages are sent successfully, so as to obtain the target message sending interval of the CPU.

2. The message sending method according to claim 1, characterized in that: After obtaining the queue to be sent, it also includes: Acquire multiple message length ranges, wherein the number of message lengths included in each message length range is the same; Obtaining the message lengths corresponding to each of the multiple messages to be sent; Determine a number of messages to be sent corresponding to each message length range according to the message lengths corresponding to each of the multiple messages to be sent and the multiple message lengths included in each message length range; The target message sending interval of the CPU includes the target message sending intervals corresponding to the multiple message length ranges, and the target message sending interval corresponding to each message length range is obtained through the acquisition process of the target message sending interval of the CPU; Accordingly, the number of messages sent by the CPU each time and the target message sending interval of the CPU are obtained, and multiple messages to be sent in the to-be-sent queue are sent according to the number of messages and the target message sending interval, including: The number of messages sent by the CPU each time and the target message sending interval of the CPU corresponding to each message length range are obtained, wherein the message length of the simulated message used in each process of obtaining the target message sending interval includes all message lengths corresponding to each message length range; For each message length range, a number of to-be-sent messages corresponding to the message length range are sent according to the number of messages and the target message sending interval corresponding to the message length range.

3. The message sending method according to claim 2, characterized in that: After obtaining the multiple message length ranges, the method further includes: Sorting all message length ranges according to the left endpoints or right endpoints corresponding to each of the message length ranges to obtain a plurality of message length ranges in order, wherein each message length range includes a unique left endpoint and a unique right endpoint; Accordingly, the target message sending interval of the CPU corresponding to each message length range is obtained, including: Based on the order of the multiple message length ranges, a target message sending interval is determined for each message length range in turn.

4. The message sending method according to claim 3, characterized in that: The step of determining the target message sending interval for each message length range in turn based on the order of the multiple message length ranges includes: Based on the order of multiple message length ranges, in the process of determining the target message sending interval corresponding to each message length range in turn, the target message sending interval determined for the previous message length range is used as the preset CPU message sending interval for the current message length range.

5. The message sending method according to claim 1, characterized in that: After obtaining the queue to be sent, it also includes: Obtaining a message type of each message to be sent, wherein the message type includes at least a command message and a non-command message; For each message to be sent, determine whether the message type is a command message; For each message to be sent, if yes, obtain the message sending interval corresponding to the instruction message, and use the message sending interval corresponding to the instruction message as the target message sending interval of the message to be sent, wherein the message sending interval corresponding to the instruction message is greater than the target message sending interval of any non-instruction message.

6. The message sending method according to claim 1, characterized in that: After obtaining the queue to be sent, it also includes: Get the preset maximum message length; Based on the preset maximum message length, all the messages to be sent in the to-be-sent queue are screened to obtain a plurality of screened messages to be sent, wherein the message length of each screened message to be sent is not greater than the preset maximum message length; Accordingly, according to the number of messages sent by the CPU each time and the target message sending interval, multiple messages to be sent in the waiting-to-send queue are sent, including: According to the number of messages sent by the CPU each time and the target message sending interval, multiple filtered messages to be sent in the to-be-sent queue are sent.

7. The message sending method according to claim 6, characterized in that: The filtering of all the to-be-sent messages in the to-be-sent queue based on the preset maximum message length includes: Based on the preset maximum message length, all the messages to be sent in the to-be-sent queue are screened to obtain a plurality of filtered messages to be sent, wherein the message length of each filtered message to be sent is greater than the preset maximum message length; According to the plurality of filtered messages to be sent, compressing to obtain a plurality of compressed filtered messages to be sent; Accordingly, according to the number of messages sent by the CPU each time and the target message sending interval, multiple filtered messages to be sent in the to-be-sent queue are sent, including: According to the number of messages sent by the CPU each time and the target message sending interval, the compressed and filtered messages to be sent in the to-be-sent queue are sent.

8. A message sending device, characterized in that: include, A message acquisition module, used to acquire a queue to be sent, wherein the queue to be sent includes a plurality of messages to be sent; The data preparation module is used to obtain the number of messages sent by the CPU each time and the target message sending interval of the CPU; A message sending module, used for sending a plurality of messages to be sent in a waiting-to-send queue according to the number of messages sent by the CPU each time and a target message sending interval; The data preparation module is used to: Get CPU clock accuracy, preset CPU message sending interval and multiple simulated messages; Based on the number of messages sent by the CPU each time and the preset CPU message sending interval, sending the multiple simulation messages, and determining whether all the multiple simulation messages are sent successfully; If yes, the preset CPU message sending interval is used as the target message sending interval of the CPU; If not, obtaining a new CPU message sending interval according to the CPU clock accuracy and the preset CPU message sending interval; The new CPU message sending interval is used as the preset CPU message sending interval, and based on the preset CPU message sending interval and the number of messages sent by the CPU each time, the multiple simulated messages are sent, and it is determined whether all the simulated messages are sent successfully, until all the multiple simulated messages are sent successfully, so as to obtain the target message sending interval of the CPU.

9. An electronic device, characterized in that: include: at least one processor; Memory; At least one application, wherein the at least one application is stored in a memory and configured to be executed by at least one processor, and the at least one application is configured to: execute the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed in a computer, the computer is caused to execute the method according to any one of claims 1 to 7.