Gateway current limiting system and method
By using a gateway rate limiting system, reverse proxy servers, and token bucket algorithms to control traffic, the problem of peak traffic exceeding the service capacity limit in microservice architectures is solved, achieving efficient and stable services and improving the robustness and fault tolerance of the system.
Patent Information
- Application Number
- CN202511165680.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-20
- Publication Date
- 2025-11-14
AI Technical Summary
In a microservice architecture, external user traffic is difficult to predict, causing traffic peaks to exceed the capacity of internal services, leading to service paralysis and cascading failures, which affect user experience and system stability.
A gateway rate limiting system is adopted, which includes a reverse proxy server, a gateway cluster, a rate limiting management center, and a business server. It controls traffic through a token bucket algorithm, configures interface rate limiting parameters and gateway registration information, and realizes distributed rate limiting management of the gateway.
Effective traffic control prevents service paralysis, ensures efficient and stable service, improves system robustness and fault tolerance, and demonstrates excellent performance in high-concurrency scenarios.
Smart Images

Figure CN120956664A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of gateway rate limiting technology, and in particular to a gateway rate limiting system and method. Background Technology
[0002] In a microservice architecture, the gateway cluster is crucial, providing a unified interface (Application Programming Interface, API) to the outside world and forwarding traffic to business services internally.
[0003] However, external user traffic is difficult to predict and often experiences sudden peaks due to trending events. When the traffic peak far exceeds the internal service's capacity limit, the internal service will be paralyzed due to resource exhaustion. At this time, request backlog and slow response will eventually lead to service unavailability, which not only affects the current user experience but may also trigger cascading failures, affecting the entire system. Therefore, how to deal with traffic fluctuations and ensure service stability is a key challenge facing microservice architecture. Summary of the Invention
[0004] This invention provides a gateway rate limiting system and method, which realizes gateway rate limiting and ensures efficient and stable service.
[0005] In a first aspect, embodiments of this disclosure provide a gateway rate limiting system, including:
[0006] The system includes a reverse proxy server, a gateway cluster, a rate limiting management center, and a business server, with the gateway cluster connected to the reverse proxy server, the rate limiting management center, and the business server, respectively.
[0007] The reverse proxy server is used to, when receiving a user's interface call request, poll and distribute the interface call request to the target gateway in the gateway cluster.
[0008] The gateway cluster is used to forward the interface call request to the business server when the forwarding conditions are met. The forwarding conditions are related to the interface rate limiting parameters and the number of gateways.
[0009] The rate limiting management center is used to configure interface rate limiting parameters and gateway registration information, including the number of gateways.
[0010] Optionally, the target gateway is specifically used for:
[0011] Determine the interface type of the interface call request, and invoke the token bucket corresponding to the interface type. The number of tokens in the token bucket is related to the interface rate limiting parameters and the number of gateways.
[0012] If a token is successfully obtained from the token bucket, the interface call request is forwarded to the business server; otherwise, an interface call failure notification is generated and sent back to the user through the reverse proxy server.
[0013] Optionally, the rate limiting management center includes a configuration center and a registration center.
[0014] The configuration center is used to configure the first interface rate limiting parameters for each interface type, and after receiving the rate limiting parameter acquisition request sent by the gateway cluster, it sends the first interface rate limiting parameters to the gateway cluster.
[0015] The registration center is used to register gateways in the gateway cluster, and after receiving a registration information retrieval request from the gateway cluster, sends the first gateway registration information to the gateway cluster.
[0016] Optionally, the gateway cluster is specifically used for:
[0017] Obtain the first interface rate limiting parameters corresponding to different interface types and the first gateway registration information of the gateway cluster from the rate limiting management center, and store the first interface rate limiting parameters and the first gateway registration information as the second interface rate limiting parameters and the second gateway registration information in memory respectively;
[0018] Based on the second interface rate limiting parameters and the number of second gateways in the second gateway registration information, determine the second single-machine rate limiting parameters for each gateway under different interface types;
[0019] Based on the second single-machine rate limiting parameter, a token bucket with a corresponding number of tokens is created, and the token bucket is stored in memory.
[0020] Optionally, the gateway cluster is further configured to:
[0021] Obtain the first interface rate limiting parameters and the first gateway registration information from the rate limiting management center according to the set cycle;
[0022] The first single-machine rate limiting parameter for each gateway under different interface types is determined based on the first interface rate limiting parameter and the number of first gateways in the first gateway registration information.
[0023] Compare the first single-machine current limiting parameter with the second single-machine current limiting parameter;
[0024] If the comparison results are inconsistent, the token bucket is updated based on the first single-machine rate limiting parameters.
[0025] Optionally, the gateway cluster is specifically used for:
[0026] When the load pressure of the gateway is detected to meet the expansion conditions, a gateway registration request is sent to the registration center in the rate limiting management center to request the registration center to register a new gateway.
[0027] Optionally, the first single-machine rate limiting parameter is calculated by dividing the first interface rate limiting parameter by the number of first gateways, and the second single-machine rate limiting parameter is calculated by dividing the second interface rate limiting parameter by the number of second gateways.
[0028] Secondly, this disclosure provides a gateway rate limiting method, applied to a gateway rate limiting system, comprising:
[0029] When a user's API call request is received via a reverse proxy server, the API call request is forwarded to the target gateway in the gateway cluster in a round-robin fashion.
[0030] Configure interface rate limiting parameters and gateway registration information through the rate limiting management center, wherein the gateway registration information includes the number of gateways;
[0031] The gateway cluster forwards the interface call request to the business server when the forwarding conditions are met. The forwarding conditions are related to the interface rate limiting parameters and the number of gateways.
[0032] Optionally, forwarding the interface call request to the business server when the forwarding conditions are met includes:
[0033] The target gateway in the gateway cluster determines the interface type of the interface call request, and calls the token bucket corresponding to the interface type. The number of tokens in the token bucket is related to the interface rate limiting parameters and the number of gateways.
[0034] If a token is successfully obtained from the token bucket, the interface call request is forwarded to the business server; otherwise, an interface call failure notification is generated and sent back to the user through the reverse proxy server.
[0035] Optionally, configuring interface rate limiting parameters and gateway registration information through the rate limiting management center includes:
[0036] Configure the first interface rate limiting parameters for each interface type through the configuration center in the rate limiting management center, and send the first interface rate limiting parameters to the gateway cluster after receiving the rate limiting parameter acquisition request sent by the gateway cluster.
[0037] Register the gateways in the gateway cluster through the registration center in the rate limiting management center, and send the first gateway registration information to the gateway cluster after receiving the registration information acquisition request sent by the gateway cluster.
[0038] This invention discloses a gateway rate limiting system and method. The system includes: a reverse proxy server, a gateway cluster, a rate limiting management center, and a service server. The gateway cluster is connected to the reverse proxy server, the rate limiting management center, and the service server. The reverse proxy server, upon receiving a user's interface call request, polls and forwards the request to target gateways within the gateway cluster. The gateway cluster, when a forwarding condition is met, forwards the interface call request to the service server. The forwarding condition is related to interface rate limiting parameters and the number of gateways. The rate limiting management center configures the interface rate limiting parameters and gateway registration information, including the number of gateways. This technical solution achieves gateway rate limiting, ensuring efficient and stable service.
[0039] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0040] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0041] Figure 1 This is a schematic diagram of the structure of a gateway rate limiting system provided in Embodiment 1 of the present invention;
[0042] Figure 2 This is a schematic diagram of another gateway rate limiting system provided in Embodiment 1 of the present invention;
[0043] Figure 3 This is a flowchart of a gateway rate limiting method provided in Embodiment 2 of the present invention. Detailed Implementation
[0044] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0045] It should be noted that the terms "first," "second," and "target," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0046] Example 1
[0047] Figure 1 This is a schematic diagram of a gateway rate limiting system provided in Embodiment 1 of the present invention. This embodiment can be applied to situations where gateway rate limiting is performed on the device under test.
[0048] like Figure 1 As shown, the gateway rate limiting system includes: reverse proxy server 1, gateway cluster 2, rate limiting management center 3 and business server 4. Gateway cluster 2 is connected to reverse proxy server 1, rate limiting management center 3 and business server 4 respectively.
[0049] Reverse proxy server 1 is used to poll and forward the API call request to the target gateway in gateway cluster 2 when it receives the API call request from the user.
[0050] Gateway cluster 2 is used to forward interface call requests to business server 4 when the forwarding conditions are met. The forwarding conditions are related to the interface rate limiting parameters and the number of gateways.
[0051] Rate limiting management center 3 is used to configure interface rate limiting parameters and gateway registration information. The gateway registration information includes the number of gateways.
[0052] In this embodiment, an interface call request can be understood as a request issued by a user to invoke a specific business service. The target gateway can be understood as the gateway used to forward the interface call request, and the target gateway is determined based on the polling status of reverse proxy server 1. Forwarding conditions can be understood as conditions used to determine whether a gateway can perform request forwarding; for example, a gateway successfully obtaining a token from the token bucket. Interface rate limiting parameters can be understood as pre-configured parameters for rate limiting the API interface; these parameters are configured as the traffic data per unit time, such as 200 requests / second. Each interface type has its corresponding interface rate limiting parameters. Gateway registration information can be understood as the relevant registration information of the gateways included in the gateway cluster; for example, it may include the number of gateways in the gateway cluster, as well as information such as the processor performance, memory, and load configuration of each gateway.
[0053] Specifically, Nginx is deployed as a reverse proxy service, and reverse proxy server 1 is set up. Reverse proxy server 1 is configured for round-robin forwarding to ensure that the traffic to each downstream gateway is the same. Therefore, when reverse proxy server 1 receives a user's API call request, it forwards the API call request in round-robin to the target gateway in gateway cluster 2 that is related to the current round-robin status. For example, if reverse proxy server 1 receives 5 API call requests in sequence, and 4 gateways are deployed in the gateway cluster, API call request 1 is forwarded to gateway 1. In this forwarding process, gateway 1 is the target gateway. The forwarding process for other API call requests is similar: API call request 2 is forwarded to gateway 2, API call request 3 to gateway 3, API call request 4 to gateway 4, and API call request 5 to gateway 1, thus achieving round-robin forwarding. The rate limiting management center 3 pre-configures API rate limiting parameters and gateway registration information. The gateway registration information includes the number of gateways. When it receives a request from gateway cluster 2, it sends the API rate limiting parameters and gateway registration information to the gateway cluster for storage and calculation of single-machine rate limiting. After receiving an interface call request, the target gateway in gateway cluster 2 calls the token bucket corresponding to the interface type of the interface call request according to the single-machine rate limiting policy. If a token can be obtained from the token bucket, the interface call request is forwarded to the business server 4. If a token cannot be obtained from the token bucket, an interface request failure notification is sent to the user through the reverse proxy server.
[0054] This embodiment provides a gateway rate limiting system, comprising: a reverse proxy server, a gateway cluster, a rate limiting management center, and a business server. The gateway cluster is connected to the reverse proxy server, the rate limiting management center, and the business server, respectively. The reverse proxy server, upon receiving a user's interface call request, polls and forwards the request to the target gateway in the gateway cluster. The gateway cluster, when a forwarding condition is met, forwards the interface call request to the business server; the forwarding condition is related to interface rate limiting parameters and the number of gateways. The rate limiting management center configures interface rate limiting parameters and gateway registration information, including the number of gateways. This technical solution achieves gateway rate limiting, ensuring efficient and stable service.
[0055] As a first optional embodiment of this example, the target gateway is specifically used for:
[0056] a1. Determine the interface type of the interface call request, and call the token bucket corresponding to the interface type. The number of tokens in the token bucket is related to the interface rate limiting parameters and the number of gateways.
[0057] In this embodiment, the interface type can be understood as different business interface types, and different interface call requests (API requests) will correspond to different interface types. The token bucket is an algorithm widely used in network traffic control, rate limiting, and bandwidth management. It controls the forwarding of interface call requests and limits average traffic by dynamically issuing tokens.
[0058] Specifically, each gateway has its corresponding token bucket, and each interface type also has its corresponding token bucket. After receiving an interface call request, the target gateway first determines the interface type of the request and retrieves the token bucket corresponding to that interface type from its own token bucket in memory. For a given interface type, the number of tokens in the token bucket is the result of dividing the interface rate limiting parameter for that type by the number of gateways. If the result only contains the quotient, the number of tokens is the quotient; if the result contains both the quotient and the remainder, the number of tokens is the sum of the quotient and the remainder.
[0059] b1. If the token is successfully obtained from the token bucket, the API call request is forwarded to the business server; otherwise, an API call failure notification is generated and sent back to the user through the reverse proxy server.
[0060] In this embodiment, the interface call failure notification can be understood as a notification used to inform the user that the interface call request they sent failed.
[0061] Specifically, the RateLimiter.tryAcquire() method is called to attempt to acquire a token from the token bucket. If successful, the traffic is forwarded to the downstream service, that is, the API call request is forwarded to the business server. If it fails, it means that the current concurrency has exceeded the rate limiting configuration corresponding to the single-machine rate limiting parameter. The API call request needs to be intercepted and an API call failure notification indicating an abnormal request should be sent to the reverse proxy server. The reverse proxy server then sends the API call failure notification back to the corresponding user.
[0062] As a second optional embodiment of this example, Figure 2 This is a schematic diagram of another gateway rate limiting system provided in Embodiment 1 of the present invention, as shown below. Figure 2 As shown: The rate limiting management center 3 includes a configuration center 31 and a registration center 32.
[0063] Configuration center 31 is used to configure the first interface rate limiting parameters for each interface type, and after receiving the rate limiting parameter acquisition request sent by gateway cluster 2, it sends the first interface rate limiting parameters to gateway cluster 2.
[0064] Registration center 32 is used to register gateways in gateway cluster 2, and after receiving the registration information retrieval request sent by gateway cluster 2, it sends the first gateway registration information to gateway cluster 2.
[0065] In this embodiment, the first interface rate limiting parameter can be understood as a new interface rate limiting parameter configured by configuration center 3. The rate limiting parameter retrieval request can be understood as a request for gateway cluster 2 to pull interface rate limiting parameters from configuration center 31. The registration information retrieval request can be understood as a request for gateway cluster 2 to pull gateway registration information from registration center 32. The first gateway registration information can be understood as new gateway registration information generated by registration center 32, including at least the number of gateways in gateway cluster 2.
[0066] Specifically, configuration center 31 is used to configure interface rate limiting parameters for each interface type; each interface type can be configured with corresponding interface rate limiting parameters. A Nacos registry center 32 is deployed as the microservice registry center, which can register new gateways in gateway cluster 2. Configuration center 31 configures the first interface rate limiting parameters for each interface type, and upon receiving a rate limiting parameter retrieval request from gateway cluster 2, it sends the first interface rate limiting parameters to gateway cluster 2 so that gateway cluster 2 can calculate single-machine rate limiting based on the first interface rate limiting parameters. Registry center 32, in response to a gateway registration request from the gateway cluster or in response to an administrator's operation, registers new gateways in gateway cluster 2, and upon receiving a registration information retrieval request from gateway cluster 2, sends the first gateway registration information to gateway cluster 2.
[0067] As a third optional embodiment of this example, gateway cluster 2 is specifically used for:
[0068] a2. Obtain the first interface rate limiting parameters and the first gateway registration information of the gateway cluster corresponding to different interface types from the rate limiting management center, and store the first interface rate limiting parameters and the first gateway registration information as the second interface rate limiting parameters and the second gateway registration information in memory respectively.
[0069] In this embodiment, the second interface rate limiting parameter can be understood as the interface rate limiting parameter stored in memory. The second gateway registration information can be understood as the gateway registration information stored in memory.
[0070] Specifically, a request to obtain rate limiting parameters is initiated to the configuration center in the rate limiting management center to retrieve the rate limiting parameters for the first interface corresponding to different interface types. A request to obtain registration information is also initiated to the registration center in the rate limiting management center to retrieve the registration information for the first gateway of the gateway cluster. The rate limiting parameters for the first interface from the configuration center are stored locally as the rate limiting parameters for the second interface, and the registration information for the first gateway from the registration center is stored locally as the registration information for the second gateway.
[0071] b2. Based on the second interface rate limiting parameters and the number of second gateways in the second gateway registration information, determine the second stand-alone rate limiting parameters for each gateway under different interface types.
[0072] In this embodiment, the number of second gateways can be understood as the number of gateways in the second gateway registration information. The second single-machine rate limiting parameter can be understood as the gateway single-machine rate limiting parameter calculated after the interface rate limiting parameters are first pulled from the configuration center, which is calculated by dividing the second interface rate limiting parameter by the number of second gateways.
[0073] Specifically, for the second interface rate limiting parameter for different interface types, the second interface rate limiting parameter is divided by the number of second gateways in the second gateway registration information. If the calculation result only contains the quotient, then the second single-machine rate limiting parameter is the quotient. If the calculation result contains both the quotient and the remainder, then the second single-machine rate limiting parameter is the sum of the quotient and the remainder.
[0074] c2. Create a token bucket with the corresponding number of tokens based on the second single-machine rate limiting parameter, and store the token bucket in memory.
[0075] In this embodiment, a token bucket is established, the second single-machine rate limiting parameter is used as the number of tokens in the token bucket, and the token bucket is stored in memory.
[0076] For example, the gateway cluster instance is implemented based on the gateway (Spring Cloud Gateway). After the instance starts, it calls the interface of the configuration center to obtain the API rate limiting configuration and calls the interface of the registry center Nacos to obtain the number of gateway cluster instances. For example, if the total rate limiting configuration of a certain API is 200 and the number of gateway instances is 4, the single-machine rate limiting quantity is calculated to be 50. The token bucket rate limiting tool (Guava RateLimiter) framework is used to create a token bucket instance with a token quantity of 50 and store it in the local memory MAP.
[0077] As a fourth optional embodiment of this example, gateway cluster 2 is also used for:
[0078] a3. Obtain the first interface rate limiting parameters and the first gateway registration information from the rate limiting management center according to the set period.
[0079] In this embodiment, the set period can be understood as the pre-set period for the gateway cluster to access the rate limiting management center. Different access periods can be set for the configuration center and the registration center in the rate limiting management center.
[0080] Specifically, after the system first accesses the configuration center and registration center in the rate limiting management center and obtains the first interface rate limiting parameters and the first gateway registration information, it cyclically retrieves new first interface rate limiting parameters and first gateway registration information from the rate limiting management center at a set periodic interval to update the memory of the gateway cluster, and then updates the single-machine rate limiting parameters of each gateway.
[0081] b3. Determine the first single-machine rate limiting parameter for each gateway under different interface types based on the first interface rate limiting parameter and the number of first gateways in the first gateway registration information.
[0082] In this embodiment, the first single-machine rate limiting parameter can be understood as the gateway single-machine rate limiting parameter calculated after pulling the interface rate limiting parameters from the configuration center starting from the second cycle. It is calculated by dividing the first interface rate limiting parameter by the number of first gateways.
[0083] Specifically, to ensure the implementation and configuration updates of gateway rate limiting, it is necessary to periodically obtain new first interface rate limiting parameters and first gateway registration information. Correspondingly, the corresponding single-machine rate limiting parameters also need to be recalculated. Therefore, for the first interface rate limiting parameters of different interface types, based on the first interface rate limiting parameters and the number of first gateways in the first gateway registration information, the first interface rate limiting parameter is divided by the number of first gateways. If the calculation result only contains the quotient, then the first single-machine rate limiting parameter is the quotient; if the calculation result contains both the quotient and the remainder, then the first single-machine rate limiting parameter is the sum of the quotient and the remainder.
[0084] c3. Compare the first single-machine current limiting parameters with the second single-machine current limiting parameters.
[0085] In this embodiment, it is determined whether the currently deployed single-machine rate limiting parameters in memory no longer meet the real-time rate limiting requirements. Therefore, the first single-machine rate limiting parameter and the second single-machine rate limiting parameter need to be compared to determine whether the single-machine rate limiting parameter needs to be updated. If the first single-machine rate limiting parameter and the second single-machine rate limiting parameter are consistent, no processing is performed, and the existing token bucket remains unchanged.
[0086] d3. If the comparison results are inconsistent, update the token bucket based on the first single-machine rate limiting parameters.
[0087] In this embodiment, if the comparison results of the first single-machine rate limiting parameter and the second single-machine rate limiting parameter are inconsistent, it indicates that the single-machine rate limiting of the gateway has changed. Therefore, the token bucket is updated based on the first single-machine rate limiting parameter. Updating the token bucket based on the first single-machine rate limiting parameter can be either creating a new token bucket to replace the current token bucket, or updating the number of tokens in the token bucket. This embodiment does not limit this.
[0088] For example, the gateway periodically obtains the rate limiting configuration (interface rate limiting parameters) and the number of instances (number of gateways) from the configuration center and the registration center to calculate the rate limiting quantity per machine. It compares the token bucket RateLimiter configuration in the local memory MAP. If the rate limiting quantity per machine changes, for example, if the number of gateway instances increases from 4 to 5, the calculated rate limiting quantity per machine changes from 50 to 40. Then, a new token bucket RateLimiter is created to replace the current token bucket RateLimiter.
[0089] As a fifth optional embodiment of this example, gateway cluster 2 is specifically used for:
[0090] When the load pressure of the gateway is detected to meet the expansion conditions, a gateway registration request is sent to the registry center in the rate limiting management center to request the registry center to register the new gateway.
[0091] In this embodiment, the expansion condition can be understood as a judgment condition used by the gateway cluster's central processing unit to alleviate the gateway load pressure when it detects that the gateway load pressure is too high. The gateway registration request can be understood as a request to the registration center to register a new gateway in the gateway cluster.
[0092] Specifically, the central processing unit of the gateway cluster monitors the operating status of the gateways in the cluster in real time. If the load pressure of the gateway is detected to be greater than a certain threshold, it is determined that the expansion conditions are met, a gateway registration request is generated and sent to the registration center in the rate limiting management center to request the registration center to register a new gateway and reduce the operating pressure of the existing gateways in the cluster.
[0093] This invention provides a gateway rate limiting system, which develops a distributed rate limiting method based on a gateway cluster. This system can configure differentiated interface rate limiting parameters for different APIs. The gateway cluster periodically obtains the interface rate limiting parameters from the configuration center and the number of gateways from the registration center, calculates the single-machine rate limiting parameters, and caches them in memory. When a gateway receives an API request, it only needs to retrieve the local memory rate limiting configuration, calculate whether it exceeds the single-machine rate limiting threshold, and thus control the flow of traffic. In this technical solution, the gateway cluster is not strongly coupled with the configuration center and registration center. Temporary unavailability of the configuration center and registration center will not affect the gateway's acquisition of local memory rate limiting parameters, improving the robustness of the architecture. The single-machine rate limiting parameters are automatically calculated based on the number of gateways in the cluster, ensuring the accuracy of the total rate limiting count even when the gateway cluster is scaled up or down. Distributed rate limiting essentially transforms into single-machine rate limiting. The calculation of API rate limiting does not rely on a common counting module, thus improving the architecture's fault tolerance. Furthermore, since the calculation only needs to be performed in the gateway's local memory, it exhibits excellent performance in high-concurrency scenarios.
[0094] Example 2
[0095] Figure 3 This is a flowchart of a gateway rate limiting method provided in Embodiment 2 of the present invention, which can be applied to the situation of gateway rate limiting for the device under test. The method is executed by the gateway rate limiting system.
[0096] like Figure 3 As shown, the method includes:
[0097] S101. When a user's interface call request is received through the reverse proxy server, the interface call request is sent to the target gateway in the gateway cluster in a round-robin fashion.
[0098] In this embodiment, when the reverse proxy server receives an API call request from a user, it round-robin the API call request to the target gateway in the gateway cluster that is related to the current round-robin status. For example, if reverse proxy server 1 receives 5 API call requests in sequence, and 4 gateways are deployed in the gateway cluster, API call request 1 will be sent to gateway 1. In this sending process, gateway 1 is the target gateway. The sending process for other API call requests is similar: API call request 2 will be sent to gateway 2, API call request 3 to gateway 3, API call request 4 to gateway 4, and API call request 5 to gateway 1, thus achieving round-robin sending.
[0099] S102. Configure interface rate limiting parameters and gateway registration information through the rate limiting management center. The gateway registration information includes the number of gateways.
[0100] In this embodiment, the rate limiting management center pre-configures interface rate limiting parameters and gateway registration information. The gateway registration information includes the number of gateways. When it receives a request from the gateway cluster, it sends the interface rate limiting parameters and gateway registration information to the gateway cluster for storage and calculation of single-machine rate limiting.
[0101] S103. Through the gateway cluster, when the forwarding conditions are met, the interface call request is forwarded to the business server. The forwarding conditions are related to the interface rate limiting parameters and the number of gateways.
[0102] In this embodiment, after receiving an interface call request, the target gateway in the gateway cluster calls the token bucket corresponding to the interface type of the interface call request according to the single-machine rate limiting policy. If a token can be obtained from the token bucket, the interface call request is forwarded to the business server. If a token cannot be obtained from the token bucket, the interface request failure notification is sent to the user through the reverse proxy server.
[0103] This embodiment provides a gateway rate limiting method, which includes: using a reverse proxy server, when receiving a user's interface call request, to round-robin distribute the request to target gateways in the gateway cluster; configuring interface rate limiting parameters and gateway registration information, including the number of gateways, through a rate limiting management center; and forwarding the interface call request to the business server through the gateway cluster when forwarding conditions are met, with the forwarding conditions related to the interface rate limiting parameters and the number of gateways. This technical solution achieves gateway rate limiting, ensuring efficient and stable service.
[0104] As a first optional embodiment of this example, the interface rate limiting parameters and gateway registration information are configured through the rate limiting management center, including:
[0105] S1021. Configure the first interface rate limiting parameters for each interface type through the configuration center in the rate limiting management center, and send the first interface rate limiting parameters to the gateway cluster after receiving the rate limiting parameter acquisition request sent by the gateway cluster.
[0106] S1022. Register the gateway in the gateway cluster through the registration center in the rate limiting management center, and send the first gateway registration information to the gateway cluster after receiving the registration information acquisition request sent by the gateway cluster.
[0107] As a second optional embodiment of this example, when the forwarding conditions are met, the interface call request is forwarded to the business server, including:
[0108] S1031, the target gateway in the gateway cluster determines the interface type of the interface call request, calls the token bucket corresponding to the interface type, and the number of tokens in the token bucket is related to the interface rate limiting parameters and the number of gateways;
[0109] S1032. If the token is successfully obtained from the token bucket, the API call request is forwarded to the business server; otherwise, an API call failure notification is generated and sent back to the user through the reverse proxy server.
[0110] As a third optional embodiment of this example, the method further includes:
[0111] S1033. Obtain the first interface rate limiting parameters corresponding to different interface types and the first gateway registration information of the gateway cluster from the rate limiting management center through the gateway cluster, and store the first interface rate limiting parameters and the first gateway registration information as the second interface rate limiting parameters and the second gateway registration information in memory respectively.
[0112] S1034. Through the gateway cluster, determine the second single-machine rate limiting parameters of each gateway under different interface types based on the second interface rate limiting parameters and the number of second gateways in the second gateway registration information.
[0113] S1035. Through the gateway cluster, create a token bucket with the corresponding number of tokens based on the second single-machine rate limiting parameters, and store the token bucket in memory.
[0114] Furthermore, the method also includes:
[0115] S1036. Obtain the first interface rate limiting parameters and the first gateway registration information from the rate limiting management center through the gateway cluster at a set period.
[0116] S1037. Through the gateway cluster, determine the first single-machine rate limiting parameter of each gateway under different interface types based on the first interface rate limiting parameter and the number of first gateways in the first gateway registration information;
[0117] S1038. Compare the first single-machine rate limiting parameter and the second single-machine rate limiting parameter through the gateway cluster;
[0118] S1039. If the comparison results are inconsistent through the gateway cluster, update the token bucket based on the first single-machine rate limiting parameters.
[0119] The first single-machine rate limiting parameter is calculated by dividing the first interface rate limiting parameter by the number of first gateways, and the second single-machine rate limiting parameter is calculated by dividing the second interface rate limiting parameter by the number of second gateways.
[0120] As a fourth optional embodiment of this example, the method further includes:
[0121] When the gateway cluster detects that the load pressure of the gateway meets the expansion conditions, it sends a gateway registration request to the registry center in the rate limiting management center to request the registry center to register a new gateway.
[0122] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0123] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A gateway rate limiting system, characterized in that, include: The system includes a reverse proxy server, a gateway cluster, a rate limiting management center, and a business server, with the gateway cluster connected to the reverse proxy server, the rate limiting management center, and the business server, respectively. The reverse proxy server is used to, when receiving a user's interface call request, poll and distribute the interface call request to the target gateway in the gateway cluster. The gateway cluster is used to forward the interface call request to the business server when the forwarding conditions are met. The forwarding conditions are related to the interface rate limiting parameters and the number of gateways. The rate limiting management center is used to configure interface rate limiting parameters and gateway registration information, including the number of gateways.
2. The system according to claim 1, characterized in that, The target gateway is specifically used for: Determine the interface type of the interface call request, and invoke the token bucket corresponding to the interface type. The number of tokens in the token bucket is related to the interface rate limiting parameters and the number of gateways. If a token is successfully obtained from the token bucket, the interface call request is forwarded to the business server; otherwise, an interface call failure notification is generated and sent back to the user through the reverse proxy server.
3. The system according to claim 1, characterized in that, The rate limiting management center includes a configuration center and a registration center. The configuration center is used to configure the first interface rate limiting parameters for each interface type, and after receiving the rate limiting parameter acquisition request sent by the gateway cluster, it sends the first interface rate limiting parameters to the gateway cluster. The registration center is used to register gateways in the gateway cluster, and after receiving a registration information retrieval request from the gateway cluster, sends the first gateway registration information to the gateway cluster.
4. The system according to claim 1, characterized in that, The gateway cluster is specifically used for: Obtain the first interface rate limiting parameters corresponding to different interface types and the first gateway registration information of the gateway cluster from the rate limiting management center, and store the first interface rate limiting parameters and the first gateway registration information as the second interface rate limiting parameters and the second gateway registration information in memory respectively; Based on the second interface rate limiting parameters and the number of second gateways in the second gateway registration information, determine the second single-machine rate limiting parameters for each gateway under different interface types; Based on the second single-machine rate limiting parameter, a token bucket with a corresponding number of tokens is created, and the token bucket is stored in memory.
5. The system according to claim 4, characterized in that, The gateway cluster is also used for: Obtain the first interface rate limiting parameters and the first gateway registration information from the rate limiting management center according to the set cycle; The first single-machine rate limiting parameter for each gateway under different interface types is determined based on the first interface rate limiting parameter and the number of first gateways in the first gateway registration information. Compare the first single-machine current limiting parameter with the second single-machine current limiting parameter; If the comparison results are inconsistent, the token bucket is updated based on the first single-machine rate limiting parameters.
6. The system according to claim 1, characterized in that, The gateway cluster is specifically used for: When the load pressure of the gateway is detected to meet the expansion conditions, a gateway registration request is sent to the registration center in the rate limiting management center to request the registration center to register a new gateway.
7. The system according to claim 5, characterized in that, The first single-machine rate limiting parameter is calculated by dividing the first interface rate limiting parameter by the number of first gateways, and the second single-machine rate limiting parameter is calculated by dividing the second interface rate limiting parameter by the number of second gateways.
8. A gateway rate limiting method, characterized in that, The gateway rate limiting system applied to any one of claims 1-7 includes: When a user's API call request is received via a reverse proxy server, the API call request is forwarded to the target gateway in the gateway cluster in a round-robin fashion. Configure interface rate limiting parameters and gateway registration information through the rate limiting management center, wherein the gateway registration information includes the number of gateways; The gateway cluster forwards the interface call request to the business server when the forwarding conditions are met. The forwarding conditions are related to the interface rate limiting parameters and the number of gateways.
9. The method according to claim 8, characterized in that, The step of forwarding the interface call request to the business server when the forwarding conditions are met includes: The target gateway in the gateway cluster determines the interface type of the interface call request, and calls the token bucket corresponding to the interface type. The number of tokens in the token bucket is related to the interface rate limiting parameters and the number of gateways. If a token is successfully obtained from the token bucket, the interface call request is forwarded to the business server; otherwise, an interface call failure notification is generated and sent back to the user through the reverse proxy server.
10. The method according to claim 8, characterized in that, The process of configuring interface rate limiting parameters and gateway registration information through the rate limiting management center includes: Configure the first interface rate limiting parameters for each interface type through the configuration center in the rate limiting management center, and send the first interface rate limiting parameters to the gateway cluster after receiving the rate limiting parameter acquisition request sent by the gateway cluster. Register the gateways in the gateway cluster through the registration center in the rate limiting management center, and send the first gateway registration information to the gateway cluster after receiving the registration information acquisition request sent by the gateway cluster.