A method, device, equipment and medium for adaptive current limiting of network requests
By adopting adaptive current limiting methods in the Internet financial industry and controlling traffic based on the growth rate of response information, the problem that existing current limiting solutions cannot cope with emergencies is solved, the docking efficiency of the financial industry is improved and labor costs are saved.
Patent Information
- Application Number
- CN202110948255.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-18
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2041-08-18
AI Technical Summary
In the Internet financial industry, existing current limiting solutions cannot effectively respond to various emergencies, resulting in a heavy traffic burden on financial institutions, affecting business processing efficiency and increasing labor costs.
An adaptive current limiting method for network requests is adopted to obtain network requests from the request queue, collect response information, count the growth rate of response information, and perform adaptive current limiting based on preset constraints, including average time consumption, network The ratio of the number of expired requests and the ratio of the number of interface errors.
It realizes the adaptive traffic limit of the network, improves the docking efficiency between the financial industry and financial institutions, saves labor costs, can flexibly schedule network requests, avoid downstream system deadlocks and effectively utilize network resources.
Smart Images

Figure CN113691604B
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of financial technology, and in particular to a method, device, equipment and medium for adaptive current limiting of network requests. Background Art
[0002] The Internet finance industry needs to connect with various financial institutions. However, due to the uneven capabilities of various financial institutions, Internet finance companies need to have good business traffic control capabilities to ensure that connecting with financial institutions with different technical capabilities does not affect business use. Internet financial flow control came into being.
[0003] However, in actual application scenarios, various complex emergencies will occur during the connection between the Internet financial industry and financial institutions. The current limiting solutions in related technologies have their own advantages, but the solution models provided are relatively fixed and there are no response strategies for various emergencies. When emergencies occur, they can only be solved by manpower, which imposes a heavy traffic burden on financial institutions, seriously affects the processing efficiency of financial services, and increases labor costs. Summary of the invention
[0004] The embodiments of the present invention provide a method, device, equipment and medium for adaptive flow limiting of network requests, which can realize adaptive flow limiting of the network, cope with various emergencies, improve the connection efficiency between the financial industry and financial institutions, and save labor costs.
[0005] In a first aspect, an embodiment of the present invention provides an adaptive current limiting method for a network request, the method being executed by a request server, the request server being connected to a target server and being used to send a network request to the target server; the method comprising:
[0006] Obtaining a network request from a request queue and sending it to the target server;
[0007] Collecting response information of the network request within a first preset time period, and collecting response information of the network request within a second preset time period; wherein the response information includes at least one dimension of average time consumption, network request expiration number ratio, and interface error number ratio;
[0008] Counting the growth rate of the response information of the network request in the second preset time period relative to the growth rate in the first preset time period;
[0009] If the growth rate of the response information meets the preset constraint condition, adaptive current limiting is performed based on the growth rate of the response information.
[0010] In a second aspect, an embodiment of the present invention further provides an adaptive current limiting device for network requests, which is configured on a target server, and includes: a network request acquisition module, which is used to acquire a network request from a request queue and send it to the target server;
[0011] A response information collection module, used to collect response information of the network request within a first preset time period, and to collect response information of the network request within a second preset time period; wherein the response information includes at least one dimension of average time consumption, network request expiration number ratio, and interface error number ratio;
[0012] A growth rate statistics module, used to count the growth rate of the response information of the network request in the second preset time period relative to the first preset time period;
[0013] The adaptive current limiting module is used to perform adaptive current limiting based on the growth rate of the response information if the growth rate of the response information meets a preset constraint condition.
[0014] In a third aspect, an embodiment of the present invention further provides an electronic device, the device comprising:
[0015] one or more processors;
[0016] a storage device for storing one or more programs,
[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement the adaptive current limiting method for network requests as described in any one of the embodiments of the present invention.
[0018] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the adaptive current limiting method for network requests as described in any one of the embodiments of the present invention.
[0019] The technical solution provided by the embodiment of the present invention obtains the network request from the request queue and sends it to the target server; collects the response information of the network request within the first preset time period, and collects the response information of the network request within the second preset time period; wherein the response information includes at least one dimension of the average time consumption, the ratio of the number of network request expiration, and the ratio of the number of interface errors; the growth rate of the response information of the network request within the second preset time period relative to the first preset time period is counted; if the growth rate of the response information meets the preset constraint condition, adaptive flow limiting is performed based on the growth rate of the response information. By executing the technical solution provided by the embodiment of the present invention, adaptive flow limiting of the network can be achieved, various emergencies can be dealt with, the docking efficiency between the financial industry and financial institutions can be improved, and labor costs can be saved. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 It is a flow chart of an adaptive current limiting method for network requests provided by an embodiment of the present invention;
[0021] Figure 2 is a flow chart of another method for adaptive current limiting of network requests provided by an embodiment of the present invention;
[0022] Figure 3 It is a flowchart of another method for adaptive current limiting of network requests provided by an embodiment of the present invention;
[0023] Figure 4 It is a schematic diagram of the structure of an adaptive current limiting device for network requests provided by an embodiment of the present invention;
[0024] Figure 5 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0025] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0026] In an application scenario of this solution, when an upstream system, such as a user, sends a request to a request server (such as generating an asset request or a loan request), the request server first stores each request in a request queue in a certain order. Then, a certain number of requests are sequentially retrieved from the request queue and sent to the target server of the downstream system (such as a financial institution). If the target server works normally, it will quickly process the request and respond to the request server. If the target server is overloaded or an exception occurs, it will feedback abnormal information to the request server or generate access timeouts, access interface errors and other problems. At this time, if the request server still sends requests to the target server at a fixed speed or quantity, it will cause the target server of the financial institution to crash, causing problems with the business processing interface. The consequences for the financial industry that needs to frequently process financial business are disastrous.
[0027] Figure 1 The flowchart of the adaptive current limiting method for network requests provided by an embodiment of the present invention is shown in FIG. 1 . The method can be executed by an adaptive current limiting device for network requests, which can be implemented by software and / or hardware, and can be configured in electronic devices such as servers. The method is applied to the scenario of the financial industry accessing financial institutions through the Internet. Figure 1 As shown, the technical solution provided by the embodiment of the present invention specifically includes:
[0028] S110: Obtain the network request from the request queue and send it to the target server.
[0029] Among them, the request queue can be an asynchronous queue for storing network requests sent by the upstream system. The network request can be an access request sent by the upstream system through the Internet. Each network request carries a request timestamp. This solution can score the network request according to the timestamp. For example, the latest network request has the highest score and the higher priority. The network requests can be arranged in the request queue from high to low priority. This solution can sequentially obtain a certain number of network requests from the request queue and send the obtained network requests to the target server so that the target server responds to the network request and completes the corresponding financial business, such as loan business.
[0030] S120: Collecting response information of the network request within a first preset time period, and collecting response information of the network request within a second preset time period.
[0031] The response information includes at least one dimension of average time consumption, network request expiration ratio, and interface error ratio.
[0032] Specifically, the first preset period can be 5 minutes, the first preset period can also be 10 minutes, and the first preset period can be set according to actual needs. The second preset period can be 5 minutes, the second preset period can also be 10 minutes, and the second preset period can be set according to actual needs. The time length of the first preset period can be the same as the time length of the second preset period, the time length of the first preset period can also be different from the time length of the second preset period, and the time length of the first preset period is preferably the same as the time length of the second preset period. After sending the network request to the target server, the target server can generate response information based on the processing result of the network request, and feed the response information back to the request server. This scheme can collect the response information of the network request within the first preset period, and this scheme can collect the response information of the network request within the second preset period. The response information can be the average time consumed when the network request accesses the target server, the response information can be the proportion of the number of access interface errors when the network request accesses the target server, the response information can also be the proportion of the number of expired messages when the network request accesses the target server, and the response information can also be other information. For example, if a network request queries the target server several times and the results returned are all being processed, then the request is considered to be an expired message.
[0033] S130: Counting the growth rate of the response information of the network request in the second preset time period relative to the first preset time period.
[0034] Among them, this scheme can count the growth rate of the response information of the network request in the second preset period relative to the first preset period based on the response information of the network request collected in the first preset period and the response information of the network request in the second preset period. For example, if the response information is the average time consumption, this scheme can count the growth rate of the average access time consumption of the network request in the second preset period relative to the first preset period. If the response information is the access interface error number ratio, this scheme can count the growth rate of the access interface error number ratio of the network request in the second preset period relative to the first preset period. If the response information is the expired message number ratio, this scheme can count the growth rate of the expired message number ratio of the network request in the second preset period relative to the first preset period. The response information can also be at least two of the average time consumption, the access interface error number ratio and the network request expired message number ratio.
[0035] S140: If the growth rate of the response information meets the preset constraint condition, adaptive current limiting is performed based on the growth rate of the response information.
[0036] Specifically, the preset constraint condition can be 0.01, and the preset constraint condition can also be 0.1. The preset constraint condition can be set according to actual needs. If the growth rate of the response information meets the preset constraint condition, this scheme performs adaptive current limiting based on the growth rate of the response information to limit the number of concurrent network requests accessing the target server, reduce the traffic load of the target server, and provide buffer time for the target server. Among them, the adaptive current limiting method can use the token bucket algorithm to control the token generation speed or control the number of tokens issued in parallel, or it can use other methods to perform adaptive current limiting.
[0037] In this embodiment, optionally, after adaptive current limiting is performed based on the growth rate of the response information, the method further includes: updating the request queue based on at least one dimension of access time consumption information, access request expiration information, and access interface error information of each of the network requests within the first preset time period and the second preset time period.
[0038] Specifically, this solution can count the access time of each network request within the first preset time period and the second preset time period, the number of access interface errors of each network request, and whether each network request is an expired message. The score of each network request in the request queue, i.e., the priority, can be updated based on at least one dimension of the access time of each network request, the number of access interface errors of each network request, and whether each network request is an expired message. The priority of network requests with too long access time, expired requests, and too many access interface errors can be lowered, and the priority of network requests that have just arrived can be increased.
[0039] Thus, by updating the request queue based on at least one dimension of the access time-consuming information, access request expiration information, and access interface error information of each network request within the first preset time period and the second preset time period, the network request can be flexibly scheduled, the business processing efficiency of the downstream system can be improved, deadlock of the downstream system can be avoided, and the effective use of network resources can be achieved.
[0040] The technical solution provided by the embodiment of the present invention obtains the network request from the request queue and sends it to the target server; collects the response information of the network request within the first preset time period, and collects the response information of the network request within the second preset time period; wherein the response information includes at least one dimension of the average time consumption, the ratio of the number of network request expiration, and the ratio of the number of interface errors; the growth rate of the response information of the network request within the second preset time period relative to the first preset time period is counted; if the growth rate of the response information meets the preset constraint condition, adaptive flow limiting is performed based on the growth rate of the response information. By executing the technical solution provided by the embodiment of the present invention, adaptive flow limiting of the network can be achieved, various emergencies can be dealt with, the docking efficiency between the financial industry and financial institutions can be improved, and labor costs can be saved.
[0041] Figure 2 1 is a flow chart of an adaptive current limiting method for network requests provided by an embodiment of the present invention. This embodiment is optimized based on the above embodiment. Figure 2 As shown, the adaptive current limiting method for network requests in an embodiment of the present invention may include:
[0042] S210: Obtain a network request from the request queue and send it to a token bucket.
[0043] Specifically, this solution can obtain a certain number of network requests from the request queue, and send the network requests to the token bucket, so that the network requests obtain the tokens in the token bucket, and thus the network requests can be sent to the target server.
[0044] In a feasible implementation, optionally, before obtaining the network request from the request queue, the method further includes: receiving at least one network request, and storing each network request in the request queue according to a request timestamp of each network request.
[0045] Among them, this scheme can receive at least one network request, and according to the request timestamp carried in the network request, set the score of the network request with the last request timestamp as the highest, that is, the score of the network request that has just arrived is set to the highest. A high score corresponds to a high priority, and each network request is stored in the request queue in order from high to low scores, and each network request is arranged from high to low priority. Alternatively, this scheme can also arrange the network request that has just arrived backwards, for example, postpone processing for 10 seconds, and give priority to network requests before 10 seconds. In this way, priority is given to network requests before 10 seconds based on the current timestamp. Network requests can be arranged according to actual needs.
[0046] Therefore, by receiving at least one network request and storing each network request in a request queue according to the request timestamp of each network request, flexible scheduling of network requests can be achieved, the business processing efficiency of the downstream system can be improved, and effective utilization of network resources can be achieved.
[0047] S220: Obtain a token for the network request from the token bucket, and send the network request to the target server based on the token.
[0048] Among them, if there are enough tokens in the token bucket, this solution can obtain the required number of tokens corresponding to the network request from the token bucket, and send the network request to the target server based on the tokens, so that the target server responds to the network request. If the number of tokens in the token bucket cannot meet the needs of the network request, the network request cannot get the token, and the network request cannot be sent to the target server, and error information is fed back to the upstream system.
[0049] S230: Collecting response information of the network request within a first preset time period, and collecting response information of the network request within a second preset time period.
[0050] S240: Count the growth rate of the response information of the network request in the second preset time period relative to the first preset time period.
[0051] S250: If the growth rate of the response information satisfies a preset constraint condition, adjusting the number of tokens issued in parallel in the token bucket and / or adjusting the speed of generating tokens based on the growth rate of the response information.
[0052] Specifically, if the growth rate of the response information meets the preset constraint conditions, this solution can adjust the number of parallel token issuances of the token bucket and / or adjust the token generation speed based on the growth rate of the response information. The number of parallel token issuances represents the number of network requests that the request server sends to the target server at the same time. The number of parallel token issuances can be 2, or the number of parallel token issuances can be 3, and the number of parallel token issuances can be set according to actual needs. The token generation speed represents the number of tokens that fall into the token bucket per unit time, and the token generation speed can be 5 per second, or the token generation speed can be 10 per second, and the token generation speed can be set according to actual needs.
[0053] In another feasible embodiment, optionally, if the growth rate of the response information satisfies a preset constraint condition, then the number of tokens issued in parallel in the token bucket and / or the token generation speed is adjusted based on the growth rate of the response information, including: if the growth rate of the average time consumption is greater than a first preset value, then the number of tokens issued in parallel in the token bucket and / or the token generation speed is adjusted based on the growth rate of the average time consumption.
[0054] Exemplarily, the first preset value may be 0.1, the first preset value may also be 0.01, and the first preset value may be set according to actual needs. If the first preset time period and the second preset time period are both five minutes, the first preset value is set to 0.1, the average time taken for all requests in the second preset time period is 10 seconds, and the average time taken for all requests in the first preset time period is 5 seconds, then the growth rate of the average time taken in the second preset time period relative to the average time taken in the first preset time period is 1, which is much greater than 0.1, then the number of tokens issued in parallel and / or the speed of generating tokens may be adjusted according to the growth rate of the average time taken of 1. For example, the number of tokens issued in parallel by the token bucket may be reduced by 1, or the speed of generating tokens may be reduced by 20%. Among them, the number of tokens issued in parallel and the speed of generating tokens may be set according to actual needs.
[0055] Therefore, if the growth rate of the average time consumption is greater than the first preset value, the number of tokens issued in parallel in the token bucket and / or the speed of generating tokens are adjusted based on the growth rate of the average time consumption. Adaptive current limiting can be performed according to the growth rate of the average time consumption of network requests, which can reduce the traffic burden of the downstream system, ensure the stability of the downstream system, and improve the docking efficiency between the upstream system and the downstream system.
[0056] In another feasible implementation, optionally, if the growth rate of the response information satisfies a preset constraint condition, then the number of tokens issued in parallel in the token bucket and / or the token generation speed is adjusted based on the growth rate of the response information, including: if the growth rate of the ratio of the number of expired network requests is greater than a second preset value, then the number of tokens issued in parallel in the token bucket and / or the token generation speed is adjusted based on the growth rate of the ratio of the number of expired network requests.
[0057] Exemplarily, the second preset value may be 0.1, the second preset value may also be 0.01, and the second preset value may be set according to actual needs. For a network request, if the response results received from the downstream system when making multiple requests to the downstream system are all being processed, the network request is considered expired. Alternatively, if the access time of a network request exceeds the preset time, the network request is considered expired. For example, the preset time may be 3 days, or the preset time may be 1 day, and the preset time may be set according to actual needs. The network request expiration number ratio may be the ratio of expired network requests to all network requests within a period of time. If the first preset time period and the second preset time period are both five minutes, the second preset value is set to 0.1, the proportion of expired network requests in the second preset time period is 30%, and the proportion of expired network requests in the first preset time period is 20%, then the growth rate of the network request expiration number ratio in the second preset time period is 0.5, which is much greater than 0.1, and the number of tokens issued in parallel and / or the speed of token generation may be adjusted according to the growth rate of the network request expiration number ratio of 0.5. For example, the number of tokens issued in parallel by the token bucket can be reduced by 1, or the token generation speed can be reduced by 20%. The number of tokens issued in parallel and the token generation speed can be set according to actual needs.
[0058] Therefore, if the growth rate of the network request expiration number ratio is greater than the second preset value, the number of tokens issued in parallel in the token bucket and / or the speed of generating tokens are adjusted based on the growth rate of the network request expiration number ratio. Adaptive current limiting can be performed according to the growth rate of the network request expiration number ratio, which can reduce the traffic burden of the downstream system, ensure the stability of the downstream system, and improve the docking efficiency between the upstream system and the downstream system.
[0059] In this embodiment, optionally, if the growth rate of the response information satisfies a preset constraint condition, the number of tokens issued in parallel in the token bucket and / or the token generation speed is adjusted based on the growth rate of the response information, including: if the growth rate of the interface error number ratio is greater than a third preset value, then the number of tokens issued in parallel in the token bucket and / or the token generation speed is adjusted based on the growth rate of the interface error number ratio.
[0060] Exemplarily, the third preset value may be 0.1, the third preset value may also be 0.15, and the third preset value may be set according to actual needs. If the downstream system suddenly becomes abnormal, when the request server sends a network request to the target server, information such as an access interface error will be received. The interface error number ratio may be the ratio of the number of interfaces that have errors in a period of time to the total number of interfaces. If the first preset time period and the second preset time period are both five minutes, the third preset value is set to 0.1, the interface error number ratio is 40% in the second preset time period, and the interface error number ratio is 20% in the first preset time period, then the interface error number ratio in the second preset time period is 1 relative to the interface error number ratio in the first preset time period. The growth rate is much greater than 0.1, and the number of tokens issued in parallel and / or the speed of generating tokens can be adjusted according to the growth rate of the interface error number ratio of 1. For example, the number of tokens issued in parallel by the token bucket can be controlled to be reduced by 1, or the speed of generating tokens can be controlled to be reduced by 20%. Among them, the number of tokens issued in parallel and the speed of generating tokens can be set according to actual needs.
[0061] Thus, if the growth rate of the interface error number ratio is greater than the third preset value, the number of parallel token issuances of the token bucket and / or the token generation speed are adjusted based on the growth rate of the interface error number ratio. Adaptive current limiting can be performed according to the growth rate of the interface error number ratio, which can reduce the traffic burden of the downstream system, ensure the stability of the downstream system, and improve the docking efficiency between the upstream system and the downstream system.
[0062] The technical solution provided by the embodiment of the present invention obtains a network request from a request queue and sends it to a token bucket, obtains the token of the network request from the token bucket, and sends the network request to a target server based on the token, collects the response information of the network request within a first preset time period, and collects the response information of the network request within a second preset time period, and counts the growth rate of the response information of the network request within the second preset time period relative to the first preset time period. If the growth rate of the response information meets the preset constraint condition, the number of tokens issued in parallel in the token bucket and / or the generation speed of the token are adjusted based on the growth rate of each response information. By implementing this solution, adaptive flow restriction of the network can be achieved, various emergencies can be dealt with, the stability of the downstream system can be guaranteed, the docking efficiency between the financial industry and financial institutions can be improved, and labor costs can be saved.
[0063] The Internet finance industry needs to connect with various financial institutions, but the capabilities of various financial institutions vary and they cannot handle the traffic from the Internet. Therefore, Internet finance companies need to be able to control business traffic and ensure that connecting with financial institutions with different technical capabilities does not affect business use.
[0064] The current limiting schemes in the related art are mainly the leaky bucket algorithm and the token bucket algorithm, but these algorithms cannot perform adaptive current limiting according to the actual business processing situation.
[0065] In order to more clearly describe the technical solution of the present invention, Figure 3 is a flow chart of an adaptive current limiting method for network requests provided by an embodiment of the present invention, such as Figure 3 As shown, the technical solution provided by the embodiment of the present invention may include the following steps:
[0066] Step 1: Asynchronous current limiting.
[0067] First, build an asynchronous request queue based on the actual business situation. The real-time requests from the Internet are placed in the asynchronous request queue. Each request corresponds to an order number, namely, assetID. Use redis's zset to build the asynchronous request queue, and arrange the incoming network requests according to the score of zset. Then, use the scheduling algorithm to retrieve the preset number of network requests in zset and send them to the target server. When sending network requests, use the token bucket algorithm to send a certain number of network requests to the downstream system (bank, trust, insurance, etc.) in parallel to ensure a buffer for the downstream system, that is, the traffic value that the downstream system can accept. However, only asynchronous flow control will require manual continuous allocation of tokens in the token bucket, and the generation speed has a relatively large labor cost, especially during manual rest time, it is difficult to ensure timeliness. Through asynchronous flow control, it is ensured that the traffic peak will not overwhelm the downstream system, and the peak can be eliminated well.
[0068] Step 2: Adaptive current limiting.
[0069] According to the business dimension, due to the asynchronous method, network requests are stored in the queue, and there will be a backlog of messages in the queue. MQ is used as a message queue. If there is a network request, it will record the number of expired messages, request time and interface error number from three dimensions, and send the record result to DynamicLimiterMetricMQListener. DynamicLimiterMetricMQListener counts the response information of network requests within the first preset time period (for example, according to a statistical window of 5 minutes) and the second preset time period (for example, according to a statistical window of 5 minutes). If the growth rate of the response information in the second preset time period meets the preset constraint condition relative to the first preset time period, then return to adjust the token parameters: for example, adjust the token parameters according to the growth rate of the ratio of expired messages in two adjacent 5 minutes. Adjust the token parameters according to the cumulative time of calling the downstream system in two adjacent 5 minutes, and then calculate the growth rate of the average time. Adjust the token parameters according to the growth rate of the ratio of the number of errors of calling the downstream interface in two adjacent 5 minutes. Among them, the token parameters include the speed of token generation and the number of tokens issued in parallel, that is, the concurrency threshold. The current limiting threshold is continuously adjusted according to the actual business situation through three dimensions, so as to achieve the effect of adaptive current limiting. At the same time, you can also re-score network requests and update the request queue based on the records of the number of expired messages, request duration, and interface errors for each network request in MQ.
[0070] Adaptive current limiting adjusts the token bucket generation algorithm in asynchronous current limiting according to the actual business situation, so as to adjust the token bucket generation rate to control the flow. If the downstream system has strong processing capabilities, the generation speed can be fast. If the downstream system has poor capabilities, the generation speed can be slowed down to protect the downstream system. Dynamic flow control is performed according to the actual business to protect the system of the downstream organization.
[0071] The technical solution provided by the embodiment of the present invention performs dynamic flow control according to the specific situation of the business, adapts to the current Internet financial business, and solves the flow control problem when the Internet financial business connects to the external or internal loan business system. It ensures the stability of the downstream system and guarantees the protection of the downstream system, supporting Internet financial and other businesses.
[0072] Figure 4 is a schematic diagram of the structure of an adaptive current limiting device for network requests provided by an embodiment of the present invention. The device can be configured in an electronic device such as a server, such as Figure 4 As shown, the device comprises:
[0073] The network request acquisition module 410 is used to acquire the network request from the request queue and send it to the target server;
[0074] A response information collection module 420 is used to collect response information of the network request within a first preset time period, and to collect response information of the network request within a second preset time period; wherein the response information includes at least one dimension of average time consumption, network request expiration number ratio, and interface error number ratio;
[0075] A growth rate statistics module 430, configured to count the growth rate of the response information of the network request in the second preset time period relative to the first preset time period;
[0076] The adaptive current limiting module 440 is configured to perform adaptive current limiting based on the growth rate of the response information if the growth rate of the response information meets a preset constraint condition.
[0077] Optionally, the network request acquisition module 410 is specifically used to: obtain the network request from the request queue and send it to the token bucket; obtain the token of the network request from the token bucket, and send the network request to the target server based on the token; accordingly, the adaptive current limiting module 440 is specifically used to: adjust the number of parallel issuance of tokens in the token bucket and / or adjust the token generation speed based on the growth rate of the response information.
[0078] Optionally, the device further includes a network request storage module, which is used to receive at least one network request before obtaining the network request from the request queue, and store each network request in the request queue according to a request timestamp of each network request.
[0079] Optionally, the device also includes a request queue update module, which is used to update the request queue based on at least one dimension of access time consumption information, access request expiration information and access interface error information of each network request within a first preset time period and a second preset time period after adaptive current limiting is performed based on the growth rate of the response information.
[0080] Optionally, the adaptive current limiting module 440 is specifically used to: if the growth rate of the average time consumption is greater than a first preset value, adjust the number of parallel issuance of tokens in the token bucket and / or adjust the token generation speed based on the growth rate of the average time consumption.
[0081] Optionally, the adaptive current limiting module 440 is specifically used to: if the growth rate of the network request expiration number ratio is greater than a second preset value, adjust the number of parallel token issuances in the token bucket and / or adjust the token generation speed based on the growth rate of the network request expiration number ratio.
[0082] Optionally, the adaptive current limiting module 440 is specifically used to: if the growth rate of the interface error number ratio is greater than a third preset value, adjust the number of parallel token issuances in the token bucket and / or adjust the token generation speed based on the growth rate of the interface error number ratio.
[0083] The device provided in the above-mentioned embodiment can execute the adaptive current limiting method for network requests provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0084] Figure 5 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention, such as Figure 5 As shown, the device includes:
[0085] one or more processors 510, Figure 5 A processor 510 is taken as an example;
[0086] Memory 520;
[0087] The device may further include: an input device 530 and an output device 540 .
[0088] The processor 510, memory 520, input device 530 and output device 540 in the device may be connected via a bus or other means. Figure 5 The example of connecting through bus is taken in the following.
[0089] The memory 520, as a non-transitory computer-readable storage medium, can be used to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to a method for adaptive current limiting of network requests in an embodiment of the present invention. The processor 510 executes various functional applications and data processing of the computer device by running the software programs, instructions and modules stored in the memory 520, that is, to implement a method for adaptive current limiting of network requests in the above method embodiment, namely:
[0090] Obtaining a network request from a request queue and sending it to the target server;
[0091] Collecting response information of the network request within a first preset time period, and collecting response information of the network request within a second preset time period; wherein the response information includes at least one dimension of average time consumption, network request expiration number ratio, and interface error number ratio;
[0092] Counting the growth rate of the response information of the network request in the second preset time period relative to the growth rate in the first preset time period;
[0093] If the growth rate of the response information meets the preset constraint condition, adaptive current limiting is performed based on the growth rate of the response information.
[0094] The memory 520 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 520 may include a high-speed random access memory, and may also include a non-transitory memory, such as at least one disk storage device, a flash memory device, or other non-transitory solid-state storage device. In some embodiments, the memory 520 may optionally include a memory remotely arranged relative to the processor 510, and these remote memories may be connected to the terminal device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0095] The input device 530 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the computer device. The output device 540 may include a display device such as a display screen.
[0096] An embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, an adaptive current limiting method for network requests provided in an embodiment of the present invention is implemented, that is,
[0097] Obtaining a network request from a request queue and sending it to the target server;
[0098] Collecting response information of the network request within a first preset time period, and collecting response information of the network request within a second preset time period; wherein the response information includes at least one dimension of average time consumption, network request expiration number ratio, and interface error number ratio;
[0099] Counting the growth rate of the response information of the network request in the second preset time period relative to the growth rate in the first preset time period;
[0100] If the growth rate of the response information meets the preset constraint condition, adaptive current limiting is performed based on the growth rate of the response information.
[0101] Any combination of one or more computer-readable media may be used. A computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: 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 thereof. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, device, or device.
[0102] Computer-readable signal media may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may 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 a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0103] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0104] Computer program code for performing the operations of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0105] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. An adaptive current limiting method for network requests, It is characterized in that The method is executed by a request server, which is connected to a target server and is used to send a network request to the target server; the method includes: Obtaining a network request from a request queue and sending it to the target server; wherein the network request carries a request timestamp, and the network request is scored according to the request timestamp; Collecting response information of the network request within a first preset time period, and collecting response information of the network request within a second preset time period; wherein the response information includes at least one dimension of average time consumption, network request expiration number ratio, and interface error number ratio; Counting the growth rate of the response information of the network request in the second preset time period relative to the growth rate in the first preset time period; If the growth rate of the response information meets the preset constraint condition, adaptive current limiting is performed based on the growth rate of the response information; After adaptive current limiting is performed based on the growth rate of the response information, the method further includes: Counting the access time of each network request within the first preset time period and the second preset time period, the number of access interface errors of each network request, and whether each network request is an expired message; Update the score of each network request in the request queue according to at least one dimension of the access time of each network request, the number of access interface errors of each network request, and whether each network request is an expired message; The request queue is updated according to the updated score of each network request in the request queue.
2. The method according to claim 1, It is characterized in that Obtaining a network request from a request queue and sending it to the target server includes: Obtaining a network request from the request queue and sending it to a token bucket; Obtaining a token for the network request from the token bucket, and sending the network request to the target server based on the token; Accordingly, adaptive current limiting is performed based on the growth rate of the response information, including: The number of tokens issued in parallel in the token bucket is adjusted based on the growth rate of the response information and / or the speed of generating tokens is adjusted.
3. The method according to claim 1 or 2, It is characterized in that Before getting the network request from the request queue, it also includes: At least one network request is received, and each network request is stored in the request queue according to a request timestamp of each network request.
4. The method according to claim 2, It is characterized in that If the growth rate of the response information satisfies the preset constraint condition, adjusting the number of tokens issued in parallel in the token bucket and / or adjusting the token generation speed based on the growth rate of the response information includes: If the growth rate of the average time consumption is greater than a first preset value, the number of tokens issued in parallel in the token bucket and / or the speed of generating tokens are adjusted based on the growth rate of the average time consumption.
5. The method according to claim 2, It is characterized in that If the growth rate of the response information satisfies the preset constraint condition, adjusting the number of tokens issued in parallel in the token bucket and / or adjusting the token generation speed based on the growth rate of the response information includes: If the growth rate of the network request expiration number ratio is greater than a second preset value, the number of tokens issued in parallel in the token bucket and / or the token generation speed are adjusted based on the growth rate of the network request expiration number ratio.
6. The method according to claim 2, It is characterized in that If the growth rate of the response information satisfies the preset constraint condition, adjusting the number of tokens issued in parallel in the token bucket and / or adjusting the token generation speed based on the growth rate of the response information includes: If the growth rate of the interface error number ratio is greater than a third preset value, the number of tokens issued in parallel in the token bucket and / or the token generation speed are adjusted based on the growth rate of the interface error number ratio.
7. An adaptive current limiting device for network requests, It is characterized in that include: A network request acquisition module is used to obtain network requests from the request queue and send them to the target server; wherein the network request carries a request timestamp, and the network request is scored according to the request timestamp; A response information collection module, used to collect response information of the network request within a first preset time period, and to collect response information of the network request within a second preset time period; wherein the response information includes at least one dimension of average time consumption, network request expiration number ratio, and interface error number ratio; A growth rate statistics module, used to count the growth rate of the response information of the network request in the second preset time period relative to the first preset time period; An adaptive current limiting module, configured to perform adaptive current limiting based on the growth rate of the response information if the growth rate of the response information meets a preset constraint condition; The device also includes a request queue update module, which is specifically used to: After adaptive current limiting is performed based on the growth rate of the response information, statistics are collected on the access time of each network request within the first preset time period and the second preset time period, the number of access interface errors of each network request, and whether each network request is an expired message; the score of each network request in the request queue is updated based on at least one dimension of the access time of each network request, the number of access interface errors of each network request, and whether each network request is an expired message; and the request queue is updated based on the updated score of each network request in the request queue.
8. An electronic device, It is characterized in that include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the adaptive current limiting method for network requests as described in any one of claims 1-6.
9. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the program is executed by a processor, the adaptive current limiting method for network requests as described in any one of claims 1 to 6 is implemented.
