A request retry method and device

By determining whether the request can be retried when the server returns a failed response, and using the retry exponential backoff algorithm to calculate the delay time, the problem in the existing technology that the number of retry requests cannot be limited and the delay cannot be determined is solved, and limited retry is achieved. The elegant retry mechanism with optimal delay avoids invalid retries.

CN113360815BActive Publication Date: 2024-10-18BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010143465.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-03-04
Publication Date
2024-10-18
Estimated Expiration
2040-03-04

AI Technical Summary

Technical Problem

The existing technology cannot effectively limit the number of retry requests, cannot perform retries gracefully, and fails to retry when the interface has not been restored, resulting in invalid retries, and directly makes intrusive modifications to the code, failing to decouple the retry logic. with normal logic.

Method used

When the server returns a failed response, it determines whether retry can be performed based on the current number of retries of the request, and uses the retry exponential backoff algorithm to calculate the delay time, limit the number of retry requests, avoid invalid retries, and combine the retry logic with Normal logic decoupling.

Benefits of technology

It implements limited retries for each request and determines the optimal time for retry delay, avoiding invalid retries without immersive modifications to the code, and provides a simple and elegant retry mechanism.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113360815B_ABST
    Figure CN113360815B_ABST
Patent Text Reader

Abstract

The present invention discloses a request retry method and device, and relates to the field of computer technology. A specific implementation of the method includes: when the response result of the first request indicates a failure, judging whether it can be retried according to the current number of retries of the first request; if it can be retried, determining the number of second requests currently being retried; if the number of second requests is less than the maximum number of retry requests, retrying after delaying the retry waiting time, otherwise waiting for the second request to be retried and then retrying after delaying the retry waiting time, the retry waiting time is calculated based on the preset initial waiting time interval and the current number of retries of the first request. This implementation can limit the number of retry requests, perform a limited number of retries for each request, and can also judge the optimal time for the retry delay to avoid too many invalid retries, without the need for immersive modification of the code, the retry logic is decoupled from the normal logic, and retry in a simple, elegant and reusable manner when the front-end call interface fails.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a request retry method and device. Background Art

[0002] In applications, it is often necessary to implement the following functions: upload data to a remote storage service or pull required data from a remote storage service, and perform other operations in the case of a successful response. This function can be simply divided into two steps: call the remote service logic package to the processing method to return the processing result; implement the retry upload logic based on the processing result of the previous step or catch the exception, otherwise continue the logical operation. When the dependent interface returns a system exception due to internal errors or other errors, the retry mechanism is particularly important, otherwise manual operation is required to call it again.

[0003] There are several schemes for the front-end ajax (Asynchronous Javascript And XML) request retry mechanism: one is "manual" retry: when calling the interface, re-request immediately when an exception occurs in the interface request through a loop. Although this method implements retry, the interface it depends on may not have recovered from the network exception, so the subsequent retries will fail. In addition, this mechanism directly makes intrusive modifications to the code, and the retry method is not elegant. The second is a retry practice similar to the Axios library (an HTTP library): through Axios response interception, after obtaining the response result, it is determined whether to retry and whether the number of retries has exceeded, and then a timer is used for delay processing, and then an axios request is initiated in a timely manner according to the above judgment result. This retry method is also not elegant enough, and it cannot determine the best time for the delay.

[0004] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0005] Both Solution 1 and Solution 2 cannot limit the number of retry requests, and cannot perform retries elegantly and effectively. In addition, when the interface that Solution 1 depends on has not recovered from the network exception, subsequent retries will fail, resulting in a large number of invalid retries. In addition, the code is directly modified in an intrusive manner, and the retry logic cannot be decoupled from the normal logic. Solution 2 cannot determine the optimal delay time, and still cannot avoid a large number of invalid retries. Summary of the invention

[0006] In view of this, an embodiment of the present invention provides a request retry method and device, which can limit the number of retry requests and perform a limited number of retries on each request. It can also determine the optimal time for the retry delay and avoid too many invalid retries. There is no need to perform immersive modification to the code, and the retry logic is decoupled from the normal logic. When the front-end call interface fails, retry is implemented in a simple, elegant and reusable way.

[0007] To achieve the above objective, according to one aspect of an embodiment of the present invention, a request retry method is provided.

