Service flow limiting method and device, storage medium and electronic device

CN116962030BActive Publication Date: 2026-08-28INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310842334.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-10
Publication Date
2026-08-28
Estimated Expiration
2043-07-10

AI Technical Summary

Technical Problem

[0004]本申请的主要目的在于提供一种服务限流方法、装置、存储介质及电子设备,以解决相关技术中应用程序的单个接口访问量过大导致服务异常的问题

Benefits of technology

[0013]通过本申请,采用以下步骤:接收客户端对目标应用程序的访问请求,解析访问请求,得到客户端的客户端IP、客户端访问目标应用程序的目标接口,其中,目标应用程序包含多个接口;判断目标接口的限流名单中是否包含客户端IP;在目标接口的限流名单中不包含客户端IP的情况下,获取目标接口的预设限流策略,其中,预设限流策略至少包括以下之一:限流频率和最大线程数,限流频率是预设时间段内限制访问目标接口的次数,最大线程数是目标接口同时处理访问请求的最大数量;基于预设限流策略执行对访问请求的限流操作,解决了相关技术中应用程序的单个接口访问量过大导致服务异常的问题。通过限流名单、限流频率和最大线程数等对访问目标接口的访问请求进行限流,从而实现针对应用程序中的单个接口的限流,进而达到了避免单个接口访问量过大导致服务异常的效果。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116962030B_ABST
    Figure CN116962030B_ABST
Patent Text Reader

Abstract

The application discloses a service flow limiting method and device, a storage medium and an electronic device. It relates to the field of information security, and the method comprises the following steps: receiving an access request of a client to a target application program, analyzing the access request to obtain the client IP of the client and a target interface accessed by the client to the target application program; determining whether the client IP is contained in a flow limiting list of the target interface; in the case that the client IP is not contained in the flow limiting list of the target interface, obtaining a preset flow limiting strategy of the target interface, wherein the preset flow limiting strategy comprises at least one of the following: a flow limiting frequency and a maximum thread number, the flow limiting frequency is the number of times of limiting access to the target interface within a preset time period, and the maximum thread number is the maximum number of access requests processed by the target interface at the same time; and performing a flow limiting operation on the access request based on the preset flow limiting strategy. Through the application, the problem that the service is abnormal due to the excessive access volume of a single interface of an application program in the related art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of information security, and more specifically, to a service rate limiting method, apparatus, storage medium, and electronic device. Background Technology

[0002] As web applications experience increasingly high traffic, high concurrency access to individual web application interfaces can lead to service disruptions. Current rate limiting solutions for web applications rely on a coarse-grained, overall rate limiting approach based on nginx (engine x, a high-performance HTTP and reverse proxy web server). However, this overall rate limiting method still cannot completely prevent service disruptions caused by excessive access to individual interfaces within a web application.

[0003] There is currently no effective solution to the problem of excessive access to a single interface of an application causing service anomalies in related technologies. Summary of the Invention

[0004] The main objective of this application is to provide a service rate limiting method, apparatus, storage medium, and electronic device to solve the problem of service anomalies caused by excessive access to a single interface of an application in related technologies.

[0005] To achieve the above objectives, according to one aspect of this application, a service rate limiting method is provided. The method includes: receiving a client's access request to a target application; parsing the access request to obtain the client's IP address and the target interface of the target application accessed by the client, wherein the target application contains multiple interfaces; determining whether the rate limiting list of the target interface contains the client's IP address; if the rate limiting list of the target interface does not contain the client's IP address, obtaining a preset rate limiting policy for the target interface, wherein the preset rate limiting policy includes at least one of the following: rate limiting frequency and maximum number of threads, wherein the rate limiting frequency is the number of times access to the target interface is restricted within a preset time period, and the maximum number of threads is the maximum number of access requests that the target interface can process simultaneously; and performing rate limiting operations on the access requests based on the preset rate limiting policy.

[0006] Optionally, before performing rate limiting on access requests based on a preset rate limiting policy, the method further includes: determining the number of rate limiting policies currently being executed by the target application, and determining whether the number of rate limiting policies is greater than or equal to a rate limiting policy number threshold; if the number of rate limiting policies is less than the rate limiting policy number threshold, determining the waiting time for executing the preset rate limiting policy; determining whether the waiting time is greater than or equal to a waiting time threshold; and if the waiting time is less than the waiting time threshold, performing the step of performing rate limiting on access requests based on the preset rate limiting policy.

[0007] Optionally, after determining whether the number of rate limiting policies is greater than or equal to the rate limiting policy number threshold, the method further includes: if the number of rate limiting policies is greater than or equal to the rate limiting policy number threshold, returning a first prompt message to the client, wherein the first prompt message is used to indicate that the server of the target application is busy; after determining whether the waiting time is greater than or equal to the waiting time threshold, the method further includes: if the waiting time is greater than or equal to the waiting time threshold, returning a first prompt message to the client.

[0008] Optionally, the rate limiting frequency is determined in the following way: the target level of the target interface is determined, and the rate limiting frequency associated with the target level is determined from the preset association table based on the target level. The preset association table contains multiple associations, and each association table contains an interface level and a rate limiting frequency. The rate limiting frequency associated with the target level is determined as the rate limiting frequency in the preset rate limiting strategy.

