Interface call timeout processing method and device, equipment and storage medium

By monitoring API call times and dynamically adjusting timeouts, marking long-running APIs and implementing rate limiting, the problems of data loss and excessively long response times during API calls were resolved, thus improving the user experience.

CN115202969BActive Publication Date: 2026-04-07CHINA PING AN PROPERTY INSURANCE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-24
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

The existing servers, with their uniform timeout settings when processing API calls, cause data to be dropped frequently or API response times to be too long, which affects user experience.

Method used

By monitoring API call times, dynamically adjusting timeout periods, marking long-running APIs and implementing rate limiting, API services can be optimized.

Benefits of technology

This avoids data loss or prolonged blocking of the request chain caused by uniform timeout settings, thus improving the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115202969B_ABST
    Figure CN115202969B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of Internet, and discloses an interface calling timeout processing method, device, equipment and storage medium. The method comprises the following steps: acquiring an interface calling request, monitoring and recording a first calling time of a thread interface processing the interface calling request in real time; when it is monitored that the first calling time exceeds a preset timeout time, marking the corresponding thread interface as a timeout interface; acquiring a second calling time of the timeout interface within a first preset time range, acquiring a shortest calling time from the second calling time, comparing the shortest calling time with the preset timeout time; if the shortest calling time is greater than the preset timeout time, marking the timeout interface as a long-time-consuming interface, calculating an average time consumption of the timeout interface processing the interface calling request within the first preset time range according to the second calling time, and adjusting the timeout time of the long-time-consuming interface according to the average time consumption. Through the above method, the timeout time can be dynamically adjusted, and the user experience is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of Internet technology, and in particular to a method, apparatus, device, and storage medium for handling interface call timeouts. Background Technology

[0002] Apps often require data aggregation, such as displaying aggregated business data from different modules over a period of time or even a whole year. However, different modules have different efficiencies in data collection and aggregation. Existing servers typically use the same timeout period for different interfaces to handle data discarding. If the timeout is too short, it can lead to high-frequency data discarding, affecting data display for users; if the timeout is too long, it can cause excessively long overall interface response times, slow app data loading and rendering, and a poor user experience. Summary of the Invention

[0003] This invention provides a method, apparatus, device, and storage medium for handling interface call timeouts, which can dynamically adjust the timeout period and improve user experience.

[0004] To solve the above-mentioned technical problems, one technical solution adopted by the present invention is: to provide an interface call timeout handling method, comprising:

[0005] Obtain the interface call request, and monitor and record the first call time of the thread interface in processing the interface call request in real time;

[0006] When it is detected that the first call time exceeds the preset timeout period, the corresponding thread interface is marked as a timeout interface;

[0007] Within a first preset time range, obtain the second call time of the timeout interface, obtain the shortest call time from the second call time, and compare the shortest call time with the preset timeout time;

[0008] If the shortest call time is greater than the preset timeout time, the timeout interface is marked as a long-time interface, and the average time taken for the timeout interface to process the interface call request within the first preset time range is calculated based on the second call time. The timeout time of the long-time interface is then adjusted based on the average time taken.

[0009] According to an embodiment of the present invention, marking the corresponding thread interface as a timeout interface when the first call time is detected to exceed a preset timeout period further includes:

[0010] When the first call time is detected to exceed the preset timeout period, the third call time of the corresponding thread interface is obtained within the second preset time range;

[0011] Calculate the first timeout percentage of the thread interface processing the interface call request based on the third call time;

[0012] Compare the first timeout percentage with a preset threshold;

[0013] If the first timeout percentage is greater than the preset threshold, then the corresponding thread interface is marked as a timeout interface.

[0014] According to an embodiment of the present invention, if the shortest call time is greater than the preset timeout time, the timeout interface is marked as a long-time-consuming interface, and the average time taken by the timeout interface to process the interface call request within the first preset time range is calculated based on the second call time, and the timeout time of the long-time-consuming interface is adjusted based on the average time taken, the method further includes:

[0015] Receive an interface call request, intercept the interface call request and read the interface identifier in the interface call request, and detect whether the target interface pointed to by the interface identifier is a long-time interface;

[0016] When the target interface is detected to be a long-running interface, the interface call request is rate-limited according to the first rate-limiting mechanism.

[0017] According to an embodiment of the present invention, the first current limiting mechanism includes:

[0018] Within the first time period, the interface call request of the long-duration interface is forwarded according to the first ratio;

[0019] Within a second duration, the interface call requests of the long-duration interface are forwarded according to a second ratio, wherein the second ratio is at least greater than the first ratio.

[0020] According to an embodiment of the present invention, after rate limiting the interface call request according to the gradient rate limiting mechanism, the process includes:

[0021] Within a third preset time range, the second timeout percentage of the long-duration interface processing the interface call request is calculated based on the fourth call time of the interface call request after rate limiting.

[0022] The second timeout percentage is compared with the preset threshold.

[0023] If the second timeout percentage is less than the preset threshold, then the long-time interface is removed from the flag and the timeout is adjusted to the preset timeout.

[0024] According to an embodiment of the present invention, after obtaining the second call time of the timeout interface within a first preset time range, obtaining the shortest call time from the second call time, and comparing the shortest call time with the preset timeout time, the method further includes:

[0025] Obtain the longest call time from the second call time, and compare the longest call time with the preset timeout time;

[0026] If the shortest call time is less than the preset timeout and the longest call time is greater than the preset timeout, then the average time taken by the timeout interface to process the interface call request within the first preset time range is calculated based on the second call time, and the timeout time of the timeout interface is adjusted based on the average time taken.

[0027] According to an embodiment of the present invention, if the shortest call time is less than the preset timeout time and the longest call time is greater than the preset timeout time, then after calculating the average time taken by the timeout interface to process the interface call request within the first preset time range based on the second call time, and adjusting the timeout time of the timeout interface based on the average time taken, the method further includes:

[0028] Receive an interface call request, intercept the interface call request and read the interface identifier in the interface call request, and detect whether the target interface pointed to by the interface identifier is a timeout interface;

[0029] When the target interface is detected as a timeout interface, the interface call request is rate-limited according to the second rate-limiting mechanism.

[0030] To solve the above-mentioned technical problems, another technical solution adopted by the present invention is: providing an interface call timeout handling device, comprising:

[0031] The acquisition module is used to acquire interface call requests, monitor and record the first call time of the thread interface in processing the interface call request in real time;

[0032] The monitoring module is used to mark the corresponding thread interface as a timeout interface when it detects that the first call time exceeds a preset timeout period;

[0033] The comparison module is used to obtain the second call time of the timeout interface within a first preset time range, obtain the shortest call time from the second call time, and compare the shortest call time with the preset timeout time.

[0034] An adjustment module is configured to mark the timed-out interface as a long-timed interface if the shortest call time is greater than the preset timeout time, calculate the average time taken for the timed-out interface to process the interface call request within the first preset time range based on the second call time, and adjust the timeout time of the long-timed interface based on the average time taken.

[0035] To solve the above-mentioned technical problems, another technical solution adopted by the present invention is to provide a computer device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the interface call timeout handling method when executing the computer program.

[0036] To solve the above-mentioned technical problems, another technical solution adopted by the present invention is to provide a computer storage medium on which a computer program is stored, wherein the computer program implements the above-mentioned interface call timeout handling method when executed by a processor.

[0037] The beneficial effects of this invention are as follows: By monitoring timeout interfaces, the shortest call time of the timeout interface is obtained within a first preset time range. When the shortest call time is greater than the preset timeout time, the timeout interface is marked as a long-time-consuming interface. The average time taken to process interface call requests by the timeout interfaces within the first preset time range is calculated based on the second call time of the timeout interface. The timeout time of the long-time-consuming interface is adjusted according to the average timeout time, thereby realizing dynamic adjustment of the timeout time. This avoids the problem of high-frequency data loss or long-term occupation of the request link caused by uniformly setting the timeout time, thus optimizing the interface service and improving the user experience. Attached Figure Description