[0008] A request retry method, comprising: when a response result returned by a server to a first request indicates a failure, judging whether the first request can be retried based on the current number of retries of the first request; when the first request can be retried, determining the number of second requests currently being retried; if the number of second requests currently being retried is less than a maximum number of retry requests, retrying the first request after a delay of a retry waiting time; if the number of second requests currently being retried is not less than the maximum number of retry requests, waiting for one of the second requests to be retried, delaying the retry waiting time and then retrying the first request, wherein the retry waiting time is calculated based on a preset initial waiting time interval and the current number of retries of the first request.

[0009] Optionally, based on the preset initial waiting time interval and the current number of retries of the first request, the retry waiting time is calculated using a retry exponential backoff algorithm with added jitter.

[0010] Optionally, based on the preset initial waiting time interval and the current number of retries of the first request, the retry waiting time is calculated in the following manner using the retry exponential backoff algorithm with added jitter:

[0011]

[0012] Among them, random_between(a,b) means taking a value in the interval [a,b) as the result.

[0013] a=base×M n , ± refers to randomly selecting an operation symbol between + and -, M is a preset positive integer, base is the preset initial waiting time interval, and n is the current number of retries of the first request.

[0014] Optionally, after the step of determining the number of second requests currently being retried, the method includes: if the current number of retries of the first request is 0, assigning a unique identifier to the first request, and caching the unique identifier of the first request in a local memory.

[0015] Optionally, if the current number of retries of the first request has not reached a preset maximum number of retries, it is determined that the first request can be retried; otherwise, it is determined that the first request cannot be retried; if the first request cannot be retried, the unique identifier of the first request cached in the local memory is deleted.

[0016] Optionally, the determining the number of second requests currently being retried includes: counting the number of unique identifiers of each request currently cached in the local memory, and determining the number of second requests currently being retried based on the statistical result.

[0017] Optionally, for any request, after executing the retry and obtaining the response result indicating success returned by the server, the unique identifier of the request cached in the local memory is deleted, and the any request is the first request or the second request.

[0018] According to another aspect of an embodiment of the present invention, a request retry device is provided.

[0019] A request retry device comprises: a retry execution condition judgment module, which is used to judge whether the first request can be retried according to the current number of retries of the first request when the response result of the first request returned by the server indicates failure; a retry request number determination module, which is used to determine the number of second requests currently being retried when the first request can be retried; a retry execution module, which is used to delay the retry waiting time to retry the first request if the number of second requests currently being retried is less than the maximum number of retry requests; if the number of second requests currently being retried is not less than the maximum number of retry requests, wait for one of the second requests to be retried, delay the retry waiting time and then retry the first request, wherein the retry waiting time is calculated based on a preset initial waiting time interval and the current number of retries of the first request.

[0020] Optionally, it also includes a retry waiting time calculation module, which is used to: calculate the retry waiting time based on the preset initial waiting time interval and the current number of retries of the first request, using a retry exponential backoff algorithm with added jitter.

[0021] Optionally, the retry waiting time calculation module is further used to: based on the preset initial waiting time interval and the current number of retries of the first request, and using the retry exponential backoff algorithm with added jitter, calculate the retry waiting time in the following manner:

[0022]

[0023] Among them, random_between(a,b) means taking a value in the interval [a,b) as the result.

[0024] a=base×M n , ± refers to randomly selecting an operation symbol between + and -, M is a preset positive integer, base is the preset initial waiting time interval, and n is the current number of retries of the first request.

[0025] Optionally, it also includes an identifier allocation and storage module, which is used to: if the current number of retries of the first request is 0, allocate a unique identifier for the first request, and cache the unique identifier of the first request in a local memory.

[0026] Optionally, the retry execution condition judgment module determines that the first request can be retried if the current number of retries of the first request has not reached a preset maximum number of retries; otherwise, it determines that the first request cannot be retried; the device also includes a first identification deletion module, which is used to: if the first request cannot be retried, delete the unique identification of the first request cached in the local memory.

[0027] Optionally, the module for determining the number of retry requests is further used to: when the first request can be retried, count the number of unique identifiers of each request currently cached in the local memory, and determine the number of second requests currently being retried based on the statistical results.

