Detailed Description
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present description. This description may be embodied in many other forms than described herein, and similar applications may be made by those skilled in the art without departing from the spirit of the disclosure, so that this disclosure is not limited to the specific implementations disclosed below.
The terminology used in the one or more embodiments of the specification is for the purpose of describing particular embodiments only and is not intended to be limiting of the one or more embodiments of the specification. As used in this specification, the singular forms "a," "an," "the," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used in one or more embodiments of the present specification refers to and encompasses any or all possible combinations of one or more of the associated listed items.
It should be understood that, although the terms first, second, etc. may be used in one or more embodiments of this specification to describe various information, these information should not be limited by these terms. These terms are only used to distinguish one type of information from another. For example, a first may also be referred to as a second, and similarly, a second may also be referred to as a first, without departing from the scope of one or more embodiments of the present description. The term "if" as used herein may be interpreted as "at..once" or "when..once" or "in response to a determination", depending on the context.
Furthermore, it should be noted that, user information (including, but not limited to, user equipment information, user personal information, etc.) and data (including, but not limited to, data for analysis, stored data, presented data, etc.) according to one or more embodiments of the present disclosure are information and data authorized by a user or sufficiently authorized by each party, and the collection, use, and processing of relevant data is required to comply with relevant laws and regulations and standards of relevant countries and regions, and is provided with corresponding operation entries for the user to select authorization or denial.
First, terms related to one or more embodiments of the present specification will be explained.
Heartbeat is a short packet of data sent periodically in network communications to maintain the connection active state or to detect the online state of both parties to the communication, a connection keep-alive mechanism commonly found in the TCP/IP protocol.
The timeout time of the network address translation (Network Address Translation, NAT for short) is a preset time threshold for the device to automatically disconnect after detecting that the connection is inactive, for releasing the occupied public network IP resources.
A transmission control protocol (Transmission Control Protocol, abbreviated as TCP) connection is a reliable two-way communication link established based on the transmission control protocol, the connection is established through three handshakes, and four waving ends the connection, so as to ensure the integrity and the sequence of data transmission.
An Acknowledgement Character (ACK) is an acknowledgement signal sent by a receiving end to a sending end in the TCP protocol, which indicates that a packet with a specific sequence number has been successfully received, and is used to implement flow control and error recovery for reliable transmission.
The dichotomy is an efficient algorithm for finding target values in a ordered data set, and the target is rapidly located by halving the search interval each time, with a time complexity of O (log n).
The interpolation method is a mathematical method for estimating the data value of an unknown point according to a known data point construction function model, and is commonly used for data complementation and trend prediction in the fields of signal processing, numerical analysis and the like.
With the development of scientific technology, network communication technology plays a key role in connection and data transmission between various devices.
Currently, for maintenance of a network connection between a transmitting end and a receiving end, a heartbeat packet transmitting mechanism with a fixed interval is generally relied on. The method ensures the continuity of communication by periodically sending heartbeat packets from a sending end to a receiving end to detect the connection state.
However, the fixed heartbeat interval adopted in the method cannot give consideration to both the energy consumption and the response speed of the equipment, if the heartbeat interval is too short, the equipment is frequently awakened to increase the power consumption, and if the heartbeat interval is too long, the detection of the connection state may be delayed, so that the communication efficiency is affected. In addition, this approach is also difficult to dynamically adjust to real-time network environments, resulting in inadequate stability under complex or varying network conditions.
In view of this, in the present specification, a heartbeat interval adjustment method is provided, and the present specification relates to a heartbeat interval adjustment device, a computing apparatus, a computer-readable storage medium, and a computer program product, which are described in detail in the following embodiments one by one.
Referring to fig. 1, fig. 1 shows a flowchart of a heartbeat interval adjustment method according to an embodiment of the present disclosure, where the heartbeat interval adjustment method is applied to a transmitting end of a network transmission system, and the network transmission system further includes a receiving end, and the method specifically includes the following steps.
Step 102, responding to the establishment of the network connection between the sending end and the receiving end, and acquiring a first heartbeat interval and a timeout duration threshold of the network connection.
The network transmission system refers to a system architecture for realizing data interaction between a sending end and a receiving end through a communication protocol (such as Transmission Control Protocol/Internet Protocol, TCP/IP for short). The core function of the network transmission system is to ensure reliable transmission of data in a complex network environment by dynamically maintaining a connection state. In the embodiment of the present disclosure, the network transmission system may support a heartbeat mechanism to cope with situations such as timeout of network address translation (Network Address Translation, NAT for short), fluctuation of weak network, etc., for example, a communication system between an internet of things device and a cloud server, or an interaction network between a mobile terminal and a distributed server cluster.
The sending end is a device or module for actively initiating a data transmission request and sending a heartbeat packet, and the receiving end is a device or module for responding to the request of the sending end and feeding back confirmation information. Specifically, the sending end and the receiving end may be mutually converted, for example, the sending end may be a client device (such as a mobile phone, intelligent hardware, etc.), and the receiving end may be a server node (such as a cloud server), or vice versa. For example, in an actual mobile communication scenario, the mobile phone may send a heartbeat packet as a sending end to the server, and the server may return a confirmation message as a receiving end to maintain the connection validity, and at the same time, the server may also send a heartbeat packet as a sending end to the mobile phone, and the mobile phone may return a confirmation message as a receiving end to maintain the connection validity. In practical applications, since the server and the like need to bear the network connection maintenance of a plurality of devices, in general, the server is used for bearing the sending end to passively receive the heartbeat packet, and the client device such as the mobile phone is used for bearing the sending end to actively send the heartbeat packet.
The heartbeat packet is a control data packet sent from the sending end to the receiving end and used for detecting the connection state, and generally contains information such as a serial number, a timestamp or a state identifier. In the embodiment of the present disclosure, the sending and receiving acknowledgement mechanism of the heartbeat packet is a key basis for determining whether the network connection fails. For example, in the TCP protocol, the heartbeat packet may be implemented by a keep-alive mechanism, while in the custom protocol, the heartbeat packet may carry a specific field (e.g., "networkTag" indicates the current network type) to assist in adjusting the policy.
The heartbeat interval is a time period for the sending end to continuously send heartbeat packets, and is used for detecting the active state of network connection. In the embodiment of the present disclosure, dynamic adjustment of the heartbeat interval is a core goal, and the duration of the heartbeat interval needs to balance energy consumption and instantaneity, i.e. if the interval is too short, frequent waking up of the device (such as a mobile phone) to send the heartbeat packet increases power consumption, and if the interval is too long, detection of abnormal connection (such as disconnection caused by NAT timeout) may be delayed. For example, the initial heartbeat interval may be set to 240 seconds, and subsequently adjusted to 120 seconds or 580 seconds depending on network conditions.
The first heartbeat interval is an initial heartbeat interval, also referred to as a start heartbeat interval (STARTHEART), determined at the time of network connection establishment, and is typically preset based on actual network connection performance, or determined based on historical data. In this embodiment of the present disclosure, the first heartbeat interval is determined and acquired based on the network connection between the sending end and the receiving end, for example, the first heartbeat interval may default to 240 seconds, and be adjusted step by comparing the subsequent response duration with the timeout duration threshold. Specifically, in Wi-Fi networks, the first heartbeat interval may be short (e.g., 120 seconds) and long (e.g., 240 seconds) in mobile networks such as 4G, 5G, etc., to accommodate stability differences in different network environments.
Alternatively, the minimum heartbeat interval and the maximum heartbeat interval may be acquired simultaneously with the acquisition of the first heartbeat interval. The minimum heartbeat interval (minHeart) is determined based on the actual condition of the network connection, and the minimum heartbeat period lower limit allowed in the heartbeat adjustment strategy is used for preventing frequent equipment awakening and resource waste caused by the too short heartbeat interval. The maximum heartbeat interval (maxHeart) is determined based on the actual condition of the network connection, and the maximum heartbeat period upper limit allowed in the heartbeat adjustment strategy is used for preventing the connection state detection delay caused by overlong heartbeat interval.
In general, the first heartbeat interval is included in the range of values of the minimum heartbeat interval and the maximum heartbeat interval. Optionally, the minimum heartbeat interval and the maximum heartbeat interval between the sending end and the receiving end may be different or the same, so as to adapt to different network connection environments. For example, the local client as the transmitting end defaults to 120 seconds for the minimum heartbeat interval, the server as the receiving end defaults to 240 seconds for the maximum heartbeat interval, 580 seconds for both the local client as the transmitting end and the server as the receiving end, and 240 seconds for the start heartbeat interval.
The timeout duration threshold is a time reference for determining whether a network connection has failed, and is typically associated with a timeout setting of a Network Address Translation (NAT) gateway or a connection management policy at the receiving end. In this embodiment of the present disclosure, the timeout duration threshold needs to cover the maximum delay that may occur in the actual network environment (for example, the NAT timeout time may be 300 seconds), and on this basis, a reasonable threshold (for example, 280 seconds slightly smaller than the NAT timeout time) is set, so as to avoid misjudgment caused by network jitter. For example, if the response time of the heartbeat packet exceeds 280 seconds, a heartbeat down-regulation strategy may be triggered to shorten the interval.
In practical applications, a network connection from a sender to a receiver may be used to establish a communication link with the receiver through a protocol handshake (such as a TCP connection), where NAT mapping, IP address allocation, etc. are typically involved. For example, when the mobile device is connected to the cloud server through the 4G network, NAT binding of the operator gateway needs to be completed first.
And under the condition that the establishment of the network connection is completed, acquiring the first heartbeat interval and a timeout duration threshold of the network connection.
In the step, a first heartbeat interval and a timeout duration threshold value of the network connection are acquired by responding to the establishment of the network connection between the sending end and the receiving end, so that a data basis is provided for the subsequent adjustment of the first heartbeat interval.
Step 104, based on the first heartbeat interval, sending the heartbeat packet to the receiving end through the network connection.
After the network connection between the transmitting end and the receiving end is established, the heartbeat packet can be transmitted to the receiving end at the first heartbeat interval through the established network connection.
Specifically, when sending the heartbeat packet to the receiving end, timing can be started after the network connection is established, and when the timing reaches the first heartbeat interval, the heartbeat packet is sent, and the timing is reset.
Optionally, before starting to time and before reaching the first heartbeat interval and sending the heartbeat packet, the sending end can verify whether the current network connection has other data packet transmission except the heartbeat packet in real time. For example, if the sender is sending service data (such as file upload, message push, etc.) to the receiver through the connection, the current timing is cancelled, that is, the sending of the heartbeat packet is temporarily stopped, so as to avoid frequent waking up of the device or occupation of bandwidth, that is, when the sender detects data transmission of the non-heartbeat packet (such as a response procedure of writing (write) data after a transmission (read) operation), the current connection is considered to be still active, so that it is not necessary to further verify whether the connection survives by sending the heartbeat packet, thereby reducing redundant operation. Meanwhile, the situation that the network connection is broken by mistake due to the fact that the connection with a receiving end (such as a server) is overtime caused by the fact that the data packet is transmitted in the network connection in a weak network environment is avoided.
In the step, by periodically sending the heartbeat packet based on the first heartbeat interval and combining the service data verification logic before sending, the real-time detection of the network connection state is ensured, the resource waste is avoided, and a data basis is provided for the subsequent dynamic adjustment of the first heartbeat interval.
And 106, under the condition that the heartbeat packet confirmation message fed back by the receiving end is received, determining the response time length.
The heartbeat packet confirmation message is response information which is fed back to the sending end and is used for confirming the validity of the connection after the receiving end receives the heartbeat packet sent by the sending end. The message may typically contain a time stamp, status identifier or sequence number, etc. field to indicate that the receiving end has successfully received the heartbeat packet and maintained the current connection. In the embodiment of the present disclosure, the sending mechanism of the heartbeat packet Acknowledgement message may be based on a keep-alive mechanism of the TCP protocol (such as Acknowledgement Character (ACK) response), or a specific field in the custom protocol. For example, in communication between the mobile device and the server, the server returns an acknowledgement message (e.g., "ACK 20250609205237") containing a timestamp immediately after receiving the heartbeat packet sent by the client, to indicate that the connection is not broken.
The response time length is the time difference between the sending end sending the heartbeat packet and the receiving end returning the heartbeat packet confirmation message, and is used for measuring the delay and the stability of the network connection. In the embodiment of the present disclosure, the calculation of the response time may be based on a difference between a transmission timestamp recorded by the transmitting end and an acknowledgement timestamp fed back by the receiving end. For example, if the sender sends a heartbeat packet at a time stamp T1 (e.g., 20250609205237), and the receiver returns an acknowledgement message at a time stamp T2 (e.g., 20250609205245), the response time is t2—t1=8 seconds. The response time is a core basis for dynamically adjusting the heartbeat interval, specifically, if the response time is smaller than a preset timeout time threshold (for example, 280 seconds), the current network is stable, the heartbeat interval can be tried to be prolonged, and if the response time exceeds the threshold, the heartbeat interval needs to be shortened to improve the connection reliability.
Specifically, the sending end may record the sending timestamp (e.g., obtain the time accurate to milliseconds through the system time API) synchronously when sending the heartbeat packet to the receiving end. When the receiving end returns the heartbeat packet confirmation message, the sending end can analyze the timestamp in the confirmation message (or record the receiving moment based on the local time), and calculate the difference between the timestamp and the receiving moment to determine the response time.
In the step, the response time is determined by recording the sending time of the heartbeat packet and the receiving time of the heartbeat packet confirmation message, and a data basis is provided for the subsequent adjustment of the first heartbeat interval.
And step 108, determining an adjustment direction based on the response time and the timeout time threshold, and adjusting the first heartbeat interval according to the adjustment direction.
The direction of adjustment is to determine the directivity strategy of the heartbeat interval to be adjusted upwards (i.e. the interval time is prolonged) or downwards (i.e. the interval time is shortened) according to the state evaluation result of the network connection. In the embodiment of the specification, the judgment of the adjustment direction is based on the comparison relation between the response time length and the timeout time length threshold, and the resource utilization rate is optimized while the connection effectiveness is ensured through matching the actual condition of network connection. Specifically, if the response time is smaller than the timeout time threshold, the current network stability is higher, so that the adjustment direction can be determined to be up-regulated, namely, the heartbeat interval is prolonged to reduce the equipment wake-up frequency, otherwise, if the response time exceeds the timeout time threshold, the adjustment direction can be determined to be down-regulated, namely, the heartbeat interval is shortened to improve the timeliness of connection detection.
Specifically, when the adjustment direction is determined, the first heartbeat interval can be adjusted in accordance with the adjustment direction.
Optionally, the first heartbeat interval is adjusted according to the adjustment direction, an optional method is to screen in the history heartbeat period which has been determined to be successfully connected based on the adjustment direction, and select the heartbeat interval adjacent to or close to the current first heartbeat interval as the adjusted first heartbeat interval, an optional method is to adjust the first heartbeat interval along the adjustment direction by a preset adjustment step length to obtain the adjusted first heartbeat interval, and an optional method is to determine an adjustment interval in the adjustment direction and adjust the first heartbeat interval based on the end value of the adjustment interval. The specific adjustment manner can be flexibly determined according to the actual implementation scenario, and the embodiment of the present disclosure does not specifically limit this.
Optionally, the first heartbeat interval is adjusted according to the adjustment direction, and the adjustment range needs to be satisfied in a range of a maximum heartbeat interval and a minimum heartbeat interval determined based on the current network connection.
In the step, the adjustment direction is determined based on the response time length and the timeout time length threshold, and the first heartbeat interval is adjusted according to the adjustment direction, so that the first heartbeat interval is reasonably adjusted based on the actual response time length and the timeout time length threshold of the network connection in a complex network environment, and the effectiveness of the network connection and the optimization of the resource consumption are ensured.
And 110, returning to the step of sending the heartbeat packet to the receiving end through the network connection based on the first heartbeat interval until the target heartbeat interval is obtained under the condition that the network connection reaches a stable state.
The steady state refers to an operation state in which the network connection between the transmitting end and the receiving end is kept low in delay, low in fluctuation and free from abnormal interruption in a certain time range. Specifically, when the number of times that the response duration of the network connection is continuously stabilized within the preset threshold range is greater than the preset threshold, and the triggering condition of direction adjustment is not performed (that is, the up-adjustment or down-adjustment of the heartbeat interval is not required), the current network connection can be considered to have entered a stable state. At this time, the reliability of the network environment is high, and the current configuration can be maintained without frequently adjusting the heartbeat interval so as to save resources.
The target heartbeat interval is the heartbeat interval which is finally determined after dynamic adjustment and is used for maintaining the effectiveness of network connection in a stable state and balancing the energy consumption and real-time requirements.
After completing the sending of the heartbeat packet, receiving the confirmation message, calculating the response time length, determining the adjustment direction and adjusting the heartbeat interval, the step of sending the heartbeat packet based on the first heartbeat interval can be performed in a returning mode, specifically, the step of continuing to send the heartbeat packet based on the heartbeat interval after the last iteration adjustment is performed. Therefore, closed loop iterative optimization aiming at the first heartbeat interval is formed, and dynamic adaptability of the network connection state is ensured.
Optionally, after the target heartbeat interval is obtained, the target heartbeat interval may be recorded in a historical heartbeat period, so that the target heartbeat interval is used as reference data when the heartbeat interval is adjusted in the case that the network environment changes later.
In the embodiment of the specification, the adjustment direction is determined based on the comparison relation between the real-time response time length of the heartbeat packet and the preset timeout time length threshold value of the network connection by dynamically adjusting the heartbeat interval, after the connection is established between the transmitting end and the receiving end, the heartbeat interval transmitted by the heartbeat packet is continuously optimized through iteration, so that the heartbeat interval is ensured to be effectively and timely connected, meanwhile, unnecessary frequent awakening and resource consumption are avoided, the state change of the network is dynamically matched through a response time length feedback mechanism, and the heartbeat interval gradually converges to the target heartbeat interval in a stable state through iteration optimization, thereby improving the instantaneity and reliability of message transmission while reducing the energy consumption of equipment, and realizing the self-adaptive optimization of the network connection.
In an alternative embodiment of the present disclosure, adjusting the first heartbeat interval in the adjustment direction includes:
inquiring a first historical heartbeat interval corresponding to the adjustment direction from the historical heartbeat period;
determining an adjustment interval in the adjustment direction under the condition that a first historical heartbeat interval corresponding to the adjustment direction is not queried, wherein the range of the adjustment interval is set based on network connection;
the first heartbeat interval is adjusted based on the adjustment interval.
The historical heartbeat period is a successfully executed heartbeat interval historical data set recorded and stored by a dynamic adjustment strategy after the network connection is established between the transmitting end and the receiving end. The historical heartbeat period generally comprises information such as heartbeat interval value after each adjustment, corresponding response time length, adjustment direction, adjustment time stamp and the like. For example, in Wi-Fi networks, the network transmission system may record a historical heartbeat cycle of [120 seconds, 180 seconds, 240 seconds, 300 seconds, 360 seconds ] for reference in subsequent adjustments.
The first historical heartbeat interval is a recorded heartbeat interval value consistent with the current adjustment direction in the historical heartbeat period. For example, if the current adjustment direction is "up" (i.e., the time interval is extended), the first historical heartbeat interval may be a value in the history that is adjacent to and longer than the current first heartbeat interval (e.g., the current first heartbeat interval is 240 seconds, and the first historical heartbeat interval may be 300 seconds). Optionally, if the first historical heartbeat interval is not obtained through screening, dynamic calculation and adjustment are required based on the adjustment interval.
The adjustment interval is a range of adjustment for the first heartbeat interval determined based on the current network connection, specifically, in an initial case, a minimum value (curMinHeart, i.e., a lower limit) and a maximum value (curMaxHeart, i.e., an upper limit) of the adjustment interval may be set as a minimum heartbeat interval (minHeart) and a maximum heartbeat interval (maxHeart) of the current network connection. The adjustment interval is used to determine a new heartbeat interval by an actual mathematical method (e.g., dichotomy, linear interpolation, etc.) without querying the first historical heartbeat interval. For example, if the current heartbeat interval is 240 seconds, the adjustment direction is "up" and the adjustment interval is [240 seconds, 580 seconds ], then the midpoint 410 seconds of the adjustment interval may be taken as a candidate for the first heartbeat interval adjustment.
In practical application, when the adjustment direction is determined, the network transmission system first retrieves and screens the heartbeat interval record consistent with the current adjustment direction from the historical heartbeat period, and preferentially selects a value adjacent to or close to the current first heartbeat interval as the first historical heartbeat interval.
Under the condition that the first historical heartbeat interval is not inquired, an initial adjustment interval is required to be determined based on the current network connection, further adjustment is carried out based on the adjustment direction, so that an adjustment interval corresponding to the adjustment direction is determined, and the first heartbeat interval is adjusted based on the adjustment interval by adopting a mathematical method.
Specifically, in the process of determining the adjustment interval, the boundary of the adjustment interval needs to be checked, that is, the determined adjustment interval needs to be satisfied within the maximum heartbeat interval and the minimum heartbeat interval.
In the embodiment of the specification, the adjustment of the first heartbeat interval is realized by combining the data retrieval of the historical heartbeat period and the dynamic calculation of the adjustment interval, the redundant calculation is reduced by screening by utilizing the existing historical data in a complex network environment, and the adjustment interval is further determined to adjust under the condition that the adjustment interval is searched for screening, so that the accuracy of the adjustment of the first heartbeat interval is ensured, and the resource utilization rate is optimized while the connection effectiveness is ensured.
In an optional embodiment of the present disclosure, the adjustment direction includes an up-adjustment direction, and the adjustment interval includes an up-adjustment interval in the up-adjustment direction, where the up-adjustment direction is an adjustment direction having a response time duration less than a timeout time duration threshold;
based on the adjustment interval, adjusting the first heartbeat interval includes:
Under the condition that the adjustment direction is an upward adjustment direction and the first heartbeat interval is a stable heartbeat interval, judging whether the continuous successful times of the heartbeats corresponding to the first heartbeat interval are larger than a preset successful times threshold value or not;
if so, setting the upper limit of the up-regulation interval as the maximum heartbeat interval of network connection, and setting the lower limit of the up-regulation interval as the first heartbeat interval;
The first heartbeat interval is adjusted based on the upper and lower limits of the up-regulation interval.
The up-regulation direction is a strategy direction for dynamically regulating the heartbeat interval according to the network connection state in the network transmission system, and specifically refers to a direction for selecting and prolonging the heartbeat interval by judging that the current network environment is stable under the condition that the response time length is smaller than a preset timeout time length threshold value. The goal of the up-direction is to reduce the device wake-up frequency by extending the heartbeat interval, reducing power consumption, while maintaining the validity of the connection. For example, in Wi-Fi networks, if the response time of a heartbeat packet is 120 seconds (less than the timeout time threshold 280 seconds), the system may determine to be up-turned, attempting to extend the heartbeat interval from 180 seconds to 200 seconds or more.
The up-regulation interval is a range of values defined based on the network connection characteristics for calculating a new heartbeat interval in the up-regulation direction. The upper limit of the up-regulation interval may typically be set to the maximum heartbeat interval (maxHeart) allowed by the current network connection, and the lower limit may typically be set to the current first heartbeat interval (curHeart) to be adjusted. For example, if the current heartbeat interval is 240 seconds and the maximum heartbeat interval is 580 seconds, the up-regulation interval may be set to [240 seconds, 580 seconds ]. After the up-regulation interval is determined, the adjusted first heartbeat interval is calculated and determined in the up-regulation interval by an actual mathematical method (such as a dichotomy method, an interpolation method and the like), so that the optimal value is gradually approximated under the condition that the adjusted interval is ensured not to exceed the range allowed by the current network continuity.
A stable heartbeat interval refers to a state in which the current heartbeat interval has been determined to be appropriate for the current network environment by successive successful verifications (e.g., successive successful transmission and receipt of acknowledgement messages). Alternatively, the steady state may be marked by a flag bit (stabled =true). For example, if the device successfully transmits heartbeat packets 10 times in a Wi-Fi network and the response time is less than 280 seconds, the flag bit stabled may be set to true, which indicates that the current heartbeat interval (e.g., 240 seconds) has entered a steady state, based on which subsequent adjustments may be optimized.
The continuous successful number of heartbeats (stabledSuccessCount) is the number of times of continuously and successfully sending and receiving the confirmation message at the current heartbeat interval, and is used for verifying the stability of the network environment. For example, if the device successfully transmits 12 heartbeat packets in succession at a heartbeat interval of 240 seconds (each response time duration is less than 280 seconds), stabledSuccessCount =12. The number of consecutive successful heartbeats may be used as a key condition for triggering the up-regulation logic, for example, only when stabledSuccessCount exceeds a preset threshold (e.g., 10 times), the network transmission system may consider the current network environment stable enough to allow for an extended heartbeat interval.
The number of consecutive failures of the heartbeat (failedCount) is a parameter value corresponding to the number of consecutive successes of the heartbeat, that is, the number of times that the heartbeat packet is continuously transmitted at the current heartbeat interval but the acknowledgement message is not received, for reflecting the instability of the current network environment.
The preset success number threshold is a fixed value (e.g. 10 times) configured by the system, and is used for judging whether the heartbeat interval has entered a steady state. For example, if stabledSuccessCount =12, the preset success number threshold is 10, the system may consider that the current heartbeat interval (e.g. 240 seconds) is stable, and may trigger the up-regulation strategy.
The maximum heartbeat interval (maxHeart) is the upper limit of the heartbeat interval allowed by the network connection, and is generally set based on the NAT timeout time (such as 600 seconds) of the network environment or the connection management policy of the receiving end, for example, the default value is 580 seconds. For example, maxHeart may be set to 580 seconds in a 4G network due to the instability of the mobile network, and 360 seconds in a Wi-Fi network. The function of this parameter is to prevent the abnormal connection from being detected in time (such as the disconnection of NAT overtime) caused by the overlong heartbeat interval, so as to balance the resource optimization and the connection reliability.
Optionally, in the case that the adjustment direction is the up direction and the first heartbeat interval is the stable heartbeat interval, information of a successful heartbeat may be recorded. Specifically, the pseudo code of the setting process may be referred to as follows:
if (stabled = true) stabledSuccessCount ++; if the heartbeat mark bit is in a stable state, adding 1 to the continuous successful times of the stable heartbeat;
success HeartList.add (curHeart); successCount ++; in the list of statistical successful heart beat periods (at the current heart beat interval), the number of successive successful heart beats;
if (successCount > =2) failedCount =0, and/if the number of continuous successful heartbeat times is greater than or equal to two, setting the number of continuous failed heartbeat times to 0, namely considering that the current heartbeat operates stably in the network environment.
In practical application, if the adjustment direction is the up-adjustment direction and the first heartbeat interval is the stable heartbeat interval, it can be further verified whether the continuous successful number of heartbeats is greater than the preset successful number threshold, if so, the upper limit of the up-adjustment interval is set to be the maximum heartbeat interval of the network connection, and the lower limit of the up-adjustment interval is set to be the first heartbeat interval, that is, the current first heartbeat interval is adjusted upwards, and the maximum heartbeat interval allowed by the current network connection is limited. Specifically, the pseudo code of this process can be referred to as follows:
if (stabled = true & stabledSuccessCount > = 10)// if the heartbeat flag bit has entered a steady state and the number of consecutive successes to stabilize the heartbeat is greater than 10;
curMaxHeart = maxHeart;// set the upper limit of the up-regulation interval to the maximum heartbeat interval;
curMinHeart = curHeart;// the lower limit of the up-regulation interval is set to the first heartbeat interval.
When the upper limit and the lower limit of the up-regulation section are determined, the first heartbeat interval is adjusted based on the upper limit and the lower limit. Alternatively, the adjustment may be performed using actual mathematical methods, such as dichotomy. Specifically, the pseudo code of this process can be referred to as follows:
curHeart = (curMinHeart + curMaxHeart)/2;// the first heartbeat interval is set to half of the sum of the upper and lower limits of the up-regulation interval.
Optionally, in the actual adjustment process, when the adjustment is performed by using the dichotomy, it needs to be verified whether the upper limit and the lower limit of the currently determined up-adjustment interval conflict, that is, whether the lower limit needs to be verified to be smaller than the upper limit, if the lower limit is larger than the upper limit, it is indicated that the determined up-adjustment interval conflicts, and the adjustment is required to be performed on the up-adjustment interval, specifically, the upper limit and the lower limit may be made equal by setting the value of the lower limit to the value of the upper limit. Specifically, the pseudo code of this process can be referred to as follows:
if (curMinHeart > curMaxHeart), curMinHeart = curMaxHeart, and/if the lower limit of the up-regulation interval is greater than the upper limit, the lower limit of the up-regulation interval is set as the upper limit of the up-regulation interval.
In the embodiment of the specification, under the condition that the adjustment direction is the up adjustment direction and the first heartbeat interval is the stable heartbeat interval, the upper limit of the up adjustment interval is set to be the maximum heartbeat interval of the network connection and the lower limit is set to be the current first heartbeat interval based on the condition that whether the continuous successful times of the heartbeat is larger than the preset successful times threshold value or not, so that the first heartbeat interval is adjusted based on the upper limit and the lower limit of the adjusted up adjustment interval, the strategy of dynamically optimizing the heartbeat interval while ensuring the effectiveness of the network connection is realized, the prolongation operation of triggering the heartbeat interval only under the condition that the network environment is continuously stable is ensured, the first heartbeat interval is adjusted by determining the upper limit and the lower limit of the up adjustment interval, the condition that the adjusted first heartbeat interval exceeds the network connection requirement range is prevented, the optimal value is gradually approximated through iteration, the timeliness of connection detection is maintained while the wakeup frequency of equipment is reduced and the power consumption is reduced, and the resource consumption and the connection reliability is effectively balanced.
In an optional embodiment of the present disclosure, the adjustment direction includes an up-adjustment direction, and the adjustment interval includes an up-adjustment interval in the up-adjustment direction, where the up-adjustment direction is an adjustment direction having a response time duration less than a timeout time duration threshold;
based on the adjustment interval, adjusting the first heartbeat interval includes:
screening out a second heartbeat interval adjacent to the first heartbeat interval in the upward adjustment direction from the historical heartbeat period under the condition that the adjustment direction is the upward adjustment direction and the first heartbeat interval is the unstable heartbeat interval;
setting the upper limit of the up-regulation interval as the maximum heartbeat interval of network connection, and setting the lower limit of the up-regulation interval as the second heartbeat interval;
The first heartbeat interval is adjusted based on the upper and lower limits of the up-regulation interval.
An unstable heartbeat interval is a state in which the current heartbeat interval has not yet passed continuous successful verification, and is generally represented by the number of continuous successful heartbeats (stabledSuccessCount) not reaching a preset success number threshold (e.g., 10), or a flag stabled =false, indicating that the heartbeat interval has not yet been determined to be suitable for the current network environment. For example, in a scenario where a mobile device connects to a server through a 4G network, if the device only successfully transmits 3 heartbeat packets at a heartbeat interval of 240 seconds (the response duration is less than 280 seconds), but the preset 10 threshold values have not been reached, the heartbeat interval is still in an unstable state and needs to be further observed and adjusted. The existence of this state means that there may be fluctuations in the network environment, and premature lengthening of the heartbeat interval is to be avoided to prevent connection anomalies.
The second heartbeat interval is selected from the historical heartbeat period, and the next heartbeat interval value which is adjacent to the current first heartbeat interval and in the up-regulating direction is used as a reference in the regulating scene of the unstable heartbeat interval. For example, if the current first heartbeat interval is 120 seconds, the adjacent up-regulation direction value recorded in the history heartbeat period is 180 seconds, and then the second heartbeat interval is 180 seconds. The second heartbeat interval is used for providing a dynamic calculation basis for the adjustment interval, so that the optimal heartbeat interval can be gradually approximated based on the existing historical data under the condition of lacking enough stability verification, and the connection reliability is ensured, and meanwhile, the resource waste is avoided.
In practical application, if the adjustment direction is the up-adjustment direction and the first heartbeat interval is an unstable heartbeat interval, it is indicated that the current first heartbeat interval is not applicable, at this time, a second heartbeat interval between the current first heartbeat interval and the first heartbeat interval in the up-adjustment direction should be screened out from the historical heartbeat period, and the second heartbeat interval is used as the adjustment basis of the upper limit and the lower limit of the up-adjustment interval.
That is, the upper limit of the up-regulation interval is set as the maximum heartbeat interval of the network connection, and the lower limit of the up-regulation interval is set as the second heartbeat interval, that is, the up-regulation is started from the screened second heartbeat interval, and the maximum heartbeat interval allowed by the current network connection is limited. Specifically, the pseudo code of this process can be referred to as follows:
if (stabled = false), curHeart = SELECTEDHEART,// if the heartbeat flag bit is in an unstable state, setting the second heartbeat interval to the current heartbeat interval;
curMaxHeart = maxHeart;// set the upper limit of the up-regulation interval to the maximum heartbeat interval;
curMinHeart = curHeart;// the lower limit of the up-regulation interval is set to the second heartbeat interval.
When the upper limit and the lower limit of the up-regulation section are determined, the first heartbeat interval is adjusted based on the upper limit and the lower limit. Alternatively, the adjustment may be performed using actual mathematical methods, such as dichotomy. Specifically, the pseudo code of this process can be referred to as follows:
curHeart = (curMinHeart + curMaxHeart)/2;// the first heartbeat interval is set to half of the sum of the upper and lower limits of the up-regulation interval.
Optionally, in the actual adjustment process, when the adjustment is performed by using the dichotomy, it needs to be verified whether the upper limit and the lower limit of the currently determined up-adjustment interval conflict, that is, whether the lower limit needs to be verified to be smaller than the upper limit, if the lower limit is larger than the upper limit, it is indicated that the determined up-adjustment interval conflicts, and the adjustment is required to be performed on the up-adjustment interval, specifically, the upper limit and the lower limit may be made equal by setting the value of the lower limit to the value of the upper limit. Specifically, the pseudo code of this process can be referred to as follows:
if (curMinHeart > curMaxHeart), curMinHeart = curMaxHeart, and/if the lower limit of the up-regulation interval is greater than the upper limit, the lower limit of the up-regulation interval is set as the upper limit of the up-regulation interval.
In the embodiment of the specification, under the condition that the adjustment direction is the upward adjustment direction and the first heartbeat interval is the unstable heartbeat interval, the heartbeat interval is dynamically adjusted based on the second heartbeat interval screened in the historical heartbeat period, so that the problem that on the premise of lacking sufficient stability verification, the optimal heartbeat interval can be gradually approximated through the existing historical data is solved, the condition that the adjustment of the heartbeat interval is always based on the known effective historical value when the stable condition is not met is ensured, the abnormal connection risk caused by blind extension of the interval due to accidental success is avoided, meanwhile, the adjustment interval is limited between the second heartbeat interval and the maximum heartbeat interval, the heartbeat interval is prevented from exceeding the network connection requirement range, and the optimal value can be gradually approximated through iterative optimization, so that the timeliness of connection detection is maintained while the equipment wakeup frequency and the power consumption are reduced, and the resource consumption and the connection reliability are effectively balanced.
In an optional embodiment of the present disclosure, after adjusting the first heartbeat interval, the method further includes:
And setting the first heartbeat interval as the lower limit of the up-regulation interval under the condition that the range of the up-regulation interval is smaller than the preset interval threshold and the adjusted first heartbeat interval is an unstable heartbeat interval.
The preset interval threshold is a fixed value of the system configuration that is used to measure whether the adjustment interval range is large enough to support efficient dynamic adjustment. The preset interval threshold is typically set based on the stability requirements of the network environment and the resource optimization objectives, for example, a default value of 10 seconds. When the difference between the upper limit and the lower limit of the up-regulation interval is smaller than the threshold, the system considers that the current regulation interval is too small to realize resource optimization by further regulating the heartbeat interval, so that a conservative strategy is needed to maintain the connection stability. For example, in a 4G network, if the upper limit of the up-regulation interval is 240 seconds and the lower limit is 235 seconds (the difference is 5 seconds), the preset interval threshold condition is triggered, and the system will not continue to prolong the heartbeat interval.
In the actual adjustment process, if the range of the up-adjustment interval is smaller than the preset interval threshold, the first heartbeat interval cannot be adjusted further accurately based on the upper and lower limits of the up-adjustment interval, which indicates that the current up-adjustment interval reaches the extremum condition. For example, cannot be adjusted by mathematical methods such as dichotomy, interpolation, etc. Therefore, the lower limit of the up-regulation interval can be directly used as the adjusted first heartbeat interval. Specifically, the pseudo code of this process can be referred to as follows:
if (curMaxHeart-curMinHeart < = 10& gt stabled = false) curHeart = curMinHeart; if the difference between the upper limit and the lower limit of the up-regulation interval is less than or equal to 10 seconds and the flag bit is not stable, the first heartbeat interval is set as the lower limit of the up-regulation interval.
In the embodiment of the specification, by setting the heartbeat interval to the lower limit of the upregulation interval under the condition that the regulated first heartbeat interval is still in an unstable state and the upregulation interval range is smaller than the preset interval threshold value, balance between resource consumption and connection reliability is achieved, abnormal connection risks caused by heartbeat interval regulation under the condition that the regulation interval reaches an extreme value are avoided, meanwhile, the stability of the heartbeat interval is maintained through a conservation strategy, resource waste caused by frequent invalid regulation is prevented, the possibility of dynamic regulation is reserved, and meanwhile, the condition that the lower heartbeat interval is maintained when the network environment is not stable so as to quickly detect connection state change is ensured, so that the robustness and the energy efficiency ratio of a system are improved in a complex network environment.
In an alternative embodiment of the present disclosure, the adjustment direction includes a down direction, the adjustment section includes a down section in the down direction, the down direction is an adjustment direction that is longer than a timeout period threshold in response;
based on the adjustment interval, adjusting the first heartbeat interval includes:
under the condition that the adjustment direction is a downward adjustment direction and the first heartbeat interval is a stable heartbeat interval, judging whether the continuous failure times of the heartbeats corresponding to the first heartbeat interval are larger than a preset failure times threshold value or not;
If so, setting the lower limit of the down-regulating interval as the minimum heartbeat interval of network connection, and setting the upper limit of the down-regulating interval as the first heartbeat interval;
The first heartbeat interval is adjusted based on the upper and lower limits of the down-regulation interval.
The down-regulating direction is a strategy direction for dynamically regulating the heartbeat interval according to the network connection state in the network transmission system, and specifically refers to a direction for selecting and shortening the heartbeat interval by judging that the current network environment is unstable under the condition that the response time length exceeds a preset timeout time length threshold value. The goal of downregulating the direction is to improve the timeliness of connection detection by shortening the heartbeat interval, and prevent connection abnormality from being not found in time due to network delay or abnormality. For example, in a scenario where the mobile device connects to the server through the 4G network, if the response time of a certain heartbeat packet is 320 seconds (exceeding the timeout threshold 280 seconds), the system may determine to turn down, and attempt to shorten the heartbeat interval from 240 seconds to 180 seconds or less, so as to speed up anomaly detection and maintain connection validity.
The down interval is a range of values defined based on the network connection characteristics for calculating a new heartbeat interval in the down direction. The upper limit of the down-regulation interval is typically set to the current first heartbeat interval (curHeart) to be adjusted, and the lower limit is typically set to the minimum heartbeat interval (minHeart) allowed by the network connection. For example, if the current heartbeat interval is 240 seconds and the minimum heartbeat interval is 120 seconds, the down-regulation interval may be set to [120 seconds, 240 seconds ]. After the down-regulation interval is determined, the adjusted heartbeat interval can be calculated and determined in the interval by an actual mathematical method (such as a dichotomy method, an interpolation method and the like), so that the adjusted interval can not be lower than the current network connection requirement, and the optimal value can be gradually approximated by iterative optimization, so that the balance between the resource consumption and the connection reliability is achieved.
The preset failure number threshold is a fixed value (e.g., 3 times) configured by the system, and is used to measure whether the number of consecutive failures reaches a condition that requires triggering a specific operation (e.g., adjusting a policy, triggering an alarm, or locking a mechanism). The threshold is typically based on the stability requirements of the network environment, resource optimization objectives or security policy settings, e.g. 3 times as default. In the network transmission system, the preset failure frequency threshold is used for judging whether the current heartbeat interval has been subjected to continuous failure and the direction needs to be adjusted (such as the stable state is changed into the downward direction) so as to prevent the abnormal connection from being detected in time. For example, in a scenario where a mobile device connects to a server through a 4G network, if the device does not receive a confirmation message (failedCount =5) continuously for 5 times at a heartbeat interval of 240 seconds, and the preset failure frequency threshold is 3 times, the system determines that the current network environment is unstable, and needs to shorten the heartbeat interval to improve the detection timeliness.
Optionally, in the case where the adjustment direction is the down direction and the first heartbeat interval is the stable heartbeat interval, the information of the current heartbeat interval may be removed from the historical heartbeat cycle (successHeartList) and the number of consecutive failures of the heartbeat may be increased by 1. Specifically, the pseudo code of the setting process may be referred to as follows:
stabledSuccessCount =0, successecount=0, faildecount++// set the steady heartbeat succession success number to 0, set the heartbeat succession success number to 0, and add 1 to the heartbeat succession failure number.
In practical application, if the adjustment direction is the down adjustment direction and the first heartbeat interval is the stable heartbeat interval, it can be further verified whether the continuous failure times of the heartbeats are greater than the preset failure times threshold, if so, the upper limit of the down adjustment interval is set as the maximum heartbeat interval of the network connection, and the lower limit of the up adjustment interval is set as the first heartbeat interval, that is, the current first heartbeat interval starts to be adjusted upwards, and the maximum heartbeat interval allowed by the current network connection is limited. Specifically, the pseudo code of this process can be referred to as follows:
if (stabled = true & failedCount > = 3)// if the heartbeat flag bit has entered a steady state and the number of consecutive failures of the steady heartbeat is 3 or more;
curMinHeart = minHeart;// setting the lower limit of the down-regulation interval to the minimum heartbeat interval;
curMaxHeart = curHeart;// set the upper limit of the down-regulation interval to the first heartbeat interval.
When the upper limit and the lower limit of the down-regulation section are determined, the first heartbeat interval is adjusted based on the upper limit and the lower limit. Alternatively, the adjustment may be performed using actual mathematical methods, such as dichotomy. Specifically, the pseudo code of this process can be referred to as follows:
curHeart = (curMinHeart + curMaxHeart)/2;// the first heartbeat interval is set to half of the sum of the upper and lower limits of the up-regulation interval.
Optionally, in the actual adjustment process, when the adjustment is performed by using the dichotomy, it needs to be verified whether the upper limit and the lower limit of the currently determined down-adjustment interval conflict, that is, whether the upper limit is smaller than the lower limit, if the upper limit is smaller than the lower limit, it is indicated that the determined down-adjustment interval conflicts, and the adjustment is required for the down-adjustment interval, specifically, the upper limit value is set to the lower limit value, so that the lower limit and the upper limit are equal. Specifically, the pseudo code of this process can be referred to as follows:
if (curMaxHeart < curMinHeart), curMaxHeart = curMinHeart, and/if the upper limit of the down-regulation interval is smaller than the lower limit, the upper limit of the down-regulation interval is set as the lower limit of the down-regulation interval.
In the embodiment of the specification, under the condition that the adjustment direction is the down adjustment direction and the first heartbeat interval is the stable heartbeat interval, the upper limit of the down adjustment interval is set to be the current heartbeat interval and the lower limit is set to be the minimum heartbeat interval of network connection based on the condition that whether the continuous failure times of the heartbeat exceeds a preset threshold value, so that the heartbeat interval is adjusted based on the upper limit and the lower limit of the adjusted down adjustment interval, the strategy of dynamically optimizing the heartbeat interval while guaranteeing the connection effectiveness is realized, the shortening operation of the heartbeat interval is ensured to be triggered only under the condition that continuous abnormality occurs in the network environment, the resource waste caused by blind adjustment due to accidental failure is avoided, meanwhile, the frequent equipment wakeup caused by the excessively short heartbeat interval is prevented, the gradual optimal value is optimized through iterative optimization, the rationality of resource consumption is maintained while the connection detection timeliness is improved, and the connection reliability and the energy consumption optimization are effectively balanced.
In an alternative embodiment of the present disclosure, the adjustment direction includes a down direction, the adjustment section includes a down section in the down direction, the down direction is an adjustment direction that is longer than a timeout period threshold in response;
based on the adjustment interval, adjusting the first heartbeat interval includes:
Screening out a third heartbeat interval adjacent to the first heartbeat interval in the downward adjustment direction from the historical heartbeat period under the condition that the adjustment direction is the downward adjustment direction and the first heartbeat interval is the unstable heartbeat interval;
Setting the lower limit of the down-regulation interval as the minimum heartbeat interval of network connection, and setting the upper limit of the down-regulation interval as the third heartbeat interval;
The first heartbeat interval is adjusted based on the upper and lower limits of the down-regulation interval.
The third heartbeat interval is selected from the historical heartbeat period, and the next heartbeat interval value which is adjacent to the current first heartbeat interval and in the downward adjustment direction is used as a reference in an adjustment scene of the unstable heartbeat interval. For example, if the current first heartbeat interval is 240 seconds, the adjacent down direction value recorded in the historical heartbeat period is 180 seconds, and then the third heartbeat interval is 180 seconds. The third heartbeat interval is used for providing a dynamic calculation basis for the adjustment interval, so that when the network environment is unstable, the heartbeat interval can be gradually shortened based on the known historical data, and excessive adjustment caused by accidental failure is avoided while the timeliness of connection detection is ensured.
In practical application, if the adjustment direction is the down adjustment direction and the first heartbeat interval is an unstable heartbeat interval, it is indicated that the current first heartbeat interval is not applicable, and at this time, a third heartbeat interval in the down adjustment direction and with the first heartbeat interval should be screened from the historical heartbeat period, and the third heartbeat interval is used as the adjustment basis of the upper limit and the lower limit of the down adjustment interval.
That is, the lower limit of the down-regulation interval is set as the minimum heartbeat interval of the network connection, and the upper limit of the down-regulation interval is set as the third heartbeat interval, that is, the down-regulation is started from the screened third heartbeat interval, and the minimum heartbeat interval allowed by the current network connection is taken as the limit. Specifically, the pseudo code of this process can be referred to as follows:
if (stabled = false & failedCount > = 3), curHeart = SELECTEDHEART,// if the heartbeat flag bit is in an unstable state and the number of consecutive heartbeats right is 3 or more, setting the third heartbeat interval as the current heartbeat interval;
curMinHeart = minHeart;// setting the lower limit of the down-regulation interval to the minimum heartbeat interval;
curMaxHeart = curHeart;// the upper limit of the down-regulation interval is set to the third heartbeat interval.
When the upper limit and the lower limit of the down-regulation section are determined, the first heartbeat interval is adjusted based on the upper limit and the lower limit. Alternatively, the adjustment may be performed using actual mathematical methods, such as dichotomy. Specifically, the pseudo code of this process can be referred to as follows:
curHeart = (curMinHeart + curMaxHeart)/2;// the first heartbeat interval is set to half of the sum of the upper and lower limits of the up-regulation interval.
Optionally, in the actual adjustment process, when the adjustment is performed by using the dichotomy, it needs to be verified whether the upper limit and the lower limit of the currently determined down-adjustment interval conflict, that is, whether the upper limit is smaller than the lower limit, if the upper limit is smaller than the lower limit, it is indicated that the determined down-adjustment interval conflicts, and the adjustment is required for the down-adjustment interval, specifically, the upper limit value is set to the lower limit value, so that the lower limit and the upper limit are equal. Specifically, the pseudo code of this process can be referred to as follows:
if (curMaxHeart < curMinHeart), curMaxHeart = curMinHeart, and/if the upper limit of the down-regulation interval is smaller than the lower limit, the upper limit of the down-regulation interval is set as the lower limit of the down-regulation interval.
In the embodiment of the specification, under the condition that the adjustment direction is the downward adjustment direction and the first heartbeat interval is the unstable heartbeat interval, the heartbeat interval is dynamically adjusted based on the third heartbeat interval screened out in the historical heartbeat period, so that the strategy that the optimal heartbeat interval can be gradually approximated through the existing historical data on the premise of lacking sufficient stability verification is realized, the condition that the adjustment of the heartbeat interval is always based on the known effective historical value when the stable condition is not satisfied is ensured, the resource waste caused by blind shortening of the interval due to accidental failure is avoided, meanwhile, the adjustment interval is limited between the minimum heartbeat interval and the third heartbeat interval, frequent equipment wakeup caused by too short heartbeat interval is prevented, and the optimal value can be gradually approximated through iterative optimization, so that the rationality of the resource consumption is maintained while the connection detection timeliness is improved, and the connection reliability and the resource consumption are effectively balanced.
In an optional embodiment of the present disclosure, after adjusting the first heartbeat interval, the method further includes:
And setting the first heartbeat interval as the minimum heartbeat interval of network connection under the condition that the range of the down-regulating interval is smaller than the preset interval threshold and the adjusted first heartbeat interval is an unstable heartbeat interval.
The preset interval threshold is a fixed value of the system configuration that is used to measure whether the adjustment interval range is large enough to support efficient dynamic adjustment. The preset interval threshold is typically set based on the stability requirements of the network environment and the resource optimization objectives, for example, a default value of 10 seconds. When the difference between the upper limit and the lower limit of the down-regulation interval is smaller than the threshold, the system considers that the current regulation interval is too small to realize resource optimization by further regulating the heartbeat interval, so that a conservative strategy is needed to maintain the connection stability. For example, in a 4G network, if the upper limit of the down-regulation interval is 240 seconds and the lower limit is 235 seconds (the difference is 5 seconds), the preset interval threshold condition is triggered, and the system will not continue to prolong the heartbeat interval.
In the actual adjustment process, if the range of the down-adjustment interval is smaller than the preset interval threshold, the first heartbeat interval cannot be adjusted further accurately based on the upper and lower limits of the down-adjustment interval, which indicates that the current down-adjustment interval reaches the extremum condition. For example, cannot be adjusted by mathematical methods such as dichotomy, interpolation, etc. Thus, the lower limit of the adjustment interval, i.e. the minimum heartbeat interval, can be directly taken as the adjusted first heartbeat interval. Specifically, the pseudo code of this process can be referred to as follows:
if (curMaxHeart-curMinHeart < = 10& gt stabled = false) curHeart = minHeart; if the difference between the upper limit and the lower limit of the up-regulation interval is less than or equal to 10 seconds and the flag bit is not stable, the first heartbeat interval is set to be the minimum heartbeat interval.
In the embodiment of the specification, by setting the heartbeat interval to the lower limit of the down-regulation interval, that is, the minimum heartbeat interval, under the condition that the regulated first heartbeat interval is still in an unstable state and the down-regulation interval range is smaller than the preset interval threshold, balance between resource consumption and connection reliability is achieved, abnormal connection risk caused by heartbeat interval regulation under the condition that the regulated interval reaches an extreme value is avoided, meanwhile, the stability of the heartbeat interval is maintained through a conservative strategy, resource waste caused by frequent invalid regulation is prevented, the possibility of dynamic regulation is maintained, and meanwhile, the lower heartbeat interval is ensured to rapidly detect connection state change when the network environment is not stable, so that the robustness and the energy efficiency ratio of the system are improved in a complex network environment.
In an optional embodiment of the present disclosure, after querying a first historical heartbeat interval corresponding to the adjustment direction from the historical heartbeat period, further includes:
and setting the first historical heartbeat interval as the adjusted first heartbeat interval under the condition that the first historical heartbeat interval corresponding to the adjustment direction is inquired.
When the first historical heartbeat interval corresponding to the adjustment direction is queried from the historical heartbeat periods, the heartbeat interval which is verified and successfully establishes network connection exists in the adjustment direction is described, so that the queried first historical heartbeat interval can be directly set as the adjusted first heartbeat interval without adjustment based on the adjustment interval.
And setting the queried first historical heartbeat interval as the adjusted first heartbeat interval, namely, sending the heartbeat packet to the receiving end through network connection.
In the embodiment of the specification, under the condition that the first historical heartbeat interval corresponding to the adjustment direction is queried from the historical heartbeat period, the first historical heartbeat interval is directly set to be the adjusted first heartbeat interval, so that the calculation process of the complex adjustment interval is skipped on the premise of supporting the existing historical data, the adjustment efficiency is remarkably improved, the resource consumption is reduced, the adjustment time is shortened, the equipment wakeup frequency and the calculation resource occupation are reduced, and the high efficiency and the reliability of heartbeat interval adjustment are realized in a complex network environment.
In an alternative embodiment of the present disclosure, the adjustment direction includes a downturn direction, the downturn direction being an adjustment direction that is responsive to a length greater than a timeout period threshold;
after determining the adjustment direction based on the response time and the timeout time threshold, further comprising:
judging whether the response time length is the response time length of the retransmission heartbeat packet or not under the condition that the adjustment direction is the downward adjustment direction;
Under the condition that the response time is the response time of retransmitting the heartbeat packet, disconnecting the network connection, and judging whether the duration of the network connection is larger than the minimum heartbeat interval of the network connection;
If not, restoring the network connection, and returning to execute the step of sending the heartbeat packet to the receiving end through the network connection based on the first heartbeat interval;
if yes, the first heartbeat interval is adjusted according to the downward adjustment direction.
The retransmission heartbeat packet is a heartbeat packet actively retransmitted by the transmitting end under the condition that the heartbeat packet acknowledgement message is not received in the network transmission system, and is used for ensuring the validity of connection. The mechanism is typically triggered based on a timeout detection, e.g. when the first transmitted heartbeat packet does not receive an acknowledgement message within a preset time (e.g. 20 seconds), the system initiates a retransmission procedure. The response time of the retransmitted heartbeat packet is an important basis for judging the network connection state, for example, in a 4G network, if the first transmitted heartbeat packet is lost due to network fluctuation, the system retransmits after 30 seconds, and the response time (such as 15 seconds) after the retransmission is recorded as the judging basis of the adjustment direction. The mechanism improves connection reliability through redundant transmission, but needs to dynamically adjust strategies in combination with network environment to avoid resource waste.
The duration of network connection is the sum of the time elapsed from the moment when the network connection is currently disconnected after the sending end and the receiving end establish network connection, and is used for measuring the stability and the active state of the connection. For example, in a scenario where a mobile device is connected to a server through Wi-Fi, if the network connection setup time is YYYY-MM-DD 23:00:00, and the current time is yyyyy-MM-DD 23:03:00, the duration of the network connection is 180 seconds.
In practical application, under the condition that the adjustment direction is determined to be the down-adjustment direction, whether the response time length is the response time length of the retransmission heartbeat packet can be verified a priori, so as to avoid misjudgment caused by accidental network errors.
And under the condition that the response time is the response time of the resending heartbeat packet, the current network connection is indicated to be invalid, so that the current network connection is required to be actively disconnected, and the network connection time is counted.
In the case that the network connection time is less than the minimum heartbeat interval, it is indicated that the current network connection time may not fail, but does not wait for the heartbeat packet acknowledgement message fed back by the receiving end, so that the first heartbeat interval does not need to be adjusted, the network connection is directly restored, and the step of sending the heartbeat packet to the receiving end through the network connection based on the first heartbeat interval is performed in a returning manner.
When the network connection time is longer than the minimum heartbeat interval, the current network connection is not received in a time period when the heartbeat packet acknowledgement message fed back by the receiving end is received, so that the current network connection is indicated to be faulty, the first heartbeat interval is adjusted according to the downward adjustment direction, then the network connection is reestablished, and the heartbeat packet is sent to the receiving end through the network connection at the first heartbeat interval after the downward adjustment.
In the embodiment of the specification, by judging whether to disconnect and restore connection or directly execute the downregulation adjustment according to the duration of network connection under the condition that the adjustment direction is the downregulation direction and the response time length is the retransmission heartbeat packet, the method realizes the protection of the connection validity and avoids the excessive adjustment strategy caused by occasional exception, ensures that the downregulation is triggered only when the network environment is continuously abnormal through the response time length verification mechanism of the retransmission heartbeat packet, thereby reducing the misjudgment risk caused by occasional packet loss, and simultaneously, prevents frequent awakening caused by blindly shortening the heartbeat interval when the connection is not stable and responds to network fluctuation rapidly under the condition that the connection is operated for a longer time by taking the duration of the network connection as the judgment basis for restoring the connection, thereby maintaining the reasonability of resource consumption and effectively balancing the connection reliability and the resource consumption while improving the connection detection timeliness.
In an alternative embodiment of the present disclosure, sending, based on the first heartbeat interval, a heartbeat packet to a receiving end through a network connection includes:
And transmitting a heartbeat packet to the receiving end through the network connection based on the first heartbeat interval when no other data packet transmitted to the receiving end through the network connection exists, wherein the other data packet is a data packet except the heartbeat packet.
In practical applications, the sending of the heartbeat packet is not triggered on a fixed periodicity, but depends on the active state of the network connection. And when the heartbeat interval arrives at each time, the sending end can detect whether other data packet transmission exists in the current network connection in real time.
If other data packet transmission exists, the sending end can suspend the sending of the heartbeat packet, and the processing of the service data is completed preferentially. For example, in a TCP connection, if the sender is performing a write operation (uploading a file), the heartbeat timer is reset until the traffic data transmission is completed.
If no service data is transmitted, the sending end sends heartbeat packets according to the first heartbeat interval so as to maintain the validity of connection.
In a weak network environment, other data packets may take longer to transmit due to network fluctuations. If the heartbeat packet is sent at a fixed heartbeat interval at this time, the receiving end may determine that the connection is disconnected because the heartbeat packet is not sent in time. Therefore, the sending end starts a timeout detection mechanism (such as 20 seconds timeout) after sending the service data, and if no response is received, the connection state is verified through the heartbeat packet, instead of blindly shortening the heartbeat interval.
In the embodiment of the specification, the heartbeat packet is sent based on the first heartbeat interval under the condition that other data packet transmission does not exist, and the sending time is dynamically adjusted by combining with the active state of network connection, so that the strategy of obviously reducing the resource consumption and the misjudgment risk while ensuring the validity of connection is realized, the resource waste caused by the competition bandwidth of the heartbeat packet and service data is avoided, the increase of the power consumption caused by frequent awakening of equipment is reduced, the adaptive optimization of the heartbeat packet sending is realized in a complex network environment by judging the network active state and the service requirement, the energy consumption and the network load of the equipment are reduced, the accuracy and the reliability of connection detection are improved, and a more efficient and stable implementation path is provided for dynamically adjusting the heartbeat interval.
Referring to fig. 2, fig. 2 is a block diagram showing the overall implementation of a heartbeat interval adjustment method according to an embodiment of the present disclosure, as shown in fig. 2:
The method comprises the steps of establishing network connection between a sending end and a receiving end, starting to time at a first heartbeat interval, suspending the time counting of the first heartbeat interval if other data packet transmission is detected in the time counting period, sending the heartbeat packet to the receiving end and acquiring response time if no other data packet transmission reaches the time counting of the first heartbeat interval, adjusting the first heartbeat interval upwards and executing the step of time counting at the first heartbeat interval if the response time is not overtime, further judging whether the response time is the response time corresponding to the retransmission heartbeat packet or not if the response time is overtime, triggering a retransmission mechanism, retransmitting the heartbeat packet, directly disconnecting the network connection and stopping the time counting if the response time corresponding to the retransmission heartbeat packet is not long, judging whether the maintenance time of the network connection is longer than the minimum heartbeat interval or not if the maintenance time of the network connection is not long, reestablishing the network connection if the maintenance time is long, reestablishing the network connection after the first heartbeat interval is down, reestablishing the network connection, returning to establish the network connection and continuing to time counting at the first heartbeat interval.
By dynamically adjusting the heartbeat interval and combining the network active state and the service data transmission condition, the resource consumption is optimized while the connection stability is ensured, and by actively disconnecting and reestablishing the network connection mechanism, the misjudgment of abnormal connection is avoided, so that the efficient and reliable connection management is realized in a complex network environment.
Corresponding to the above method embodiments, the present disclosure further provides an embodiment of a heartbeat interval adjusting device, and fig. 3 shows a schematic structural diagram of the heartbeat interval adjusting device provided in one embodiment of the present disclosure. As shown in fig. 3, the apparatus includes:
An obtaining module 302, configured to obtain a first heartbeat interval and a timeout duration threshold of the network connection in response to establishing the network connection between the transmitting end and the receiving end;
A transmitting module 304 configured to transmit a heartbeat packet to the receiving end through a network connection based on the first heartbeat interval;
A determining module 306, configured to determine a response duration when receiving a heartbeat packet acknowledgement message fed back by the receiving end;
An adjustment module 308 configured to determine an adjustment direction based on the response time and the timeout time threshold, and adjust the first heartbeat interval according to the adjustment direction;
The execution module 310 is configured to return to executing the step of sending the heartbeat packet to the receiving end through the network connection based on the first heartbeat interval until the target heartbeat interval is obtained in a case that the network connection reaches a steady state.
Optionally, the adjustment module 308 is further configured to query a first historical heartbeat interval corresponding to the adjustment direction from the historical heartbeat cycles, determine an adjustment interval in the adjustment direction if the first historical heartbeat interval corresponding to the adjustment direction is not queried, wherein a range of the adjustment interval is set based on the network connection, and adjust the first heartbeat interval based on the adjustment interval.
Optionally, the adjustment direction includes an up-adjustment direction, the adjustment section includes an up-adjustment section in the up-adjustment direction, the up-adjustment direction is an adjustment direction with a response time length smaller than a timeout time length threshold, the adjustment module 308 is further configured to determine whether a heartbeat continuous success number corresponding to the first heartbeat interval is greater than a preset success number threshold if the adjustment direction is the up-adjustment direction and the first heartbeat interval is a stable heartbeat interval, if so, set an upper limit of the up-adjustment section as a maximum heartbeat interval of the network connection and set a lower limit of the up-adjustment section as the first heartbeat interval, and adjust the first heartbeat interval based on the upper limit and the lower limit of the up-adjustment section.
Optionally, the adjustment direction comprises an up-adjustment direction, the adjustment interval comprises an up-adjustment interval in the up-adjustment direction, the up-adjustment direction is an adjustment direction with a response time length smaller than a timeout time length threshold, the adjustment module 308 is further configured to screen out a second heartbeat interval adjacent to the first heartbeat interval in the up-adjustment direction from the historical heartbeat period when the adjustment direction is the up-adjustment direction and the first heartbeat interval is an unstable heartbeat interval, set an upper limit of the up-adjustment interval as a maximum heartbeat interval of network connection, set a lower limit of the up-adjustment interval as the second heartbeat interval, and adjust the first heartbeat interval based on the upper limit and the lower limit of the up-adjustment interval.
Optionally, the adjustment module 308 is further configured to set the first heartbeat interval to a lower limit of the up-regulation interval in case the range of the up-regulation interval is smaller than a preset interval threshold and the adjusted first heartbeat interval is an unstable heartbeat interval.
Optionally, the adjustment direction includes a down-regulation direction, the adjustment section includes a down-regulation section in the down-regulation direction, the down-regulation direction is an adjustment direction in which the response time is longer than a timeout period threshold, the adjustment module 308 is further configured to determine whether the number of continuous heartbeat failures corresponding to the first heartbeat interval is greater than a preset failure number threshold when the adjustment direction is the down-regulation direction and the first heartbeat interval is a stable heartbeat interval, if so, set a lower limit of the down-regulation section as a minimum heartbeat interval of the network connection, set an upper limit of the down-regulation section as the first heartbeat interval, and adjust the first heartbeat interval based on the upper limit and the lower limit of the down-regulation section.
Optionally, the adjustment direction includes a downturn direction, the adjustment interval includes a downturn interval in the downturn direction, the downturn direction is an adjustment direction that is responsive to a length greater than a timeout period threshold, the adjustment module 308 is further configured to filter out a third heartbeat interval adjacent to the first heartbeat interval in the downturn direction from the historical heartbeat period if the adjustment direction is the downturn direction and the first heartbeat interval is an unstable heartbeat interval, set a lower limit of the downturn interval as a network connected minimum heartbeat interval, set an upper limit of the downturn interval as the third heartbeat interval, and adjust the first heartbeat interval based on the upper and lower limits of the downturn interval.
Optionally, the adjustment module 308 is further configured to set the first heartbeat interval to a minimum heartbeat interval of the network connection in a case where the range of the down-regulation interval is less than the preset interval threshold and the adjusted first heartbeat interval is an unstable heartbeat interval.
Optionally, the adjustment direction includes a down direction, the down direction being an adjustment direction in which the response time is longer than a timeout period threshold, the adjustment module 308 is further configured to determine whether the response time is a response time for retransmitting the heartbeat packet if the adjustment direction is the down direction, disconnect the network connection if the response time is a response time for retransmitting the heartbeat packet and determine whether the duration of the network connection is greater than a minimum heartbeat interval of the network connection if the response time is the response time for retransmitting the heartbeat packet, if not, resume the network connection and return to perform the step of transmitting the heartbeat packet to the receiving end through the network connection based on the first heartbeat interval, and if so, adjust the first heartbeat interval according to the down direction.
Optionally, the adjustment module 308 is further configured to set the first historical heartbeat interval as the adjusted first heartbeat interval if the first historical heartbeat interval corresponding to the adjustment direction is queried.
Optionally, the sending module 304 is further configured to send the heartbeat packet to the receiving end over the network connection based on the first heartbeat interval in the absence of other data packets sent to the receiving end over the network connection, wherein the other data packets are data packets other than the heartbeat packet.
According to the heartbeat interval adjusting device, based on comparison of response time length and timeout time length threshold, historical heartbeat period data and an adjustment interval strategy are combined, the heartbeat interval is prolonged to reduce equipment wakeup frequency and energy consumption when a network environment is stable through an adaptive adjustment mechanism for adjusting the heartbeat interval upwards or downwards, the interval is shortened to speed up fault detection when the network environment is abnormal, erroneous disconnection caused by accidental packet loss is avoided through judging logic of resending heartbeat packets and connection duration, connection effectiveness and robustness are guaranteed to be maintained in a complex network environment, adjustment efficiency is further improved through priority multiplexing of historical successful heartbeat intervals, and finally dynamic balance is achieved between connection reliability and resource optimization.
The above is a schematic scheme of a heartbeat interval adjusting device in this embodiment. It should be noted that, the technical solution of the heartbeat interval adjusting device and the technical solution of the heartbeat interval adjusting method belong to the same conception, and details of the technical solution of the heartbeat interval adjusting device which are not described in detail can be referred to the description of the technical solution of the heartbeat interval adjusting method.
Fig. 4 illustrates a block diagram of a computing device 400 provided in accordance with one embodiment of the present description. The components of the computing device 400 include, but are not limited to, a memory 410 and a processor 420. Processor 420 is coupled to memory 410 via bus 430 and database 450 is used to hold data.
Computing device 400 also includes access device 440, access device 440 enabling computing device 400 to communicate via one or more networks 460. Examples of such networks include a public switched telephone network (Public Switched Telephone Network, PSTN for short), a local area network (Local Area Network, LAN for short), a wide area network (Wide Area Network, WAN for short), a personal area network (Personal Area Network, PAN for short), or a combination of communication networks such as the internet. The access device 440 may include one or more of any type of network interface, wired or wireless, such as a network interface card (NIC, network interface controller), such as an IEEE802.11 wireless local area network (Wireless Local Area Network, WLAN) wireless interface, a worldwide interoperability for microwave access (Worldwide Interoperability for Microwave Access, wi-MAX) interface, an ethernet interface, a universal serial bus (Universal Serial Bus, USB) interface, a cellular network interface, a bluetooth interface, a near field Communication (NEAR FIELD Communication, NFC).
In one embodiment of the present description, the above-described components of computing device 400, as well as other components not shown in FIG. 4, may also be connected to each other, such as by a bus. It should be understood that the block diagram of the computing device shown in FIG. 4 is for exemplary purposes only and is not intended to limit the scope of the present description. Those skilled in the art may add or replace other components as desired.
Computing device 400 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., tablet, personal digital assistant, laptop, notebook, netbook, etc.), mobile phone (e.g., smart phone), wearable computing device (e.g., smart watch, smart glasses, etc.), or other type of mobile device, or a stationary computing device such as a desktop or personal computer (Personal Computer, abbreviated as PC). Computing device 400 may also be a mobile or stationary server.
The processor 420 is configured to execute a computer program/instruction that, when executed by the processor, implements the steps of the heartbeat interval adjustment method described above.
The foregoing is a schematic illustration of a computing device of this embodiment. It should be noted that, the technical solution of the computing device and the technical solution of the heartbeat interval adjustment method belong to the same concept, and details of the technical solution of the computing device, which are not described in detail, can be referred to the description of the technical solution of the heartbeat interval adjustment method.
An embodiment of the present disclosure also provides a computer-readable storage medium storing a computer program/instruction that, when executed by a processor, implements the steps of the heartbeat interval adjustment method described above.
The above is an exemplary version of a computer-readable storage medium of the present embodiment. It should be noted that, the technical solution of the storage medium and the technical solution of the heartbeat interval adjustment method belong to the same concept, and details of the technical solution of the storage medium, which are not described in detail, can be referred to the description of the technical solution of the heartbeat interval adjustment method.
An embodiment of the present specification also provides a computer program product comprising computer programs/instructions which, when executed by a processor, implement the steps of the heartbeat interval adjustment method described above.
The above is an exemplary version of a computer program of the present embodiment. It should be noted that, the technical solution of the computer program and the technical solution of the heartbeat interval adjustment method belong to the same conception, and details of the technical solution of the computer program, which are not described in detail, can be referred to the description of the technical solution of the heartbeat interval adjustment method.
The foregoing describes specific embodiments of the present disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
The computer instructions include computer program code that may be in source code form, object code form, executable file or some intermediate form, etc. The computer readable medium may include any entity or device capable of carrying the computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer Memory, a Read-Only Memory (ROM), a random access Memory (Random Access Memory RAM), an electrical carrier signal, a telecommunications signal, a software distribution medium, and so forth. It should be noted that the content of the computer readable medium can be increased or decreased appropriately according to the requirements of the patent practice, for example, in some areas, according to the patent practice, the computer readable medium does not include an electric carrier signal and a telecommunication signal.
It should be noted that, for simplicity of description, the foregoing method embodiments are all expressed as a series of combinations of actions, but it should be understood by those skilled in the art that the embodiments are not limited by the order of actions described, as some steps may be performed in other order or simultaneously according to the embodiments of the present disclosure. Further, those skilled in the art will appreciate that the embodiments described in the specification are all preferred embodiments, and that the acts and modules referred to are not necessarily all required for the embodiments described in the specification.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and for parts of one embodiment that are not described in detail, reference may be made to related descriptions of other embodiments.
The preferred embodiments of the present specification disclosed above are merely used to help clarify the present specification. Alternative embodiments are not intended to be exhaustive or to limit the invention to the precise form disclosed. Obviously, many modifications and variations are possible in light of the teaching of the embodiments. The embodiments were chosen and described in order to best explain the principles of the embodiments and the practical application, to thereby enable others skilled in the art to best understand and utilize the invention. This specification is to be limited only by the claims and the full scope and equivalents thereof.