[0038] Figure 1 This is a schematic diagram of the system architecture according to an embodiment of the present invention;

[0039] Figure 2 This is a flowchart illustrating an interface call timeout handling method according to an embodiment of the present invention;

[0040] Figure 3 This is a flowchart illustrating an interface call timeout handling method according to another embodiment of the present invention;

[0041] Figure 4 This is a flowchart illustrating an interface call timeout handling method according to another embodiment of the present invention;

[0042] Figure 5 This is a flowchart illustrating an interface call timeout handling method according to another embodiment of the present invention;

[0043] Figure 6 This is a schematic diagram of the interface call timeout handling device according to an embodiment of the present invention;

[0044] Figure 7This is a schematic diagram of the structure of a computer device according to an embodiment of the present invention;

[0045] Figure 8 This is a schematic diagram of the structure of a computer storage medium according to an embodiment of the present invention. Detailed Implementation

[0046] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.

[0047] The terms "first," "second," and "third" used in this invention are for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined as "first," "second," or "third" may explicitly or implicitly include at least one of that feature. In the description of this invention, "a plurality of" means at least two, such as two, three, etc., unless otherwise explicitly specified. All directional indications (such as up, down, left, right, front, back, etc.) in the embodiments of this invention are only used to explain the relative positional relationships and movements between components in a specific orientation (as shown in the figures). If the specific orientation changes, the directional indications also change accordingly. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices.

[0048] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0049] The present invention provides an interface call timeout handling method, which can be applied to, for example... Figure 1The system architecture 100 shown uses a multi-threaded approach to aggregate data. This architecture includes an aggregation module 10, multiple business modules 20 connected to the aggregation module 10, a storage module 30, and a scheduled task module 40. The aggregation module 10 has an aggregation interface 101, and the business modules 20 have thread interfaces. For example, if there are business modules A, B, and C, then the corresponding thread interfaces are 1, 2, and 3. The thread interfaces can connect to related parties or a database. The aggregation module 10 calls thread interfaces 1, 2, and 3 through the aggregation interface 101 to perform data aggregation and display. The storage module 30 stores the call time and timeout of each thread interface. The scheduled task module 40 is used to execute scheduled calculation tasks.

[0050] Specifically, when a user views data within the app, data display requests from different business modules are involved. The aggregation interface 101 receives the user's interface call request and forwards it to the corresponding thread interface. The thread interface retrieves the corresponding response data through the interface call and returns it to the aggregation interface 101. The aggregation interface 101 then integrates the data using a multi-threaded approach and displays it on the front end. During this process, the aggregation interface 101 has a preset timeout period, which is the interface call time between the aggregation module 10 and the business module 20. If a thread does not receive response data within the preset timeout period, the data for that thread is discarded. If response data is received within the preset timeout period, it is used for aggregation and display. In this system architecture 100, the initial default timeout period for each thread interface is consistent with the preset timeout period of the aggregation interface 101. Assuming that the timeout of each thread interface is always consistent with the preset timeout of the aggregation interface, since the data collection and aggregation efficiency of each business module is different, if the timeout is too short, it is easy to cause high-frequency data loss, affecting the display of user data; if the timeout is too long, it is easy to cause the overall response time of the interface to be too long, the APP to load and render data too slowly, and the user experience to be poor. Therefore, the present invention can realize the independent dynamic adjustment of the timeout of the thread interface through multi-threading.

[0051] Figure 2 This is a flowchart illustrating an interface call timeout handling method according to an embodiment of the present invention. It should be noted that if substantially the same result is obtained, the method of the present invention does not necessarily require further explanation. Figure 2 The illustrated process sequence is limited. For example... Figure 2 As shown, the method includes the following steps:

[0052] Step S201: Obtain the interface call request, monitor and record the first call time of the thread interface processing the interface call request in real time.

[0053] In step S201, the first call time is the time elapsed between the aggregation interface sending the interface call request and receiving the response data. In one feasible implementation, the first call time is stored in Redis as a key-value pair. For example, if the first call time of thread interface 1 is 3 seconds, then it is stored as: (thread interface 1: 3S).