[0009] Optionally, when the preset rate limiting strategy includes a rate limiting frequency and a maximum number of threads, the rate limiting operation on access requests based on the preset rate limiting strategy includes: determining the number of access requests received by the target interface within a preset time period, calculating the ratio of the number to the preset time period to obtain the interface access frequency; determining the number of access requests that the target interface is expected to execute at that time to obtain the number to be executed; determining whether the interface access frequency is greater than or equal to the rate limiting frequency; if the interface access frequency is greater than or equal to the rate limiting frequency, adding the access request to the queue of interfaces to be accessed, wherein the queue of interfaces to be accessed contains all access requests waiting to access the target interface; if the interface access frequency is less than the rate limiting frequency, determining whether the number to be executed is greater than or equal to the maximum number of threads; if the number to be executed is greater than or equal to the maximum number of threads, adding the access request to the queue to be processed, wherein the queue to be processed contains all access requests that have accessed the target interface and are waiting to be processed; if the number to be executed is less than the maximum number of threads, processing the access request.

[0010] Optionally, before determining whether the rate limiting list of the target interface contains the client IP, the method further includes: determining the historical access volume of each client IP to the target interface in the same batch; if the historical access volume in the same batch is greater than or equal to the access volume threshold of the target interface, adding the client IP to the rate limiting list; after determining whether the rate limiting list of the target interface contains the client IP, the method further includes: if the rate limiting list of the target interface contains the client IP, returning a second prompt message to the client, wherein the second prompt message is used to indicate that the target application denies the client's access.

[0011] Optionally, before parsing the access request, the method further includes: determining the total number of access requests for all interfaces of the target application; determining whether the total number of access requests is greater than or equal to a total number of access requests threshold; if the total number of access requests is greater than or equal to the total number of access requests threshold, returning a first prompt message to the client; if the total number of access requests is less than the total number of access requests threshold, performing the step of parsing the access request.

[0012] To achieve the above objectives, according to another aspect of this application, a service rate limiting device is provided. The device includes: a receiving unit, configured to receive a client's access request to a target application, parse the access request, and obtain the client's IP address and the target interface of the target application accessed by the client, wherein the target application includes multiple interfaces; a first judging unit, configured to judge whether the rate limiting list of the target interface contains the client's IP address; an obtaining unit, configured to obtain a preset rate limiting policy for the target interface if the client's IP address is not included in the rate limiting list of the target interface, wherein the preset rate limiting policy includes at least one of the following: rate limiting frequency and maximum number of threads, wherein the rate limiting frequency is the number of times access to the target interface is restricted within a preset time period, and the maximum number of threads is the maximum number of access requests that the target interface can process simultaneously; and a first execution unit, configured to perform rate limiting operations on the access requests based on the preset rate limiting policy.

[0013] This application employs the following steps: receiving a client's access request to a target application; parsing the access request to obtain the client's IP address and the target interface of the target application, wherein the target application contains multiple interfaces; determining whether the client's IP address is included in the rate-limiting list of the target interface; if the client's IP address is not included in the rate-limiting list of the target interface, obtaining the preset rate-limiting policy of the target interface, wherein the preset rate-limiting policy includes at least one of the following: rate-limiting frequency and maximum number of threads, where the rate-limiting frequency is the number of times access to the target interface is restricted within a preset time period, and the maximum number of threads is the maximum number of access requests that the target interface can handle simultaneously; and performing rate-limiting operations on the access requests based on the preset rate-limiting policy, thus solving the problem of excessive access to a single interface of an application causing service abnormalities in related technologies. By rate-limiting access requests to the target interface through rate-limiting lists, rate-limiting frequencies, and maximum number of threads, rate-limiting is achieved for a single interface in the application, thereby preventing excessive access to a single interface from causing service abnormalities. Attached Figure Description

[0014] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:

[0015] Figure 1This is a flowchart of a service rate limiting method provided according to an embodiment of this application;

[0016] Figure 2 This is a schematic diagram of a service rate limiting system provided according to an embodiment of this application;

[0017] Figure 3 This is a flowchart of an optional service rate limiting method provided according to an embodiment of this application;

[0018] Figure 4 This is a schematic diagram of a service rate limiting device provided according to an embodiment of this application;

[0019] Figure 5 This is a schematic diagram of an electronic device provided according to an embodiment of this application. Detailed Implementation

[0020] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.

[0021] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.

[0022] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application 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 for the embodiments of this application 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.

[0023] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data used for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.

[0024] For ease of description, the following explains some of the nouns or terms used in the embodiments of this application:

[0025] Javaweb: Using Java technology to solve technical stack problems in related Internet fields.

[0026] The present invention will now be described in conjunction with preferred implementation steps. Figure 1 This is a flowchart of a service rate limiting method provided according to an embodiment of this application, such as... Figure 1 As shown, the method includes the following steps:

[0027] Step S101: Receive the client's access request to the target application, parse the access request, and obtain the client's client IP and the target interface of the target application to which the client accesses. The target application contains multiple interfaces.

