Response result cache optimization method and device, equipment, storage medium and product

By using the Bloom filter in the API gateway to determine the idempotence of the request and dynamically adjusting the bit array size according to the request rate, the problem of high false alarm rate of the Bloom filter is solved, and the system efficiency and response speed are improved.

CN119583648APending Publication Date: 2025-03-07CHINA TELECOM CLOUD TECH CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202411738660.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-29
Publication Date
2025-03-07

AI Technical Summary

Technical Problem

In the prior art, the Bloom filter has a high false alarm rate when judging whether the elements are in the set, especially when the number of elements is large, the false alarm rate will increase significantly, resulting in inefficiency of the system.

Method used

By obtaining the historical request set and the historical response result set, use the Bloom filter to determine whether the new request is idempotent with the historical request. If it matches, the corresponding response result will be returned. At the same time, the bit array size of the Bloom filter is dynamically adjusted according to the request rate of the gateway receiving requests to reduce the false positive rate.

Benefits of technology

It effectively reduces the false alarm rate of the Bloom filter and improves the efficiency and response speed of the system. Especially during the high request rate period, dynamic adjustment of the bit array size can optimize the performance of the filter while saving space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119583648A_ABST
    Figure CN119583648A_ABST
Patent Text Reader

Abstract

The invention relates to a response result cache optimization method and device, equipment, a storage medium and a product. The method comprises the following steps: acquiring a historical request set and a historical response result set; obtaining a filter, judging whether a target historical request idempotent with a new request exists in the historical request set or not based on the filter under the condition that the new request is received, and if yes, returning a historical response result corresponding to the target historical request; and obtaining a request rate at which the gateway receives the request, and adjusting the bit array size of the filter based on the request rate. By adopting the method, the false alarm rate of the filter can be effectively reduced, and the occupied space is saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of network technology, and in particular to a response result cache optimization method, device, equipment, storage medium and product. Background Art

[0002] In the API gateway, there is a common scenario: a large number of idempotent requests are often received, that is, multiple requests for the same resource are made, and the same return results are expected. If each request is a complex request that calls a complete service link, these idempotent requests will cause resource waste and significant time overhead. Therefore, it is necessary to cache the request results in the API gateway. For the received request, first check whether it exists in the cache. If it exists, directly return the response result. This is very critical and necessary.

[0003] However, in the prior art, after setting the result cache, a new problem will arise: in a short period of time, a large number of requests are received but none of them hit the cache. Each time, the cache is checked first and then the database is checked, which will increase the system overhead. A common solution is to use Bloom filters to efficiently determine whether an element is in the set, but the original Bloom filter has a problem: there is a certain false alarm rate, and the more elements there are, the higher the false alarm rate. Summary of the invention

[0004] Based on this, it is necessary to provide a response result cache optimization method, device, computer equipment, computer-readable storage medium and computer program product that can reduce the false alarm rate in response to the above technical problems.

[0005] In a first aspect, the present application provides a response result cache optimization method, comprising:

[0006] Get the historical request set and historical response result set;

[0007] Obtain a filter, and when a new request is received, determine based on the filter whether there is a target historical request in the historical request set that is idempotent with the new request, and if so, return a historical response result corresponding to the target historical request;

[0008] A request rate at which the gateway receives requests is obtained, and a bit array size of the filter is adjusted based on the request rate.

[0009] In one embodiment, obtaining a historical request set and a historical response result set includes:

[0010] Obtain a cache plug-in and routing configuration parameters of the cache plug-in;

[0011] Based on the routing configuration parameters, historical requests and corresponding historical response results received by the gateway within a preset period are cached, the set of historical requests is determined as the historical request set, and the set of historical response results is determined as the historical response result set.

[0012] In one embodiment, obtaining the filter includes:

[0013] Initializing basic parameters of the filter, wherein the basic parameters include at least an initial bit array size and an initial number of hash functions;

[0014] The filter is created based on the initial bit array size and the initial number of hash functions.

[0015] In one embodiment, adjusting the bit array size of the filter based on the request rate includes:

[0016] Obtaining a first rate threshold and a second rate threshold, wherein the first rate threshold is greater than the second rate threshold;

[0017] If the request rate is greater than the first rate threshold, enlarging the length of the bit array;

[0018] If the request rate is less than the second rate threshold, shorten the length of the bit array.

[0019] In one embodiment, the step of expanding the length of the bit array comprises:

[0020] Obtaining an expansion factor of the filter, multiplying the length of the current bit array by the expansion factor to obtain the length of the expanded bit array;

[0021] The shortening of the length of the bit array comprises:

[0022] A reduction factor of the filter is obtained, and the length of the current bit array is multiplied by the reduction factor to obtain a shortened bit array length.

[0023] In one of the embodiments, if there is no target historical request in the historical request set that is idempotent with the new request, a service is requested from the backend based on the new request.

[0024] In a second aspect, the present application also provides a response result cache optimization device, including:

[0025] The acquisition module is used to obtain the historical request set and the historical response result set;

[0026] A filtering module, used to obtain a filter, and when a new request is received, determine based on the filter whether there is a target historical request in the historical request set that is idempotent with the new request, and if so, return a historical response result corresponding to the target historical request;

[0027] The adjustment module is used to obtain a request rate at which the gateway receives requests, and adjust the bit array size of the filter based on the request rate.

[0028] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:

[0029] Get the historical request set and historical response result set;

[0030] Obtain a filter, and when a new request is received, determine based on the filter whether there is a target historical request in the historical request set that is idempotent with the new request, and if so, return a historical response result corresponding to the target historical request;

[0031] A request rate at which the gateway receives requests is obtained, and a bit array size of the filter is adjusted based on the request rate.

[0032] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:

[0033] Get the historical request set and historical response result set;

[0034] Obtain a filter, and when a new request is received, determine based on the filter whether there is a target historical request in the historical request set that is idempotent with the new request, and if so, return a historical response result corresponding to the target historical request;

[0035] A request rate at which the gateway receives requests is obtained, and a bit array size of the filter is adjusted based on the request rate.

[0036] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:

[0037] Get the historical request set and historical response result set;

[0038] Obtain a filter, and when a new request is received, determine based on the filter whether there is a target historical request in the historical request set that is idempotent with the new request, and if so, return a historical response result corresponding to the target historical request;

[0039] A request rate at which the gateway receives requests is obtained, and a bit array size of the filter is adjusted based on the request rate.

[0040] The above-mentioned response result cache optimization method, device, computer equipment, computer-readable storage medium and computer program product dynamically adjust the bit array of the filter based on the request rate at which the gateway receives the request, and can automatically adapt to the busy and idle periods of the gateway, avoiding the problem of too long bit arrays occupying space and too short bit arrays causing a high false alarm rate. It can reduce the false alarm rate of the filter while saving space. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0042] Figure 1 This is one of the flowcharts of a response result cache optimization method in one embodiment;

[0043] Figure 2 The second flowchart of the response result cache optimization method in one embodiment is shown;

[0044] Figure 3 is a flow chart of the sub-steps of step 102 in one embodiment;

[0045] Figure 4 It is a flowchart of a response result cache optimization method in a specific embodiment;

[0046] Figure 5 It is a structural block diagram of a response result cache optimization device in one embodiment;

[0047] Figure 6 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0048] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0049] In the API gateway, there is a very common scenario: a large number of idempotent requests are often received, that is, multiple requests for the same resource are made, and the same return results are expected. If each request is a complex request that calls the entire service link, these idempotent requests will cause resource waste and significant time overhead. Therefore, it is necessary to cache the request results in the API gateway. For the received request, first check whether it exists in the cache. If it exists, directly return the response result. This is very critical and necessary. The common implementation method of result caching is to use redis, etc., but it is necessary to manually set the key in the project code, which is not flexible and convenient enough.

[0050] In addition, after setting up the result cache, a new problem will arise: in a short period of time, a large number of requests are received but none of them hit the cache. Each time, the cache is checked first and then the database is checked, which will increase the system overhead. A common solution is to use a Bloom filter to efficiently determine whether an element is in the set, that is, to map it to a bit array through a hash operation and determine whether the corresponding bit is 1. However, there is a problem in the original Bloom filter: there is a certain false positive rate, and when the corresponding bit is 1, it does not mean that the element exists, and the more elements there are, the higher the false positive rate. The false positive rate can be reduced by increasing the length of the array in the Bloom filter, but the length cannot be expanded indefinitely.

[0051] Based on this, this application proposes an API gateway result caching strategy based on a plug-in configuration routing strategy, which can flexibly and efficiently implement result caching; and a method for dynamically adjusting the array length of the filter to reduce the misjudgment rate.