[0054] Step S202: When the first call time is detected to exceed the preset timeout period, the corresponding thread interface is marked as a timeout interface.

[0055] In step S202, the default timeout time for each thread interface is initialized to be consistent with the preset timeout time for the aggregation interface. In one feasible implementation, when a user enters the APP interface and makes a data aggregation interface call, data is loaded by calling the thread interface of the corresponding business module through multi-threaded calls. The preset timeout time for the aggregation interface is 3 seconds, so the timeout time for each business module's thread interface to discard data after timeout is also preset to 3 seconds. If the timeout exceeds 3 seconds, the data is discarded. In this embodiment, the timeout time for each thread interface is stored in Redis as key-value pairs. For example, if the timeout time for thread interface 1 is 3 seconds and the timeout time for thread interface 2 is 3 seconds, then it is stored as: (aggregation interface - thread interface 1: 3S), (aggregation interface - thread interface 2: 3S). This embodiment compares the recorded first call time with the timeout time of the corresponding thread interface in real time. When the first call time exceeds the preset timeout time, the corresponding thread interface is marked as a timeout interface.

[0056] In another possible implementation, please refer to Figure 3 Step S202 further includes the following steps:

[0057] Step S301: When the first call time is detected to exceed the preset timeout, the third call time of the corresponding thread interface is obtained within the second preset time range.

[0058] In step S301, the third call time is stored in Redis. After the first call time is detected to exceed the preset timeout period for the first time, the third call time of the corresponding thread interface is obtained within the second preset time range.

[0059] Step S302: Calculate the percentage of timeouts in the thread interface for processing interface call requests based on the third call time.

[0060] In step S302, the first timeout percentage of the third call time is calculated by the JOB timed task. The first timeout percentage is the ratio of the number of interface call requests that exceed the timeout period to the total number of interface call requests in the third call time.

[0061] Step S303: Compare the first timeout percentage with the preset threshold.

[0062] In step S303, the preset threshold can be adjusted, either manually set by the user or automatically set by the computer. For example, the preset threshold is 80%.

[0063] Step S304: If the proportion of the first timeout is greater than the preset threshold, then mark the corresponding thread interface as a timeout interface.

[0064] In step S304, if the first timeout rate of thread interface 1 is greater than 80%, it means that 80% of the interface call requests processed by thread interface 1 are timeouts, then thread interface 1 is marked as a timeout interface.

[0065] Step S203: Obtain the second call time of the timeout interface within the first preset time range, obtain the shortest call time from the second call time, and compare the shortest call time with the preset timeout time.

[0066] In step S203, the second call time is stored in Redis. Assuming that thread interface 1 is a timeout interface, within the first preset time range, Redis stores (thread interface 1: 3.5S), (thread interface 1: 4S), and (thread interface 1: 5S). At the same time, the timeout time stored in Redis is (aggregate interface - thread interface 1: 3S). Therefore, the shortest call time within the first preset time range is (thread interface 1: 3.5S). (thread interface 1: 3.5S) is compared with (aggregate interface - thread interface 1: 3S).

[0067] Step S204: If the shortest call time is greater than the preset timeout time, the timeout interface is marked as a long-time interface, and the average time taken to process the interface call request of the timeout interface within the first preset time range is calculated based on the second call time, and the timeout time of the long-time interface is adjusted based on the average time taken.

[0068] In step S204, assuming the shortest call time for timeout interface 1 is greater than the preset timeout time, then timeout interface 1 is also a long-duration interface. The average time taken to process interface call requests within the first preset time range is calculated using a JOB scheduled task. This average time is used as the latest timeout time for the long-duration interface, and the corresponding Redis value is updated. The average time is the ratio of the sum of the second call times within the first preset time range to the total number of interface call requests. In this embodiment, a timeout time that is too short for a long-duration interface can easily lead to high-frequency data loss, affecting user data display. Therefore, the timeout time is extended by adjusting it to the average time.