[0028] Specifically, the client can be any device capable of logging into a webpage, such as a mobile phone, computer, or tablet. The target application is a web application, which users access by visiting a webpage. The target application receives a large number of client access requests daily. Since the target application's server has a limited capacity, it's necessary to rate-limit these client requests. Different interfaces within the target application handle different numbers of requests, which can lead to service disruptions due to excessive traffic to a particular interface. By receiving client access requests to the target application, the system parses the requests, obtains the client's IP address, and determines the target interface the client is accessing.

[0029] Step S102: Determine whether the rate limiting list of the target interface contains the client IP.

[0030] Specifically, each interface has a rate-limiting list. When a client's access request is received by the target application, the request is intercepted by a filter deployed on the target application's server. Then, the rate-limiting list information of the target interface is queried. The rate-limiting list contains a storage table of rate-limiting service interface information. If the client IP is in the rate-limiting list, the access request is directly intercepted, restricting the client's access. If the client IP is not in the rate-limiting list, the access request is processed normally.

[0031] Step S103: If the target interface does not contain the client IP in the rate limiting list, obtain the preset rate limiting policy of the target interface. The preset rate limiting policy includes at least one of the following: rate limiting frequency and maximum number of threads. The rate limiting frequency is the number of times the target interface is restricted within a preset time period, and the maximum number of threads is the maximum number of access requests that the target interface can process at the same time.

[0032] Specifically, if the target interface's rate-limiting list does not contain the client IP, it indicates that there are no large-volume accesses in the client IP's historical access records. However, the target interface may currently be handling a large number of access requests. In this case, it is also necessary to obtain the target interface's preset rate-limiting policy and process access requests based on the preset rate-limiting policy. The preset rate-limiting policy is obtained by accessing the rate-limiting service interface list information storage table. The rate-limiting service interface list information storage table records the rate-limiting control parameters for each interface, that is, each interface corresponds to a rate-limiting policy. The rate-limiting policy includes at least one of the following: rate-limiting frequency and maximum number of threads, and may also include rate-limiting wait timeout time, etc.

[0033] Step S104: Perform rate limiting operation on access requests based on the preset rate limiting policy.

[0034] Specifically, access requests are rate-limited based on preset rate-limiting strategies, such as the rate-limiting frequency and maximum thread count. For example, if the interface access frequency is greater than or equal to the rate-limiting frequency, the access request is added to the queue of interfaces to be accessed. If the number of access requests to be executed is greater than or equal to the maximum thread count, the access request is added to the processing queue, waiting for the target interface to have available threads before processing the access requests in the processing queue. After the rate-limiting operation is completed, the processing result is fed back to the client.

[0035] The service rate limiting method provided in this application receives client access requests to a target application, parses the access requests to obtain the client's IP address and the target interface of the target application, where the target application contains multiple interfaces. It then determines whether the client's IP address is included in the rate limiting list of the target interface. If the client's IP address is not included in the rate limiting list, it obtains a preset rate limiting policy for the target interface. This preset rate limiting policy includes at least one of the following: rate limiting frequency and maximum number of threads. The rate limiting frequency is the number of times access to the target interface is restricted within a preset time period, and the maximum number of threads is the maximum number of access requests that the target interface can process simultaneously. Based on the preset rate limiting policy, it performs rate limiting operations on the access requests, solving the problem in related technologies where excessive access to a single interface of an application leads to service abnormalities. By rate limiting access requests to the target interface through rate limiting lists, rate limiting frequencies, and maximum number of threads, it achieves rate limiting for a single interface in the application, thereby preventing excessive access to a single interface from causing service abnormalities.

[0036] Optionally, in the service rate limiting method provided in this application embodiment, before performing rate limiting operations on access requests based on the preset rate limiting policy, the method further includes: determining the number of rate limiting policies currently being executed by the target application, and determining whether the number of rate limiting policies is greater than or equal to the rate limiting policy number threshold; if the number of rate limiting policies is less than the rate limiting policy number threshold, determining the waiting time for executing the preset rate limiting policy; determining whether the waiting time is greater than or equal to the waiting time threshold; and if the waiting time is less than the waiting time threshold, performing the step of performing rate limiting operations on access requests based on the preset rate limiting policy.

[0037] Specifically, since each interface has a rate-limiting policy, the target application may have multiple rate-limiting policies executing simultaneously. If too many rate-limiting policies execute concurrently, it may affect other services of the target application. Therefore, a rate-limiting policy quantity threshold is used to limit the number of rate-limiting policies executed. If the number of rate-limiting policies is less than the threshold, the waiting time for the preset rate-limiting policy to be executed needs to be determined. If the waiting time is less than the waiting time threshold, the step of performing rate-limiting operations on access requests based on the preset rate-limiting policy is executed. By limiting the execution of preset rate-limiting policies through the rate-limiting policy quantity threshold and the waiting time threshold, the normal service of the target application is not affected by the execution of rate-limiting policies.