[0052] Specifically, in one embodiment, Figure 1 As shown, a response result cache optimization method is provided. This embodiment uses the method applied to a terminal as an example for illustration. It can be understood that the method can also be applied to a server, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps:

[0053] Step 101, obtaining a historical request set and a historical response result set;

[0054] Step 102, obtaining a filter, and in the case of receiving a new request, determining whether there is a target historical request in the historical request set that is idempotent with the new request based on the filter, and if so, returning a historical response result corresponding to the target historical request;

[0055] Step 103: Obtain a request rate at which the gateway receives requests, and adjust a bit array size of the filter based on the request rate.

[0056] Among them, exemplary, this embodiment is applied to API Gateway (Application Programming Interface, Gateway), which is a key basic component in the full life cycle management of API, responsible for API configuration, release, version rollback, security, load balancing, etc. API Gateway is the entrance of all terminal traffic, responsible for routing terminal API requests to the correct upstream service for processing, and then returning the returned data to the original requester.

[0057] Exemplarily, this embodiment optimizes the traditional result cache. Cache is an optimization technology used to improve the performance and response speed of a program or system. The basic idea is that for repeated calculations or operations that produce the same output for the same set of inputs, the results can be cached to avoid repeated calculations, thereby saving calculations and resources.

[0058] See also Figure 2 , the filter is used to determine whether the currently received request is an idempotent request with historical requests. Idempotence means that the impact of multiple executions is the same as the impact of one execution. Therefore, the actual return results of idempotent requests are the same. If so, the historical response results of the target historical requests are directly returned to avoid calls to the backend. In actual application scenarios, the request rate of the API gateway is not fixed. For example, during e-commerce promotions, the number of requests to the API gateway is high; during the late night hours of daily life, the request rate of the API gateway is low. Therefore, this embodiment proposes to dynamically adjust the bit array size of the filter according to the request rate of the API gateway, so that the bit array size of the filter adapts to the request rate, while saving space, reducing the false alarm rate of the filter.

[0059] In the above-mentioned response result cache optimization method, the bit array of the filter is dynamically adjusted based on the request rate at which the gateway receives the request, which can automatically adapt to the busy and idle periods of the gateway, avoiding the problem of too long bit arrays occupying space and too short bit arrays causing a high false alarm rate. It can reduce the false alarm rate of the filter while saving space.

[0060] In an exemplary embodiment, obtaining a historical request set and a historical response result set includes: obtaining a cache plug-in and routing configuration parameters of the cache plug-in; based on the routing configuration parameters, caching historical requests and corresponding historical response results received by the gateway within a preset period, determining the set of historical requests as the historical request set, and determining the set of historical response results as the historical response result set.

[0061] The response speed of the API gateway can be improved by caching the response results of requests. In the past, most result caches were implemented through tools such as Redis, which needed to be configured in the console code, which was not flexible enough. Therefore, this embodiment provides an API gateway result cache method based on a plug-in configuration routing strategy. Users can configure different cache strategies in specific routes, such as setting cache keys, cache expiration times, etc., to achieve fine-grained and customized results, and can achieve flexible and efficient result cache.

[0062] This implementation method aims to solve the problem of low system efficiency caused by a large number of idempotent requests in the API gateway. It proposes to increase the response speed by adding result cache in the API gateway. When there is a request, if it exists in the cache, the cached result is returned to relieve the request pressure of the backend service. In addition, in view of the defect that most traditional result caches are hard-coded in the console code, a method of configuring proxy-cache at the route level plug-in of the result cache is proposed. Users can customize the cache configuration for each route, which is more flexible and fine-grained.

[0063] In an exemplary embodiment, see Figure 3 , the filter acquisition includes:

[0064] Initializing basic parameters of the filter, wherein the basic parameters include at least an initial bit array size and an initial number of hash functions; and creating the filter based on the initial bit array size and the initial number of hash functions.

[0065] Exemplarily, the filter used in this application is a Bloom filter, which is a binary vector and a series of random mapping functions, and can be used to quickly check whether an element is in a set. Common scenarios include URL deduplication in web crawlers, spelling checking, blacklist filtering, etc.

[0066] By configuring the API result cache based on the routing strategy of the plug-in, the response speed of a large number of idempotent requests can be effectively improved, thereby improving the user experience. However, there is another problem at the same time: when a large number of requests that do not hit the cache appear in a short period of time, it will cause an avalanche effect on the backend service.