[0069] An embodiment of the present invention provides an interface call timeout handling method that monitors timeout interfaces, obtains the shortest call time of timeout interfaces within a first preset time range, and marks the timeout interface as a long-time-consuming interface when the shortest call time is greater than the preset timeout time. The method then calculates the average time taken to process interface call requests for timeout interfaces within the first preset time range based on the second call time of the timeout interfaces, and adjusts the timeout time of long-time-consuming interfaces according to the average timeout time. This achieves dynamic adjustment of the timeout time, avoiding the problem of high-frequency data loss or long-term occupation of the request link caused by uniformly setting the timeout time, thus optimizing interface services and improving user experience.

[0070] Figure 4 This is a flowchart illustrating an interface call timeout handling method according to another embodiment of the present invention. It should be noted that if substantially the same result is achieved, the method of the present invention does not necessarily require further clarification. Figure 4 The illustrated process sequence is limited. For example... Figure 4 As shown, the method includes the following steps:

[0071] Step S401: Obtain the interface call request, monitor and record the first call time of the thread interface processing the interface call request in real time.

[0072] In this embodiment, Figure 4 Step S401 and Figure 2 The steps in step S201 are similar and will not be repeated here for the sake of simplicity.

[0073] Step S402: When the first call time is detected to exceed the preset timeout period, the corresponding thread interface is marked as a timeout interface.

[0074] In this embodiment, Figure 4 Step S402 and Figure 2 The steps in step S202 are similar and will not be repeated here for the sake of simplicity.

[0075] Step S403: Obtain the second call time of the timeout interface within the first preset time range, obtain the shortest call time from the second call time, and compare the shortest call time with the preset timeout time.

[0076] In this embodiment, Figure 4 Step S403 and Figure 2 The steps in step S203 are similar and will not be repeated here for the sake of simplicity.

[0077] Step S404: If the shortest call time is greater than the preset timeout time, the timeout interface is marked as a long-time interface, and the average time taken to process the interface call request of the timeout interface within the first preset time range is calculated based on the second call time. The timeout time of the long-time interface is adjusted based on the average time taken.

[0078] In this embodiment, Figure 4 Step S404 and Figure 2 The steps in step S204 are similar and will not be repeated here for the sake of simplicity.

[0079] Step S405: Receive the interface call request, intercept the interface call request and read the interface identifier in the interface call request, and check whether the target interface pointed to by the interface identifier is a long-running interface.

[0080] In step S405, the interface call request includes an interface URL, which at least includes an interface identifier. The interface identifier corresponds one-to-one with the target interface. In this embodiment, an interceptor can be set on the aggregated interface. All interface call requests must pass through the interceptor before they can be allowed. The interceptor retrieves the flag of long-running interfaces from Redis storage and checks whether the target interface pointed to by the interface identifier is a long-running interface.

[0081] Step S406: When the target interface is detected to be a long-running interface, the interface call request is rate-limited according to the first rate-limiting mechanism.

[0082] In step S406, when a long-duration interface is detected as the target interface, the interceptor performs rate limiting on the interface call requests according to a first rate limiting mechanism. The first rate limiting mechanism includes: within a first duration, forwarding interface call requests for the long-duration interface according to a first proportion; within a second duration, forwarding interface call requests for the long-duration interface according to a second proportion, where the second proportion is at least greater than the first proportion. For example, in the first minute, the interceptor only allows 10% of the call requests for the long-duration interface; in the second minute, the interceptor only allows 20% of the call requests for the long-duration interface. This achieves the purpose of rate limiting for long-duration interfaces, preventing resource consumption, further quickly releasing some resources, and improving user experience.

[0083] Step S407: Within the third preset time range, calculate the second timeout percentage of long-time interface call requests based on the fourth call time of the interface call requests after rate limiting.

[0084] In step S407, timeout adjustment and rate limiting were performed on the long-duration interfaces in the above steps. The processing time of the interface call requests allowed by the interceptor in the rate limiting process is the fourth call time. In this embodiment, the second timeout ratio of the fourth call time is calculated by the JOB timed task within the third preset time range. The second timeout ratio is the ratio of the number of interface call requests that exceed the timeout time to the total number of interface call requests in the fourth call time.