[0038] It should be noted that the detailed execution mechanism of the rate limiting policy is as follows: each rate limiting policy corresponds to a newly created token bucket that limits access requests per second to (X) requests. The default size of X is 100. The size of the token bucket is the peak concurrent execution capacity of the rate limiting policy. When processing access requests, if the interface does not require rate limiting, the access request is directly allowed. If the interface requires rate limiting, a token is taken from the token bucket, and the rate limiting policy corresponding to the token is executed. Each token has its own waiting time threshold. If the waiting time for the rate limiting policy execution exceeds the waiting time threshold in the rate limiting service policy information table, or if there are no tokens in the token bucket, the client is returned that the current server is busy and to try again later. Otherwise, the access request is allowed.

[0039] Optionally, in the service rate limiting method provided in the embodiments of this application, after determining whether the number of rate limiting policies is greater than or equal to the rate limiting policy number threshold, the method further includes: if the number of rate limiting policies is greater than or equal to the rate limiting policy number threshold, returning a first prompt message to the client, wherein the first prompt message is used to indicate that the server of the target application is busy; after determining whether the waiting time is greater than or equal to the waiting time threshold, the method further includes: if the waiting time is greater than or equal to the waiting time threshold, returning a first prompt message to the client.

[0040] Specifically, if the number of rate limiting policies is greater than or equal to the rate limiting policy number threshold, it means that multiple interfaces of the target application are currently performing rate limiting operations. To avoid service anomalies, the target application cannot currently execute the preset rate limiting policy. In this case, the first prompt message, such as "The server is currently busy, please try again later," is returned to the client. If the number of rate limiting policies is less than the rate limiting policy number threshold, it means that the target application can currently execute the preset rate limiting policy. However, the target application may not have idle threads to process the preset rate limiting policy. Therefore, the preset rate limiting policy needs to wait for processing. When the waiting time exceeds the waiting time threshold, the first prompt message "The server is currently busy, please try again later" is also returned to the client. By returning the first prompt message to the client, the client is informed of the processing progress of the access request.

[0041] Optionally, in the service rate limiting method provided in this application embodiment, the rate limiting frequency is determined in the following way: determining the target level of the target interface, determining the rate limiting frequency associated with the target level from a preset association table based on the target level, wherein the preset association table contains multiple associations, each association table contains an interface level and a rate limiting frequency; and determining the rate limiting frequency associated with the target level as the rate limiting frequency in the preset rate limiting strategy.

[0042] Specifically, since different interfaces of the target application have different functions and require different client access volumes, a corresponding level is set for each interface, and a rate limiting frequency is set for each level. The higher the average access volume of an interface, the higher the rate limiting frequency is set, thereby ensuring the normal access needs of clients to the interface. Based on the historical average access volume of each interface of the target application, a correlation is established between the level and the rate limiting frequency. For each interface, the specific rate limiting frequency is obtained from a preset correlation table based on the interface level. The corresponding rate limiting frequency is provided to interfaces of different levels through the preset correlation table.

[0043] Rate limiting operations on access requests are performed by using rate limiting frequency and maximum thread count. Optionally, in the service rate limiting method provided in this application embodiment, when the preset rate limiting strategy includes rate limiting frequency and maximum thread count, the rate limiting operation on access requests based on the preset rate limiting strategy includes: determining the number of access requests received by the target interface within a preset time period, calculating the ratio of the number to the preset time period to obtain the interface access frequency; determining the number of access requests that the target interface is expected to execute at the moment to obtain the number to be executed; determining whether the interface access frequency is greater than or equal to the rate limiting frequency; if the interface access frequency is greater than or equal to the rate limiting frequency, adding the access request to the queue of interfaces to be accessed, wherein the queue of interfaces to be accessed contains all access requests waiting to access the target interface; if the interface access frequency is less than the rate limiting frequency, determining whether the number to be executed is greater than or equal to the maximum thread count; if the number to be executed is greater than or equal to the maximum thread count, adding the access request to the queue to be processed, wherein the queue to be processed contains all access requests that have accessed the target interface and are waiting to be processed; if the number to be executed is less than the maximum thread count, processing the access request.

[0044] For example, if the preset time period is 1 second, and the target interface receives 10 access requests within 1 second, then the interface access frequency is 10 times / second. The number of access requests currently awaiting execution on the target interface, i.e., the number to be executed, is 20. If the rate limiting frequency is 5 times / second, and the interface access frequency exceeds the rate limiting frequency, it means that the target interface is currently receiving too many access requests and cannot process them directly. Therefore, the currently received access requests are added to the queue of requests to be accessed. These requests will be processed when the interface access frequency falls below the rate limiting frequency. If the target interface's maximum thread count is 10, meaning it can process 10 access requests simultaneously, and the number of requests to be executed exceeds the maximum thread count, it means the target interface cannot process all current access requests simultaneously. Therefore, these requests are added to the queue of requests to be processed. The access requests in the queue will be processed when the number of requests to be processed is less than the maximum thread count. By using rate limiting frequency and maximum thread count to rate-limit the target interface, service abnormalities caused by excessive access volume on a single interface can be avoided.

[0045] Optionally, in the service rate limiting method provided in this application embodiment, before determining whether the rate limiting list of the target interface contains a client IP, the method further includes: determining the historical access volume of each client IP to the target interface in the same batch; if the historical access volume in the same batch is greater than or equal to the access volume threshold of the target interface, adding the client IP to the rate limiting list; after determining whether the rate limiting list of the target interface contains a client IP, the method further includes: if the rate limiting list of the target interface contains a client IP, returning a second prompt message to the client, wherein the second prompt message is used to indicate that the target application denies the client's access.