[0028] Optionally, it also includes a second identification deletion module, which is used to: for any request, after executing the retry and obtaining the response result indicating success returned by the server, delete the unique identification of the request cached in the local memory, wherein any request is the first request or the second request.

[0029] According to yet another aspect of the embodiments of the present invention, an electronic device is provided.

[0030] An electronic device includes: one or more processors; and a memory for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the request retry method provided by an embodiment of the present invention.

[0031] According to yet another aspect of an embodiment of the present invention, a computer readable medium is provided.

[0032] A computer readable medium stores a computer program, which, when executed by a processor, implements a request retry method provided by an embodiment of the present invention.

[0033] An embodiment of the above invention has the following advantages or beneficial effects: when the response result returned by the server to the first request indicates failure, it is determined whether the first request can be retried according to the current number of retries of the first request, and when the retry can be performed, the number of second requests currently being retried is determined; if the number of second requests currently being retried is less than the maximum number of retry requests, the first request is retried after the retry waiting time is delayed; if the number of second requests currently being retried is not less than the maximum number of retry requests, the first request is retried after the retry waiting time is delayed, and the retry waiting time is calculated based on the preset initial waiting time interval and the current number of retries of the first request, using the retry exponential backoff algorithm with added jitter. It can limit the number of retry requests, perform a limited number of retries on each request, and determine the optimal time for the retry delay to avoid too many invalid retries, without the need to immersively modify the code, decouple the retry logic from the normal logic, and implement retry in a simple, elegant and reusable way when the front-end call interface fails.

[0034] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific implementation examples. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0036] Figure 1 is a schematic diagram of main steps of a request retry method according to a first embodiment of the present invention;

[0037] Figure 2 is a schematic diagram of a request retry principle according to a second embodiment of the present invention;

[0038] Figure 3 is a schematic diagram of a request retry process according to a third embodiment of the present invention;

[0039] Figure 4 is a schematic diagram of main modules of a request retry device according to a fourth embodiment of the present invention;

[0040] Figure 5 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0041] Figure 6 It is a schematic diagram of the structure of a computer system of a terminal device suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0042] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0043] Figure 1 FIG. 4 is a schematic diagram of main steps of a request retry method according to a first embodiment of the present invention.

[0044] like Figure 1 As shown, the request retry method of the embodiment of the present invention mainly includes the following steps S101 to S103.

[0045] Step S101: when the response result returned by the server to the first request indicates a failure, determine whether the first request can be retried according to the current number of retries of the first request.

[0046] Step S102: when the first request can be retried, determine the number of second requests currently being retried.

[0047] Step S103: If the number of second requests currently being retried is less than the maximum number of retry requests, then retry the first request after delaying the retry waiting time; if the number of second requests currently being retried is not less than the maximum number of retry requests, then wait for one of the second requests to be retried, then retry the first request after delaying the retry waiting time, and the retry waiting time is calculated based on the preset initial waiting time interval and the current number of retries of the first request.

[0048] The first request and the second request of the embodiment of the present invention are requests from the client to the server, which are used to request data from the server. The server maps the URL (Uniform Resource Locator) of the request to the corresponding interface to return the requested data to the client. The first request refers to a request corresponding to one interface, and the second request refers to a request corresponding to another interface. The first request and the second request correspond to different interfaces.

[0049] In one embodiment, the retry waiting time is calculated based on a preset initial waiting time interval and the current number of retries of the first request, using a retry exponential backoff algorithm with added jitter.

[0050] Specifically, based on the preset initial waiting time interval and the current number of retries of the first request, the retry waiting time can be calculated as follows using a retry exponential backoff algorithm with added jitter:

[0051]

[0052] Among them, random_between(a,b) means taking a value in the interval [a,b) as the result.

[0053] a=base×M n , ± refers to randomly selecting an operation symbol between + and -, M is a preset positive integer, base is a preset initial waiting time interval, and n is the current number of retries of the first request.

[0054] For example, assuming a is 200 and b is 300, then according to the random_between(a,b) calculation rule, a value in [200,300) can be randomly selected as the retry waiting time.

[0055] In one embodiment, after determining the number of second requests currently being retried, the method includes: if the current number of retries of the first request is 0, assigning a unique identifier to the first request, and caching the unique identifier of the first request in a local memory.