[0085] Step S408: Compare the second timeout percentage with the preset threshold.

[0086] In step S408, the preset threshold may be the same as or different from the preset threshold in step S303.

[0087] Step S409: If the proportion of the second timeout is less than the preset threshold, remove the marker for the long-time interface and adjust the timeout time to the preset timeout time.

[0088] In step S409, assuming the preset threshold is 80%, if the second timeout ratio of long-time interface is less than 80%, it means that 80% of the interface call requests processed by the long-time interface are not timed out. Then, the long-time interface is removed from the flag and the timeout time is adjusted to the preset timeout time.

[0089] In this embodiment, after adjusting the timeout and rate limiting, the processing time of the interface call request after rate limiting is calculated to prevent the timeout from being too long. The timeout is then readjusted based on the calculation results to avoid the timeout being too long, which would cause the overall interface response time to be too long and affect the user experience.

[0090] The interface call timeout handling method of this invention, based on the above embodiments, performs rate limiting on the interface call request according to the first rate limiting mechanism to achieve the purpose of rate limiting for long-duration interfaces, prevent resource occupation, further quickly release some resources, and improve user experience. In addition, after rate limiting, the timeout time is readjusted to avoid the timeout time being too long, which would cause the overall interface response time to be too long and affect the user experience.

[0091] Figure 5 This is a flowchart illustrating an interface call timeout handling method according to another embodiment of the present invention. It should be noted that if substantially the same result is achieved, the method of the present invention does not necessarily require further clarification. Figure 5 The illustrated process sequence is limited. For example... Figure 5 As shown, the method includes the following steps:

[0092] Step S501: Obtain the interface call request, monitor and record the first call time of the thread interface processing the interface call request in real time.

[0093] In this embodiment, Figure 5 Step S501 and Figure 2 The steps in step S201 are similar and will not be repeated here for the sake of simplicity.

[0094] Step S502: When the first call time is detected to exceed the preset timeout period, the corresponding thread interface is marked as a timeout interface.

[0095] In this embodiment, Figure 5 Step S502 and Figure 2 The steps in step S202 are similar and will not be repeated here for the sake of simplicity.

[0096] Step S503: Obtain the second call time of the timeout interface within the first preset time range, obtain the shortest call time from the second call time, and compare the shortest call time with the preset timeout time.

[0097] In step S503, the second call time is stored in Redis. Assuming that thread interface 1 is a timeout interface, within the first preset time range, Redis stores (thread interface 1: 2S), (thread interface 1: 4S), and (thread interface 1: 5S). At the same time, the timeout time stored in Redis is (aggregate interface - thread interface 1: 3S). Therefore, the shortest call time within the first preset time range is (thread interface 1: 2S). (thread interface 1: 2S) is compared with (aggregate interface - thread interface 1: 3S).

[0098] Step S504: Obtain the longest call time from the second call time and compare the longest call time with the preset timeout time.

[0099] In step S504, in the above scenario, the longest call time is (thread interface 1: 5S), and the preset timeout is (aggregate interface - thread interface 1: 3S).

[0100] Step S505: If the shortest call time is less than the preset timeout time and the longest call time is greater than the preset timeout time, then calculate the average time taken for the timeout interface to process the interface call request within the first preset time range based on the second call time, and adjust the timeout time of the timeout interface based on the average time taken.

[0101] In step S505, if the preset timeout is greater than the shortest call time but less than the longest call time, the timeout interface is not marked as having a long duration; only the timeout is adjusted. The average processing time for interface call requests within the first preset time range is calculated using a JOB scheduled task. This average time is used as the latest timeout for the timeout interface, and the corresponding Redis value is updated. The average timeout is the ratio of the sum of all second call times within the first preset time range to the total number of interface call requests.

[0102] Step S506: Receive the interface call request, intercept the interface call request and read the interface identifier in the interface call request, and check whether the target interface pointed to by the interface identifier is a timeout interface.