[0046] Specifically, by querying the historical access records of the target interface in the target application, it is determined whether each client IP has a history of exceeding the access threshold of the target interface in the same batch of historical accesses. If the number of requests from a client IP to the target interface in the same batch exceeds the concurrency limit, i.e., exceeds the access threshold, the client IP is added to the rate-limiting list. If the client IP's access exceeds the access threshold in two consecutive batches, the record in the rate-limiting list is automatically modified to restrict access to the target interface from that client IP. After confirming the client IP information, if the client's access exceeding the access threshold is due to a legitimate request, the restriction on the client IP is manually lifted; if the client's request is illegitimate, its access to the target interface is restricted. When the client IP corresponding to the access request is found in the rate-limiting list for the target interface, a second prompt message is returned to the client, such as "Sorry, you do not have permission to access." By setting up the rate-limiting list, malicious requests from clients are prevented, thus improving the security of the target application.

[0047] Before performing fine-grained rate limiting on interfaces, the total number of accesses to all interfaces of the target application is first controlled by overall rate limiting. Optionally, in the service rate limiting method provided in this application embodiment, before parsing the access request, the method further includes: determining the total number of access requests for all interfaces of the target application; determining whether the total number of accesses is greater than or equal to a total number of accesses threshold; if the total number of accesses is greater than or equal to the total number of accesses threshold, returning a first prompt message to the client; if the total number of accesses is less than the total number of accesses threshold, performing the step of parsing the access request.

[0048] Specifically, during certain periods, such as holidays, the overall access volume of the target application may increase significantly. In this case, you can configure Nginx to enable the built-in rate limiting function of the target application to control the total number of requests. If the total number of requests is greater than or equal to a threshold, all requests are distributed evenly across multiple servers of the target application, and an initial notification is returned to each client. If the total number of requests is less than the threshold, the request parsing process is executed. This overall rate limiting ensures that the target application will not experience service disruptions due to excessive access volume.

[0049] According to another embodiment of this application, a service rate limiting system is also provided. Figure 2 This is a schematic diagram of a service rate limiting system provided according to an embodiment of this application. For example... Figure 2 As shown, the system includes:

[0050] Rate limiting service strategy information storage device 201: used to record the parameter information of rate limiting of the service interface provided by the web system, that is, the rate limiting strategy for the request of a single interface, and to provide strategy data for rate limiting operation.

[0051] Rate limiting gray list information storage device 202: By recording information such as IPs that do not comply with the rate limiting policy, access requests, and interfaces in access requests, the access of the IP to the interface is restricted.

[0052] Service request filtering device 203: For user access to the interface, the service request filtering device 203 first queries the gray list in the rate limiting gray list information storage device 202. If the access passes the gray list mechanism, it then queries the rate limiting policy in the rate limiting service policy information storage device 201 and performs rate limiting operation on the access.

[0053] Rate limiting result information and feedback device 204: After the user's access request is filtered and rate-limited by the service request filtering device 203, the corresponding rate limiting result information is returned to the user.

[0054] According to the service rate limiting system provided in the embodiments of this application, fine-grained rate limiting control is performed on the specific interfaces of web applications, including specific control information such as interface request IP, concurrency, maximum number of threads, and timeout time. It achieves safe and effective rate limiting control for single interface access, thus improving the service rate limiting framework of web applications.

[0055] According to another embodiment of this application, an optional service rate limiting method is also provided. Figure 3 This is a flowchart of an optional service rate limiting method provided according to an embodiment of this application. For example... Figure 3 As shown, the method includes:

[0056] Step S301: Enable rate limiting through nginx configuration to control the maximum number of requests to the overall web system service.

[0057] Specifically, by configuring nginx to distribute the load of web service requests evenly across multiple servers and reverse proxy them, the requests for the web service are distributed evenly across multiple servers.

[0058] Step S302: Record the rate limiting control parameters of each API interface through the rate limiting service interface list information storage table, and store a rate limiting policy for each API.

[0059] Specifically, the rate limiting strategy includes the rate limiting frequency per second, rate limiting timeout, interface level, maximum number of threads, and rate limiting frequencies for different levels. When a web request accesses an interface, the rate limiting strategy information for that interface is queried from the rate limiting service interface list information storage table.

[0060] Step S303: Intercept requests through the request filter of the web application system, and query the rate limiting graylist information and rate limiting policy information to control requests.

[0061] Specifically, when nginx distributes rate-limited requests to a web server, the request filter deployed on that server processes the requests based on rate-limiting greylist information and rate-limiting policy information.

[0062] Step S304: Process the gray list request through the gray list information storage table stored in the rate limiting service interface.

[0063] Specifically, it determines whether the client IP that sent the request is in the gray list and marked as abnormal. If it is in the gray list, the request is directly blocked and access is restricted. If it is not in the gray list, normal access is granted.

[0064] Step S305: Query the rate limiting policy information of the interface that has been stored in the rate limiting service interface list information storage table, and limit the request based on the rate limiting policy information.