[0056] Preferably, in addition to caching the unique identifier of the first request in the local memory, data related to the first request (including data in the request header and the request body) may also be cached in the local memory.

[0057] Based on the current number of retries of the first request, determine whether the first request can be retried. Specifically, if the current number of retries of the first request does not reach the preset maximum number of retries, determine that the first request can be retried; otherwise, determine that the first request cannot be retried.

[0058] In one embodiment, when the first request cannot be retried, the unique identifier of the first request cached in the local memory is deleted.

[0059] In addition to deleting the unique identifier of the first request cached in the local memory, if the local memory also caches data related to the first request (including data in the request header and the request body), the data related to the first request is also deleted from the local memory.

[0060] In one embodiment, determining the number of second requests currently being retried includes: counting the number of unique identifiers of each request currently cached in the local memory, and determining the number of second requests currently being retried based on the statistical result. Specifically, the number of unique identifiers of each request currently cached in the local memory is the number of second requests currently being retried.

[0061] In one embodiment, for any request, after the retry is completed and a response result indicating success is returned by the server, the unique identifier of the request cached in the local memory is deleted, and any request is the first request or the second request.

[0062] In addition to deleting the unique identifier of the request cached in the local memory, if the local memory also caches data related to the request, such as data in the request header and request body of the request, then the request related data is also deleted from the local memory.

[0063] Figure 2 FIG. 4 is a schematic diagram of a request retry principle according to a second embodiment of the present invention.

[0064] like Figure 2 As shown, assuming that the retry mechanism is enabled for the request, this embodiment sets the maximum number of retries retry=3, and the retry waiting time conforms to the exponential backoff with the addition of a random value.

[0065] The exponential backoff for retries without jitter is as follows:

[0066] Retry wait time = base × M n

[0067] In this embodiment, M is set to 2, n is the current number of retries of the request, base is the initial waiting time interval, and the initial waiting time interval is set to 200 ms (milliseconds).

[0068] This embodiment adds jitter on the basis of the above formula, which increases randomness of the waiting time and can avoid conflicts to a certain extent, as shown below:

[0069]

[0070] Among them, random_between(a,b) means taking a value in the interval [a,b) as the result, a=base×M n , “±” means randomly selecting an operation symbol between “+” and “-”.

[0071] When M is set to 2 and base is set to 200ms, the retry wait time is calculated as follows:

[0072] Retry wait time = random_between(200×2 n ,200×2 n ±100×2 n )

[0073] The request in the embodiment of the present invention is an ajax request sent by the client to the server. There may be multiple ajax requests, such as Figure 2 As shown, assume that there are ajax request 1, ajax request 2, ..., ajax request n, ajax request n+1.

[0074] When an ajax request is initiated in the application, first determine whether the interface is abnormal based on the response result. If the response result indicates failure, it means that the interface is abnormal, otherwise the interface is normal. If the interface is abnormal, continue to determine how many times the ajax request corresponding to the interface has been retried. If no retry has been performed, the first retry is performed after a delay of S1 = random_between (200, 200 ± 100)) milliseconds. If a retry has been performed once, it is necessary to perform a second retry after a delay of S2 = random_between (400, 400 ± 200)) milliseconds; if two retries have been performed, it is necessary to perform a third retry after a delay of S3 = random_between (800, 800 ± 400)) milliseconds. After the third retry is performed, regardless of whether the response result meets expectations, the request operation on the interface is terminated, and the third retry result is obtained or an exception is thrown.

[0075] When each interface fails to respond, a unique identifier (ID) is set for the ajax request corresponding to the interface during the first retry, and the ID and all parameters of the ajax request (including the data in the request header and request body) are cached in the local memory. When the requested interface responds successfully or the request fails after reaching the maximum number of retries, the unique ID and request parameters of the request cached in the local memory are deleted. This method can simply determine the number of requests currently being retried, and then control the number of retry requests. By limiting the number of retry requests, it is possible to prevent the client from retrying too many requests in the same time period.

[0076] Figure 3 FIG. 4 is a schematic diagram of a request retry process according to a third embodiment of the present invention.

[0077] In the project, there are many static resources and functional logic requests on the front end. If there is a sudden network fluctuation or other unstable situation of CDN (Content Delivery Network) when requesting a static resource, the probability of successful interface request can be increased by enabling the retry mechanism.