[0103] In this embodiment, Figure 5 Step S506 and Figure 4 The steps in step S405 are similar and will not be repeated here for the sake of simplicity.

[0104] Step S507: When the target interface is detected as a timeout interface, the interface call request is rate-limited according to the second rate-limiting mechanism.

[0105] In step S507, when a timeout is detected in the target interface, the interceptor applies a second rate-limiting mechanism to the interface call requests. This second rate-limiting mechanism differs from the first; it forwards timeout interface call requests according to a third ratio (50%) within a preset time period. For example, within one minute, the interceptor only allows 50% of timeout interface call requests, thus achieving rate limiting for timeout interfaces, preventing resource consumption, quickly releasing some resources, and improving user experience.

[0106] The interface call timeout handling method of this invention, based on the above embodiments, reduces resource consumption or high-frequency data loss by rate limiting the timeout interface, thereby improving user experience.

[0107] Figure 6 This is a schematic diagram of the interface call timeout handling device according to an embodiment of the present invention. Figure 6 As shown, the device 60 includes an acquisition module 61, a monitoring module 62, a comparison module 63, and an adjustment module 64.

[0108] The acquisition module 61 is used to acquire interface call requests, monitor and record the first call time of the thread interface processing the interface call request in real time;

[0109] The monitoring module 62 is used to mark the corresponding thread interface as a timeout interface when it detects that the first call time exceeds the preset timeout period;

[0110] The comparison module 63 is used to obtain the second call time of the timeout interface within the first preset time range, obtain the shortest call time from the second call time, and compare the shortest call time with the preset timeout time.

[0111] The adjustment module 64 is used to mark the timed-out interface as a long-time interface if the shortest call time is greater than the preset timeout time, and to calculate the average time taken to process the interface call request of the timed-out interface within the first preset time range based on the second call time, and adjust the timeout time of the long-time interface based on the average time taken.

[0112] Please see Figure 7 , Figure 7 This is a schematic diagram of the structure of a computer device according to an embodiment of the present invention. Figure 7 As shown, the computer device 70 includes a processor 71 and a memory 72 coupled to the processor 71.

[0113] The memory 72 stores program instructions for implementing the interface call timeout handling described in any of the above embodiments.

[0114] The processor 71 is used to execute program instructions stored in the memory 72 to handle calls to the timeout interface.

[0115] The processor 71 can also be referred to as a CPU (Central Processing Unit). The processor 71 may be an integrated circuit chip with signal processing capabilities. The processor 71 can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. A general-purpose processor can be a microprocessor or any conventional processor.

[0116] See Figure 8 , Figure 8 This is a schematic diagram of the structure of a computer storage medium according to an embodiment of the present invention. The computer storage medium of this embodiment stores a program file 81 capable of implementing all the above methods. This program file 81 can be stored in the computer storage medium in the form of a software product, including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned computer storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks, or terminal devices such as computers, servers, mobile phones, and tablets.

[0117] In the embodiments provided by this invention, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection between apparatuses or units, and may be electrical, mechanical, or other forms.

[0118] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0119] The above are merely embodiments of the present invention and do not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.

Claims

1. A method for handling interface call timeouts, characterized in that, include: Obtain the interface call request, and monitor and record the first call time of the thread interface in processing the interface call request in real time; When it is detected that the first call time exceeds the preset timeout period, the corresponding thread interface is marked as a timeout interface; Within a first preset time range, obtain the second call time of the timeout interface, obtain the shortest call time from the second call time, and compare the shortest call time with the preset timeout time; If the shortest call time is greater than the preset timeout time, the timeout interface is marked as a long-time interface, and the average time taken for the timeout interface to process the interface call request within the first preset time range is calculated based on the second call time. The timeout time of the long-time interface is then adjusted based on the average time taken.