[0065] Specifically, for the policy entries in the rate limiting policy information, the detailed control mechanism is as follows: each policy corresponds to a newly created token bucket with a limit of (X) per second. The token bucket size is 100, which is the peak concurrency of the rate limiting policy. When processing a request, if it is not an API that requires rate limiting, the request is allowed directly. If it is an API that requires rate limiting, a token is taken from the token bucket, and the waiting time for the rate limiting policy to be executed is exceeded. If the waiting time exceeds the timeout field in the rate limiting service policy information table or there are no tokens in the token bucket, the current server is busy and please try again later. Otherwise, the request is allowed.

[0066] Step S306: Add client IPs whose request volume for a single interface exceeds the concurrency limit to the gray list.

[0067] Specifically, if a client IP's access to the interface exceeds the concurrency limit for two consecutive batches, the gray list will be automatically modified to restrict the client IP's access to the interface. Once the client IP's access is confirmed to be normal, the restriction on the client IP will be manually lifted.

[0068] Step S307: After rate limiting the requests from the client IP, the corresponding processing result is fed back to the client.

[0069] The optional service rate limiting method provided in this application allows for the configurability of key parameters. Based on overall web service rate limiting, it enables fine-grained rate limiting for specific interfaces accessed by individual client IPs, including precise rate limiting of concurrency and maximum thread count. This effectively controls overall system concurrency to prevent excessive load and supports managing anomalies caused by excessive concurrency on individual interfaces, significantly ensuring system security. Secondary development is possible to meet different project requirements, allowing for iterative optimization and upgrades such as degradation and rate limiting for different services, satisfying rate limiting needs across various scenarios.

[0070] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.

[0071] This application also provides a service rate limiting device. It should be noted that the service rate limiting device of this application can be used to execute the service rate limiting method provided in this application. The service rate limiting device provided in this application is described below.

[0072] Figure 4 This is a schematic diagram of a service rate limiting device provided according to an embodiment of this application. For example... Figure 4 As shown, the device includes:

[0073] The receiving unit 401 is used to receive the client's access request to the target application, parse the access request, and obtain the client's client IP and the target interface of the target application accessed by the client. The target application contains multiple interfaces.

[0074] The first judgment unit 402 is used to determine whether the rate limiting list of the target interface contains the client IP;

[0075] The acquisition unit 403 is used to acquire the preset rate limiting policy of the target interface when the client IP is not included in the rate limiting list of the target interface. The preset rate limiting policy includes at least one of the following: rate limiting frequency and maximum number of threads. The rate limiting frequency is the number of times the target interface is restricted within a preset time period, and the maximum number of threads is the maximum number of access requests that the target interface can process at the same time.

[0076] The first execution unit 404 is used to perform rate limiting operations on access requests based on a preset rate limiting policy.

[0077] The service rate limiting device provided in this application embodiment receives client access requests to a target application through a receiving unit 401, parses the access requests to obtain the client's IP address and the target interface of the target application accessed by the client, wherein the target application contains multiple interfaces; a first judging unit 402 judges whether the rate limiting list of the target interface contains the client's IP address; an obtaining unit 403 obtains a preset rate limiting policy for the target interface if the rate limiting list of the target interface does not contain the client's IP address, wherein the preset rate limiting policy includes at least one of the following: rate limiting frequency and maximum number of threads, wherein the rate limiting frequency is the number of times the target interface is restricted within a preset time period, and the maximum number of threads is the maximum number of access requests that the target interface can process simultaneously; and a first execution unit 404 executes rate limiting operations on the access requests based on the preset rate limiting policy, thereby solving the problem in related technologies where excessive access to a single interface of an application leads to service abnormalities. By rate limiting access requests to the target interface through rate limiting lists, rate limiting frequencies, and maximum number of threads, rate limiting is achieved for a single interface in the application, thereby avoiding service abnormalities caused by excessive access to a single interface.

[0078] Optionally, in the service rate limiting device provided in this application embodiment, the device further includes: a first determining unit, configured to determine the number of rate limiting policies currently being executed by the target application, and determine whether the number of rate limiting policies is greater than or equal to a rate limiting policy number threshold; a second determining unit, configured to determine the waiting time for executing a preset rate limiting policy when the number of rate limiting policies is less than the rate limiting policy number threshold; a second judging unit, configured to judge whether the waiting time is greater than or equal to a waiting time threshold; and a second execution unit, configured to execute the step of performing rate limiting operation on the access request based on the preset rate limiting policy when the waiting time is less than the waiting time threshold.

[0079] Optionally, in the service rate limiting device provided in the embodiments of this application, the device further includes: a first prompting unit, used to return a first prompting message to the client when the number of rate limiting policies is greater than or equal to a rate limiting policy number threshold, wherein the first prompting message is used to indicate that the server of the target application is busy; the device further includes: a second prompting unit, used to return a first prompting message to the client when the waiting time is greater than or equal to a waiting time threshold.

[0080] Optionally, in the service rate limiting device provided in this application embodiment, the rate limiting frequency is determined in the following way: determining the target level of the target interface, determining the rate limiting frequency associated with the target level from a preset association table based on the target level, wherein the preset association table contains multiple associations, each association table contains an interface level and a rate limiting frequency; and determining the rate limiting frequency associated with the target level as the rate limiting frequency in the preset rate limiting strategy.