[0078] like Figure 3 As shown, the maximum number of retries is preset to 3, and the maximum number of retry requests is 3. The request retry process includes the following steps S301 to S309. The request retry process of this embodiment is executed by the client.

[0079] Step S301: Send the nth first request to the server.

[0080] Step S302: Determine whether the status code in the response result returned by the server (ie, the response status code) is greater than or equal to 400. If so, execute step S303; otherwise, execute step S309.

[0081] If code≥400, it means the request failed. If code<400, it means the request succeeded.

[0082] Step S303: Determine whether the current number of retries of the first request is less than 3, if so, execute step S304, otherwise execute step S309.

[0083] Step S304: Whether the number of second requests currently being retried is less than 3, if so, execute step S306, otherwise execute step S305.

[0084] Step S305: Wait for one of the second requests to be retried to complete, and then execute step S306.

[0085] Step S306: Cache the request parameters and response results of the first request into the local memory. If the current number of retries of the first request = 0, assign a unique ID to the first request and also cache the assigned unique ID into the local memory.

[0086] Before the first request is retried for the first time, a unique ID is assigned to the first request, and the unique ID, request parameters, and response result of the first request are cached in the local memory. Before subsequent retries, since the unique ID and request parameters of the first request have been cached, only the response result can be updated.

[0087] Step S307: retry the first request after delaying the retry waiting time, and increase the current number of retries of the first request by 1.

[0088] The retry wait time can be calculated as follows:

[0089] Retry wait time = random_between(200×2 n ,200×2 n ±100×2 n )

[0090] Wherein, n is the current number of retries of the first request.

[0091] You can set random_between(200×2 n ,200×2 n ±100×2 n ).

[0092] For example, when the first request fails, n=0, and the front-end timer is used to set a delay of random_between(200,200±100) milliseconds, so that the first retry logic is executed after a delay of random_between(200,200±100) milliseconds. Since the retry is not performed immediately but delayed by random_between(200,200±100)) milliseconds, it avoids the situation where the requested resource or the remote interface it depends on has not been restored, and the request fails as a result of an immediate retry.

[0093] After the first retry fails, n=1, and a delay of random_between(400,400±200) milliseconds is set through the front-end timer, so that the waiting time before executing the second retry is random_between(200,200±100)) milliseconds. The embodiment of the present invention applies the principle of exponential backoff. For continuous errors, the retry waiting time will become longer and longer, and jitter is added to effectively determine the optimal time for the retry delay and avoid too many invalid retries.

[0094] Similarly, after the second retry fails, the delay is random_between(800,800±400)).

[0095] Step S308: Determine whether the response status code returned by the server is less than 400. If so, execute step S309. Otherwise, set n=n+1 and then re-execute step S301.

[0096] Step S309: Get the final response result of the first request, reset the current number of retries of the first request to 0, and delete the unique ID of the first request from the local memory.

[0097] In this step, in addition to deleting the unique ID of the first request from the local memory, the request parameters, response results and other data of the first request are also deleted from the local memory.

[0098] Since there are unstable dependency scenarios in functional logics such as interface access, data loading access, and data upload verification, it is necessary to obtain the expected results through retries. The retry mechanism can protect the system from the impact caused by network fluctuations and temporary unavailability of dependent services, allowing the system to run more stably. It can also improve the reliability of applications and reduce the operating costs of developers. The embodiment of the present invention implements front-end retries in a more elegant way, decouples the retry logic from the business logic, and uses a retry exponential backoff algorithm with added jitter to calculate the retry waiting time of the front-end ajax request retry, thereby achieving better process control. The number of retry requests can be limited by local caching and adding a unique ID.

[0099] Figure 4 FIG. 4 is a schematic diagram of main modules of a request retry device according to a fourth embodiment of the present invention.

[0100] like Figure 4 As shown, a request retry device 400 according to an embodiment of the present invention mainly includes: a retry execution condition judgment module 401 , a retry request quantity determination module 402 , and a retry execution module 403 .

[0101] The retry execution condition judgment module 401 is used to judge whether the first request can be retried according to the current number of retries of the first request when the response result returned by the server to the first request indicates a failure.