[0067] Based on this, the present application proposes to use Bloom filter to determine whether an element exists in a set, which can greatly alleviate the pressure of backend service requests.

[0068] Using filters can check in advance whether there are requests in the historical request set that are idempotent with the new request. However, filters may produce false positives (i.e. false positives: the element is not actually in the set, but the filter thinks it is), but will not produce false negatives (i.e. false negatives: the element is actually in the set, but the filter thinks it is not).

[0069] Exemplarily, the false alarm rate (false positive rate) may be calculated based on Formula 1;

[0070] Formula 1:

[0071] ;

[0072] Where m is the bit array size of the Bloom filter, i.e. the total number of bits. K is the number of hash functions, and n is the number of elements inserted into the Bloom filter. This formula can also be simplified to Formula 2;

[0073] Formula 2:

[0074] ;

[0075] When the number of elements n increases, the false positive rate will also increase. For a given k, to maintain the stability of k, m must be proportional to n. When the bit array size is too long, storage space will be wasted; conversely, if the storage space is too short, the false positive rate will increase.

[0076] In real-world scenarios, the request rate of the API gateway is not fixed. For example, during e-commerce promotions, the number of requests to the API gateway is high; during the night, the request rate of the API gateway is low. Therefore, this embodiment proposes to dynamically adjust the bit array size of the Bloom filter according to the request rate of the API gateway, so that both the storage space and the false alarm rate can be optimized.

[0077] The basic parameters for initializing the filter include:

[0078] Initial bit array size ; Initial number of hash functions k; Initial number of elements ; First rate threshold and the second rate threshold , used to decide when to resize the bit array; the expansion factor of the filter and reduction factor .

[0079] See also Figure 4 In an exemplary embodiment, adjusting the bit array size of the filter based on the request rate includes:

[0080] Obtain a first rate threshold and a second rate threshold, wherein the first rate threshold is greater than the second rate threshold; if the request rate is greater than the first rate threshold, expand the length of the bit array; if the request rate is less than the second rate threshold, shorten the length of the bit array.

[0081] In an exemplary embodiment, the expanding the length of the bit array includes: obtaining an expansion factor of the filter, multiplying the length of the current bit array by the expansion factor, and obtaining the expanded length of the bit array; the shortening the length of the bit array includes: obtaining a reduction factor of the filter, multiplying the length of the current bit array by the reduction factor, and obtaining the shortened length of the bit array.

[0082] Exemplarily, when the request rate R is greater than the first rate threshold When the length of the bit array is expanded, see Formula 3:

[0083] ;

[0084] Increasing the bit array length at this point will reduce the false positive rate, thereby reducing the false alarm rate.

[0085] When the request rate R is less than the second rate threshold When the length of the bit array is reduced, see formula 4:

[0086] ;

[0087] At this time, reducing the length of the bit array will save storage space, but will increase the false alarm rate.

[0088] In this embodiment, the occupied space and false alarm rate of the filter are balanced by dynamically adjusting the length of the bit array based on the request rate. In order to solve the problem that the false positive rate in the traditional Bloom filter is high and the storage space is wasted by increasing the size of the bit array, a method of monitoring the request rate, setting high and low thresholds, and dynamically adjusting the size of the Bloom filter bit array is proposed, so that the storage space size and false positive rate of the API gateway are both optimal.

[0089] In an exemplary embodiment, the method further includes: if there is no target historical request idempotent with the new request in the historical request set, requesting a service from the backend based on the new request. When there is no target historical request in the historical request set, it is necessary to continue requesting the backend service.

[0090] To explain the application response result cache optimization method in detail, the following is a most detailed embodiment:

[0091] In a specific embodiment, step 102 of this embodiment specifically includes: configuring the API gateway result cache based on the routing strategy of the plug-in. Specifically, a proxy-cache routing-level plug-in can be set to bind a specific route. The implementation steps of the plug-in algorithm are as follows:

[0092] First, define the routing configuration parameters. For example, this application provides the following parameter definitions:

[0093] # Cache strategy, specify whether to store cache data on disk or in memory:

[0094] cache_strategy:disk;

[0095] # Specify the cache area:

[0096] cache_zone: disk_cache_one;

[0097] # Cache key, you can use variables, the default is ["$host", "$request_uri"]:

[0098] cache_key: ["$uri", "-cache-id"];

[0099] #Whether to skip cache retrieval, that is, not to search for data in the cache. You can use variables. When the value of this parameter is not empty or non-'0', the cache retrieval will be skipped:

[0100] cache_bypass: ["$arg_bypass"];

[0101] #Determine whether to cache based on the request method. The method can be ["GET", "POST", "HEAD"], and the default is ["GET", "HEAD"]:

[0102] cache_method: ["GET", "POST", "HEAD"];

[0103] #Determine whether to cache based on the response code. The supported range is [200,599]. The default is [200, 301, 404]:

[0104] cache_http_status: [200, 301, 404];

[0105] # Whether to return the Expires and Cache-Control response headers to the client. The default is false:

[0106] hide_cache_headers: false ;

[0107] # Whether to comply with the Cache-Control behavior in the HTTP protocol specification. The default value is false:

[0108] cache_control: false ;

[0109] #Whether to cache data, you can use variables. When the value of this parameter is not empty or non-'0', the data will not be cached:

[0110] no_cache: ["$arg_no_cache"];

[0111] # When the cache_control option is not enabled or the server does not return a cache control header after enabling it, provide a cache time, 300 seconds by default:

[0112] cache_ttl: 300 .

[0113] After the definition is completed, the parameters are checked to determine whether each parameter value is legal; the defined cache_key is concatenated to obtain the cache key in the system.

[0114] When a request is received within a preset period, the system generates a cache file name and determines whether there is an idempotent request with the new request in the historical request set. The system determines whether to cache the request method (request method), response result (response code) and other conditions according to the user-configured parameters, and writes the response result to the cache file.

[0115] When a new request arrives, based on whether the data is cached in the user configuration, the data in the cache file is returned or the backend service is continued to be requested.

[0116] A specific embodiment of step 103 is:

[0117] Initialization parameters: Set the initial bit array size , the initial number of hash functions k and the initial number of elements ;

[0118] Function to create Bloom filter: Create a new Bloom filter based on the given bit array size and number of hash functions;

[0119] Insert element into Bloom filter: insert element item into the current Bloom filter;

[0120] Check if the element is in the Bloom filter;

[0121] Monitor request rate: Continuously monitor the request rate R of the API gateway at each moment;

[0122] Adjust the bit array size of the current bloom filter: If , then expand the bit array size: ;if , then reduce the bit array size: ;

[0123] Update Bloom filter: resize the Bloom filter based on the current request rate, create a new Bloom filter and reinsert existing elements.

[0124] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0125] Based on the same inventive concept, the embodiment of the present application also provides a response result cache optimization device for implementing the response result cache optimization method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more response result cache optimization device embodiments provided below can refer to the limitations of the response result cache optimization method above, and will not be repeated here.

[0126] In an exemplary embodiment, Figure 5 As shown, a response result cache optimization device 500 is provided, comprising: an acquisition module 501, a filtering module 502 and an adjustment module 503, wherein:

[0127] Acquisition module 501, used to acquire a historical request set and a historical response result set;

[0128] The filtering module 502 is used to obtain a filter, and when a new request is received, determine whether there is a target historical request idempotent with the new request in the historical request set based on the filter, and if so, return a historical response result corresponding to the target historical request;

[0129] The adjustment module 503 is used to obtain the request rate at which the gateway receives the requests, and adjust the bit array size of the filter based on the request rate.

[0130] The acquisition module 501 is further used for:

[0131] Obtain a cache plug-in and routing configuration parameters of the cache plug-in;

[0132] Based on the routing configuration parameters, historical requests and corresponding historical response results received by the gateway within a preset period are cached, the set of historical requests is determined as the historical request set, and the set of historical response results is determined as the historical response result set.

[0133] The filtering module 502 is further used for:

[0134] Initializing basic parameters of the filter, wherein the basic parameters include at least an initial bit array size and an initial number of hash functions;

[0135] The filter is created based on the initial bit array size and the initial number of hash functions.

[0136] The adjustment module 503 is further used for:

[0137] Obtaining a first rate threshold and a second rate threshold, wherein the first rate threshold is greater than the second rate threshold;

[0138] If the request rate is greater than the first rate threshold, enlarging the length of the bit array;

[0139] If the request rate is less than the second rate threshold, shorten the length of the bit array.

[0140] The adjustment module 503 is further used for:

[0141] Obtaining an expansion factor of the filter, multiplying the length of the current bit array by the expansion factor to obtain the length of the expanded bit array;

[0142] The shortening of the length of the bit array comprises:

[0143] A reduction factor of the filter is obtained, and the length of the current bit array is multiplied by the reduction factor to obtain a shortened bit array length.

[0144] The filtering module 502 is further used for:

[0145] If there is no target historical request that is idempotent with the new request in the historical request set, a service is requested from the backend based on the new request.

[0146] Each module in the above-mentioned response result cache optimization device can be implemented in whole or in part by software, hardware and their combination. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0147] In an exemplary embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as shown in FIG. Figure 6 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, near field communication (NFC) or other technologies. When the computer program is executed by the processor, a response result cache optimization method is implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.

[0148] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0149] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:

[0150] Get the historical request set and historical response result set;

[0151] Obtain a filter, and when a new request is received, determine based on the filter whether there is a target historical request in the historical request set that is idempotent with the new request, and if so, return a historical response result corresponding to the target historical request;

[0152] A request rate at which the gateway receives requests is obtained, and a bit array size of the filter is adjusted based on the request rate.

[0153] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

[0154] Get the historical request set and historical response result set;

[0155] Obtain a filter, and when a new request is received, determine based on the filter whether there is a target historical request in the historical request set that is idempotent with the new request, and if so, return a historical response result corresponding to the target historical request;

[0156] A request rate at which the gateway receives requests is obtained, and a bit array size of the filter is adjusted based on the request rate.

[0157] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:

[0158] Get the historical request set and historical response result set;

[0159] Obtain a filter, and when a new request is received, determine based on the filter whether there is a target historical request in the historical request set that is idempotent with the new request, and if so, return a historical response result corresponding to the target historical request;

[0160] A request rate at which the gateway receives requests is obtained, and a bit array size of the filter is adjusted based on the request rate.

[0161] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0162] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.

[0163] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0164] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A response result cache optimization method, characterized in that: The method comprises: Get the historical request set and historical response result set; Obtain a filter, and when a new request is received, determine based on the filter whether there is a target historical request in the historical request set that is idempotent with the new request, and if so, return a historical response result corresponding to the target historical request; A request rate at which the gateway receives requests is obtained, and a bit array size of the filter is adjusted based on the request rate.

2. The method according to claim 1, characterized in that: The acquisition of the historical request set and the historical response result set includes: Obtain a cache plug-in and routing configuration parameters of the cache plug-in; Based on the routing configuration parameters, historical requests and corresponding historical response results received by the gateway within a preset period are cached, the set of historical requests is determined as the historical request set, and the set of historical response results is determined as the historical response result set.

3. The method according to claim 1, characterized in that The obtaining filter comprises: Initializing basic parameters of the filter, wherein the basic parameters include at least an initial bit array size and an initial number of hash functions; The filter is created based on the initial bit array size and the initial number of hash functions.

4. The method according to claim 1, characterized in that: The adjusting the bit array size of the filter based on the request rate comprises: Obtaining a first rate threshold and a second rate threshold, wherein the first rate threshold is greater than the second rate threshold; If the request rate is greater than the first rate threshold, enlarging the length of the bit array; If the request rate is less than the second rate threshold, shorten the length of the bit array.

5. The method according to claim 4, characterized in that The step of expanding the length of the bit array comprises: Obtaining an expansion factor of the filter, multiplying the length of the current bit array by the expansion factor to obtain the length of the expanded bit array; The shortening of the length of the bit array comprises: A reduction factor of the filter is obtained, and the length of the current bit array is multiplied by the reduction factor to obtain a shortened bit array length.

6. The method according to claim 1, characterized in that The method further comprises: If there is no target historical request that is idempotent with the new request in the historical request set, a service is requested from the backend based on the new request.

7. A response result cache optimization device, characterized in that: The device comprises: The acquisition module is used to obtain the historical request set and the historical response result set; A filtering module, used to obtain a filter, and when a new request is received, determine based on the filter whether there is a target historical request in the historical request set that is idempotent with the new request, and if so, return a historical response result corresponding to the target historical request; The adjustment module is used to obtain a request rate at which the gateway receives requests, and adjust the bit array size of the filter based on the request rate.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

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

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Expandable Bloom filter enquiring method and element inserting method thereof

    CN101082923A

  • Method and system for responding to data requests by utilizing caches

    CN108804447A

  • Request method, device, server, system and storage medium

    CN110891090A

  • Idempotent control method and device

    CN112633851A

  • Event processing method and device, terminal equipment and storage medium

    CN113419792A