[0081] Optionally, in the service rate limiting device provided in this application embodiment, when the preset rate limiting strategy includes rate limiting frequency and maximum number of threads, the first execution unit 404 includes: a first determining module, used to determine the number of access requests received by the target interface within a preset time period, calculate the ratio of the number to the preset time period, and obtain the interface access frequency; a second determining module, used to determine the number of access requests to be executed by the target interface, and obtain the number to be executed; a first judging module, used to judge whether the interface access frequency is greater than or equal to the rate limiting frequency; a first adding module, used to add the access request to the queue of interfaces to be accessed when the interface access frequency is greater than or equal to the rate limiting frequency, wherein the queue of interfaces to be accessed contains all access requests waiting to access the target interface; a second judging module, used to judge whether the number to be executed is greater than or equal to the maximum number of threads when the interface access frequency is less than the rate limiting frequency; a second adding module, used to add the access request to the queue to be processed when the number to be executed is greater than or equal to the maximum number of threads, wherein the queue to be processed contains all access requests that have accessed the target interface and are waiting to be processed; and a processing module, used to process the access request when the number to be executed is less than the maximum number of threads.

[0082] Optionally, in the service rate limiting device provided in the embodiments of this application, the device further includes: a third determining unit, used to determine the historical access volume of each client IP to the target interface in the same batch; an adding unit, used to add the client IP to the rate limiting list when the historical access volume in the same batch is greater than or equal to the access volume threshold of the target interface; the device further includes: a third prompting unit, used to return a second prompting message to the client when the client IP is included in the rate limiting list of the target interface, wherein the second prompting message is used to indicate that the target application denies the client's access.

[0083] Optionally, in the service rate limiting device provided in the embodiments of this application, the device further includes: a fourth determining unit, used to determine the total number of access requests for all interfaces of the target application; a third judging unit, used to judge whether the total number of access requests is greater than or equal to a total number of access requests threshold; a fourth prompting unit, used to return a first prompt message to the client when the total number of access requests is greater than or equal to the total number of access requests threshold; and a third execution unit, used to execute the step of parsing the access requests when the total number of access requests is less than the total number of access requests threshold.

[0084] The service rate limiting device includes a processor and a memory. The receiving unit 401, the first judgment unit 402, the acquisition unit 403, and the first execution unit 404 are all stored in the memory as program units. The processor executes the program units stored in the memory to realize the corresponding functions.

[0085] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and kernel parameters can be adjusted to prevent excessive access to a single interface from causing service disruptions.

[0086] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0087] This invention provides a computer-readable storage medium storing a program that, when executed by a processor, implements a service rate limiting method.

[0088] This invention provides a processor for running a program, wherein the program executes a service rate limiting method during runtime.

[0089] Figure 5 This is a schematic diagram of an electronic device provided according to an embodiment of this application. For example... Figure 5As shown, electronic device 501 includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs the following steps: receiving a client's access request to a target application; parsing the access request to obtain the client's IP address and the target interface of the target application, wherein the target application contains multiple interfaces; determining whether the client's IP address is included in the rate-limiting list of the target interface; if the client's IP address is not included in the rate-limiting list of the target interface, obtaining a preset rate-limiting policy for the target interface, wherein the preset rate-limiting policy includes at least one of the following: rate-limiting frequency and maximum number of threads, where the rate-limiting frequency is the number of times access to the target interface is restricted within a preset time period, and the maximum number of threads is the maximum number of access requests that the target interface can process simultaneously; and performing rate-limiting operations on the access requests based on the preset rate-limiting policy. The device in this document can be a server, PC, PAD, mobile phone, etc.

[0090] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program with the following method steps: receiving a client's access request to a target application; parsing the access request to obtain the client's IP address and the target interface of the target application accessed by the client, wherein the target application contains multiple interfaces; determining whether the client's IP address is included in the rate-limiting list of the target interface; if the client's IP address is not included in the rate-limiting list of the target interface, obtaining a preset rate-limiting policy for the target interface, wherein the preset rate-limiting policy includes at least one of the following: rate-limiting frequency and maximum number of threads, wherein the rate-limiting frequency is the number of times access to the target interface is restricted within a preset time period, and the maximum number of threads is the maximum number of access requests that the target interface can process simultaneously; and performing rate-limiting operations on the access requests based on the preset rate-limiting policy.

[0091] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0092] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0093] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0094] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0095] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0096] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0097] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0098] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0099] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0100] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

Claims

1. A service rate limiting method, characterized in that, include: Receive a client's access request to a target application, parse the access request, and obtain the client's client IP and the target interface of the target application accessed by the client, wherein the target application contains multiple interfaces; Determine whether the client IP is included in the rate limiting list of the target interface; If the client IP is not included in the rate limiting list of the target interface, obtain the preset rate limiting policy of the target interface. The preset rate limiting policy includes at least one of the following: rate limiting frequency and maximum number of threads. The rate limiting frequency is the number of times the target interface is restricted within a preset time period, and the maximum number of threads is the maximum number of access requests that the target interface can process at the same time. The access request is rate-limited based on the preset rate-limiting policy. Before performing rate limiting on the access request based on the preset rate limiting policy, the method further includes: determining the number of rate limiting policies currently being executed by the target application, and determining whether the number of rate limiting policies is greater than or equal to a rate limiting policy number threshold; if the number of rate limiting policies is less than the rate limiting policy number threshold, determining a waiting time for executing the preset rate limiting policy; determining whether the waiting time is greater than or equal to a waiting time threshold; and if the waiting time is less than the waiting time threshold, performing the step of performing rate limiting on the access request based on the preset rate limiting policy.

