Heartbeat detection method, device, electronic device and storage medium
By dividing the heartbeat cycle into multiple time periods according to the number of service consumers, and sending heartbeat messages one after another, the performance bottleneck caused by the center of the microservice architecture is solved, and the normal allocation of service call resources is ensured.
Patent Information
- Application Number
- CN202210195292.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-01
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2042-03-01
AI Technical Summary
In the microservice architecture, as the service scale grows, heartbeat detection leads to performance bottlenecks. The service provider sends a large number of heartbeat detection messages at the same time, resulting in the normal service call being unable to allocate resources, resulting in the service call timeout.
The preset heartbeat cycle is divided into multiple time periods according to the number of service consumers, and heartbeat messages are sent to the service consumers in sequence in chronological order to avoid sending a large number of messages at the same time causing pressure on server resources.
By dispersing the heartbeat detection time period, instantaneous pressure on server resources is avoided, normal service calls are not affected, and the problem of service calls timeout is solved.
Smart Images

Figure CN114567577B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the fields of microservice architecture and finance, and more specifically to a heartbeat detection method, device, equipment, medium and program product. Background Art
[0002] Microservices, also known as distributed services, are a backend architecture method that advocates splitting the backend services in a single application into relatively independent and relatively small services, and deploying these small services in a distributed manner. In the microservice framework, once a connection is established between the service consumer (caller) and the service provider (callee), a heartbeat check needs to be performed regularly to confirm that the connection is normal.
[0003] In the process of realizing the inventive concept of the present disclosure, the inventors found that there are at least the following problems in the related technology: as the scale of online services grows, when one consumer provider corresponds to a large number of service consumers, since the heartbeat detection is performed periodically, the service provider will send heartbeat detection messages to these service consumers at the same time. At this time, the heartbeat detection is likely to cause performance bottlenecks, resulting in the inability to allocate resources for normal service calls, thereby causing service call timeouts. Summary of the invention
[0004] In view of the above problems, the present disclosure provides a heartbeat detection method, apparatus, device, medium and program product.
[0005] According to a first aspect of the present disclosure, a heartbeat detection method is provided, comprising:
[0006] Determine the number of service consumers connected to the service provider, wherein the number of the service consumers is M, M≥1;
[0007] Divide the preset heartbeat cycle into M first time periods, wherein each of the first time periods corresponds to one of the service consumers;
[0008] Sending heartbeat messages to the M service consumers in sequence according to the time sequence of the M first time periods; and
[0009] In response to the operation of sending the above-mentioned heartbeat message, a heartbeat detection is performed on the above-mentioned service consumer according to a preset detection rule.
[0010] According to an embodiment of the present disclosure, sending heartbeat messages to the M service consumers in sequence according to the time sequence of the M first time periods includes:
[0011] In the i-th first time period, obtaining the address information of the i-th service consumer corresponding to the i-th first time period, where 1≤i≤M;
[0012] Sending an i-th heartbeat message to the i-th service consumer within the i-th first time period according to the address information of the i-th service consumer; and
[0013] Receive the i-th response message returned by the i-th service consumer, and complete the heartbeat detection of the i-th service consumer.
[0014] According to an embodiment of the present disclosure, the above heartbeat detection method further includes:
[0015] Record the i-th sending time of sending the i-th heartbeat message and the i-th receiving time of receiving the i-th response message;
[0016] Determine, according to the i-th receiving time and the i-th sending time, the i-th duration for performing heartbeat detection on the i-th service consumer;
[0017] In the case that the i-th duration is less than the i-th first time period, after the i-th first time period is exhausted, a heartbeat detection is performed on the i+1-th service consumer.
[0018] According to an embodiment of the present disclosure, the above heartbeat detection method further includes:
[0019] In the case where the i-th duration is greater than the i-th first time period, the remaining duration in the preset heartbeat cycle is divided into N second time periods according to the number of remaining service consumers, wherein the duration of the second time period is less than the duration of the first time period, N=Mi;
[0020] The heartbeat messages are sent to the remaining service consumers in sequence according to the time sequence of the N second time periods.
[0021] According to an embodiment of the present disclosure, when the i-th duration is greater than the i-th first time period, dividing the remaining duration in the preset heartbeat cycle into N second time periods according to the number of remaining service consumers includes:
[0022] Determine the total duration of heartbeat detection for the first i service consumers;
[0023] Determine the remaining time according to the preset heartbeat cycle and the total time;
[0024] According to the remaining time and the number of the remaining service consumers, the remaining time is divided into N second time periods.
[0025] According to an embodiment of the present disclosure, in response to the operation of sending the heartbeat message, performing heartbeat detection on the service consumer according to a preset detection rule includes:
[0026] In response to the operation of sending the above-mentioned heartbeat message, when a response message returned by the above-mentioned service consumer is received within a preset time period, a heartbeat detection is performed on the above-mentioned service consumer according to the above-mentioned response message;
[0027] If the heartbeat detection is normal, it is determined that the service consumer is connected to the service provider normally.
[0028] Or in response to the operation of sending the above-mentioned heartbeat message, if the above-mentioned response message returned by the above-mentioned service consumer is not received within the above-mentioned preset time period, it is determined that the above-mentioned service consumer is disconnected from the above-mentioned service provider.
[0029] According to an embodiment of the present disclosure, the above-mentioned determination of the number of service consumers connected to the service provider includes:
[0030] Obtain a list of service consumers corresponding to the above service providers;
[0031] The number of the service consumers connected to the service provider is determined according to the service consumer list.
[0032] A second aspect of the present disclosure provides a heartbeat detection device, comprising: a first determination module, configured to determine the number of service consumers connected to a service provider, wherein the number of the service consumers is M, and M≥1;
[0033] A first division module, used to divide the preset heartbeat cycle into M first time periods, wherein each of the first time periods corresponds to one of the service consumers;
[0034] A first sending module, configured to send heartbeat messages to the M service consumers in sequence according to the time sequence of the M first time periods; and
[0035] The heartbeat detection module is used to respond to the operation of sending the above-mentioned heartbeat message and perform heartbeat detection on the above-mentioned service consumer according to preset detection rules.
[0036] The third aspect of the present disclosure provides an electronic device, comprising: one or more processors; and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors execute the heartbeat detection method.
[0037] The fourth aspect of the present disclosure further provides a computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, causes the processor to execute the above-mentioned heartbeat detection method.
[0038] The fifth aspect of the present disclosure also provides a computer program product, including a computer program, which implements the above-mentioned heartbeat detection method when executed by a processor.
[0039] According to an embodiment of the present disclosure, by determining the number of service consumers connected to a service provider, the preset heartbeat cycle is divided into M first time periods according to the number of service consumers (e.g., M), and each first time period corresponds to a service consumer; then, heartbeat messages are sent to the M service consumers in sequence according to the time sequence of the M first time periods; thereafter, in response to the operation of sending the heartbeat message, the service provider performs heartbeat detection on the service consumer according to the preset detection rules, thereby avoiding the instantaneous pressure on server resources caused by sending a large number of heartbeat messages at the same time and affecting other normal service calls. At least partially solves the problem in the related art that a service provider sends a large number of heartbeat detection messages at the same time, resulting in a normal service call not being allocated resources, thereby causing a service call timeout. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The above contents and other objects, features and advantages of the present disclosure will become more apparent through the following description of the embodiments of the present disclosure with reference to the accompanying drawings, in which:
[0041] Figure 1 The application scenario diagram of the heartbeat detection method, apparatus, device, medium and program product according to the embodiments of the present disclosure is schematically shown;
[0042] Figure 2 The flowchart of the heartbeat detection method according to the embodiment of the present disclosure is schematically shown;
[0043] Figure 3 A flowchart of a heartbeat detection method according to another embodiment of the present disclosure is schematically shown;
[0044] Figure 4 The structure block diagram of the heartbeat detection device according to the embodiment of the present disclosure is schematically shown;
[0045] Figure 5 A structural block diagram of a heartbeat detection device according to another embodiment of the present disclosure is schematically shown; and
[0046] Figure 6 A block diagram of an electronic device suitable for implementing a heartbeat detection method according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0047] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present disclosure. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of the embodiments of the present disclosure. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of the concepts of the present disclosure.
[0048] The terms used herein are only for describing specific embodiments and are not intended to limit the present disclosure. The terms "comprise", "include", etc. used herein indicate the existence of the features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.
[0049] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification, and should not be interpreted in an idealized or overly rigid manner.
[0050] When using expressions such as "at least one of A, B, and C, etc.", they should generally be interpreted according to the meaning of the expression commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).
[0051] Microservices, also known as distributed services, are a backend architecture method that advocates splitting the backend services in a single application into relatively independent and relatively small services, and deploying these small services in a distributed manner. In the microservice framework, once a connection is established between the service consumer (caller) and the service provider (callee), a heartbeat check needs to be performed regularly to confirm that the connection is normal.
[0052] Heartbeat detection refers to the process of confirming that the connection is normal through regular detection once a connection is established between the microservice consumer (caller) and the service provider (callee). Both the service consumer and the service provider will perform heartbeat detection regularly, and when they find that the other party is offline, they will recycle the connection.
[0053] However, as the scale of online services grows, when the number of service consumers connected to a service provider reaches tens of thousands, heartbeat detection will bring about a performance bottleneck. This is mainly because heartbeat detection is performed regularly, that is, heartbeat detection messages will be sent to each other at the same time. Therefore, as the number of service consumers increases, a service provider needs to face tens of thousands of service consumers. At this time, the service provider will send heartbeat detection messages to these service consumers regularly (for example, once a minute), and each time a heartbeat detection is performed, the server must complete a series of actions such as message serialization, allocation of work threads, and sending network requests. This will bring instant processing pressure to the server's network and CPU, resulting in normal service calls being unable to allocate resources, resulting in service call timeouts.
[0054] In view of this, the present disclosure addresses the above technical problems by dividing the preset heartbeat cycle into M first time periods according to the number of service consumers, and sending heartbeat messages to the M service consumers in sequence according to the time sequence of the M first time periods, thereby avoiding the instantaneous pressure on server resources caused by sending a large number of heartbeat messages at the same time and affecting other normal service calls.
[0055] Specifically, an embodiment of the present disclosure provides a heartbeat detection method, including: determining the number of service consumers connected to a service provider, wherein the number of the service consumers is M, and M≥1; dividing a preset heartbeat cycle into M first time periods, wherein each of the first time periods corresponds to one of the service consumers; sending heartbeat messages to the M service consumers in sequence according to the time sequence of the M first time periods; and in response to the operation of sending the heartbeat message, performing heartbeat detection on the service consumers according to preset detection rules.
[0056] It should be noted that the heartbeat detection method and device provided in the embodiments of the present disclosure can be used in the field of microservice architecture technology and the financial field. The heartbeat detection method and device provided in the embodiments of the present disclosure can also be used in any field other than the field of microservice architecture technology and the financial field. The application field of the heartbeat detection method and device provided in the embodiments of the present disclosure is not limited.
[0057] In the technical solution of the present disclosure, the user's authorization or consent is obtained before obtaining or collecting the user's personal information.
[0058] In the technical solution disclosed in the present invention, the acquisition, collection, storage, use, processing, transmission, provision, disclosure and application of data are in compliance with the provisions of relevant laws and regulations, necessary confidentiality measures are taken, and do not violate public order and good morals.
[0059] Figure 1The application scenario diagram of the heartbeat detection method, apparatus, device, medium and program product according to the embodiments of the present disclosure is schematically shown.
[0060] like Figure 1 As shown, the application scenario 100 according to this embodiment may include a network, a service consumer, and a service provider. The network 101 is used to provide a medium for a communication link between the service provider and service consumer A, service consumer B, ..., service consumer X. The network 101 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0061] The service provider can interact with service consumer A, service consumer B, ... service consumer X through the network 101 to receive or send messages, etc. Service consumer A, service consumer B, ... service consumer X can serve various callers. For example, when performing a transfer service, the transfer service needs to call the SMS notification service to obtain a verification code. In this case, the transfer service is the service consumer. When performing a financial management service, the financial management service needs to call the transfer service. In this case, the financial management service is the service consumer. (This is just an example).
[0062] The service provider can serve various callees. For example, when performing a transfer service, the transfer service needs to call the SMS notification service to obtain a verification code. In this case, the service provider is the SMS notification service. When performing a transfer service, the transfer service needs to call the account balance inquiry service to inquire about the account balance. In this case, the service provider is the account balance inquiry service (for example only).
[0063] The service provider is also used to send heartbeat messages to service consumer A, service consumer B ... service consumer X in sequence through network 101 within a preset heartbeat period, and perform heartbeat detection on service consumer A, service consumer B ... service consumer X.
[0064] It should be noted that the heartbeat detection method provided in the embodiment of the present disclosure can generally be performed by a service provider. The service provider sends a heartbeat message to the service consumer A through the network 101. After receiving the response message returned by the service consumer A, the service provider sends a heartbeat message to the service consumer B, performs a heartbeat detection on the service consumer B, and so on, until the heartbeat detection of the service consumer X is completed.
[0065] It should be understood that Figure 1 The number of service consumers, networks, and service providers in the example is only illustrative. Any number of service consumers, networks, and service providers may be provided as required.
[0066] The following will be based on Figure 1 The scene described by Figure 2-3 The heartbeat detection method of the disclosed embodiment is described in detail.
[0067] Figure 2 The flowchart of the heartbeat detection method according to the embodiment of the present disclosure is schematically shown.
[0068] like Figure 2 As shown, the heartbeat detection method of this embodiment includes operations S210 to S230, and the heartbeat detection method can be executed by a server.
[0069] In operation S210, the number of service consumers connected to the service provider is determined, wherein the number of the service consumers is M, and M≥1.
[0070] According to an embodiment of the present disclosure, a service provider may include, for example, a service of a callee. A service consumer may include, for example, a service of a caller. For example, a microservice framework includes a transfer service, an account query service, a credit card service, a financial management service, a text message notification service, and the like.
[0071] According to an embodiment of the present disclosure, for example, when performing a transfer service, the transfer service needs to call the SMS notification service to obtain a verification code. In this case, the SMS notification service is the service provider and the transfer service is the service consumer. When performing a transfer service, the transfer service needs to call the account balance inquiry service to inquire about the account balance. In this case, the account balance inquiry service is the service provider and the transfer service is the service consumer. When performing a financial management service, the financial management service needs to call the transfer service. In this case, the transfer service is the service provider and the financial management service is the service consumer.
[0072] According to an embodiment of the present disclosure, each service provider has a corresponding service consumer list, wherein the service consumer list records identification information, address information, function information, etc. of all service consumers connected to the service provider.
[0073] According to an embodiment of the present disclosure, the determining the number of service consumers connected to the service provider includes: obtaining a service consumer list corresponding to the service provider; and determining the number of the service consumers connected to the service provider according to the service consumer list.
[0074] According to an embodiment of the present disclosure, a service consumer list corresponding to a service provider is obtained, and the number of service consumers in the service consumer list is read, thereby determining the number of service consumers connected to the service provider.
[0075] In operation S220, the preset heartbeat cycle is divided into M first time periods, wherein each of the first time period corresponds to one of the service consumers.
[0076] According to an embodiment of the present disclosure, dividing the preset heartbeat cycle into M first time periods may include, for example, evenly dividing the preset heartbeat cycle into M first time periods.
[0077] According to an embodiment of the present disclosure, for example, the heartbeat period is preset to one minute, and one minute is divided by the number of service consumers (for example, the number of service consumers is ten thousand), to obtain a first time period of 6 milliseconds, and then a heartbeat message is sent to one of the service consumers every 6 milliseconds, so as to evenly distribute the heartbeat messages within the specified time period, reduce the heartbeat message sending rate, and thus reduce the instantaneous pressure on the server.
[0078] In operation S230, heartbeat messages are sent to the M service consumers in sequence according to the time sequence of the M first time periods.
[0079] According to an embodiment of the present disclosure, the sending of heartbeat messages to the M service consumers in sequence according to the time sequence of the M first time periods includes: obtaining address information of the i-th service consumer corresponding to the i-th first time period within the i-th first time period, wherein 1≤i≤M; sending an i-th heartbeat message to the i-th service consumer within the i-th first time period according to the address information of the i-th service consumer; and receiving an i-th response message returned by the i-th service consumer to complete the heartbeat detection of the i-th service consumer.
[0080] According to an embodiment of the present disclosure, for example, i=1, the address information of the first service consumer in the service consumer list is obtained, and then a heartbeat message is sent to the service consumer according to the obtained address information. After receiving a response message returned by the service consumer, the heartbeat detection of the service consumer is completed.
[0081] For example, i=2, obtain the address information of the second service consumer in the service consumer list, and then send a heartbeat message to the service consumer according to the obtained address information. After receiving the response message returned by the service consumer, complete the heartbeat detection of the service consumer.
[0082] In operation S240, in response to the operation of sending the heartbeat message, a heartbeat detection is performed on the service consumer according to a preset detection rule.
[0083] According to an embodiment of the present disclosure, in response to the operation of sending the above-mentioned heartbeat message, performing heartbeat detection on the above-mentioned service consumer according to preset detection rules includes: in response to the operation of sending the above-mentioned heartbeat message, when a response message returned by the above-mentioned service consumer is received within a preset time period, performing heartbeat detection on the above-mentioned service consumer according to the above-mentioned response message; when the above-mentioned heartbeat detection is normal, determining that the connection between the above-mentioned service consumer and the above-mentioned service provider is normal; or in response to the operation of sending the above-mentioned heartbeat message, when the above-mentioned response message returned by the above-mentioned service consumer is not received within the above-mentioned preset time period, determining that the above-mentioned service consumer is disconnected from the above-mentioned service provider.
[0084] According to an embodiment of the present disclosure, the preset detection rule may include whether a response message returned by the service consumer is received within a preset time period. For example, if a response message returned by the above-mentioned service consumer is received within a preset time period, it is determined whether the response message is correct. If the response message is correct, it is determined that the above-mentioned service consumer is connected to the above-mentioned service provider normally. If a response message returned by the above-mentioned service consumer is not received within a preset time period, it is determined that the above-mentioned service consumer is disconnected from the above-mentioned service provider, and the service consumer is removed from the service consumer list.
[0085] According to an embodiment of the present disclosure, by determining the number of service consumers connected to a service provider, the preset heartbeat cycle is divided into M first time periods according to the number of service consumers (e.g., M), and each first time period corresponds to a service consumer; then, heartbeat messages are sent to the M service consumers in sequence according to the time sequence of the M first time periods; thereafter, in response to the operation of sending the heartbeat message, the service provider performs heartbeat detection on the service consumer according to the preset detection rules, thereby avoiding the instantaneous pressure on server resources caused by sending a large number of heartbeat messages at the same time and affecting other normal service calls. At least partially solves the problem in the related art that a service provider sends a large number of heartbeat detection messages at the same time, resulting in a normal service call not being allocated resources, thereby causing a service call timeout.
[0086] According to an embodiment of the present disclosure, the above-mentioned heartbeat detection method also includes: recording the i-th sending time of sending the above-mentioned i-th heartbeat message and the i-th receiving time of receiving the above-mentioned i-th response message; determining the i-th duration used for heartbeat detection on the above-mentioned i-th service consumer based on the above-mentioned i-th receiving time and the above-mentioned i-th sending time; in a case where the above-mentioned i-th duration is less than the above-mentioned i-th first time period, after the time of the above-mentioned i-th first time period is exhausted, performing heartbeat detection on the above-mentioned i+1-th service consumer.
[0087] According to an embodiment of the present disclosure, for example, i=1, the duration of the first time period is 6 milliseconds, the first sending time of the first heartbeat message is a, and the first receiving time of the first response message is b. Then, the first duration used for heartbeat detection on the first service consumer is ba. When ba is less than 6 milliseconds, for example, ba is 1 millisecond, wait for 6 milliseconds to expire, obtain the address information of the second service consumer from the service consumer list, and send a heartbeat message to the second service consumer.
[0088] According to an embodiment of the present disclosure, a heartbeat detection is performed on the next service consumer after the duration of each first time period has expired, so that multiple heartbeat detections can be dispersed as much as possible within a preset heartbeat cycle, thereby reducing the instantaneous pressure on the server.
[0089] According to an embodiment of the present disclosure, the above-mentioned heartbeat detection method also includes: in a case where the above-mentioned i-th duration is greater than the above-mentioned i-th first time period, according to the number of remaining service consumers, the remaining duration in the above-mentioned preset heartbeat cycle is divided into N second time periods, wherein the duration of the above-mentioned second time period is less than the duration of the above-mentioned first time period, N=Mi; and the above-mentioned heartbeat message is sent to the remaining service consumers in sequence according to the time order of the above-mentioned N second time periods.
[0090] According to an embodiment of the present disclosure, in the case that the i-th duration is greater than the i-th first time period, dividing the remaining duration in the preset heartbeat cycle into N second time periods according to the number of remaining service consumers includes: determining the total duration used for heartbeat detection of the first i service consumers; determining the remaining duration according to the preset heartbeat cycle and the total duration; dividing the remaining duration into N second time periods according to the remaining duration and the number of remaining service consumers.
[0091] According to an embodiment of the present disclosure, for example, i=2, the second duration ba is greater than the duration of the first time period (for example, 6 milliseconds), and the interval time for sending the heartbeat message needs to be recalculated. The total duration (for example, 1 second) used for heartbeat detection of the first service consumer and the second service consumer is obtained, and then the total duration of 1 second is subtracted from the preset heartbeat cycle (for example, 1 minute), and the remaining duration is 59 seconds; thereafter, according to the number of service consumers in the service consumer list that have not performed heartbeat detection (for example, 9998) and the remaining duration of 59 seconds, the remaining duration of 59 seconds is divided by the number of service consumers that have not performed heartbeat detection, 9998, to obtain the second time period, and then heartbeat messages are sent to the remaining 9998 service consumers in sequence according to the heartbeat interval of the second time period.
[0092] It should be noted that the preset heartbeat cycle (for example, one minute) here is much longer than the timeout period of a single heartbeat detection, to prevent the extreme situation where the first heartbeat takes longer than the preset heartbeat cycle.
[0093] According to the embodiments of the present disclosure, each time a heartbeat detection is completed, the heartbeat interval needs to be recalculated to ensure that the remaining heartbeat detections are always evenly distributed within the remaining duration, so that the heartbeat detection can be performed as smoothly as possible.
[0094] Figure 3 The following schematically shows a flow chart of a heartbeat detection method according to another embodiment of the present disclosure.
[0095] like Figure 3 As shown, the heartbeat detection method of this embodiment includes operations S301 to S316.
[0096] In operation S301, a service consumer list corresponding to a service provider is obtained, wherein the service consumer list includes address information of each service consumer.
[0097] In operation S302, the number of service consumers connected to the service provider is determined according to the service consumer list, where the number of service consumers is M, and M≥1.
[0098] In operation S303, the preset heartbeat cycle is divided into M first time periods, wherein each first time period corresponds to a service consumer.
[0099] In operation S304, in the ith first time period, address information of the ith service consumer corresponding to the ith first time period in the service consumer list is obtained, where 1≤i≤M.
[0100] In operation S305, an i-th heartbeat message is sent to the i-th service consumer according to the address information of the i-th service consumer.
[0101] In operation S306, the i-th sending time of sending the i-th heartbeat message is recorded.
[0102] In operation S307, it is determined whether the service provider has received the i-th response message returned by the i-th service consumer. If the service provider has received the i-th response message returned by the i-th service consumer, operations S308 to S315 are performed; if the service provider has not received the i-th response message returned by the i-th service consumer, operation S316 is performed.
[0103] In operation S308, the i-th receiving time of receiving the i-th response message is recorded.
[0104] In operation S309 , an i th duration for performing heartbeat detection on the i th service consumer is determined according to the i th receiving time and the i th sending time.
[0105] In operation S310, it is determined whether the i-th duration exceeds the duration of the i-th first time period. If the i-th duration is not the duration of the i-th first time period, operation S311 is performed; if the i-th duration exceeds the duration of the i-th first time period, operations S312 to S315 are performed.
[0106] In operation S311, after the time of the i-th first time period is exhausted, a heartbeat detection is performed on the (i+1)-th service consumer.
[0107] In operation S312, the total duration of the heartbeat detection for the first i service consumers is determined.
[0108] In operation S313, the remaining time is determined according to the preset heartbeat cycle and the total time.
[0109] In operation S314, the remaining time is divided into N second time periods according to the remaining time and the number of remaining service consumers, where N=Mi.
[0110] In operation S315, heartbeat messages are sent to the remaining service consumers in sequence according to the heartbeat interval of the second time period.
[0111] In operation S316, it is determined that the service consumer is disconnected from the service provider, and the service consumer is removed from the service consumer list.
[0112] According to the embodiments of the present disclosure, by dividing the preset heartbeat cycle into M first time periods according to the number of service consumers, and sending heartbeat messages to the M service consumers in sequence according to the time sequence of the M first time periods, it is avoided that a large number of heartbeat messages are sent at the same time to cause instantaneous pressure on server resources and affect other normal service calls. At the same time, after the heartbeat detection of each service consumer is completed, the heartbeat interval will be re-settled to ensure that the remaining heartbeat detection is always evenly distributed in the remaining time, so that the heartbeat detection is as smooth as possible.
[0113] It should be noted that, unless it is explicitly stated that there is a sequence of execution between different operations shown in the flowchart in the embodiments of the present disclosure, or there is a sequence of execution between different operations in technical implementation, otherwise, the execution order of multiple operations may not be prioritized, and multiple operations may also be executed simultaneously.
[0114] Based on the above heartbeat detection method, the present disclosure also provides a heartbeat detection device. Figure 4 The device is described in detail.
[0115] Figure 4 The structural block diagram of the heartbeat detection device according to an embodiment of the present disclosure is schematically shown.
[0116] like Figure 4 As shown, the heartbeat detection device 400 of this embodiment includes a first determination module 410 , a first division module 420 , a first sending module 430 and a heartbeat detection module 440 .
[0117] The first determination module 410 is used to determine the number of service consumers connected to the service provider, wherein the number of service consumers is M, and M≥1. In one embodiment, the first determination module 410 may be used to perform the operation S210 described above, which will not be described in detail herein.
[0118] The first division module 420 is used to divide the preset heartbeat cycle into M first time periods, wherein each first time period corresponds to one of the service consumers. In one embodiment, the first division module 420 can be used to perform the operation S220 described above, which will not be described in detail herein.
[0119] The first sending module 430 is used to send heartbeat messages to the M service consumers in sequence according to the time sequence of the M first time periods. In one embodiment, the first sending module 430 can be used to perform the operation S230 described above, which will not be repeated here.
[0120] The heartbeat detection module 440 is used to perform heartbeat detection on the service consumer according to a preset detection rule in response to the operation of sending the heartbeat message. In one embodiment, the heartbeat detection module 440 can be used to perform the operation S240 described above, which will not be described in detail here.
[0121] According to an embodiment of the present disclosure, the first sending module includes a first acquiring unit, a sending unit and a receiving unit.
[0122] The first acquisition unit is used to acquire, within the i-th first time period, the address information of the i-th service consumer corresponding to the i-th first time period, wherein 1≤i≤M.
[0123] A sending unit is used to send an i-th heartbeat message to the i-th service consumer within the i-th first time period according to the address information of the i-th service consumer.
[0124] The receiving unit is used to receive the i-th response message returned by the i-th service consumer and complete the heartbeat detection of the i-th service consumer.
[0125] Figure 5 The structural block diagram of a heartbeat detection device according to another embodiment of the present disclosure is schematically shown.
[0126] like Figure 5 As shown, the heartbeat detection device 400 of this embodiment includes, in addition to a first determination module 410 , a first division module 420 , a first sending module 430 and a heartbeat detection module 440 , a recording module 450 , a second determination module 460 and an exhaustion module 470 .
[0127] The recording module 450 is used to record the i-th sending time of sending the i-th heartbeat message and the i-th receiving time of receiving the i-th response message.
[0128] The second determining module 460 is used to determine an i-th duration used for performing heartbeat detection on the i-th service consumer according to the i-th receiving time and the i-th sending time.
[0129] The exhaustion module 470 is used to perform a heartbeat detection on the i+1th service consumer after the i-th first time period is exhausted when the i-th time period is less than the i-th first time period.
[0130] According to an embodiment of the present disclosure, the above-mentioned heartbeat detection device also includes a second dividing module and a second sending module.
[0131] A second division module is used to divide the remaining duration in the preset heartbeat cycle into N second time periods according to the number of remaining service consumers when the i-th duration is greater than the i-th first time period, wherein the duration of the second time period is less than the duration of the first time period, and N=Mi;
[0132] The second sending module is used to send the above-mentioned heartbeat messages to the remaining above-mentioned service consumers in sequence according to the time sequence of the N above-mentioned second time periods.
[0133] According to an embodiment of the present disclosure, the second division module includes a first determination unit, a second determination unit and a division unit.
[0134] The first determining unit is used to determine the total duration used for performing heartbeat detection on the first i service consumers.
[0135] The second determining unit is used to determine the remaining time according to the preset heartbeat cycle and the total time.
[0136] The dividing unit is used to divide the remaining time into N second time periods according to the remaining time and the number of the remaining service consumers.
[0137] According to an embodiment of the present disclosure, the heartbeat detection module includes a heartbeat detection unit, a third determination unit and a fourth determination unit.
[0138] The heartbeat detection unit is used to respond to the operation of sending the above-mentioned heartbeat message, and when a response message returned by the above-mentioned service consumer is received within a preset time period, perform a heartbeat detection on the above-mentioned service consumer according to the above-mentioned response message.
[0139] The third determining unit is used to determine that the connection between the service consumer and the service provider is normal when the heartbeat detection is normal.
[0140] The fourth determining unit is used to determine that the service consumer is disconnected from the service provider in response to the operation of sending the heartbeat message and when the response message returned by the service consumer is not received within the preset time period.
[0141] According to an embodiment of the present disclosure, the above-mentioned first determination module includes a second acquisition unit and a fifth determination unit.
[0142] The second acquisition unit is used to acquire a list of service consumers corresponding to the service provider.
[0143] A fifth determining unit is used to determine the number of the service consumers connected to the service provider according to the service consumer list.
[0144] According to the embodiments of the present disclosure, the number of service consumers connected to the service provider is determined by using a first determination module, and then the preset heartbeat cycle is divided into M first time periods by using a first division module, each first time period corresponds to a service consumer; and the heartbeat message is sent to the M service consumers in sequence according to the time sequence of the M first time periods by using a first sending module; then the heartbeat detection module responds to the operation of sending the heartbeat message and performs heartbeat detection on the service consumer according to the preset detection rules, thereby avoiding the instantaneous pressure on the server resources caused by sending a large number of heartbeat messages at the same time and affecting other normal service calls. At least partially solves the problem in the related art that the service provider sends a large number of heartbeat detection messages at the same time, resulting in the normal service call not being allocated resources, thereby causing the service call timeout.
[0145] According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits, or at least part of the functions of any one of them can be implemented in one module. According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits can be split into multiple modules for implementation. According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits can be at least partially implemented as hardware circuits, such as field programmable gate arrays (FPGAs), programmable logic arrays (PLAs), systems on chips, systems on substrates, systems on packages, application specific integrated circuits (ASICs), or can be implemented by hardware or firmware in any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware, and firmware, or in any appropriate combination of any of them. Alternatively, according to the embodiments of the present invention, one or more of the modules, submodules, units, and subunits can be at least partially implemented as computer program modules, and when the computer program modules are run, the corresponding functions can be performed.
[0146] According to an embodiment of the present disclosure, any multiple modules of the first determination module 410, the first division module 420, the first sending module 430, the heartbeat detection module 440, the recording module 450, the second determination module 460 and the exhaustion module 470 can be combined in one module for implementation, or any one of the modules can be split into multiple modules. Alternatively, at least part of the functions of one or more of these modules can be combined with at least part of the functions of other modules and implemented in one module. According to an embodiment of the present disclosure, at least one of the first determination module 410, the first division module 420, the first sending module 430, the heartbeat detection module 440, the recording module 450, the second determination module 460 and the exhaustion module 470 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation modes of software, hardware and firmware or in a suitable combination of any of them. Alternatively, at least one of the first determination module 410, the first division module 420, the first sending module 430, the heartbeat detection module 440, the recording module 450, the second determination module 460 and the exhaustion module 470 can be at least partially implemented as a computer program module, which can perform corresponding functions when the computer program module is executed.
[0147] It should be noted that the heartbeat detection device part in the embodiment of the present disclosure corresponds to the heartbeat detection method part in the embodiment of the present disclosure. The description of the heartbeat detection device part specifically refers to the heartbeat detection method part, which will not be repeated here.
[0148] Figure 6 A block diagram of an electronic device suitable for implementing a heartbeat detection method according to an embodiment of the present disclosure is schematically shown.
[0149] like Figure 6 As shown, the electronic device 600 according to an embodiment of the present disclosure includes a processor 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. The processor 601 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 601 may also include an onboard memory for caching purposes. The processor 601 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present disclosure.
[0150] In RAM 603, various programs and data required for the operation of electronic device 600 are stored. Processor 601, ROM 602 and RAM 603 are connected to each other via bus 604. Processor 601 performs various operations of the method flow according to the embodiment of the present disclosure by executing the program in ROM 602 and / or RAM 603. It should be noted that the program can also be stored in one or more memories other than ROM 602 and RAM 603. Processor 601 can also perform various operations of the method flow according to the embodiment of the present disclosure by executing the program stored in the one or more memories.
[0151] According to an embodiment of the present disclosure, the electronic device 600 may further include an input / output (I / O) interface 605, which is also connected to the bus 604. The electronic device 600 may further include one or more of the following components connected to the I / O interface 605: an input portion 606 including a keyboard, a mouse, etc.; an output portion 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 608 including a hard disk, etc.; and a communication portion 609 including a network interface card such as a LAN card, a modem, etc. The communication portion 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage portion 608 as needed.
[0152] The present disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present disclosure is implemented.
[0153] According to an embodiment of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, an apparatus or a device. For example, according to an embodiment of the present disclosure, a computer-readable storage medium may include the ROM 602 and / or RAM 603 described above and / or one or more memories other than ROM 602 and RAM 603.
[0154] The embodiment of the present disclosure also includes a computer program product, which includes a computer program, and the computer program contains program code for executing the method shown in the flowchart. When the computer program product is run in a computer system, the program code is used to enable the computer system to implement the heartbeat detection method provided by the embodiment of the present disclosure.
[0155] The above functions defined in the system / device of the embodiment of the present disclosure are performed when the computer program is executed by the processor 601. According to the embodiment of the present disclosure, the system, device, module, unit, etc. described above can be implemented by a computer program module.
[0156] In one embodiment, the computer program may rely on tangible storage media such as optical storage devices, magnetic storage devices, etc. In another embodiment, the computer program may also be transmitted and distributed in the form of signals on a network medium, and downloaded and installed through the communication part 609, and / or installed from a removable medium 611. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0157] In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the processor 601, the above functions defined in the system of the embodiment of the present disclosure are performed. According to the embodiment of the present disclosure, the system, device, apparatus, module, unit, etc. described above can be implemented by a computer program module.
[0158] According to an embodiment of the present disclosure, the program code for executing the computer program provided by the embodiment of the present disclosure can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, Java, C++, python, "C" language or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on the remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect through the Internet).
[0159] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0160] It will be appreciated by those skilled in the art that the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways, even if such combinations and / or combinations are not explicitly described in the present disclosure. In particular, the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways without departing from the spirit and teachings of the present disclosure. All of these combinations and / or combinations fall within the scope of the present disclosure.
[0161] The embodiments of the present disclosure are described above. However, these embodiments are only for illustrative purposes and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the various embodiments cannot be used in combination to advantage. The scope of the present disclosure is defined by the attached claims and their equivalents. Without departing from the scope of the present disclosure, those skilled in the art may make a variety of substitutions and modifications, which should all fall within the scope of the present disclosure.
Claims
1. A heartbeat detection method, include: Determine the number of service consumers connected to the service provider, wherein the number of the service consumers is M, and M≥1; Divide the preset heartbeat cycle into M first time periods, wherein each of the first time periods corresponds to one of the service consumers; Sending heartbeat messages to the M service consumers in sequence according to the time sequence of the M first time periods; In response to the operation of sending the heartbeat message, performing a heartbeat detection on the service consumer according to a preset detection rule; After sending the heartbeat messages to the M service consumers in sequence according to the time sequence of the M first time periods, the method further includes: For an i-th service consumer among the M service consumers, record the i-th sending time of sending an i-th heartbeat message to the i-th service consumer and the i-th receiving time of receiving an i-th response message; Determine, according to the i-th receiving time and the i-th sending time, an i-th duration for performing heartbeat detection on the i-th service consumer; In the case where the i-th duration is greater than the i-th first time period, the remaining duration in the preset heartbeat cycle is divided into N second time periods according to the number of remaining service consumers, wherein the duration of the second time period is less than the duration of the first time period, N=Mi; The heartbeat messages are sent to the remaining service consumers in sequence according to the time sequence of the N second time periods.
2. The method according to claim 1, in, The sending heartbeat messages to the M service consumers in sequence according to the time sequence of the M first time periods includes: In the i-th first time period, acquiring address information of the i-th service consumer corresponding to the i-th first time period, where 1≤i≤M; Sending an i-th heartbeat message to the i-th service consumer within the i-th first time period according to the address information of the i-th service consumer; and Receive an i-th response message returned by the i-th service consumer, and complete the heartbeat detection of the i-th service consumer.
3. The method according to claim 2, further comprising: include: In the case that the i-th duration is less than the i-th first time period, after the i-th first time period is exhausted, a heartbeat detection is performed on the (i+1)th service consumer.
4. The method according to claim 1, in, In the case where the i-th duration is greater than the i-th first time period, dividing the remaining duration in the preset heartbeat cycle into N second time periods according to the number of remaining service consumers includes: Determine the total duration of heartbeat detection for the first i service consumers; Determine the remaining duration according to the preset heartbeat cycle and the total duration; The remaining time is divided into N second time periods according to the remaining time and the number of the remaining service consumers.
5. The method according to claim 1, in, In response to the operation of sending the heartbeat message, performing heartbeat detection on the service consumer according to a preset detection rule includes: In response to the operation of sending the heartbeat message, when a response message returned by the service consumer is received within a preset time period, a heartbeat detection is performed on the service consumer according to the response message; In the case where the heartbeat detection is normal, determining that the service consumer is connected normally with the service provider; Or in response to the operation of sending the heartbeat message, if the response message returned by the service consumer is not received within the preset time period, it is determined that the service consumer is disconnected from the service provider.
6. The method according to claim 1, in, Determining the number of service consumers connected to the service provider includes: Obtain a list of service consumers corresponding to the service provider; The number of the service consumers connected to the service provider is determined according to the service consumer list.
7. A heartbeat detection device, include: A first determination module is used to determine the number of service consumers connected to the service provider, wherein the number of the service consumers is M, and M≥1; A first division module, used to divide the preset heartbeat cycle into M first time periods, wherein each of the first time periods corresponds to one of the service consumers; A first sending module, used to send heartbeat messages to the M service consumers in sequence according to the time sequence of the M first time periods; A heartbeat detection module, configured to perform a heartbeat detection on the service consumer according to a preset detection rule in response to the operation of sending the heartbeat message; A recording module, used for recording, for an i-th service consumer among the M service consumers, an i-th sending time of sending an i-th heartbeat message to the i-th service consumer and an i-th receiving time of receiving an i-th response message; A second determining module, configured to determine an i-th duration for performing heartbeat detection on the i-th service consumer according to the i-th receiving time and the i-th sending time; a second division module, configured to divide the remaining duration in the preset heartbeat cycle into N second time periods according to the number of remaining service consumers when the i-th duration is greater than the i-th first time period, wherein the duration of the second time period is less than the duration of the first time period, and N=Mi; and The second sending module is used to send the heartbeat messages to the remaining service consumers in sequence according to the time sequence of the N second time periods.
8. An electronic device, include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors execute the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, causes the processor to execute the method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Heartbeat packet sending method and device based on intermediate server and computer device
CN110149368A
Service heartbeat monitoring method and related device
CN112511368A
Heartbeat detection method and device
CN113114538A