2. The interface call timeout handling method according to claim 1, characterized in that, The step of marking the corresponding thread interface as a timeout interface when the first call time is detected to exceed the preset timeout period further includes: When the first call time is detected to exceed the preset timeout period, the third call time of the corresponding thread interface is obtained within the second preset time range; Calculate the first timeout percentage of the thread interface processing the interface call request based on the third call time; Compare the first timeout percentage with a preset threshold; If the first timeout percentage is greater than the preset threshold, then the corresponding thread interface is marked as a timeout interface.

3. The interface call timeout handling method according to claim 2, characterized in that, If the shortest call time is greater than the preset timeout time, the timeout interface is marked as a long-running interface. The average processing time of the interface call request within the first preset time range is calculated based on the second call time. After adjusting the timeout time of the long-running interface based on the average processing time, the method further includes: Receive an interface call request, intercept the interface call request and read the interface identifier in the interface call request, and detect whether the target interface pointed to by the interface identifier is a long-time interface; When the target interface is detected to be a long-running interface, the interface call request is rate-limited according to the first rate-limiting mechanism.

4. The interface call timeout handling method according to claim 3, characterized in that, The first rate limiting mechanism includes: Within the first time period, the interface call request of the long-duration interface is forwarded according to the first ratio; Within a second duration, the interface call requests of the long-duration interface are forwarded according to a second ratio, wherein the second ratio is at least greater than the first ratio.

5. The interface call timeout handling method according to claim 4, characterized in that, After rate limiting the interface call request according to the first rate limiting mechanism, the process includes: Within a third preset time range, the second timeout percentage of the long-duration interface processing the interface call request is calculated based on the fourth call time of the interface call request after rate limiting. The second timeout percentage is compared with the preset threshold. If the second timeout percentage is less than the preset threshold, then the long-time interface is removed from the flag and the timeout is adjusted to the preset timeout.

6. The interface call timeout handling method according to claim 4, characterized in that, After obtaining the second call time of the timeout interface within a first preset time range, obtaining the shortest call time from the second call time, and comparing the shortest call time with the preset timeout time, the method further includes: Obtain the longest call time from the second call time, and compare the longest call time with the preset timeout time; If the shortest call time is less than the preset timeout and the longest call time is greater than the preset timeout, then the average time taken by the timeout interface to process the interface call request within the first preset time range is calculated based on the second call time, and the timeout time of the timeout interface is adjusted based on the average time taken.

7. The interface call timeout handling method according to claim 6, characterized in that, If the shortest call time is less than the preset timeout time and the longest call time is greater than the preset timeout time, then after calculating the average time taken by the timeout interface to process the interface call request within the first preset time range based on the second call time, and adjusting the timeout time of the timeout interface based on the average time taken, the method further includes: Receive an interface call request, intercept the interface call request and read the interface identifier in the interface call request, and detect whether the target interface pointed to by the interface identifier is a timeout interface; When the target interface is detected as a timeout interface, the interface call request is rate-limited according to the second rate-limiting mechanism. The second rate-limiting mechanism is different from the first rate-limiting mechanism. The second rate-limiting mechanism forwards the interface call request of the timeout interface according to a third ratio within a preset time period. The third ratio is 50%.

8. An interface call timeout handling device, characterized in that, include: The acquisition module is used to acquire interface call requests, monitor and record the first call time of the thread interface in processing the interface call request in real time; The monitoring module is used to mark the corresponding thread interface as a timeout interface when it detects that the first call time exceeds a preset timeout period; The comparison module is used to obtain the second call time of the timeout interface within a first preset time range, obtain the shortest call time from the second call time, and compare the shortest call time with the preset timeout time. An adjustment module is configured to mark the timed-out interface as a long-timed interface if the shortest call time is greater than the preset timeout time, calculate the average time taken for the timed-out interface to process the interface call request within the first preset time range based on the second call time, and adjust the timeout time of the long-timed interface based on the average time taken.

9. A computer device, comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, when the processor executes the computer program, it implements the interface call timeout handling method as described in any one of claims 1-7.

10. A computer storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the interface call timeout handling method as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Interface performance monitoring method, device and equipment and computer readable storage medium

    CN109753406A

  • Method and device for adjusting interface calling timeout time and medium

    CN114546611A