Service calling method and device, electronic equipment and storage medium
By intercepting service call requests and determining the timeout duration, invalid calls are avoided, thus solving the problem of unreasonable timeout settings for inter-service calls, reducing service load, and improving response efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2026-03-24
AI Technical Summary
In existing technologies, the timeout settings for inter-service calls are often unreasonable, leading to increased service load due to invalid calls and making it impossible to effectively avoid invalid calls.
By intercepting the call request, we can determine whether its timeout duration meets the conditions. If it does not meet the conditions, we can handle the request timeout to avoid invalid calls.
Effectively avoids invalid calls, reduces service load, and improves response efficiency.
Smart Images

Figure CN119211368B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a service invocation method, apparatus, electronic device, and storage medium. Background Technology
[0002] In current network architectures, inter-service calls are a common scenario, involving communication and collaboration between different services. The timeout duration for inter-service calls is an important configuration. The timeout duration refers to the maximum time a service can wait for a response during an inter-service call. Setting a timeout duration can protect services and ensure system stability and predictability.
[0003] Currently, timeout settings for inter-service calls are typically based on experience or historical data analysis. However, timeouts set in these ways are unreasonable in certain situations. For example, network issues may increase inter-service latency, leading to timeouts, or multiple sequential inter-service calls may time out before the request reaches the intermediate link. In these cases, the service does not stop calling downstream services until the timeout period is reached; however, these calls are invalid, resulting in wasted waiting time and increased unnecessary service load. Summary of the Invention
[0004] The purpose of this invention is to provide a service invocation method, apparatus, electronic device, and storage medium to avoid invalid invocations and reduce the invalid load on services. The specific technical solution is as follows:
[0005] In a first aspect of this invention, a service invocation method is provided, comprising:
[0006] After intercepting the call request sent by the calling service to the called service, the timeout duration of the call request is obtained, and it is determined whether the timeout duration meets the first condition.
[0007] If the timeout duration does not meet the first condition, the calling service is controlled to perform request timeout processing;
[0008] When the timeout period meets the first condition, the calling service is controlled to send the calling request to the called service.
[0009] Optionally, the method further includes:
[0010] After intercepting the call request received by the called service, the timeout duration of the call request is obtained, and it is determined whether the timeout duration meets the second condition.
[0011] If the timeout duration does not meet the second condition, the called service is controlled to return a request timeout response to the calling service;
[0012] When the timeout period meets the second condition, the called service is controlled to process the call request.
[0013] Optionally, determining whether the timeout duration meets the first condition includes:
[0014] When the calling service is a first type of calling service, the historical request response duration of the called service is obtained; the first type of calling service refers to the calling service that initiated the sending of the calling request;
[0015] When the historical request response time is less than or equal to the timeout time, it is determined that the timeout time satisfies the first condition;
[0016] If the duration of the historical request response is longer than the timeout duration, it is determined that the timeout duration does not meet the first condition.
[0017] Optionally, determining whether the timeout duration meets the first condition includes:
[0018] When the calling service is a second type of calling service, the historical request response duration of the called service, the starting time of the calling request, and the forwarding time of the calling service sending the calling request are obtained; the second type of calling service refers to the calling service that receives and forwards the calling request.
[0019] Calculate the first duration by subtracting the forwarding time point from the starting time point, and calculate the second duration by adding the first duration to the historical request response duration;
[0020] When the second duration is less than or equal to the timeout duration, it is determined that the timeout duration satisfies the first condition;
[0021] If the second duration is greater than the timeout duration, it is determined that the timeout duration does not meet the first condition.
[0022] Optionally, obtaining the historical request response duration of the invoked service includes:
[0023] Obtain the response times of multiple requests from the invoked service within the most recent preset time period;
[0024] The response times of the multiple requests are sorted in ascending order, and the response time of the Nth request after sorting is taken as the historical response time of the called service, where N is a preset positive integer.
[0025] Optionally, determining whether the timeout duration meets the second condition includes:
[0026] Obtain the historical request processing time of the called service, the time point at which the called service receives the call request, and the starting time point of the call request;
[0027] Calculate the third duration by subtracting the receiving time from the starting sending time, and calculate the fourth duration by adding the third duration to the historical request processing duration;
[0028] When the fourth duration is less than or equal to the timeout duration, it is determined that the timeout duration satisfies the second condition;
[0029] When the fourth duration is greater than the timeout duration, it is determined that the timeout duration does not satisfy the second condition.
[0030] Optionally, controlling the invocation service to handle request timeouts includes:
[0031] When the calling service is a first type of calling service, the calling service is controlled to send a timeout duration adjustment notification to the specified user; the first type of calling service refers to the calling service that initiated the sending of the calling request;
[0032] When the calling service is a second type of calling service, the calling service is controlled to return a request timeout response to its upstream calling service; the second type of calling service refers to the calling service that receives and forwards the calling request.
[0033] In a second aspect of the invention, a service invocation apparatus is also provided, comprising:
[0034] The first judgment module is used to obtain the timeout duration of the call request after intercepting the call request sent by the calling service to the called service, and to determine whether the timeout duration meets the first condition.
[0035] The first control module is used to control the calling service to perform request timeout processing when the timeout duration does not meet the first condition;
[0036] The second control module is used to control the calling service to send the calling request to the called service when the timeout duration meets the first condition.
[0037] Optionally, the device further includes:
[0038] The second judgment module is used to obtain the timeout duration of the call request after intercepting the call request received by the called service, and to determine whether the timeout duration meets the second condition.
[0039] The third control module is used to control the called service to return a request timeout response to the calling service when the timeout duration does not meet the second condition.
[0040] The fourth control module is used to control the called service to process the call request when the timeout duration meets the second condition.
[0041] Optionally, the first determination module includes:
[0042] The first acquisition unit is used to acquire the historical request response duration of the called service when the calling service is a first type of calling service; the first type of calling service refers to the calling service that initiated the sending of the calling request;
[0043] The first determining unit is configured to determine that the timeout duration satisfies the first condition when the historical request response duration is less than or equal to the timeout duration; and to determine that the timeout duration does not satisfy the first condition when the historical request response duration is greater than the timeout duration.
[0044] Optionally, the first determination module includes:
[0045] The second acquisition unit is used to acquire, when the calling service is a second type of calling service, the historical request response duration of the called service, the starting time of the call request, and the forwarding time of the call request sent by the calling service; the second type of calling service refers to the calling service that receives and forwards the call request.
[0046] The first calculation unit is used to calculate a first duration obtained by subtracting the forwarding time point from the starting time point, and to calculate a second duration obtained by adding the first duration to the historical request response duration;
[0047] The second determining unit is configured to determine that the timeout duration satisfies the first condition when the second duration is less than or equal to the timeout duration; and to determine that the timeout duration does not satisfy the first condition when the second duration is greater than the timeout duration.
[0048] Optionally, the first acquisition unit is specifically used to acquire multiple request response durations of the called service within the most recent preset time period; sort the multiple request response durations in ascending order, and take the Nth request response duration after sorting as the historical request response duration of the called service, where N is a preset positive integer.
[0049] Optionally, the second determination module includes:
[0050] The third acquisition unit is used to acquire the historical request processing time of the called service, the receiving time point when the called service receives the call request, and the starting sending time point of the call request;
[0051] The second calculation unit is used to calculate the third duration obtained by subtracting the receiving time point from the starting sending time point, and to calculate the fourth duration obtained by adding the third duration to the historical request processing duration.
[0052] The third determining unit is configured to determine that the timeout duration satisfies the second condition when the fourth duration is less than or equal to the timeout duration; and to determine that the timeout duration does not satisfy the second condition when the fourth duration is greater than the timeout duration.
[0053] Optionally, the first control module includes:
[0054] The notification unit is used to control the calling service to send a timeout duration adjustment notification to a specified user when the calling service is a first type of calling service; the first type of calling service refers to the calling service that initiated the sending of the calling request;
[0055] The response unit is used to control the calling service to return a request timeout response to its upstream calling service when the calling service is a second type of calling service; the second type of calling service refers to the calling service that receives and forwards the calling request.
[0056] In another aspect of the present invention, an electronic device is also provided, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; the memory is used to store computer programs; and the processor is used to implement any of the service invocation methods described above when executing the programs stored in the memory.
[0057] In another aspect of the present invention, a computer-readable storage medium is also provided, wherein instructions are stored therein, which, when executed on a computer, cause the computer to implement any of the service invocation methods described above.
[0058] In another aspect of the present invention, a computer program product containing instructions is also provided, which, when run on a computer, enables the computer to implement any of the service invocation methods described above.
[0059] The service invocation method, apparatus, electronic device, and storage medium provided in this embodiment of the invention intercept the invocation request sent by the invocation service. If the timeout duration of the invocation request does not meet the first condition before the invocation service sends the invocation request to the invoked service, the invocation request will not be sent to the invoked service, and request timeout processing will be performed, thereby avoiding invalid invocation and reducing the invalid load of the service. Attached Figure Description
[0060] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below.
[0061] Figure 1 This is a flowchart illustrating the steps of a service invocation method in an embodiment of the present invention.
[0062] Figure 2 This is a flowchart illustrating the steps of another service invocation method in an embodiment of the present invention.
[0063] Figure 3 This is a flowchart of a service invocation process according to an embodiment of the present invention.
[0064] Figure 4 This is a structural block diagram of a service invocation device according to an embodiment of the present invention.
[0065] Figure 5 This is a structural block diagram of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0066] The technical solutions of the present invention will now be described with reference to the accompanying drawings in the embodiments of the present invention.
[0067] The service invocation method in this embodiment of the invention can be applied to scenarios such as invocation between two services or serial invocation between multiple services.
[0068] The service invocation method in this embodiment of the invention can be executed by a component set in the service. This component performs operations such as intercepting the invocation request and determining the timeout duration, thereby determining whether the service should continue to send or process the invocation request. This is described in detail below.
[0069] Figure 1 This is a flowchart illustrating the steps of a service invocation method in an embodiment of the present invention.
[0070] like Figure 1 As shown, a service invocation method may include the following steps:
[0071] Step 101: After intercepting the call request sent by the calling service to the called service, obtain the timeout duration of the call request and determine whether the timeout duration meets the first condition. If not, proceed to step 102; if yes, proceed to step 103.
[0072] When the service in which the component resides acts as the calling service, the component can intercept the calling service's call request before the call request is sent to the called service.
[0073] Since it is necessary to determine whether to continue sending the call request to the called service based on the timeout duration of the call request, the component can obtain the timeout duration of the call request after intercepting the call request sent by the calling service.
[0074] The timeout duration of the call request can be preset by a specified user (such as an administrator). The timeout duration of the call request sent by the calling service to different called services can be the same or different. It can be set according to actual needs. This embodiment does not impose any restrictions on this.
[0075] For example, when a service generates a call request, it can include information such as the timeout duration of the call request. Therefore, after intercepting the call request sent by the service, the component can parse the call request to obtain information such as the timeout duration of the call request.
[0076] Since the called service requires a certain amount of time to respond to the call request, the component, after obtaining the timeout duration of the call request, can determine whether the timeout duration meets the first condition. The process of determining whether the timeout duration meets the first condition will be described in detail in later embodiments.
[0077] Step 102: When the timeout duration does not meet the first condition, control the calling service to perform request timeout processing.
[0078] When the component determines that the timeout duration does not meet the first condition, it assumes that the current call request is very likely to time out. Therefore, the calling service will no longer send the call request to the called service, and the component will control the calling service to perform request timeout processing.
[0079] In implementation, the component can send a notification to the calling service that the timeout duration does not meet the first condition. After receiving the notification that the timeout duration does not meet the first condition, the calling service will perform request timeout processing.
[0080] Step 103: When the timeout duration meets the first condition, control the calling service to send the calling request to the called service.
[0081] When the component determines that the timeout duration meets the first condition, it assumes that the call request is highly likely to succeed. Therefore, it controls the calling service to send the call request to the called service so that the called service can perform subsequent processing on the call request.
[0082] In implementation, the component can send a notification to the calling service that the timeout duration meets the first condition. After receiving the notification that the timeout duration meets the first condition, the calling service sends the call request to the called service.
[0083] In this embodiment of the invention, by intercepting the call request sent by the calling service, if the timeout duration of the call request does not meet the first condition before the calling service sends the call request to the called service, the call request will no longer be sent to the called service, and request timeout processing will be performed, thereby avoiding invalid calls and reducing the invalid load on the service.
[0084] Figure 2 This is a flowchart illustrating the steps of another service invocation method in an embodiment of the present invention.
[0085] like Figure 2 As shown, a service invocation method may include the following steps:
[0086] Step 201: After intercepting the call request sent by the calling service to the called service, obtain the timeout duration of the call request and determine whether the timeout duration meets the first condition. If not, proceed to step 202; if yes, proceed to step 203.
[0087] Considering that the called service may be a first type of called service or a second type of called service, different methods will be used to determine whether the timeout duration meets the first condition for the first type of called service and the second type of called service.
[0088] In this context, the first type of invocation service refers to the service that initiates the invocation request; the second type of invocation service refers to the invocation service that receives and forwards the invocation request, specifically, the service that receives the invocation request sent by its upstream invocation service and forwards the invocation request to its downstream invoked service. For example, in the service invocation process, if the service invocation order is service 1 calls service 2, and service 2 then calls service 3, then service 1 is the first type of invocation service, and service 2 is the second type of invocation service.
[0089] For example, when the calling service is a first type of calling service, the process of determining whether the timeout duration meets the first condition may include: obtaining the historical request response duration of the called service; determining that the timeout duration meets the first condition when the historical request response duration is less than or equal to the timeout duration; and determining that the timeout duration does not meet the first condition when the historical request response duration is greater than the timeout duration. In this way, by comparing the historical request response duration of the called service with the timeout duration of the calling request, it can accurately reflect whether the called service can complete the response to the calling request before the timeout duration of the calling request is reached, resulting in a more accurate judgment.
[0090] In the calling service, the request response time of the called service can be recorded in history when the calling service calls the called service. Therefore, the historical request response time of the called service can be obtained based on these recorded request response times.
[0091] For example, the process of obtaining the historical request response duration of the called service may include: obtaining multiple request response durations of the called service within a recent preset time period; sorting the multiple request response durations in ascending order, and taking the Nth request response duration after sorting as the historical request response duration of the called service, where N is a preset positive integer. The historical request response duration selected in this way can more accurately represent the request response status of the called service. The specific values of the preset time period and N can be set according to actual needs; this embodiment does not impose any restrictions on this.
[0092] For example, the P999 value can be used as the historical request response time of the called service. The P999 value represents that the request response time of 99.9% of the calls does not exceed this value. Therefore, 1000 request response times within the most recent preset time period (e.g., 5 minutes) can be obtained; these 1000 request response times can be sorted in ascending order, and the 999th (i.e., the 99.9% position) request response time can be used as the historical request response time of the called service.
[0093] For example, when the calling service is a second type of calling service, the process of determining whether the timeout duration meets the first condition may include: obtaining the historical request response duration of the called service, the starting time of the calling request, and the forwarding time of the calling service sending the calling request; calculating a first duration obtained by subtracting the starting time from the forwarding time and calculating a second duration obtained by adding the first duration to the historical request response duration; determining that the timeout duration meets the first condition when the second duration is less than or equal to the timeout duration; and determining that the timeout duration does not meet the first condition when the second duration is greater than the timeout duration.
[0094] The process of obtaining the historical request response duration of the called service can be referred to the relevant content above, and will not be discussed in detail here.
[0095] For example, when a component intercepts a call request sent by a first-type service, it can record the current time as the starting time of the call request and add information such as the starting time of the call request to the call request. Therefore, the starting time of the call request can be obtained by parsing the call request.
[0096] For example, when a component intercepts a call request sent by a second type of service, it can record the current time as the forwarding time of the call request.
[0097] The first duration, obtained by subtracting the initial sending time from the forwarding time point, refers to the time consumed from the start of the call request being sent by the first type of calling service to the start of the call request being sent by the second type of calling service. The second duration, obtained by adding the first duration to the historical request response duration, refers to the time consumed from the start of the call request being sent by the first type of calling service to the start of the call request being sent by the current second type of calling service, plus the historical request response duration of the called service. Therefore, the second duration can represent the total time that the call request will take from its initial sending to its completion of the response from the called service. By comparing the total time that the call request will take from its initial sending to its completion of the response from the called service with the timeout duration of the call request, this method can accurately reflect whether the called service can complete the response to the call request before the timeout duration is reached, resulting in a more accurate assessment.
[0098] Step 202: When the timeout duration does not meet the first condition, control the calling service to perform request timeout processing. Considering that the calling service may be a first type of calling service or a second type of calling service, the calling service will be controlled to perform different request timeout processing methods for the first type of calling service and the second type of calling service.
[0099] For example, when the calling service is a first type of calling service, the calling service can be controlled to send a timeout duration adjustment notification to a specified user (such as an administrator) so that the specified user can adjust the timeout duration in a timely manner.
[0100] The timeout adjustment notification may include information such as the timeout duration of the call request and the historical request response time of the called service. A designated user can adjust the timeout duration of the call request according to the actual situation based on the timeout adjustment notification, for example, by adjusting the timeout duration of the call request to be greater than the historical request response time of the called service, and so on.
[0101] For example, when the calling service is a second type of calling service, the calling service can be controlled to return a request timeout response to its upstream calling service, so that the calling service will no longer process the calling request and reduce invalid load.
[0102] If the calling service that received the request timeout response has an upstream calling service, then the service sequentially returns a request timeout response to the upstream calling service until it returns a request timeout response to the first type of calling service. Upon receiving the request timeout response, the first type of calling service can send a timeout duration adjustment notification to a specified user (e.g., an administrator). The specified user can adjust the timeout duration of the call request according to the actual situation based on the timeout duration adjustment notification.
[0103] Step 203: When the timeout duration meets the first condition, control the calling service to send the call request to the called service. Step 204: After intercepting the call request received by the called service, obtain the timeout duration of the call request and determine whether the timeout duration meets the second condition. If not, proceed to step 205; if yes, proceed to step 206.
[0104] When the service in which the component resides is the called service, the component can intercept the call request received by the called service when the called service receives the call request.
[0105] Since it is necessary to determine whether the called service should continue to process the call request based on the timeout duration of the call request, the component can obtain the timeout duration of the call request after intercepting the call request received by the called service.
[0106] For example, when a service generates a call request, it can include information such as the timeout duration of the call request. Therefore, after intercepting the call request received by the called service, the component can parse the call request to obtain information such as the timeout duration of the call request.
[0107] Since the called service needs a certain amount of time to process the call request, the component can determine whether the timeout duration meets the second condition after obtaining the timeout duration of the call request.
[0108] For example, the process of determining whether the timeout duration satisfies the second condition may include: obtaining the historical request processing duration of the called service, the receiving time point when the called service receives the call request, and the starting sending time point of the call request; calculating a third duration obtained by subtracting the receiving time point from the starting sending time point, and calculating a fourth duration obtained by adding the third duration to the historical request processing duration; determining that the timeout duration satisfies the second condition when the fourth duration is less than or equal to the timeout duration; and determining that the timeout duration does not satisfy the second condition when the fourth duration is greater than the timeout duration.
[0109] In the called service, the historical processing time of the called service in processing the call requests sent by the calling service can be recorded. Therefore, the historical request processing time of the called service can be obtained based on these recorded request processing times.
[0110] For example, the process of obtaining the historical request processing time of the called service may include: obtaining multiple request processing times of the called service within a recent preset time period; and taking the average of the multiple request processing times as the historical request processing time of the called service.
[0111] For example, when a component intercepts a call request received by a called service, it can record the current time as the time when the called service received the call request.
[0112] For example, when a component intercepts a call request sent by a first-type service, it can record the current time as the starting time of the call request and add information such as the starting time of the call request to the call request. Therefore, the starting time of the call request can be obtained by parsing the call request.
[0113] The third duration, obtained by subtracting the initial sending time from the receiving time, refers to the time consumed from when the call request is sent by the first type of calling service to when it is received by the called service. The fourth duration, obtained by adding the third duration to the historical request processing time, refers to the total time that will elapse from when the call request is sent by the first type of calling service to when it is received by the called service. This fourth duration, combined with the historical request processing time of the called service, represents the total time that will elapse from when the call request is initially sent to when it is finally processed by the called service. By comparing the total time that will elapse from when the call request is initially sent to when it is finally processed by the called service with the timeout duration of the call request, this method can accurately reflect whether the called service can complete the processing of the call request before the timeout duration is reached, resulting in a more accurate assessment.
[0114] Step 205: When the timeout duration does not meet the second condition, control the called service to return a request timeout response to the calling service.
[0115] When the component determines that the timeout duration does not meet the second condition, it assumes that the current call request is very likely to time out. Therefore, the called service will no longer process the call request, and the component will control the called service to return a request timeout response to the calling service.
[0116] In implementation, the component can send a notification to the called service that the timeout duration does not meet the second condition. After receiving the notification that the timeout duration does not meet the second condition, the called service returns a request timeout response to the calling service.
[0117] If the calling service that received the request timeout response has an upstream calling service, then the service sequentially returns a request timeout response to the upstream calling service until it returns a request timeout response to the first type of calling service. Upon receiving the request timeout response, the first type of calling service can send a timeout duration adjustment notification to a specified user (e.g., an administrator). The specified user can adjust the timeout duration of the call request according to the actual situation based on the timeout duration adjustment notification.
[0118] Step 206: When the timeout duration meets the second condition, control the called service to process the call request.
[0119] When the component determines that the timeout duration meets the second condition, it assumes that the call request is highly likely to succeed, and therefore controls the called service to process the call request.
[0120] In implementation, the component can send a notification to the called service that the timeout duration meets the second condition. After receiving the notification that the timeout duration meets the second condition, the called service processes the call request.
[0121] After processing the call request, if there is no downstream called service of the called service, the called service will return the call request processing result to the calling service; if there is a downstream called service of the called service, the called service will act as the calling service and continue to send the call request to the downstream called service, so that the component can intercept the call request sent by the calling service and repeat the above steps 201 to 206.
[0122] In this embodiment of the invention, in addition to controlling the calling service, control over the called service is further added. By intercepting the call request received by the called service, if the timeout duration of the call request does not meet the second condition before the called service processes the call request, the called service will no longer process the call request and will promptly return a request timeout response to the calling service, thereby avoiding invalid processing of the call request, improving the response efficiency of the service call, and reducing the invalid load on the service.
[0123] Figure 3 This is a flowchart of a service invocation process according to an embodiment of the present invention. Figure 3 In the above, service A is the first type of service call.
[0124] like Figure 3 As shown, the service invocation process may include:
[0125] (1) Service A is preparing to call Service B and sends a call request to Service B. The component of Service A intercepts the call request sent by Service A.
[0126] (2) The component of service A obtains the timeout duration of the call request, the start time of the call request, and the historical request response duration of service B.
[0127] (3) The component of service A determines whether the timeout period of the call request is sufficient.
[0128] That is, determine whether the timeout duration of the call request meets the first condition.
[0129] Specifically, the timeout duration of the call request is compared with the historical request response duration of service B. If the historical request response duration of service B is less than or equal to the timeout duration of the call request, the timeout duration of the call request is determined to be sufficient (i.e., the first condition is met). If the historical request response duration of service B is greater than the timeout duration of the call request, the timeout duration of the call request is determined to be insufficient (i.e., the first condition is not met).
[0130] (4) If the timeout period of the call request is insufficient, service A sends a timeout period adjustment notification to the specified user.
[0131] (5) If the timeout period of the call request is sufficient, service A sends a call request to service B.
[0132] (6) Service B receives the call request sent by Service A, and the component of Service B intercepts the call request received by Service B.
[0133] (7) The component of service B determines whether the timeout period of the call request is sufficient.
[0134] That is, determine whether the timeout duration of the call request meets the second condition.
[0135] Specifically, the system obtains the historical request processing time of service B, the reception time of service B receiving the call request, and the start time of the call request. It calculates the third duration by subtracting the reception time from the start time and calculates the fourth duration by adding the third duration to the historical request processing time. It compares the timeout duration of the call request with the fourth duration. If the fourth duration is less than or equal to the timeout duration of the call request, it is determined that the timeout duration of the call request is sufficient (i.e., the second condition is met). If the fourth duration is greater than the timeout duration of the call request, it is determined that the timeout duration of the call request is insufficient (i.e., the second condition is not met).
[0136] (8) If the timeout period of the call request is insufficient, service B returns a request timeout response to service A.
[0137] (9) If the timeout period of the call request is sufficient, then Service B will process the internal logic of the call request interface.
[0138] (10) Service B completes the call request and sends a call request to Service C. The component of Service B intercepts the call request sent by Service B.
[0139] (11) The component of service B determines whether the timeout period of the call request is sufficient.
[0140] Specifically, the forwarding time point when Service B sends the call request and the starting time point of the call request are obtained. The fifth duration is calculated by subtracting the starting time point from the forwarding time point. The timeout duration of the call request is compared with the fifth duration. If the fifth duration is less than or equal to the timeout duration of the call request, the timeout duration of the call request is determined to be sufficient. If the fifth duration is greater than the timeout duration of the call request, the timeout duration of the call request is determined to be insufficient.
[0141] (12) If the timeout period of the call request is insufficient, service B returns a request timeout response to service A.
[0142] (13) If the timeout duration of the call request is sufficient, the component of service B obtains the historical request response duration of service C, the forwarding time point when service B sends the call request, the starting time point of the call request, and the timeout duration of the call request.
[0143] (14) The component of service B determines whether the timeout period of the call request is sufficient.
[0144] That is, determine whether the timeout duration of the call request meets the first condition.
[0145] Specifically, a first duration is calculated by subtracting the forwarding time from the initial sending time, and a second duration is calculated by adding the first duration to the historical request response duration of service C. If the second duration is less than or equal to the timeout duration of the call request, the timeout duration of the call request is determined to be sufficient (i.e., the first condition is met); if the second duration is greater than the timeout duration of the call request, the timeout duration of the call request is determined to be insufficient (i.e., the first condition is not met).
[0146] (15) If the timeout period of the call request is insufficient, service B returns a request timeout response to service A.
[0147] (16) If the timeout period of the call request is sufficient, service B sends the call request to service C.
[0148] (17) The internal processing logic of service C is the same as that of service B.
[0149] (18) After service C completes the call request, it returns the call request processing result to service B.
[0150] (19) Service B returns the result of the call request processing to Service A.
[0151] The service call process will be described below with specific examples.
[0152] Service A prepares to call Service B at time t1, with a timeout duration set to m. The P999 value of the request-response time for Service A calling Service B in the past 5 minutes is x. If x is greater than m, the request will likely time out, and a timeout response can be returned directly, reminding the administrator to adjust the timeout duration. If x is less than or equal to m, the request will likely succeed; let's assume x is less than or equal to m. Service B receives Service A's call request at time t2. The network latency between Service A and Service B for this call request is t2-t1, and Service B's average request processing time in the past 5 minutes is n. If t2-t1+n is greater than m, a timeout response is returned early. If t2-t1+n is less than or equal to m, Service B continues processing its internal interface logic and handles the call request. Service B completes processing the call request at time t3. At this point, Service B prepares to call Service C, and the P999 value of the request-response time for Service B calling Service C in the past 5 minutes is y. If t3-t1+y is greater than m, a timeout response is returned. If t3-t1+y is less than or equal to m, then continue to call service N. The logic for subsequent interface calls is similar and will not be repeated here.
[0153] In this embodiment of the invention, it is possible to dynamically determine whether to return a request timeout response directly or to continue processing for a call request, which greatly saves invalid waiting time, improves response time, and reduces invalid machine load.
[0154] Figure 4 This is a structural block diagram of a service invocation device according to an embodiment of the present invention.
[0155] like Figure 4 As shown, the service invocation device may include the following modules:
[0156] The first judgment module 301 is used to obtain the timeout duration of the call request after intercepting the call request sent by the calling service to the called service, and to determine whether the timeout duration meets the first condition.
[0157] The first control module 302 is used to control the calling service to perform request timeout processing when the timeout duration does not meet the first condition;
[0158] The second control module 303 is used to control the calling service to send the calling request to the called service when the timeout duration meets the first condition.
[0159] Optionally, the device further includes:
[0160] The second judgment module is used to obtain the timeout duration of the call request after intercepting the call request received by the called service, and to determine whether the timeout duration meets the second condition.
[0161] The third control module is used to control the called service to return a request timeout response to the calling service when the timeout duration does not meet the second condition.
[0162] The fourth control module is used to control the called service to process the call request when the timeout duration meets the second condition.
[0163] Optionally, the first determination module 301 includes:
[0164] The first acquisition unit is used to acquire the historical request response duration of the called service when the calling service is a first type of calling service; the first type of calling service refers to the calling service that initiated the sending of the calling request;
[0165] The first determining unit is configured to determine that the timeout duration satisfies the first condition when the historical request response duration is less than or equal to the timeout duration; and to determine that the timeout duration does not satisfy the first condition when the historical request response duration is greater than the timeout duration.
[0166] Optionally, the first determination module 301 includes:
[0167] The second acquisition unit is used to acquire, when the calling service is a second type of calling service, the historical request response duration of the called service, the starting time of the call request, and the forwarding time of the call request sent by the calling service; the second type of calling service refers to the calling service that receives and forwards the call request.
[0168] The first calculation unit is used to calculate a first duration obtained by subtracting the forwarding time point from the starting time point, and to calculate a second duration obtained by adding the first duration to the historical request response duration;
[0169] The second determining unit is configured to determine that the timeout duration satisfies the first condition when the second duration is less than or equal to the timeout duration; and to determine that the timeout duration does not satisfy the first condition when the second duration is greater than the timeout duration.
[0170] Optionally, the first acquisition unit is specifically used to acquire multiple request response durations of the called service within the most recent preset time period; sort the multiple request response durations in ascending order, and take the Nth request response duration after sorting as the historical request response duration of the called service, where N is a preset positive integer.
[0171] Optionally, the second determination module includes:
[0172] The third acquisition unit is used to acquire the historical request processing time of the called service, the receiving time point when the called service receives the call request, and the starting sending time point of the call request;
[0173] The second calculation unit is used to calculate the third duration obtained by subtracting the receiving time point from the starting sending time point, and to calculate the fourth duration obtained by adding the third duration to the historical request processing duration.
[0174] The third determining unit is configured to determine that the timeout duration satisfies the second condition when the fourth duration is less than or equal to the timeout duration; and to determine that the timeout duration does not satisfy the second condition when the fourth duration is greater than the timeout duration.
[0175] Optionally, the first control module 302 includes:
[0176] The notification unit is used to control the calling service to send a timeout duration adjustment notification to a specified user when the calling service is a first type of calling service; the first type of calling service refers to the calling service that initiated the sending of the calling request;
[0177] The response unit is used to control the calling service to return a request timeout response to its upstream calling service when the calling service is a second type of calling service; the second type of calling service refers to the calling service that receives and forwards the calling request.
[0178] In this embodiment of the invention, by intercepting the call request sent by the calling service, if the timeout duration of the call request does not meet the first condition before the calling service sends the call request to the called service, the call request will not be sent to the called service again, and request timeout processing will be performed, thereby avoiding invalid calls; by intercepting the call request received by the called service, if the timeout duration of the call request does not meet the second condition before the called service processes the call request, the called service will not process the call request again, and will promptly return a request timeout response to the calling service, thereby avoiding invalid processing of call requests, improving the response efficiency of service calls, and reducing the invalid load on the service.
[0179] This invention also provides an electronic device, such as... Figure 5 As shown, it includes a processor 401, a communication interface 402, a memory 403, and a communication bus 404, wherein the processor 401, the communication interface 402, and the memory 403 communicate with each other through the communication bus 404.
[0180] Memory 403 is used to store computer programs;
[0181] When processor 401 executes the program stored in memory 403, it performs the following steps:
[0182] After intercepting the call request sent by the calling service to the called service, the timeout duration of the call request is obtained, and it is determined whether the timeout duration meets the first condition.
[0183] If the timeout duration does not meet the first condition, the calling service is controlled to perform request timeout processing;
[0184] When the timeout period meets the first condition, the calling service is controlled to send the calling request to the called service.
[0185] Optionally, the method further includes:
[0186] After intercepting the call request received by the called service, the timeout duration of the call request is obtained, and it is determined whether the timeout duration meets the second condition.
[0187] If the timeout duration does not meet the second condition, the called service is controlled to return a request timeout response to the calling service;
[0188] When the timeout period meets the second condition, the called service is controlled to process the call request.
[0189] Optionally, determining whether the timeout duration meets the first condition includes:
[0190] When the calling service is a first type of calling service, the historical request response duration of the called service is obtained; the first type of calling service refers to the calling service that initiated the sending of the calling request;
[0191] When the historical request response time is less than or equal to the timeout time, it is determined that the timeout time satisfies the first condition;
[0192] If the duration of the historical request response is longer than the timeout duration, it is determined that the timeout duration does not meet the first condition.
[0193] Optionally, determining whether the timeout duration meets the first condition includes:
[0194] When the calling service is a second type of calling service, the historical request response duration of the called service, the starting time of the calling request, and the forwarding time of the calling service sending the calling request are obtained; the second type of calling service refers to the calling service that receives and forwards the calling request.
[0195] Calculate the first duration by subtracting the forwarding time point from the starting time point, and calculate the second duration by adding the first duration to the historical request response duration;
[0196] When the second duration is less than or equal to the timeout duration, it is determined that the timeout duration satisfies the first condition;
[0197] If the second duration is greater than the timeout duration, it is determined that the timeout duration does not meet the first condition.
[0198] Optionally, obtaining the historical request response duration of the invoked service includes:
[0199] Obtain the response times of multiple requests from the invoked service within the most recent preset time period;
[0200] The response times of the multiple requests are sorted in ascending order, and the response time of the Nth request after sorting is taken as the historical response time of the called service, where N is a preset positive integer.
[0201] Optionally, determining whether the timeout duration meets the second condition includes:
[0202] Obtain the historical request processing time of the called service, the time point at which the called service receives the call request, and the starting time point of the call request;
[0203] Calculate the third duration by subtracting the receiving time from the starting sending time, and calculate the fourth duration by adding the third duration to the historical request processing duration;
[0204] When the fourth duration is less than or equal to the timeout duration, it is determined that the timeout duration satisfies the second condition;
[0205] When the fourth duration is greater than the timeout duration, it is determined that the timeout duration does not satisfy the second condition.
[0206] Optionally, controlling the invocation service to handle request timeouts includes:
[0207] When the calling service is a first type of calling service, the calling service is controlled to send a timeout duration adjustment notification to the specified user; the first type of calling service refers to the calling service that initiated the sending of the calling request;
[0208] When the calling service is a second type of calling service, the calling service is controlled to return a request timeout response to its upstream calling service; the second type of calling service refers to the calling service that receives and forwards the calling request.
[0209] The communication bus mentioned above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0210] The communication interface is used for communication between the aforementioned terminal and other devices.
[0211] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0212] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0213] In another embodiment of the present invention, a computer-readable storage medium is also provided, which stores instructions that, when executed on a computer, cause the computer to implement any of the service invocation methods described in the above embodiments.
[0214] In another embodiment of the present invention, a computer program product containing instructions is also provided, which, when run on a computer, enables the computer to implement any of the service invocation methods described in the above embodiments.
[0215] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0216] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0217] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0218] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention are included within the scope of protection of the present invention.
Claims
1. A service invocation method, characterized in that, include: Before the calling service sends a call request, but before the call request is sent to the called service, the call request sent by the calling service to the called service is intercepted, and the timeout duration of the call request is obtained. When the calling service is a first type of calling service, the historical request response time of the called service is compared with the timeout time of the calling request to determine whether the timeout time meets the first condition; wherein, the first type of calling service refers to the service that initiated the calling request; When the calling service is a second type of calling service, the historical request response duration of the called service, the starting time of the calling request, and the forwarding time of the calling service sending the calling request are obtained; the second type of calling service refers to the calling service that receives and forwards the calling request; a first duration is obtained by subtracting the starting time from the forwarding time, and a second duration is obtained by adding the first duration to the historical request response duration; if the second duration is less than or equal to the timeout duration, the timeout duration is determined to satisfy the first condition; if the second duration is greater than the timeout duration, the timeout duration is determined to not satisfy the first condition. If the timeout duration does not meet the first condition, the calling service is controlled to perform request timeout processing; When the timeout period meets the first condition, the calling service is controlled to send the calling request to the called service.
2. The method according to claim 1, characterized in that, The method further includes: After intercepting the call request received by the called service, the timeout duration of the call request is obtained, and it is determined whether the timeout duration meets the second condition. If the timeout duration does not meet the second condition, the called service is controlled to return a request timeout response to the calling service; When the timeout period meets the second condition, the called service is controlled to process the call request.
3. The method according to claim 1, characterized in that, When the calling service is a first type of calling service, the historical request response time of the called service is compared with the timeout time of the calling request to determine whether the timeout time meets the first condition, including: When the calling service is a first type of calling service, the historical request response duration of the called service is obtained; the first type of calling service refers to the calling service that initiated the sending of the calling request; When the historical request response time is less than or equal to the timeout time, it is determined that the timeout time satisfies the first condition; If the duration of the historical request response is longer than the timeout duration, it is determined that the timeout duration does not meet the first condition.
4. The method according to claim 1 or 3, characterized in that, Obtaining the historical request response duration of the invoked service includes: Obtain the response times of multiple requests from the invoked service within the most recent preset time period; The response times of the multiple requests are sorted in ascending order, and the response time of the Nth request after sorting is taken as the historical response time of the called service, where N is a preset positive integer.
5. The method according to claim 2, characterized in that, Determining whether the timeout duration meets the second condition includes: Obtain the historical request processing time of the called service, the time point at which the called service receives the call request, and the starting time point of the call request; Calculate the third duration by subtracting the receiving time from the starting sending time, and calculate the fourth duration by adding the third duration to the historical request processing duration; When the fourth duration is less than or equal to the timeout duration, it is determined that the timeout duration satisfies the second condition; When the fourth duration is greater than the timeout duration, it is determined that the timeout duration does not satisfy the second condition.
6. The method according to claim 1, characterized in that, Controlling the request timeout handling of the called service includes: When the calling service is a first type of calling service, the calling service is controlled to send a timeout duration adjustment notification to the specified user; the first type of calling service refers to the calling service that initiated the sending of the calling request; When the calling service is a second type of calling service, the calling service is controlled to return a request timeout response to its upstream calling service; the second type of calling service refers to the calling service that receives and forwards the calling request.
7. A service invocation device, characterized in that, include: The first judgment module is used to intercept the call request sent by the calling service to the called service before the call request is sent to the called service, obtain the timeout duration of the call request, and determine whether the timeout duration meets the first condition. The first control module is used to control the calling service to perform request timeout processing when the timeout duration does not meet the first condition; The second control module is used to control the calling service to send the calling request to the called service when the timeout duration meets the first condition; The first determination module includes: The first acquisition unit is used to acquire the historical request response duration of the called service when the calling service is a first type of calling service; the first type of calling service refers to the calling service that initiated the sending of the calling request; The first determining unit is configured to determine that the timeout duration satisfies the first condition when the historical request response duration is less than or equal to the timeout duration; and to determine that the timeout duration does not satisfy the first condition when the historical request response duration is greater than the timeout duration. The second acquisition unit is used to acquire, when the calling service is a second type of calling service, the historical request response duration of the called service, the starting time of the call request, and the forwarding time of the call request sent by the calling service; the second type of calling service refers to the calling service that receives and forwards the call request. The first calculation unit is used to calculate a first duration obtained by subtracting the forwarding time point from the starting time point, and to calculate a second duration obtained by adding the first duration to the historical request response duration; The second determining unit is configured to determine that the timeout duration satisfies the first condition when the second duration is less than or equal to the timeout duration; and to determine that the timeout duration does not satisfy the first condition when the second duration is greater than the timeout duration.
8. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method as described in any one of claims 1-6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-6.
Citation Information
Patent Citations
Service timeout management method and device
CN113783822A