[0102] The retry request quantity determination module 402 is used to determine the number of second requests currently being retried when the first request can be retried.

[0103] The retry execution module 403 is used to delay the retry waiting time and then retry the first request if the number of second requests currently being retried is less than the maximum number of retry requests; if the number of second requests currently being retried is not less than the maximum number of retry requests, wait for one of the second requests to be retried, then delay the retry waiting time and then retry the first request, and the retry waiting time is calculated based on a preset initial waiting time interval and the current number of retries of the first request.

[0104] In one embodiment, the request retry device 400 further includes a retry waiting time calculation module for calculating the retry waiting time based on a preset initial waiting time interval and the current number of retries of the first request, using a retry exponential backoff algorithm with added jitter.

[0105] The retry waiting time calculation module can be specifically used to calculate the retry waiting time in the following manner based on the preset initial waiting time interval and the current number of retries of the first request and using the retry exponential backoff algorithm with added jitter:

[0106]

[0107] Among them, random_between(a,b) means taking a value in the interval [a,b) as the result.

[0108] a=base×M n , ± refers to randomly selecting an operation symbol between + and -, M is a preset positive integer, base is a preset initial waiting time interval, and n is the current number of retries of the first request.

[0109] In one embodiment, the request retry device 400 further includes an identifier allocation and storage module, which is used to: if the current number of retries of the first request is 0, allocate a unique identifier for the first request, and cache the unique identifier of the first request in a local memory.

[0110] The retry execution condition judgment module 401 determines that the first request can be retried if the current number of retries of the first request does not reach the preset maximum number of retries; otherwise, it determines that the first request cannot be retried.

[0111] In one embodiment, the request retry device 400 further includes a first identifier deleting module, which is used to delete the unique identifier of the first request cached in the local memory when the first request cannot be retried.

[0112] The retry request quantity determination module 402 can be specifically used to: when the first request can be retried, count the number of unique identifiers of each request currently cached in the local memory, and determine the number of second requests currently being retried based on the statistical results.

[0113] In one embodiment, the request retry device 400 also includes a second identification deletion module, which is used to: for any request, after the retry is completed and a response result indicating success is returned by the server, delete the unique identification of the request cached in the local memory, any request being a first request or a second request.

[0114] The first identification deletion module and the second identification deletion module mentioned above can be implemented as the same module.

[0115] In addition, the specific implementation content of the request retry device in the embodiment of the present invention has been described in detail in the request retry method described above, so the repeated content will not be described again here.

[0116] Figure 5 An exemplary system architecture 500 is shown to which a request retry method or a request retry apparatus according to an embodiment of the present invention can be applied.

[0117] like Figure 5As shown, system architecture 500 may include terminal devices 501, 502, 503, a network 504 and a server 505. Network 504 is used to provide a medium for communication links between terminal devices 501, 502, 503 and server 505. Network 504 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0118] Users can use terminal devices 501, 502, 503 to interact with server 505 through network 504 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 501, 502, 503, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).

[0119] The terminal devices 501 , 502 , and 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

[0120] The server 505 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 501, 502, and 503. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.

[0121] It should be noted that the request retry method provided in the embodiment of the present invention is generally executed by the terminal devices 501 , 502 , 503 , and accordingly, the request retry device is generally arranged in the terminal devices 501 , 502 , 503 .

[0122] It should be understood that Figure 5 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0123] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 of a terminal device suitable for implementing an embodiment of the present application. Figure 6 The terminal device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0124] like Figure 6As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0125] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.

[0126] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present application are executed.

[0127] It should be noted that the computer-readable medium shown in the present invention can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal can take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0128] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0129] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be provided in a processor, for example, may be described as: a processor including a retry execution condition judgment module, a retry request quantity determination module, and a retry execution module. Among them, the names of these modules do not constitute a limitation on the modules themselves in certain cases, for example, the retry execution condition judgment module may also be described as "a module for judging whether the first request can be retried according to the current number of retries of the first request when the response result returned by the server to the first request indicates a failure".

[0130] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: when the response result of the first request returned by the server indicates failure, judging whether the first request can be retried according to the current number of retries of the first request; when the first request can be retried, determining the number of second requests currently being retried; if the number of second requests currently being retried is less than the maximum number of retry requests, retrying the first request after delaying the retry waiting time; if the number of second requests currently being retried is not less than the maximum number of retry requests, waiting for one of the second requests to be retried, delaying the retry waiting time and then retrying the first request, wherein the retry waiting time is calculated based on the preset initial waiting time interval and the current number of retries of the first request.

