Data transmission method and apparatus, electronic device, and computer-readable storage medium
Patent Information
- Application Number
- CN202611158395.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-31
- Publication Date
- 2026-10-30
AI Technical Summary
[0003]然而,上述相关方案采用的重传机制的重传效果有限,在网络质量差时,重传的消息依然有较高的丢失概率
通信重传模块,用于向接收端发送多次心跳请求;
Smart Images

Figure CN123020487A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of communication technology, and in particular relates to a data transmission method, apparatus, electronic device and computer-readable storage medium. Background Technology
[0002] Reliable data transmission is crucial in the field of communications, but data loss can easily occur due to sudden network anomalies. Related solutions have adopted various retransmission mechanisms, such as simple retry mechanisms and forward error correction retransmission.
[0003] However, the retransmission mechanism used in the above-mentioned solutions has limited retransmission effectiveness. When the network quality is poor, retransmitted messages still have a high probability of being lost. Summary of the Invention
[0004] This application aims to at least address one of the technical problems existing in related technologies. To this end, this application proposes a data transmission method, apparatus, electronic device, and computer-readable storage medium, which can significantly reduce the probability of message loss and improve the reliability of communication.
[0005] Firstly, this application provides a data transmission method applied at a sending end, the method comprising: If the network quality indicators do not meet the preset conditions, the scheduling of messages from the sending buffer queue will be suspended, and the messages to be received will continue to be cached in the sending buffer queue. Send multiple heartbeat requests to the receiving end; If a heartbeat response message is continuously received from the receiving end, and the cumulative number of heartbeat response messages reaches a first preset number, the message scheduling from the sending buffer queue is resumed, and the scheduled message is sent to the receiving end.
[0006] According to the data transmission method of this application, when the network quality indicators do not meet the preset conditions, the output of messages from the sending buffer queue is paused, and the received messages are continued to be cached in the sending buffer queue; multiple heartbeat requests are sent to the receiving end; and when multiple heartbeat reply packets are received from the receiving end in response to the heartbeat requests, messages continue to be output from the sending buffer queue and the output messages are sent to the receiving end. That is, when the network quality is poor, the received messages are cached but not transmitted, and data transmission continues after the network quality recovers. This effectively prevents the loss of valid messages immediately due to exceeding the maximum retransmission limit, prevents subsequent data transmission from becoming unreliable, reduces processing complexity, significantly reduces the probability of message loss, and improves the reliability of communication.
[0007] According to one embodiment of this application, after the message to be received is buffered into the send buffer queue, the method further includes: If the number of cached messages in the sending buffer queue reaches the capacity threshold, the messages in the sending buffer queue are stored offline, and the sending buffer queue is cleared. After resuming message scheduling from the send buffer queue, the method further includes: The messages stored offline are reloaded to the send buffer queue.
[0008] According to one embodiment of this application, the step of reloading the offline-stored message back to the sending buffer queue includes: The offline stored messages are reloaded to the sending buffer queue at a first preset rate. The recovery of messages scheduled from the send buffer queue includes: Messages are scheduled from the sending buffer queue at a second preset rate; The second preset rate is not less than the first preset rate.
[0009] According to one embodiment of this application, after sending the scheduled message to the receiving end, the method further includes: Store the scheduled messages and the timeout thresholds corresponding to the scheduled messages in the pending confirmation list; If an acknowledgment message is received from the receiving end for the scheduled message within the timeout threshold, the scheduled message is removed from the pending acknowledgment list; if the scheduled message has been marked as a retransmission message, the scheduled message and the corresponding retransmission count are removed from the retransmission list. If no acknowledgment message is received from the receiving end for the scheduled message within the timeout threshold, and the scheduled message is not marked as a retransmission message, the scheduled message is transferred from the pending acknowledgment list to the retransmission list, the scheduled message is marked as a retransmission message, and the corresponding retransmission count is updated. If no acknowledgment message is received from the receiver for the scheduled message within the timeout threshold, and the scheduled message has been marked as a retransmission message, the corresponding retransmission count is updated in the retransmission list.
[0010] According to one embodiment of this application, after transferring the scheduled message from the pending acknowledgment list to the retransmission list, or after updating the corresponding retransmission count in the retransmission list, the method further includes: Update the retransmission wait time for each retransmitted message in the retransmission list; When the retransmission wait time for any of the retransmission messages in the retransmission list reaches the retransmission duration threshold, the retransmission message is enqueued into the sending buffer queue.
[0011] According to one embodiment of this application, after updating the retransmission count, the method further includes: If the number of retransmissions of any of the retransmission messages exceeds the second preset number, the retransmission waiting time for each of the retransmission messages in the retransmission list is paused. If a heartbeat response message is received continuously from the receiving end, and the cumulative number of heartbeat response messages reaches a first preset number, the retransmission waiting time for each retransmission message in the retransmission list is restored.
[0012] According to one embodiment of this application, network quality indicators include one or more of the following: blocking rate of the sending buffer queue, retransmission rate, number of retransmissions of any message, and number of circuit breakers.
[0013] Secondly, this application provides a data transmission apparatus, which includes: The queue caching module is used to pause message scheduling from the sending buffer queue if the network quality indicators do not meet the preset conditions, and to cache the messages to be received in the sending buffer queue. The communication retransmission module is used to send multiple heartbeat requests to the receiving end; The sending module is configured to, if it continuously receives heartbeat response messages returned by the receiving end, and the cumulative number of heartbeat response messages reaches a first preset number, resume scheduling messages from the sending buffer queue and send the scheduled messages to the receiving end.
[0014] According to the data transmission apparatus of this application, when the network quality indicators do not meet preset conditions, message output from the sending buffer queue is paused, and the received messages are continued to be cached in the sending buffer queue; multiple heartbeat requests are sent to the receiving end; and when multiple heartbeat reply packets are received from the receiving end in response to the heartbeat requests, messages continue to be output from the sending buffer queue and the output messages are sent to the receiving end. That is, when the network quality is poor, the received messages are cached but not transmitted, and data transmission continues after the network quality recovers. This effectively prevents the loss of valid messages immediately due to exceeding the maximum retransmission limit, prevents subsequent data transmission from becoming unreliable, reduces processing complexity, significantly reduces the probability of message loss, and improves the reliability of communication.
[0015] Thirdly, this application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the data transmission method provided in the first aspect above.
[0016] Fourthly, this application provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the data transmission method provided in the first aspect above.
[0017] Fifthly, this application provides a chip including a processor and a communication interface coupled to the processor, the processor being used to run programs or instructions to implement the data transmission method provided in the first aspect.
[0018] In a sixth aspect, this application provides a computer program product, including a computer program that, when executed by a processor, implements the data transmission method provided in the first aspect above.
[0019] The above-described one or more technical solutions in the embodiments of this application have at least one of the following technical effects: When network quality indicators fail to meet preset conditions, message output from the FIFO (First-In, First-Out) structure is paused, and received messages are continued to be cached in the FIFO structure. Multiple heartbeat requests are sent to the receiving end. If multiple heartbeat reply packets are received from the receiving end in response to the heartbeat requests, messages are continued to be output from the FIFO structure, and the output messages are sent to the receiving end. In other words, when network quality is poor, received messages are cached but not transmitted. Once network quality recovers, data transmission resumes. This effectively prevents the immediate loss of valid messages due to exceeding the maximum retransmission limit, prevents subsequent data transmission from becoming unreliable, reduces processing complexity, significantly reduces the probability of message loss, and improves communication reliability.
[0020] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0021] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which: Figure 1 This is one of the flowcharts illustrating the data transmission method provided in the embodiments of this application; Figure 2 This is a schematic diagram of the structure of the data transmission device provided in the embodiments of this application; Figure 3 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0022] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0023] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0024] The data transmission method, apparatus, electronic device, and computer-readable storage medium provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.
[0025] like Figure 1 As shown in the figure, this application provides a flowchart of a data transmission method applied to the sending end, including steps 110, 120 and 130.
[0026] Step 110: If the network quality indicators do not meet the preset conditions, pause the scheduling of messages from the sending buffer queue, and continue to cache the received messages in the sending buffer queue.
[0027] In this application embodiment, the sending end and the receiving end are devices capable of data communication. The two can establish a communication connection based on a defined communication protocol, which can be a low-level communication protocol such as TCP connection, IP connection, Modbus, or raw message.
[0028] In practical applications, the sending end can be a terminal, and the receiving end can be a server.
[0029] Under good network conditions, the sender and receiver can communicate normally. The sender has a first-in-first-out (FIFO) structure, which buffers messages to be sent to the receiver. Once the messages in the FIFO structure are output, they can be sent to the receiver through a communication interface (such as an Ethernet interface, serial port, CAN, etc.).
[0030] A send buffer queue is a data structure used to cache messages to be sent. For example, it can be a first-in, first-out (FIFO) queue, where messages follow a first-in, first-out (FIFO) principle. The FIFO structure is used to temporarily cache messages that the device needs to send. Sending is non-blocking, which can act as flow control, preventing data loss due to sudden communication interruptions or interface delays caused by hardware malfunctions.
[0031] In addition, the first-in-first-out queue can output data periodically through an independent thread and communicate with the receiving end through a communication interface, so it is necessary to ensure that the data output speed is fast enough.
[0032] In practice, this first-in-first-out (FIFO) structure can be a message queue, a buffer, or something else; there are no restrictions on the specific implementation.
[0033] A message can include a message header and a message body.
[0034] The message header is the metadata part of the message, containing key attribute information about the message itself, including but not limited to: message identifier (ID), source address, destination address, message type, length field, timestamp, and checksum.
[0035] The message body is also the data part of the message, including but not limited to one or more of the following: multimedia data (such as audio and video data), text data, application data, files, and control information.
[0036] In a certain scenario, a message may include information such as the data type of the vehicle image, whether retransmission is required, and the message timestamp.
[0037] Network quality indicators are metrics that indicate the quality (or state) of a network. Network quality indicators include at least the number of message retransmissions, and also one or more of the following: first-in-first-out (FIFO) blocking rate, retransmission rate, and number of circuit breakers.
[0038] The preset conditions are the threshold conditions for determining normal network communication, which include at least the number of retransmissions of any message being less than the retransmission number threshold, and may also include the real-time blocking rate being less than the blocking rate threshold, the retransmission rate being less than the retransmission rate threshold, and the number of circuit breakers being less than the circuit breaker number threshold.
[0039] If the network quality indicators do not meet the preset conditions, it indicates that the network quality is poor. In this case, continuing to retransmit messages will likely result in message loss and invalid retransmission.
[0040] To avoid triggering a circuit breaker when network quality indicators do not meet preset conditions, the output of messages from the first-in-first-out (FIFO) structure is suspended in the above situation. However, the receiving end can still collect or receive new messages. In this case, the acquired messages continue to be cached in the FIFO structure to maintain message integrity.
[0041] Step 120: Send multiple heartbeat requests to the receiving end.
[0042] When network quality indicators do not meet preset conditions, the network connection is usually disconnected. In this case, it is necessary to re-establish the network connection. Therefore, the sending end needs to continuously send heartbeat requests to the receiving end.
[0043] Heartbeat request is a common mechanism in network communication used to detect and maintain the active state of a connection.
[0044] The heartbeat request includes information such as a request identifier (used to indicate a unique heartbeat request, which can be a sequence number or acknowledgment number), source address, destination address, and timestamp, indicating that the sender corresponding to the source address requests the establishment of a communication connection with the receiver corresponding to the destination address.
[0045] In practical applications, the interval between adjacent heartbeat messages is relatively short and can be set according to actual needs, generally between a few seconds and one minute.
[0046] Step 130: If heartbeat response messages are continuously received from the receiving end, and the cumulative number of heartbeat response messages reaches a first preset number, resume scheduling messages from the sending buffer queue and send the scheduled messages to the receiving end.
[0047] In cases of poor network quality, the heartbeat request may be lost. In such cases, the receiving end may not receive the heartbeat request or may not receive it in a timely manner, and therefore will not respond to the heartbeat request.
[0048] However, when the network quality is good, the receiving end can usually receive the heartbeat request sent by the sending end. After authenticating the sending end and passing the authentication, it will respond to the heartbeat request and generate a heartbeat reply packet.
[0049] A heartbeat response is a message or data packet in network communication that corresponds to a heartbeat request. Its main function is to confirm the receiver's active status in response to the sender's heartbeat request. A heartbeat response indicates that the receiver is still active and can respond to the request normally.
[0050] The heartbeat response packet includes a request identifier of the heartbeat request being responded to, indicating the specific heartbeat request being responded to.
[0051] The fact that the receiving end occasionally receives a heartbeat reply packet does not mean that the network quality is good. If the heartbeat request is sent multiple times in a row (the specific number is a preset value, such as 3 times) and a heartbeat reply packet is received, it means that the network status has recovered, the network quality is good, and normal communication is possible. In this case, the buffer queue can be controlled to output messages, and the output messages can be sent to the receiving end through the communication interface, that is, the data interaction between the sending end and the receiving end can be restored.
[0052] When the cumulative number of heartbeat response messages received by the sending end reaches the first preset number, it is determined that the network quality has returned to normal and the communication link is stable. The buffer keep-alive state is terminated, messages are resumed from the sending buffer queue, and the messages obtained from the scheduling are sent to the receiving end, thus restoring normal data transmission services at both ends.
[0053] The data transmission method provided in this application, when the network quality indicators do not meet preset conditions, suspends the output of messages from the sending buffer queue and continues to cache the received messages in the sending buffer queue; sends multiple heartbeat requests to the receiving end; and when multiple heartbeat reply packets are received from the receiving end in response to the heartbeat requests, continues to output messages from the sending buffer queue and sends the output messages to the receiving end. That is, when the network quality is poor, the received messages are cached but not transmitted, and data transmission continues after the network quality recovers. This effectively prevents the loss of valid messages immediately due to exceeding the maximum retransmission limit, prevents subsequent data transmission from becoming unreliable, reduces processing complexity, significantly reduces the probability of message loss, and improves the reliability of communication.
[0054] In some embodiments, after the message to be received is buffered in the send buffer queue, the method further includes: If the number of cached messages in the sending buffer queue reaches the capacity threshold, the messages in the sending buffer queue are stored offline, and the sending buffer queue is cleared. After resuming message scheduling from the send buffer queue, the method further includes: The messages stored offline are reloaded to the send buffer queue.
[0055] After the sending end enters the circuit breaker state, the buffer queue continues to cache messages to be sent, but no messages are output. Since the capacity of the buffer queue is prioritized, the amount of messages temporarily cached in the buffer queue continues to increase as the network quality does not recover. The amount of messages refers to the number of messages.
[0056] To prevent data loss due to message overflow in the buffer queue, when the message volume in the buffer queue reaches the capacity threshold (the capacity threshold refers to the maximum number of elements that can be accommodated when storing data (1 message can be 1 element), the messages in the buffer queue can be stored offline. Specifically, they can be stored in a database, or on a solid-state drive, optical disc, etc., thereby preventing data loss.
[0057] After messages in the buffer queue are stored offline, in order for new messages to be received, the messages in the buffer queue need to be cleared and new messages continue to be cached in the buffer queue.
[0058] Furthermore, once network quality is restored, i.e. after receiving multiple heartbeat response packets from the receiver in response to the heartbeat request, offline stored messages can continue to be cached in a buffer queue, thereby enabling the retransmission of messages generated during the offline phase (the phase in which communication connections are lost due to poor network quality).
[0059] After the network is restored and the sending end resumes scheduling messages from the sending buffer queue, the sending end reloads the previously offline stored historical messages back to the sending buffer queue, and retransmits the offline messages cached during the network anomaly, ensuring that all messages are transmitted completely without any data loss.
[0060] In some embodiments, the step of reloading the offline-stored message back to the sending buffer queue includes: The offline stored messages are reloaded to the sending buffer queue at a first preset rate. The recovery of messages scheduled from the send buffer queue includes: Messages are scheduled from the sending buffer queue at a second preset rate; The second preset rate is not less than the first preset rate.
[0061] After the network quality is restored, the messages stored offline need to be cached in the buffer queue. The messages from each offline storage can be cached in the buffer queue according to the order in which the messages were collected or received.
[0062] After the network quality is restored, messages that need to be cached should be output from the buffer queue. To avoid overflow, the buffer queue needs to output messages at a relatively fast speed.
[0063] The first rate is the rate at which offline stored messages are cached into the buffer queue. The second rate is the rate at which messages are output from the buffer queue. To avoid overflow, the output rate needs to be faster than the storage rate, meaning the second rate must not be less than the first rate.
[0064] When reloading offline stored messages back to the sending buffer queue, the sending end reloads offline messages at a uniform rate according to a first preset rate to avoid queue blockage caused by a large number of messages entering the queue at any moment.
[0065] After message scheduling is restored at the sending end, messages are scheduled from the sending buffer queue at a second preset rate, and the second preset rate is not less than the first preset rate. This rate constraint can ensure that the message scheduling dequeue speed is not lower than the offline message reload enqueue speed, avoid queue overflow problems, and ensure orderly and stable message transmission.
[0066] In some embodiments, after sending the scheduled message to the receiving end, the method further includes: Store the scheduled messages and the timeout thresholds corresponding to the scheduled messages in the pending confirmation list; If an acknowledgment message is received from the receiving end for the scheduled message within the timeout threshold, the scheduled message is removed from the pending acknowledgment list; if the scheduled message has been marked as a retransmission message, the scheduled message and the corresponding retransmission count are removed from the retransmission list. If no acknowledgment message is received from the receiving end for the scheduled message within the timeout threshold, and the scheduled message is not marked as a retransmission message, the scheduled message is transferred from the pending acknowledgment list to the retransmission list, the scheduled message is marked as a retransmission message, and the corresponding retransmission count is updated. If no acknowledgment message is received from the receiver for the scheduled message within the timeout threshold, and the scheduled message has been marked as a retransmission message, the corresponding retransmission count is updated in the retransmission list.
[0067] There is a pre-defined handshake data protocol between the communication end and the receiving end for various types of information. After receiving a message, the receiving end needs to send a handshake data packet for the received message. This handshake data packet is usually used to confirm the receipt and validity of the message.
[0068] The handshake data packet typically includes the source address, destination address, message identifier, handshake type, and status code (success, failure, etc.).
[0069] After sending a message, the sender waits for a handshake data packet from the receiver. A ready wait list technique can be used here, adding the sent message and its attributes (message type, message size, sending timestamp, etc.) to the wait list.
[0070] In addition, each message has a timeout period, which is a specified time window after the message is sent to wait for the receiver's acknowledgment or response. It refers to the maximum allowed time interval before receiving the receiver's acknowledgment or response. If the expected response is not received within this time, the corresponding timeout handling mechanism will be triggered.
[0071] After the sending end sends the scheduled message to the receiving end, it stores the scheduled message and its corresponding timeout threshold in a preset pending acknowledgment list to track the message reception and acknowledgment status. Each message corresponds to an independent timeout threshold, which can be dynamically adjusted based on network latency and round-trip time, or preset to a fixed value.
[0072] The timeout duration for each message can be preset or dynamically adjusted, such as dynamically adjusting based on network latency and round-trip time (RTT), or dynamically adjusting based on the number of retransmissions.
[0073] If a handshake data packet is received from the receiver for the output message within the timeout period, the wait list can be queried (e.g., by binary search, by index lookup, etc.) and the output message can be deleted from the wait list.
[0074] In addition, linked list technology is used to store messages that need to be retransmitted, specifically a retransmission list.
[0075] Retransmitted messages have a retransmission identifier (or retransmission tag). The retransmission identifier indicates that the message is a retransmission message. The retransmission list records messages that need to be retransmitted, retransmission messages for which handshake data packets have not yet been received, the number of retransmissions, and the retransmission wait time, etc.
[0076] After receiving a handshake data packet for a certain output message, if the output message has a retransmission flag, the output message and the corresponding retransmission count must be removed from the retransmission list.
[0077] If the receiver does not receive a handshake data packet in response to the output message within the timeout period, it indicates that the receiver did not receive or did not receive the message sent by the sender in a timely manner. In this case, the message needs to be reliably retransmitted.
[0078] Specifically, if the output message does not have a retransmission flag, a retransmission flag needs to be set for it, and the output message needs to be moved to the retransmission list from the waiting list, and its retransmission count (i.e., retransmission count + 1) and retransmission waiting time need to be updated.
[0079] Once it is determined that an output message has a retransmission flag, the retransmission count and retransmission wait time are updated directly in the retransmission list.
[0080] The retransmission waiting time is the time it takes to re-buy the data in the buffer queue. To avoid invalid retransmissions, the retransmission waiting time can be positively correlated with the number of retransmissions.
[0081] In some embodiments, after transferring the scheduled message from the pending acknowledgment list to the retransmission list, or after updating the corresponding retransmission count in the retransmission list, the method further includes: Update the retransmission wait time for each retransmitted message in the retransmission list; When the retransmission wait time for any of the retransmission messages in the retransmission list reaches the retransmission duration threshold, the retransmission message is enqueued into the sending buffer queue.
[0082] When the retransmission wait countdown for any message in the retransmission list ends, the message is enqueued into the buffer queue, allowing it to be resent to the sender. For any retransmission message in the retransmission list, when its retransmission wait time reaches a preset retransmission duration threshold, the retransmission message is re-enqueued into the sending buffer queue, awaiting rescheduling for retransmission, thus achieving automatic message retry and retransmission.
[0083] In some embodiments, after updating the retransmission count, the method further includes: If the number of retransmissions of any of the retransmission messages exceeds the second preset number, the retransmission waiting time for each of the retransmission messages in the retransmission list is paused. If a heartbeat response message is received continuously from the receiving end, and the cumulative number of heartbeat response messages reaches a first preset number, the retransmission waiting time for each retransmission message in the retransmission list is restored.
[0084] Since the number of retransmissions is an important indicator for entering the circuit breaker state, after updating the retransmission count of a message, it is necessary to determine whether the number of retransmissions of the already output message exceeds the target number. If so, the sending end enters the circuit breaker state.
[0085] After entering the circuit breaker state, in addition to pausing the output of messages in the buffer queue, the retransmission waiting countdown for each message in the retransmission list is also paused.
[0086] The retransmission wait countdown for each retransmission message in the retransmission list is paused, and the retransmission list also stops pushing retransmission messages to the buffer queue.
[0087] However, after receiving multiple heartbeat response packets from the receiving end in response to the heartbeat request, i.e. after the network is restored, the retransmission waiting countdown for each message in the retransmission list continues to resume.
[0088] If the number of retransmissions of any retransmission message exceeds the second preset number, it is determined that the message has failed to retransmit multiple times and the link is seriously abnormal. This triggers a secondary circuit breaker mechanism, suspends the retransmission waiting time of all retransmission messages in the retransmission list, stops invalid retransmission scheduling, and saves system resources.
[0089] In some embodiments, after restoring the retransmission wait time for each of the retransmission messages in the retransmission list, the method further includes: For a target message whose retransmission count exceeds the second preset number, if the retransmission waiting time of the target message reaches the retransmission duration threshold, the target message is re-enqueued to the sending buffer queue and removed from the retransmission list; After the target message is dequeued from the sending buffer queue, the target message is removed from the pending confirmation list.
[0090] For messages that trigger a circuit breaker and exceed the target number of retransmissions, the message will not be retransmitted indefinitely. After the circuit breaker recovers, the message can be retransmitted one last time. That is, messages that exceed the target number of retransmissions are enqueued into the buffer queue for the last time, and messages that exceed the target number of retransmissions and their corresponding retransmission counts are removed from the retransmission list. In other words, no further retransmissions will be performed. In addition, after dequeuing messages that exceed the target number of retransmissions from the buffer queue, messages that exceed the target number of retransmissions and their corresponding retransmission counts are removed from the waiting list. That is, we no longer care whether the message can be retransmitted successfully. Even if the retransmission fails, it will not be retransmitted. This method can ensure that message data is not lost to the greatest extent and will not be restricted by a single message.
[0091] Understandably, when the retransmission wait time for a target message reaches the retransmission duration threshold, the target message is re-enqueued into the sending buffer queue for a final fallback retransmission. Simultaneously, the target message and its corresponding retransmission count are removed from the retransmission list to prevent further retransmissions. Once the target message is dequeued from the sending buffer queue and sent, it is completely removed from the pending acknowledgment list, terminating the entire message tracking process. This avoids unnecessary use of list resources and maximizes message transmission integrity.
[0092] In some embodiments, the network quality metrics include one or more of the following: blocking rate of the sending buffer queue, retransmission rate, number of retransmissions of any message, and number of circuit breakers.
[0093] The blocking rate refers to the percentage of messages in the buffer queue that cannot be output due to insufficient resources within a certain period of time.
[0094] Taking a buffer queue as an example, in practice, the amount of messages in the queue can be recorded in real time. A continuously excessively large sending queue indicates that there is a certain degree of blockage in data transmission. The excessive amount of messages makes the network transmission hardware unable to meet the network communication requirements, and continuous network optimization is needed.
[0095] The retransmission rate refers to the proportion of data packets or messages that the sender needs to retransmit due to packet loss or timeout in network communication. It can reflect the current network quality to a certain extent.
[0096] The circuit breaker count refers to the number of times the circuit breaker mechanism is triggered in a system due to a failure of a certain service or component. In this embodiment, it can specifically refer to the number of times a network connection is disconnected. The circuit breaker mechanism is a protective measure used to prevent continuous calls to faulty services, thereby avoiding further waste of resources and system crashes.
[0097] The number of circuit breakers and the timing of their failures can reflect the extremely abnormal network conditions currently existing in the network, which can effectively help in on-site analysis and optimization of network data communication anomalies.
[0098] By analyzing one or more of the following metrics—blocking rate, retransmission rate, number of retransmissions of any message, and number of circuit breakers—we can effectively improve the anti-interference capability of device communication, its ability to cope with network anomalies, assist in network quality assessment, and provide a reference for network optimization.
[0099] The data transmission method provided in this application can be executed by a data transmission device. This application uses a data transmission device executing the data transmission method as an example to illustrate the data transmission device provided in this application.
[0100] This application also provides a data transmission device applied at the sending end.
[0101] like Figure 2 As shown, the data transmission device includes: a buffer queue module 210, a communication retransmission module 220, and a transmission module 230.
[0102] The queue caching module 210 is used to pause the scheduling of messages from the sending buffer queue if the network quality indicators do not meet the preset conditions, and to cache the messages to be received in the sending buffer queue. The communication retransmission module 220 is used to send multiple heartbeat requests to the receiving end; The sending module 230 is configured to, if it continuously receives heartbeat response messages returned by the receiving end and the cumulative number of heartbeat response messages reaches a first preset number, resume scheduling messages from the sending buffer queue and send the scheduled messages to the receiving end.
[0103] According to the data transmission apparatus provided in the embodiments of this application, when the network quality indicators do not meet the preset conditions, the output of messages from the buffer queue is paused, and the received messages are continued to be cached in the buffer queue; multiple heartbeat requests are sent to the receiving end; when multiple heartbeat reply packets are received from the receiving end in response to the heartbeat requests, messages continue to be output from the buffer queue and the output messages are sent to the receiving end. That is, when the network quality is poor, the received messages are cached but not transmitted, and the data transmission continues after the network quality is restored. This effectively prevents the loss of valid messages immediately due to exceeding the maximum retransmission limit, prevents subsequent data transmission from becoming unreliable, and reduces processing complexity. It can significantly reduce the probability of message loss and improve the reliability of communication.
[0104] In some embodiments, the data transmission apparatus further includes: An offline storage module is used to store the messages in the sending buffer queue offline and clear the sending buffer queue if the number of cached messages in the sending buffer queue reaches a capacity threshold. The history retransmission module is used to reload the offline-stored messages back to the sending buffer queue after resuming message scheduling from the sending buffer queue.
[0105] In some embodiments, the history retransmission module is specifically used to reload the offline stored messages back to the sending buffer queue at a first preset rate; Buffer queue module 210 is used to schedule messages from the sending buffer queue at a second preset rate; The second preset rate is not less than the first preset rate.
[0106] In some embodiments, the data transmission device includes: The handshake waiting module is used for: Store the scheduled messages and the timeout thresholds corresponding to the scheduled messages in the pending confirmation list; If an acknowledgment message is received from the receiving end for the scheduled message within the timeout threshold, the scheduled message is removed from the pending acknowledgment list; if the scheduled message has been marked as a retransmission message, the scheduled message and the corresponding retransmission count are removed from the retransmission list. If no acknowledgment message is received from the receiving end for the scheduled message within the timeout threshold, and the scheduled message is not marked as a retransmission message, the scheduled message is transferred from the pending acknowledgment list to the retransmission list, the scheduled message is marked as a retransmission message, and the corresponding retransmission count is updated. If no acknowledgment message is received from the receiver for the scheduled message within the timeout threshold, and the scheduled message has been marked as a retransmission message, the corresponding retransmission count is updated in the retransmission list.
[0107] In some embodiments, the data transmission apparatus further includes: Update the retransmission wait time for each retransmitted message in the retransmission list; When the retransmission wait time for any of the retransmission messages in the retransmission list reaches the retransmission duration threshold, the retransmission message is enqueued into the sending buffer queue.
[0108] In some embodiments, the retransmission module is configured to: If the number of retransmissions of any of the retransmission messages exceeds the second preset number, the retransmission waiting time for each of the retransmission messages in the retransmission list is paused. If a heartbeat response message is received continuously from the receiving end, and the cumulative number of heartbeat response messages reaches a first preset number, the retransmission waiting time for each retransmission message in the retransmission list is restored.
[0109] In some embodiments, the retransmission module is configured to: if the number of retransmissions of any retransmission message exceeds a second preset number, pause the retransmission waiting time for each of the retransmission messages in the retransmission list; If heartbeat response messages are continuously received from the receiving end, and the cumulative number of heartbeat response messages reaches a first preset number, the method further includes: Restore the retransmission wait time for each of the retransmission messages in the retransmission list.
[0110] In some embodiments, network quality metrics include one or more of the following: buffer queue blocking rate, retransmission rate, number of retransmissions of any message, and number of circuit breakers.
[0111] The data transmission device in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the specific device.
[0112] The data transmission device in this application embodiment can be a device with an operating system. This operating system can be a Microsoft (Windows) operating system, an Android operating system, an iOS operating system, or other possible operating systems; this application embodiment does not specifically limit the specific operating system.
[0113] The data transmission device provided in this application embodiment can achieve... Figure 1 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.
[0114] In some embodiments, such as Figure 3As shown, this application embodiment also provides an electronic device 300, including a processor 301, a memory 302, and a computer program stored in the memory 302 and executable on the processor 301. When the program is executed by the processor 301, it implements the various processes of the above-described data transmission method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0115] 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 can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 301 may also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.
[0116] The memory 302 may be a ROM (Read Only Memory) or other type of static storage device capable of storing static information and instructions, RAM (Random Access Memory) or other type of dynamic storage device capable of storing information and instructions, or it may be an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium capable of carrying or storing computer programs and capable of being read by a computer, without limitation herein.
[0117] The memory 302 is used to store computer programs that execute the embodiments of this application, and the execution is controlled by the processor 301. The processor 301 is used to execute the computer programs stored in the memory 302 to implement the steps shown in the foregoing method embodiments.
[0118] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.
[0119] This application also provides a non-transitory computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described data transmission method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0120] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0121] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described data transmission method.
[0122] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0123] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above data transmission method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0124] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0125] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0126] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the related technology, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0127] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
[0128] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0129] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.
Claims
1. A data transmission method, characterized in that, Applied to the sending end, including: If the network quality indicators do not meet the preset conditions, the scheduling of messages from the sending buffer queue will be suspended, and the messages to be received will continue to be cached in the sending buffer queue. Send multiple heartbeat requests to the receiving end; If a heartbeat response message is continuously received from the receiving end, and the cumulative number of heartbeat response messages reaches a first preset number, the message scheduling from the sending buffer queue is resumed, and the scheduled message is sent to the receiving end.
2. The data transmission method according to claim 1, characterized in that, After the message to be received is buffered into the send buffer queue, the method further includes: If the number of cached messages in the sending buffer queue reaches the capacity threshold, the messages in the sending buffer queue are stored offline, and the sending buffer queue is cleared. After resuming message scheduling from the send buffer queue, the method further includes: The messages stored offline are reloaded to the send buffer queue.
3. The data transmission method according to claim 2, characterized in that, The step of reloading the offline stored messages back to the sending buffer queue includes: The offline stored messages are reloaded to the sending buffer queue at a first preset rate. The recovery of messages scheduled from the send buffer queue includes: Messages are scheduled from the sending buffer queue at a second preset rate; The second preset rate is not less than the first preset rate.
4. The data transmission method according to claim 1, characterized in that, After sending the scheduled message to the receiving end, the method further includes: Store the scheduled messages and the timeout thresholds corresponding to the scheduled messages in the pending confirmation list; If an acknowledgment message is received from the receiving end for the scheduled message within the timeout threshold, the scheduled message is removed from the pending acknowledgment list; if the scheduled message has been marked as a retransmission message, the scheduled message and the corresponding retransmission count are removed from the retransmission list. If no acknowledgment message is received from the receiving end for the scheduled message within the timeout threshold, and the scheduled message is not marked as a retransmission message, the scheduled message is transferred from the pending acknowledgment list to the retransmission list, the scheduled message is marked as a retransmission message, and the corresponding retransmission count is updated. If no acknowledgment message is received from the receiver for the scheduled message within the timeout threshold, and the scheduled message has been marked as a retransmission message, the corresponding retransmission count is updated in the retransmission list.
5. The data transmission method according to claim 4, characterized in that, After transferring the scheduled message from the pending acknowledgment list to the retransmission list, or after updating the corresponding retransmission count in the retransmission list, the method further includes: Update the retransmission wait time for each retransmitted message in the retransmission list; When the retransmission wait time for any of the retransmission messages in the retransmission list reaches the retransmission duration threshold, the retransmission message is enqueued into the sending buffer queue.
6. The data transmission method according to claim 4 or 5, characterized in that, After updating the retransmission count, the method further includes: If the number of retransmissions of any of the retransmission messages exceeds the second preset number, the retransmission waiting time for each of the retransmission messages in the retransmission list is paused. If a heartbeat response message is received continuously from the receiving end, and the cumulative number of heartbeat response messages reaches a first preset number, the retransmission waiting time for each retransmission message in the retransmission list is restored.
7. The data transmission method according to claim 6, characterized in that, After restoring the retransmission wait time for each of the retransmission messages in the retransmission list, the method further includes: For a target message whose retransmission count exceeds the second preset number, if the retransmission waiting time of the target message reaches the retransmission duration threshold, the target message is re-enqueued to the sending buffer queue and removed from the retransmission list; After the target message is dequeued from the sending buffer queue, the target message is removed from the pending confirmation list.
8. The data transmission method according to claim 1, characterized in that, The network quality indicators include one or more of the following: blocking rate of the sending buffer queue, retransmission rate, number of retransmissions of any message, and number of circuit breakers.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the data transmission method as described in any one of claims 1-8.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the data transmission method as described in any one of claims 1-8.