2. The method according to claim 1, characterized in that, After determining whether the number of rate limiting policies is greater than or equal to the rate limiting policy number threshold, the method further includes: If the number of rate limiting policies is greater than or equal to the rate limiting policy number threshold, a first prompt message is returned to the client, wherein the first prompt message is used to indicate that the server of the target application is busy; After determining whether the waiting time is greater than or equal to the waiting time threshold, the method further includes: If the waiting time is greater than or equal to the waiting time threshold, the first prompt message is returned to the client.

3. The method according to claim 1, characterized in that, The current limiting frequency is determined in the following way: Determine the target level of the target interface, and based on the target level, determine the rate limiting frequency associated with the target level from a preset association table. The preset association table contains multiple associations, and each association contains an interface level and a rate limiting frequency. The rate limiting frequency associated with the target level is determined as the rate limiting frequency in the preset rate limiting strategy.

4. The method according to any one of claims 1 to 3, characterized in that, When the preset rate limiting policy includes the rate limiting frequency and the maximum number of threads, performing rate limiting operations on the access request based on the preset rate limiting policy includes: Determine the number of access requests received by the target interface within the preset time period, calculate the ratio of the number to the preset time period, and obtain the interface access frequency. Determine the number of access requests expected to be executed at the target interface to obtain the number of requests to be executed; Determine whether the interface access frequency is greater than or equal to the rate limiting frequency; If the interface access frequency is greater than or equal to the rate limiting frequency, the access request is added to the queue of interfaces to be accessed, wherein the queue of interfaces to be accessed contains all access requests waiting to access the target interface; If the interface access frequency is less than the rate limiting frequency, determine whether the number of threads to be executed is greater than or equal to the maximum number of threads. If the number of pending requests is greater than or equal to the maximum number of threads, the access request is added to the processing queue, wherein the processing queue contains all access requests that have accessed the target interface and are waiting to be processed; If the number of pending requests is less than the maximum number of threads, the access request is processed.

5. The method according to claim 1, characterized in that, Before determining whether the client IP is included in the rate-limiting list of the target interface, the method further includes: Determine the historical access volume of each client IP to the target interface for the same batch; If the historical access volume of the same batch is greater than or equal to the access volume threshold of the target interface, the client IP will be added to the rate limiting list. After determining whether the client IP is included in the rate-limiting list of the target interface, the method further includes: If the client IP is included in the rate-limiting list of the target interface, a second prompt message is returned to the client, wherein the second prompt message indicates that the target application denies the client's access.

6. The method according to claim 1, characterized in that, Before parsing the access request, the method further includes: Determine the total number of access requests for all interfaces of the target application; Determine whether the total number of visits is greater than or equal to the total number of visits threshold; If the total number of accesses is greater than or equal to the total number of accesses threshold, a first prompt message is returned to the client; If the total number of accesses is less than the total number of accesses threshold, the step of parsing the access request is performed.

7. A service rate limiting device, characterized in that, include: The receiving unit is used to receive a client's access request to a target application, parse the access request, and obtain the client's client IP and the target interface of the target application accessed by the client, wherein the target application includes multiple interfaces; The first judgment unit is used to determine whether the client IP is included in the rate limiting list of the target interface; The acquisition unit is used to acquire the preset rate limiting policy of the target interface when the client IP is not included in the rate limiting list of the target interface. The preset rate limiting policy includes at least one of the following: rate limiting frequency and maximum number of threads. The rate limiting frequency is the number of times the target interface is restricted within a preset time period, and the maximum number of threads is the maximum number of access requests that the target interface can process at the same time. The first execution unit is used to perform rate limiting operations on the access request based on the preset rate limiting policy; The service rate limiting device further includes: a first determining unit, configured to determine the number of rate limiting policies currently being executed by the target application, and to determine whether the number of rate limiting policies is greater than or equal to a rate limiting policy number threshold; a second determining unit, configured to determine a waiting time for executing the preset rate limiting policy when the number of rate limiting policies is less than the rate limiting policy number threshold; a second judging unit, configured to judge whether the waiting time is greater than or equal to a waiting time threshold; and a second executing unit, configured to execute a step of performing rate limiting operation on the access request based on the preset rate limiting policy when the waiting time is less than the waiting time threshold.

8. A non-volatile storage medium, characterized in that, The non-volatile storage medium includes a stored program, wherein the program, when running, controls the device where the non-volatile storage medium resides to execute the service rate limiting method according to any one of claims 1 to 6.

9. An electronic device, characterized in that, It includes one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the service rate limiting method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Interface security control method in network security, and interface security control terminal device

    CN109309666A