[0131] According to the technical solution of the embodiment of the present invention, when the response result returned by the server to the first request indicates failure, it is determined whether the first request can be retried according to the current number of retries of the first request. If the retry can be performed, the number of second requests currently being retried is determined; if the number of second requests currently being retried is less than the maximum number of retry requests, the first request is retried after the retry waiting time is delayed; if the number of second requests currently being retried is not less than the maximum number of retry requests, the first request is retried after the retry waiting time is delayed, and the retry waiting time is calculated based on the preset initial waiting time interval and the current number of retries of the first request, using the retry exponential backoff algorithm with added jitter. It can limit the number of retry requests, perform a limited number of retries on each request, and determine the optimal time for the retry delay to avoid too many invalid retries. There is no need to modify the code in an immersive manner, decouple the retry logic from the normal logic, and implement retry in a simple, elegant and reusable way when the front-end interface fails to call.

[0132] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A request retry method, characterized in that: include: When the response result returned by the server to the first request indicates a failure, judging whether the first request can be retried according to the current number of retries of the first request; If the first request can be retried, determining the number of second requests currently being retried; If the number of the second requests currently being retried is less than the maximum number of retry requests, retry the first request after delaying the retry waiting time; if the number of the second requests currently being retried is not less than the maximum number of retry requests, wait until one of the second requests is retried, delay the retry waiting time, and then retry the first request, where the retry waiting time is calculated based on a preset initial waiting time interval and the current number of retries of the first request; The determining of the number of second requests currently being retried includes: counting the number of unique identifiers of each request currently cached in the local memory, and determining the number of second requests currently being retried based on the statistical results; wherein the number of unique identifiers of each request currently cached in the local memory is the number of second requests currently being retried.

2. The method according to claim 1, characterized in that: The retry waiting time is calculated based on the preset initial waiting time interval and the current number of retries of the first request, using a retry exponential backoff algorithm with added jitter.

3. The method according to claim 1, characterized in that After the step of determining the number of second requests currently being retried, including: If the current number of retries of the first request is 0, a unique identifier is allocated to the first request, and the unique identifier of the first request is cached in a local memory.

4. The method according to claim 3, characterized in that If the current number of retries of the first request does not reach the preset maximum number of retries, determine that the first request can be retried; otherwise, determine that the first request cannot be retried; In a case where the first request cannot be retried, the unique identifier of the first request cached in the local memory is deleted.

5. The method according to claim 1, characterized in that For any request, after executing the retry and obtaining the response result indicating success returned by the server, the unique identifier of the request cached in the local memory is deleted, and the any request is the first request or the second request.

6. A request retry device, characterized in that: include: A retry execution condition judgment module, used for judging whether the first request can be retried according to the current number of retries of the first request when the response result returned by the server to the first request indicates a failure; a retry request quantity determination module, configured to determine the number of second requests currently being retried if the first request can be retried; A retry execution module, configured to, if the number of the second requests currently being retried is less than the maximum number of retry requests, delay the retry wait time before retrying the first request; if the number of the second requests currently being retried is not less than the maximum number of retry requests, wait for one of the second requests to be retried, delay the retry wait time before retrying the first request, wherein the retry wait time is calculated based on a preset initial waiting time interval and the current number of retries of the first request; The determining of the number of second requests currently being retried includes: counting the number of unique identifiers of each request currently cached in the local memory, and determining the number of second requests currently being retried based on the statistical results; wherein the number of unique identifiers of each request currently cached in the local memory is the number of second requests currently being retried.

7. The device according to claim 6, characterized in that It also includes a retry waiting time calculation module, which is used to calculate the retry waiting time based on the preset initial waiting time interval and the current number of retries of the first request, using a retry exponential backoff algorithm with added jitter.

8. An electronic device, characterized in that: include: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors are enabled to implement the method according to any one of claims 1 to 5.

9. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Trivial file transfer protocol (TFTP) accelerated file retry option

    CN104010023A

  • Network request method, device and processing system for android operation system

    CN105847184A