Heartbeat cycle determination method and device, electronic equipment and storage medium
By using the interval elimination method and the golden segmentation search method within the target heartbeat cycle interval, the optimal heartbeat cycle is determined, which solves the problem of resource waste and connection disconnection caused by improper heartbeat cycle settings, and realizes the maintenance of long connections and efficient utilization of resources.
Patent Information
- Application Number
- CN202510081138.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-17
- Publication Date
- 2025-05-13
AI Technical Summary
In the prior art, setting the heartbeat cycle is too small, resulting in waste of flow and power. setting it too large may cause the connection to be disconnected and lose the function of keeping the heartbeat alive connection.
By using the interval elimination method and the golden segmentation search method within the target heartbeat cycle interval, the optimal heartbeat cycle that meets the current heartbeat detection needs is determined.
The flexibility of determining the heartbeat cycle is achieved, allowing long connections between the client and the server to be maintained while reducing resource waste.
Smart Images

Figure CN119996489A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a method, device, electronic device and storage medium for determining a heartbeat cycle. Background Art
[0002] At present, in order to ensure a long connection between the client and the server, the client and the server will each send and receive messages at a fixed heartbeat cycle to notify each other of their online status. If the heartbeat cycle is set too small, a large amount of traffic and power in the client will be used for heartbeat detection, resulting in a waste of traffic and power. If the heartbeat cycle is set too large, the client and the server may be disconnected before the heartbeat message is sent because there is no data exchange for too long, and the heartbeat connection loses its function of keeping the connection alive.
[0003] It can be seen that how to flexibly set the heartbeat cycle is a technical problem that needs to be solved urgently. Summary of the invention
[0004] The embodiments of the present application provide a method, device, electronic device and storage medium for determining a heartbeat cycle, which can adaptively determine a heartbeat cycle that meets current heartbeat detection requirements.
[0005] In a first aspect, an embodiment of the present application provides a method for determining a heartbeat cycle, the method comprising:
[0006] Determine the target heartbeat cycle interval and heartbeat detection requirements;
[0007] Based on the interval elimination method, an optimal heartbeat cycle that meets the heartbeat detection requirements is determined from the target heartbeat cycle interval.
[0008] In the embodiment of the present application, it can be considered that there is an extreme value that meets the current heartbeat detection requirements within the target heartbeat cycle interval, so the interval that cannot contain the extreme value point can be eliminated in continuous iterations through the interval elimination method, so that the search interval continues to converge until the optimal heartbeat cycle that meets the current heartbeat detection requirements is determined. The method has a small amount of calculation and can determine the optimal heartbeat cycle relatively quickly.
[0009] Optionally, determining an optimal heartbeat cycle that meets the heartbeat detection requirement from the target heartbeat cycle interval based on an interval elimination method includes:
[0010] The optimal heartbeat cycle is determined from the target heartbeat cycle interval based on the golden section search method.
[0011] In an embodiment of the present application, the optimal heartbeat cycle that meets the heartbeat detection requirements can be determined from the target heartbeat cycle interval through the golden section search method. This method has a small amount of calculation and a fast convergence speed.
[0012] Optionally, determining the optimal heartbeat cycle from the target heartbeat cycle interval based on the golden section search method includes:
[0013] Determine a first golden section point of the target heartbeat cycle interval, and use the heartbeat cycle corresponding to the first golden section point as a first target heartbeat cycle;
[0014] Perform heartbeat detection based on the first target heartbeat cycle to obtain a first heartbeat detection result;
[0015] In response to the first heartbeat detection result indicating that the first target heartbeat cycle is available, determining whether the interval size of the target heartbeat cycle interval is less than a set value;
[0016] In response to the interval size of the target heartbeat cycle interval being not less than the set value, updating the lower limit value of the target heartbeat cycle interval to the first target heartbeat cycle;
[0017] The optimal heartbeat cycle is determined from the updated target heartbeat cycle interval based on the golden section search method.
[0018] In the embodiment of the present application, the heartbeat cycle corresponding to the golden section point in the target heartbeat cycle interval can be used as a detection object to determine whether it can maintain a long connection between the client and the server. If the heartbeat cycle corresponding to the golden section point can maintain a long connection between the client and the server, it is further determined whether the interval length of the target heartbeat cycle interval is less than the set value. If the interval length is greater than the set value, it indicates that the target heartbeat cycle interval needs to be further reduced. The above-mentioned heartbeat cycle that has been confirmed to maintain a long connection between the client and the server is used as the lower limit of the target heartbeat cycle to further reduce the target heartbeat cycle interval, so that the optimal heartbeat cycle can be found from the heartbeat cycle corresponding to the golden section point later.
[0019] Optionally, after performing heartbeat detection based on the first target heartbeat cycle to obtain a first heartbeat detection result, the method further includes:
[0020] In response to the first heartbeat detection result indicating that the first target heartbeat cycle is unavailable, the upper limit value of the target heartbeat cycle interval is updated to the first target heartbeat cycle.
[0021] In the embodiment of the present application, the heartbeat cycle corresponding to the golden section point within the target heartbeat cycle interval can be used as a detection object to determine whether it can maintain a long connection between the client and the server. If the heartbeat cycle corresponding to the golden section point cannot maintain a long connection between the client and the server, it indicates that the heartbeat cycle corresponding to the golden section point is too large. At this time, the heartbeat cycle corresponding to the golden section point can be used as the upper limit of the target heartbeat cycle interval, so that the optimal heartbeat cycle can be found from the heartbeat cycle smaller than the golden section point.
[0022] Optionally, determine the target heartbeat cycle interval, including:
[0023] Determine the initial heartbeat cycle;
[0024] Perform multiple heartbeat detections according to the initial heartbeat cycle to obtain multiple third heartbeat detection results;
[0025] In response to the plurality of third heartbeat detection results all indicating that the initial heartbeat cycle is available, increasing the initial heartbeat cycle to obtain a first candidate heartbeat cycle;
[0026] Perform heartbeat detection according to the first candidate heartbeat cycle to obtain a fourth heartbeat detection result;
[0027] In response to the fourth heartbeat detection result indicating that the first candidate heartbeat cycle is unavailable, the target heartbeat cycle interval is determined according to the initial heartbeat cycle and the first candidate heartbeat cycle.
[0028] In an embodiment of the present application, the initial heartbeat cycle can be determined based on artificial experience, and then it is judged whether it can maintain a long connection between the client and the server. If the initial heartbeat cycle can maintain a long connection between the client and the server, it indicates that the initial heartbeat cycle is available, then the initial heartbeat cycle can be continued to increase, so as to obtain the first candidate heartbeat cycle, and then it is judged whether it can maintain a long connection between the client and the server. If the first candidate heartbeat cycle cannot maintain a long connection between the client and the server, it indicates that the first candidate heartbeat cycle is unavailable, that is, the optimal heartbeat cycle can only be screened from the heartbeat cycle that is less than the first candidate heartbeat cycle. Therefore, the initial heartbeat cycle can be used as the lower limit value and the first candidate heartbeat cycle can be used as the upper limit value to preliminarily determine the target heartbeat cycle interval.
[0029] Optionally, increasing the initial heartbeat cycle to obtain a first candidate heartbeat cycle includes:
[0030] The initial heartbeat cycle is multiplied to obtain the first candidate heartbeat cycle.
[0031] In an embodiment of the present application, by multiplying the initial heartbeat cycle, the first candidate heartbeat cycle obtained can be significantly different from the initial heartbeat cycle, which is conducive to the first candidate heartbeat cycle obtaining a larger value. Once it is determined that the larger first candidate heartbeat cycle is unavailable, the target heartbeat cycle interval can be determined relatively quickly.
[0032] Optionally, after performing a plurality of heartbeat detections according to the initial heartbeat cycle to obtain a plurality of third heartbeat detection results, the method further includes:
[0033] In response to the plurality of third heartbeat detection results all indicating that the initial heartbeat cycle is unavailable, reducing the initial heartbeat cycle to obtain a second candidate heartbeat cycle;
[0034] Perform heartbeat detection according to the second candidate heartbeat cycle to obtain a fifth heartbeat detection result;
[0035] In response to the fifth heartbeat detection result indicating that the second candidate heartbeat cycle is available, the second candidate heartbeat cycle is used as the initial heartbeat cycle.
[0036] In the embodiment of the present application, the initial heartbeat period can be determined according to artificial experience, and then it is judged whether it can keep a long connection between the client and the server. If the initial heartbeat period cannot keep a long connection between the client and the server, it indicates that the initial heartbeat period is set too large and is unavailable, so the current initial heartbeat period can be reduced to obtain a second candidate heartbeat period. Then it is judged whether it can keep a long connection between the client and the server. If the second candidate heartbeat period can keep a long connection between the client and the server, it indicates that the second candidate heartbeat period is available, so the second candidate heartbeat period is used as the initial heartbeat period.
[0037] In a second aspect, an embodiment of the present application provides a device for determining a heartbeat cycle, the device comprising:
[0038] A first determination unit, used to determine a target heartbeat cycle interval and a heartbeat detection requirement;
[0039] The second determining unit is used to determine the optimal heartbeat cycle that meets the heartbeat detection requirement from the target heartbeat cycle interval based on the interval elimination method.
[0040] Optionally, the second determining unit includes:
[0041] A heartbeat cycle determination unit is used to determine the optimal heartbeat cycle from the target heartbeat cycle interval based on the golden section search method.
[0042] Optionally, the heartbeat cycle determining unit includes:
[0043] The processing subunit determines a first golden section point of the target heartbeat cycle interval, and uses the heartbeat cycle corresponding to the first golden section point as a first target heartbeat cycle;
[0044] a detection subunit, configured to perform heartbeat detection based on the first target heartbeat cycle to obtain a first heartbeat detection result;
[0045] A judging subunit, configured to judge whether the interval size of the target heartbeat cycle interval is less than a set value in response to the first heartbeat detection result indicating that the first target heartbeat cycle is available;
[0046] The processing subunit is further configured to update the lower limit value of the target heartbeat cycle interval to the first target heartbeat cycle in response to the interval size of the target heartbeat cycle interval being not less than the set value;
[0047] The heartbeat cycle determination subunit is used to determine the optimal heartbeat cycle from the updated target heartbeat cycle interval based on the golden section search method.
[0048] Optionally, the processing subunit is further configured to update an upper limit value of the target heartbeat cycle interval to the first target heartbeat cycle in response to the first heartbeat detection result indicating that the first target heartbeat cycle is unavailable.
[0049] Optionally, the first determining unit includes:
[0050] An initial heartbeat cycle determining subunit, used to determine an initial heartbeat cycle;
[0051] A detection unit, configured to perform a plurality of heartbeat detections according to the initial heartbeat cycle to obtain a plurality of third heartbeat detection results;
[0052] A processing unit, configured to, in response to the plurality of third heartbeat detection results all indicating that the initial heartbeat cycle is available, increase the initial heartbeat cycle to obtain a first candidate heartbeat cycle;
[0053] The detection unit is further configured to perform heartbeat detection according to the first candidate heartbeat cycle to obtain a fourth heartbeat detection result;
[0054] The heartbeat cycle determination subunit is configured to determine the target heartbeat cycle interval according to the initial heartbeat cycle and the first candidate heartbeat cycle in response to the fourth heartbeat detection result indicating that the first candidate heartbeat cycle is unavailable.
[0055] Optionally, the processing unit is specifically used for:
[0056] The initial heartbeat cycle is multiplied to obtain the first candidate heartbeat cycle.
[0057] Optionally, the processing unit is further configured to: in response to the plurality of third heartbeat detection results all indicating that the initial heartbeat cycle is unavailable, reduce the initial heartbeat cycle to obtain a second candidate heartbeat cycle;
[0058] The detection unit is further configured to perform heartbeat detection according to the second candidate heartbeat cycle to obtain a fifth heartbeat detection result;
[0059] The initial heartbeat cycle determining subunit is further configured to use the second candidate heartbeat cycle as the initial heartbeat cycle in response to the fifth heartbeat detection result indicating that the second candidate heartbeat cycle is available.
[0060] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory for storing a computer program and a processor for executing the computer program, wherein when the computer program is executed by the processor, the electronic device is triggered to execute the steps of the method described in any embodiment of the first aspect.
[0061] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and when the computer program is executed by a processor, the processor executes the steps of the method described in any embodiment of the first aspect.
[0062] It should be understood that the second to fourth aspects of the embodiments of the present application are consistent with the technical solutions of the first aspect of the embodiments of the present application, and the beneficial effects achieved by each aspect and the corresponding feasible implementation methods are similar and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0064] Figure 1 A flowchart of a method for determining a heartbeat cycle provided in an embodiment of the present application;
[0065] Figure 2 A flowchart of a method for determining a target heartbeat cycle interval provided in an embodiment of the present application;
[0066] Figure 3 A flowchart of a method for determining an optimal heartbeat cycle based on a golden section search method provided in an embodiment of the present application;
[0067] Figure 4 A flowchart of a method for determining an optimal heartbeat cycle based on a golden section search method provided in an embodiment of the present application;
[0068] Figure 5 A schematic diagram of the structure of a device for determining a heartbeat cycle provided in an embodiment of the present application;
[0069] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0070] In order to better understand the technical solution of this specification, the embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0071] It should be clear that the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this specification.
[0072] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit this specification. The singular forms of "a", "said" and "the" used in the embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.
[0073] Currently, data can be transmitted between the client and the server based on different communication protocols. For example, the communication protocol can be the Message Queuing Telemetry Transport (MQTT) protocol, the Transmission Control Protocol (TCP), etc. This application does not impose any special restrictions on this.
[0074] In order to ensure a long connection between the client and the server, the client and the server will each send and exchange messages at a fixed heartbeat cycle to notify each other of their online status. For example, the client actively sends a heartbeat packet PINGREQ to the server periodically at a fixed heartbeat cycle. When the server receives the heartbeat packet from the client, it responds and returns a heartbeat packet PINGRESP to confirm each other's existence and normal communication. Within a fixed heartbeat cycle, if the server does not receive a heartbeat packet from the client, it will consider that the client no longer exists and actively release the current connection of the client; if the client does not receive a response heartbeat packet from the server within the cycle after sending the heartbeat packet, the client also believes that there is a problem with the connection with the server, actively disconnects the current connection, and tries to re-request the connection.
[0075] The inventor of the present application has found that in the above process, if the heartbeat period is set too small, a large amount of traffic and power in the client will be used for heartbeat detection, resulting in a waste of traffic and power. If the heartbeat period is set too large, the client and the server may be disconnected before the heartbeat message is sent because there is no data exchange for too long, and the heartbeat connection loses its function of keeping the connection alive.
[0076] It can be seen that how to flexibly set the heartbeat cycle is a technical problem that needs to be solved urgently.
[0077] In view of this, an embodiment of the present application provides a method for determining a heartbeat cycle. In this method, the optimal heartbeat cycle that meets the current heartbeat detection requirements is determined by using the interval elimination method within a determined target heartbeat cycle interval, thereby enabling the client and the server to maintain a long connection while also reducing the waste of related resources.
[0078] The technical solution protected by this application is described in detail below with reference to the accompanying drawings.
[0079] See also Figure 1 , is a flow chart of a method for determining a heartbeat period provided in an embodiment of the present application, the method can be applied to a client, and the flow of the method is described as follows:
[0080] Step 101: Determine the target heartbeat cycle interval and heartbeat detection requirements.
[0081] In the embodiment of the present application, the heartbeat detection requirement can be considered to include three dimensions: first, the traffic consumption dimension; second, the power consumption dimension; and third, the keep-alive connection dimension.
[0082] In terms of traffic consumption, if the heartbeat period is T heart The client consumes Flow per hour of heartbeat packets. The size of each heartbeat packet sent and the size of the reply heartbeat packet are F send and F receive , the traffic consumed by the client's heartbeat packets per hour is shown in formula (1):
[0083]
[0084] From the above formula (1), it can be seen that the smaller the heartbeat period Theart is, the greater the traffic consumption Flow is, that is, the greater the traffic consumption of the client will be; conversely, the larger the heartbeat period Theart is, the smaller the traffic consumption Flow is, that is, the smaller the traffic consumption of the client will be.
[0085] In terms of power consumption, the power consumption of the heartbeat packet per hour is E, the power consumption of sleep per hour is Esleep, and the power consumption of work after sending each heartbeat packet is Ework. The power consumption of the client's heartbeat packet per hour is shown in formula (2):
[0086]
[0087] It can be seen from the above formula (2) that when the heartbeat cycle Theart is smaller, the heartbeat packets are sent more frequently, the client is started more frequently, and the working power consumption E is greater; conversely, when the heartbeat cycle Theart is larger, the heartbeat packets are sent less frequently, the client is started less frequently, and the working power consumption E is smaller.
[0088] For the keep-alive connection dimension, the smaller the heartbeat cycle Theart is, the better the effect of the keep-alive connection is, that is, the higher the possibility of maintaining a long connection between the client and the server is; conversely, the larger the heartbeat cycle Theart is, the worse the effect of the keep-alive connection is, that is, the lower the possibility of maintaining a long connection between the client and the server is.
[0089] In summary, from the perspective of traffic consumption and power consumption, we hope that the heartbeat cycle Theart is as large as possible. From the perspective of keep-alive connection, we hope that the heartbeat cycle Theart is as small as possible.
[0090] The target heartbeat cycle interval can be considered as an interval containing the extreme value points of the heartbeat cycle, and the heartbeat cycle within the target heartbeat cycle interval can be considered to be monotonic, that is, as the heartbeat cycle increases, the corresponding power consumption / flow consumption decreases. The following is a detailed description of how to determine the target heartbeat cycle interval.
[0091] See also Figure 2 , is a flowchart of a method for determining a target heartbeat cycle interval provided in an embodiment of the present application. Step 101 can be implemented by executing sub-steps 1011 to 1019:
[0092] Step 1011: Determine the initial heartbeat cycle.
[0093] Step 1012: Perform multiple heartbeat detections according to the initial heartbeat cycle to obtain multiple third heartbeat detection results.
[0094] Step 1013: Determine whether the initial heartbeat cycle is available based on the plurality of third heartbeat detection results. If available, jump to step 1014; if not available, jump to step 1017.
[0095] Step 1014: Increase the initial heartbeat cycle to obtain a first candidate heartbeat cycle.
[0096] Step 1015: Perform heartbeat detection according to the first candidate heartbeat cycle to obtain a fourth heartbeat detection result.
[0097] Step 1016: In response to the fourth heartbeat detection result indicating that the first candidate heartbeat cycle is unavailable, a target heartbeat cycle interval is determined according to the initial heartbeat cycle and the first candidate heartbeat cycle.
[0098] Step 1017: Reduce the initial heartbeat cycle to obtain a second candidate heartbeat cycle.
[0099] Step 1018: Perform heartbeat detection according to the second candidate heartbeat cycle to obtain a fifth heartbeat detection result.
[0100] Step 1019 : In response to the fifth heartbeat detection result indicating that the second candidate heartbeat cycle is available, the second candidate heartbeat cycle is used as the initial heartbeat cycle, and the process jumps to step 1011 .
[0101] In the embodiment of the present application, the initial heartbeat period can be determined based on manual experience, and then it can be determined whether it can maintain a long connection between the client and the server.
[0102] If the initial heartbeat cycle can maintain a long connection between the client and the server, it indicates that the initial heartbeat cycle is available, and the initial heartbeat cycle can be further increased to obtain the first candidate heartbeat cycle. As a possible implementation method, the initial heartbeat cycle can be multiplied to obtain the first candidate heartbeat cycle. That is, it is beneficial for the first candidate heartbeat cycle to obtain a larger value. Once it is determined that the larger first candidate heartbeat cycle is unavailable, the target heartbeat cycle interval can be determined relatively quickly. For example, when performing the multiplication process, 2 times or more of the initial heartbeat cycle can be taken, and this application does not impose any special restrictions on this. After obtaining the first candidate heartbeat cycle, it can be determined whether it can maintain a long connection between the client and the server. If the first candidate heartbeat cycle cannot maintain a long connection between the client and the server, it indicates that the first candidate heartbeat cycle is unavailable, that is, the optimal heartbeat cycle can only be selected from the heartbeat cycle that is less than the first candidate heartbeat cycle. Therefore, the initial heartbeat cycle can be used as the lower limit value and the first candidate heartbeat cycle can be used as the upper limit value to preliminarily determine the target heartbeat cycle interval.
[0103] If the initial heartbeat cycle cannot maintain a long connection between the client and the server, it indicates that the initial heartbeat cycle is set too large and is unavailable, so the current initial heartbeat cycle can be reduced to obtain a second candidate heartbeat cycle. As a possible implementation method, the initial heartbeat cycle can be multiplied to obtain a second candidate heartbeat cycle. That is, it is beneficial for the second candidate heartbeat cycle to obtain a smaller value. Once it is determined that the smaller second candidate heartbeat cycle is available, the initial heartbeat cycle can be determined more quickly. After obtaining the second candidate heartbeat cycle, it can be determined whether it can maintain a long connection between the client and the server. If the second candidate heartbeat cycle can maintain a long connection between the client and the server, it indicates that the second candidate heartbeat cycle is available, and the second candidate heartbeat cycle is used as the initial heartbeat cycle.
[0104] Step 102: Determine the optimal heartbeat cycle that meets the heartbeat detection requirements from the target heartbeat cycle interval based on the interval elimination method.
[0105] In the embodiment of the present application, the interval elimination method can eliminate the interval that cannot contain the extreme value point in continuous iteration, so that the search interval continues to converge until the optimal heartbeat period that meets the current heartbeat detection requirements is determined. The method has a small amount of calculation and can determine the optimal heartbeat period relatively quickly.
[0106] See also Figure 3 , is a flowchart of a method for determining an optimal heartbeat cycle based on a golden section search method provided in an embodiment of the present application. Step 102 can be implemented by executing sub-step 1021:
[0107] Step 1021: Determine the optimal heartbeat cycle from the target heartbeat cycle interval based on the golden section search method.
[0108] In an embodiment of the present application, the optimal heartbeat cycle that meets the heartbeat detection requirements can be determined from the target heartbeat cycle interval through the golden section search method. This method has a small amount of calculation and a fast convergence speed.
[0109] The process of determining the optimal heartbeat cycle based on the golden section search method is described in detail below.
[0110] See also Figure 4 , is a flowchart of a method for determining an optimal heartbeat cycle based on a golden section search method provided in an embodiment of the present application. Step 1021 can be specifically performed by executing sub-steps 10211 to 10217:
[0111] Step 10211: Determine the first golden section point of the target heartbeat cycle interval, and use the heartbeat cycle corresponding to the first golden section point as the first target heartbeat cycle.
[0112] Step 10212: Perform heartbeat detection based on the first target heartbeat cycle to obtain a first heartbeat detection result.
[0113] Step 10213: Determine whether the first target heartbeat cycle is available according to the first heartbeat detection result, and if not, jump to step 10214. If available, jump to step 10215.
[0114] Step 10214: Update the upper limit value of the target heart cycle interval to the first target heart cycle, and jump to step 10211.
[0115] Step 10215: Determine whether the interval size of the target heartbeat cycle interval is smaller than the set value.
[0116] Step 10216: In response to the interval size of the target heartbeat cycle interval being not less than the set value, the lower limit value of the target heartbeat cycle interval is updated to the first target heartbeat cycle.
[0117] Step 10217: Determine the optimal heartbeat cycle from the updated target heartbeat cycle interval based on the golden section search method.
[0118] In the embodiment of the present application, the heartbeat cycle corresponding to the golden section point within the target heartbeat cycle interval can be used as the detection object. For example, the heartbeat cycle corresponding to the golden section point should satisfy formula (3):
[0119] (T-min) / (max-min)=0.618 (3)
[0120] Wherein, T represents the heartbeat cycle corresponding to the golden section point in the target heartbeat cycle interval, min represents the lower limit of the target heartbeat cycle interval, and max represents the upper limit of the target heartbeat cycle interval.
[0121] On this basis, it can be determined whether the heartbeat cycle corresponding to the golden section point can maintain a long connection between the client and the server. If the heartbeat cycle corresponding to the golden section point cannot maintain a long connection between the client and the server, it indicates that the heartbeat cycle corresponding to the golden section point is too large. At this time, the heartbeat cycle corresponding to the golden section point can be used as the upper limit of the target heartbeat cycle range, so that the optimal heartbeat cycle can be found from the heartbeat cycle smaller than the golden section point.
[0122] If the heartbeat cycle corresponding to the golden section point can maintain a long connection between the client and the server, it is further determined whether the interval length of the target heartbeat cycle interval is less than the set value. If the above interval length is not greater than the set value, it indicates that the interval length of the current target heartbeat interval meets the accuracy requirements. At this time, the heartbeat cycle corresponding to the golden section point in the target heartbeat cycle interval can be used as the optimal heartbeat cycle, or the heartbeat cycle corresponding to the middle point in the target heartbeat cycle interval can be used as the optimal heartbeat cycle. This application does not impose any special restrictions on this.
[0123] If the length of the above interval is greater than the set value, it indicates that there is a need to further improve the accuracy of the target heartbeat cycle interval. In this case, the heartbeat cycle that has been confirmed to be able to maintain a long connection between the client and the server will be used as the lower limit of the target heartbeat cycle to further narrow the target heartbeat cycle interval. This will facilitate the subsequent search for the optimal heartbeat cycle from the heartbeat cycle corresponding to the golden section point. The specific method for determining the optimal heartbeat cycle is similar to the above and will not be repeated here.
[0124] See also Figure 5 , an embodiment of the present application provides a device for determining a heartbeat cycle, the device comprising:
[0125] A first determining unit 201 is used to determine a target heartbeat cycle interval and a heartbeat detection requirement;
[0126] The second determining unit 202 is used to determine an optimal heartbeat cycle that meets the heartbeat detection requirement from the target heartbeat cycle interval based on the interval elimination method.
[0127] Optionally, the second determining unit 202 includes:
[0128] The heartbeat cycle determination unit is used to determine the optimal heartbeat cycle from the target heartbeat cycle interval based on the golden section search method.
[0129] Optionally, the heartbeat cycle determination unit includes:
[0130] The processing subunit determines a first golden section point of the target heartbeat cycle interval, and uses the heartbeat cycle corresponding to the first golden section point as the first target heartbeat cycle;
[0131] A detection subunit, configured to perform heartbeat detection based on a first target heartbeat cycle to obtain a first heartbeat detection result;
[0132] A judging subunit, configured to judge whether the interval size of the target heartbeat cycle interval is less than a set value in response to the first heartbeat detection result indicating that the first target heartbeat cycle is available;
[0133] The processing subunit is further configured to update the lower limit value of the target heartbeat cycle interval to a first target heartbeat cycle in response to the interval size of the target heartbeat cycle interval being not less than a set value;
[0134] The heartbeat cycle determination subunit is used to determine the optimal heartbeat cycle from the updated target heartbeat cycle interval based on the golden section search method.
[0135] Optionally, the processing subunit is further configured to update the upper limit value of the target heartbeat cycle interval to the first target heartbeat cycle in response to the first heartbeat detection result indicating that the first target heartbeat cycle is unavailable.
[0136] Optionally, the first determining unit 201 includes:
[0137] An initial heartbeat cycle determining subunit, used to determine an initial heartbeat cycle;
[0138] A detection unit, configured to perform multiple heartbeat detections according to an initial heartbeat cycle to obtain multiple third heartbeat detection results;
[0139] A processing unit is configured to, in response to the plurality of third heartbeat detection results all indicating that the initial heartbeat cycle is available, increase the initial heartbeat cycle to obtain a first candidate heartbeat cycle;
[0140] The detection unit is further used to perform heartbeat detection according to the first candidate heartbeat cycle to obtain a fourth heartbeat detection result;
[0141] The heartbeat cycle determination subunit is configured to determine a target heartbeat cycle interval according to the initial heartbeat cycle and the first candidate heartbeat cycle in response to the fourth heartbeat detection result indicating that the first candidate heartbeat cycle is unavailable.
[0142] Optionally, the processing unit is specifically used for:
[0143] The initial heartbeat cycle is multiplied to obtain a first candidate heartbeat cycle.
[0144] Optionally, the processing unit is further configured to: in response to the plurality of third heartbeat detection results all indicating that the initial heartbeat cycle is unavailable, reduce the initial heartbeat cycle to obtain a second candidate heartbeat cycle;
[0145] The detection unit is further used to perform heartbeat detection according to the second candidate heartbeat cycle to obtain a fifth heartbeat detection result;
[0146] The initial heartbeat cycle determining subunit is further configured to, in response to the fifth heartbeat detection result indicating that the second candidate heartbeat cycle is available, use the second candidate heartbeat cycle as the initial heartbeat cycle.
[0147] See also Figure 6, is an electronic device provided in an embodiment of the present application, the electronic device includes at least one processor 301, the processor 301 is used to execute a computer program stored in a memory, and implement the embodiment of the present application as provided in the following Figure 1-4 Schematic diagram of the steps of the flow chart of the method for determining the heartbeat cycle shown.
[0148] Optionally, the processor 301 may specifically be a central processing unit, a specific ASIC, or one or more integrated circuits for controlling program execution.
[0149] Optionally, the electronic device may further include a memory 302 connected to the at least one processor 301, and the memory 302 may include a ROM, a RAM, and a disk memory. The memory 302 is used to store data required by the processor 301 when it is running, that is, it stores instructions that can be executed by the at least one processor 301. The at least one processor 301 executes the instructions stored in the memory 302 to execute the following steps: Figure 1-4 The method shown. Wherein, the number of the memory 302 is one or more. Wherein, the number of the memory 302 is one or more.
[0150] The present application also provides a computer storage medium, wherein the computer storage medium stores a computer program, and when the computer program is run on a processor, the processor executes Figure 1-4 method.
[0151] The above description is only a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of this specification should be included in the scope of protection of this specification.
Claims
1. A method for determining a heartbeat cycle, characterized in that: The method comprises: Determine the target heartbeat cycle interval and heartbeat detection requirements; Based on the interval elimination method, an optimal heartbeat cycle that meets the heartbeat detection requirements is determined from the target heartbeat cycle interval.
2. The method according to claim 1, characterized in that Determining an optimal heartbeat cycle that meets the heartbeat detection requirement from the target heartbeat cycle interval based on an interval elimination method includes: The optimal heartbeat cycle is determined from the target heartbeat cycle interval based on the golden section search method.
3. The method according to claim 2, characterized in that Determining the optimal heartbeat cycle from the target heartbeat cycle interval based on the golden section search method includes: Determine a first golden section point of the target heartbeat cycle interval, and use the heartbeat cycle corresponding to the first golden section point as a first target heartbeat cycle; Perform heartbeat detection based on the first target heartbeat cycle to obtain a first heartbeat detection result; In response to the first heartbeat detection result indicating that the first target heartbeat cycle is available, determining whether the interval size of the target heartbeat cycle interval is less than a set value; In response to the interval size of the target heartbeat cycle interval being not less than the set value, updating the lower limit value of the target heartbeat cycle interval to the first target heartbeat cycle; The optimal heartbeat cycle is determined from the updated target heartbeat cycle interval based on the golden section search method.
4. The method according to claim 3, characterized in that After performing heartbeat detection based on the first target heartbeat cycle to obtain a first heartbeat detection result, the method further includes: In response to the first heartbeat detection result indicating that the first target heartbeat cycle is unavailable, the upper limit value of the target heartbeat cycle interval is updated to the first target heartbeat cycle.
5. The method according to any one of claims 1 to 4, characterized in that: Determine the target heart rate interval, including: Determine the initial heartbeat cycle; Perform multiple heartbeat detections according to the initial heartbeat cycle to obtain multiple third heartbeat detection results; In response to the plurality of third heartbeat detection results all indicating that the initial heartbeat cycle is available, increasing the initial heartbeat cycle to obtain a first candidate heartbeat cycle; Perform heartbeat detection according to the first candidate heartbeat cycle to obtain a fourth heartbeat detection result; In response to the fourth heartbeat detection result indicating that the first candidate heartbeat cycle is unavailable, the target heartbeat cycle interval is determined according to the initial heartbeat cycle and the first candidate heartbeat cycle.
6. The method according to claim 5, characterized in that The initial heartbeat cycle is enlarged to obtain a first candidate heartbeat cycle, including: The initial heartbeat cycle is multiplied to obtain the first candidate heartbeat cycle.
7. The method according to claim 5, characterized in that After performing multiple heartbeat detections according to the initial heartbeat cycle to obtain multiple third heartbeat detection results, the method further includes: In response to the plurality of third heartbeat detection results all indicating that the initial heartbeat cycle is unavailable, reducing the initial heartbeat cycle to obtain a second candidate heartbeat cycle; Perform heartbeat detection according to the second candidate heartbeat cycle to obtain a fifth heartbeat detection result; In response to the fifth heartbeat detection result indicating that the second candidate heartbeat cycle is available, the second candidate heartbeat cycle is used as the initial heartbeat cycle.
8. A device for determining a heartbeat cycle, characterized in that: The device comprises: A first determination unit, used to determine a target heartbeat cycle interval and a heartbeat detection requirement; The second determining unit is used to determine the optimal heartbeat cycle that meets the heartbeat detection requirement from the target heartbeat cycle interval based on the interval elimination method.
9. An electronic device, characterized in that: comprising a memory and a processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.