A service data flow limiting method and device, computer equipment and storage medium

By using a token bucket-based rate limiting method, the problem of the inability to perform fine-grained rate limiting in existing technologies is solved, enabling reasonable distribution of business requests from different companies in the insurance business scenario and protecting system load balance.

CN116886626BActive Publication Date: 2026-11-24CHINA PING AN PROPERTY INSURANCE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310678509.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-08
Publication Date
2026-11-24
Estimated Expiration
2043-06-08

AI Technical Summary

Technical Problem

Existing rate limiting models cannot limit rates for more granular business scenarios, resulting in unbalanced system load. This is especially true in insurance business scenarios where different companies have significantly different call volumes, making it impossible to distinguish the rate limiting targets.

Method used

A token bucket-based rate limiting method is adopted. By receiving business requests, reading a preset Map set, obtaining the unique business key and the corresponding token bucket rate limiter, determining the rate limiting conditions according to the token bucket algorithm, and allocating rate limiting tokens, fine-grained rate limiting for different business requests is achieved.

Benefits of technology

It implements fine-grained rate limiting for different business requests, preventing excessive traffic, protecting the system, ensuring system load balancing, and avoiding congestion from low-traffic business requests.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116886626B_ABST
    Figure CN116886626B_ABST
Patent Text Reader

Abstract

This application belongs to the field of financial technology and discloses a method, apparatus, computer device, and storage medium for business data rate limiting based on a token bucket. The method includes: receiving a business request sent by a user terminal; reading a preset Map set; obtaining a target business unique key corresponding to the business path and a target rate limiter corresponding to the target business unique key from the preset Map set; allocating a rate limiting token to the business request according to the target rate limiter; when a response to a business request is required, determining whether the business request contains request content; if the business request does not contain request content, responding to the business request; otherwise, determining whether the rate limiting token of the business request meets the rate limiting conditions according to the token bucket algorithm and the token bucket rate limiter; if the rate limiting token meets the rate limiting conditions, delaying the response for a preset time; otherwise, responding to the business request. The advantage of this application is that it can perform traffic distribution based on finer-grained business processes, making business rate limiting more reasonable.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of financial technology, and in particular to a method, apparatus, computer equipment, and storage medium for limiting business data based on a token bucket. Background Technology

[0002] Rate limiting is a way to degrade services. The purpose of rate limiting is to protect the system by limiting the rate of concurrent requests or the number of requests within a time window. Once the rate limit is reached, the system can refuse service, queue or wait, or degrade. However, for special application scenarios, especially in the insurance business scenario in the financial insurance field, intelligent rate limiting becomes the main problem to be solved.

[0003] Current industry-standard rate limiting models typically restrict traffic, with the finest granularity being the API level. However, they don't differentiate based on the source of the API requests, treating all requests indiscriminately without individual differences. For example, insurance company A exposes an API that both insurance companies B and C call. Insurance company B has a low call volume (QPS of 5), so the system load is not strained; however, insurance company C has a very high call volume (QPS of 1000), which may cause excessive system load. In this insurance business scenario, we need to rate limit insurance company C, but we cannot affect insurance company B's calls, because insurance company B's traffic is very small and should not be rate-limited. However, current industry-standard rate limiting models can only limit the API exposed by insurance company A, and cannot limit rate for more granular business scenarios. Summary of the Invention

[0004] The technical problem this application aims to solve is that existing rate limiting models in the industry can only limit the rate of the interfaces exposed by Insurance Company A, and cannot limit the rate of more granular business scenarios.

[0005] This application adopts the following technical solution to solve the above-mentioned technical problems: it provides a service data rate limiting method based on token bucket, including the following steps:

[0006] Receive a service request sent by a user terminal, wherein the service request carries at least a service path;

[0007] Read a preset Map set, wherein the Map set includes a business unique key corresponding to each business path and a token bucket rate limiter corresponding to each business unique key;

[0008] Obtain the target business unique key corresponding to the business path and the target rate limiter corresponding to the target business unique key from the preset Map set;

[0009] A rate limiting token is allocated to the service request according to the target rate limiter;

[0010] When it is necessary to respond to the business request, it is determined whether the business request contains request content;

[0011] If the requested content is not present in the business request, then the business request is responded to;

[0012] If the requested content exists in the business request, then the rate limiting token of the business request is determined according to the token bucket algorithm and the token bucket rate limiter to determine whether the rate limiting token of the business request meets the rate limiting conditions.

[0013] If the rate limiting token meets the rate limiting conditions, the response will be delayed for a preset time.

[0014] If the rate limiting token does not meet the rate limiting conditions, then the service request will be responded to.

[0015] Preferably, before the step of reading the preset Map collection, the following steps are also included:

[0016] Read the business path carried in the business request;

[0017] Based on the traffic volume of business requests along the same business path, the business requests are divided into primary business requests and secondary business requests.

[0018] Build a unique business key for main business requests with the same business path;

[0019] Assign a unified business unique key to all secondary business requests.

[0020] Preferably, the token bucket rate limiter includes multiple sets of primary token buckets and secondary token buckets. The multiple sets of primary token buckets are used to limit primary service requests, and the secondary token buckets are used to limit secondary service requests. Before the step of reading the preset Map set, the following steps are also included:

[0021] Set the capacity b of the token bucket;

[0022] Set the number of tokens r added to the bucket per second based on the average rate of user business requests;

[0023] When there is a request of n bytes, subtract n tokens from the token bucket.

[0024] If the business request has already performed a token add operation, then determine whether the number of tokens in the token bucket is greater than n.

[0025] If the number of tokens in the token bucket is greater than n, the size of the token bucket is set according to the rate of business requests; otherwise, access is denied.

[0026] Specifically, when the number of tokens in the token bucket equals b, newly generated tokens will be discarded. The size of the token bucket capacity b is proportional to the average rate of service requests.

[0027] Preferably, the current limiting method of the token bucket current limiter is as follows:

[0028] Retrieve the unique key of the business request;

[0029] Traverse the Map collection and find the token bucket that matches the business unique key in the Map collection;

[0030] Send tokens to business requests via the token bucket;

[0031] Determine whether a business request carries a token, and rate-limit business requests that do not carry a token.

[0032] Preferably, the step of allocating a rate limiting token to the service request according to the target rate limiter specifically includes the following steps:

[0033] The rate limiting token is preferentially allocated to service requests that have a delayed response time.

[0034] Preferably, the step of responding to the service request specifically includes the following steps:

[0035] Determine if there are any pending or unprocessed business requests;

[0036] If there are pending service requests, then add those service requests to the queue.

[0037] If there are no pending business requests, then determine whether the number of tokens in the token bucket is less than the number of bytes in the business request.

[0038] If the number of tokens in the token bucket is less than the number of bytes in the service request, then the service request will be rejected.

[0039] If the number of tokens in the token bucket is greater than or equal to the number of bytes in the business request, a normal response is given, and a token is matched for the business request.

[0040] A token bucket-based business data rate limiting device includes:

[0041] A request receiving module is used to receive service requests sent by user terminals, wherein the service request carries at least a service path;

[0042] The Map collection reading module is used to read a preset Map collection, wherein the Map collection includes a business unique key corresponding to each business path and a token bucket rate limiter corresponding to each business unique key;

[0043] The rate limiter acquisition module is used to acquire the target business unique key corresponding to the business path and the target rate limiter corresponding to the target business unique key from the preset Map set;

[0044] The token allocation module is used to allocate a rate limiting token to the service request according to the target rate limiter;

[0045] The request content determination module is used to determine whether the business request contains request content when it is necessary to respond to the business request.

[0046] The first response module is used to respond to the business request if the requested content does not exist in the business request.

[0047] The rate limiting condition judgment module is used to determine whether the rate limiting token of the service request meets the rate limiting condition if the service request contains the request content, based on the token bucket algorithm and the token bucket rate limiter.

[0048] The delayed response module is used to delay the response for a preset time if the rate limiting token meets the rate limiting condition.

[0049] The second response module is used to respond to the service request if the rate limiting token does not meet the rate limiting conditions.

[0050] Preferably, the device further includes:

[0051] The business path reading module is used to read the business path carried in the business request;

[0052] The request segmentation module is used to divide the business requests into main business requests and secondary business requests based on the traffic volume of business requests along the same business path.

[0053] The unique key building module is used to build a unique business key for main business requests with the same business path;

[0054] The unique key allocation module is used to assign a unified business unique key to all sub-business requests.

[0055] A computer device includes a memory and a processor, the memory storing computer-readable instructions, the processor executing the computer-readable instructions to implement the steps of the rate limiting method described above.

[0056] A computer-readable storage medium storing computer-readable instructions, which, when executed by a processor, implement the steps of the current limiting method described above.

[0057] Compared with existing technologies, this application provides a service rate limiter based on the token bucket algorithm, which has the following advantages:

[0058] This application provides a service data rate limiting method based on a token bucket, comprising: receiving a service request sent by a user terminal, wherein the service request carries at least a service path; reading a preset Map set, wherein the Map set includes a service unique key corresponding to each service path and a token bucket rate limiter corresponding to each service unique key; obtaining a target service unique key corresponding to the service path and a target rate limiter corresponding to the target service unique key from the preset Map set; allocating a rate limiting token to the service request according to the target rate limiter; when it is necessary to respond to the service request, determining whether the service request contains request content; if the service request does not contain request content, responding to the service request; if the service request contains request content, determining whether the rate limiting token of the service request meets the rate limiting conditions according to the token bucket algorithm and the token bucket rate limiter; if the rate limiting token meets the rate limiting conditions, delaying the response for a preset time; if the rate limiting token does not meet the rate limiting conditions, responding to the service request. Compared to existing technologies, this application accepts requests through the company's external interface, categorizes the request content and assigns unique keys to each, then establishes token buckets and assigns unique keys to them, associating the token bucket unique keys with business unique keys. The token generation speed of the token bucket matches the average rate of business requests. By establishing token buckets, business traffic can be rate-limited to prevent excessive traffic and protect the system. A Map collection is also established to store the key-value relationship between all business unique keys and business rate limiters, preserving the relationship between business requests and token buckets, facilitating the search for dedicated rate-limiting buckets for each business. By assigning unique keys to businesses, rate limiting can be applied separately to each business. This application enables more granular business-based traffic distribution, making business rate limiting more reasonable. Attached Figure Description

[0059] Figure 1 This is an exemplary system architecture diagram to which this application can be applied;

[0060] Figure 2 This is a flowchart illustrating the implementation of the token bucket-based service data rate limiting method provided in Embodiment 1 of this application.

[0061] Figure 3 This is a schematic diagram of the service data rate limiting device based on token bucket provided in Embodiment 2 of this application;

[0062] Figure 4 This is a schematic diagram of the structure of one embodiment of the computer device according to this application. Detailed Implementation

[0063] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0064] like Figure 1 As shown, system architecture 100 may include terminal devices 101, 102, and 103, a network 104, and a server 105. Network 104 serves as the medium for providing communication links between terminal devices 101, 102, and 103 and server 105. Network 104 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.

[0065] Users can use terminal devices 101, 102, and 103 to interact with server 105 via network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, and 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social media platform software, etc.

[0066] Terminal devices 101, 102, and 103 can be various electronic devices with displays and support web browsing, including but not limited to smartphones, tablets, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 players (Moving Picture Experts Group Audio Layer IV), laptops, and desktop computers, etc.

[0067] Server 105 can be a server that provides various services, such as a backend server that supports the pages displayed on terminal devices 101, 102, and 103.

[0068] It should be noted that the token bucket-based service data rate limiting method provided in this application is generally executed by a server / terminal device, and correspondingly, a token bucket-based service data rate limiting device is generally installed in the server / terminal device.

[0069] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.

[0070] Continue to refer to Figure 2 The flowchart illustrates a rate limiting method for business data according to this application. A rate limiting method for business data based on a token bucket includes the following steps:

[0071] Step S201: Receive a service request sent by a user terminal, wherein the service request carries at least a service path.

[0072] In this application embodiment, a token bucket-based service data rate limiting method runs on electronic devices (e.g., Figure 1 The server / terminal device shown can receive access requests from terminal devices via wired or wireless connections. It should be noted that the wireless connection methods mentioned above may include, but are not limited to, 3G / 4G / 5G connections, WiFi connections, Bluetooth connections, WiMAX connections, Zigbee connections, UWB (ultra wideband) connections, and other currently known or future wireless connection methods.

[0073] In this embodiment of the application, service requests are received through an external interface, which can be a computing device, a network device, or a storage device. The path corresponding to each service request can be obtained through the IP address of the service request. Service requests with the same IP address are assigned the same unique key based on the IP address of the service request, and requests with the same path are sorted and classified.

[0074] Step S202: Read the preset Map set, wherein the Map set includes a business unique key corresponding to each business path and a token bucket rate limiter corresponding to each business unique key.

[0075] In this embodiment of the application, a preset Map set can be used to match business requests carrying unique business keys with their corresponding token bucket rate limiters, so that the token bucket rate limiters can target and limit the business requests.

[0076] Step S203: Obtain the target business unique key corresponding to the business path and the target rate limiter corresponding to the target business unique key from the preset Map collection.

[0077] Step S204: Assign a rate limiting token to the service request based on the target rate limiter.

[0078] In this embodiment of the application, a token is obtained from the Map collection based on the business unique key. The Map collection can be used to set up different token buckets for business requests from different paths.

[0079] Step S205: When a business request needs to be responded to, determine whether the business request contains request content;

[0080] Step S206: If the business request does not contain any requested content, then respond to the business request.

[0081] In this embodiment of the application, the received business requests may include requests with empty content. These requests are responded to normally.

[0082] Step S207: If the business request contains request content, then determine whether the rate limiting token of the business request meets the rate limiting conditions based on the token bucket algorithm and the token bucket rate limiter.

[0083] Step S208: If the rate limiting token meets the rate limiting conditions, the response is delayed for a preset time.

[0084] Step S209: If the rate limiting token does not meet the rate limiting conditions, then respond to the service request.

[0085] In this embodiment, taking an insurance business scenario as an example, if insurance company A exposes an interface that both insurance company B and insurance company C need to call, insurance company B has a smaller call volume (QPS of 5) and the system load is not under pressure. However, insurance company C has a very large call volume (QPS of 1000), which may lead to excessive system load. In this case, insurance company A will obtain the business unique key B1 and business unique key C1 corresponding to insurance company B and insurance company C respectively, as well as the token bucket rate limiter B2 corresponding to business unique key B1 and the token bucket rate limiter C2 corresponding to business unique key C1, based on the preset Map set. Then, it will allocate rate limiting tokens B3 and C3 to insurance company B and insurance company C respectively based on the token bucket rate limiter B2 and token bucket rate limiter C2. When it is necessary to respond to the request of insurance company B or insurance company C, it first determines whether the request of insurance company B or insurance company C to call this interface has request content. If there is no request content, it responds directly. If there is request content, it is necessary to further determine whether the request needs to be rate limited based on the corresponding rate limiting token, thereby effectively distinguishing the source of the request interface (insurance company B or insurance company C) for rate limiting.

[0086] This application provides a method for rate limiting of service data based on a token bucket, comprising: receiving a service request sent by a user terminal, wherein the service request carries at least a service path; reading a preset Map set, wherein the Map set includes a service unique key corresponding to each service path and a token bucket rate limiter corresponding to each service unique key; obtaining a target service unique key corresponding to the service path and a target rate limiter corresponding to the target service unique key from the preset Map set; allocating a rate limiting token to the service request according to the target rate limiter; when a service request needs to be responded to, determining whether the service request contains request content; if the service request does not contain request content, responding to the service request; if the service request contains request content, determining whether the rate limiting token of the service request meets the rate limiting conditions according to the token bucket algorithm and the token bucket rate limiter; if the rate limiting token meets the rate limiting conditions, delaying the response for a preset time; if the rate limiting token does not meet the rate limiting conditions, responding to the service request. Compared to existing technologies, this application accepts requests through the company's external interface, categorizes the request content and assigns unique keys to each, then establishes token buckets and assigns unique keys to them, associating the token bucket unique keys with business unique keys. The token generation speed of the token bucket matches the average rate of business requests. By establishing token buckets, business traffic can be rate-limited to prevent excessive traffic and protect the system. A Map collection is also established to store the key-value relationship between all business unique keys and business rate limiters, preserving the relationship between business requests and token buckets, facilitating the search for dedicated rate-limiting buckets for each business. By assigning unique keys to businesses, rate limiting can be applied separately to each business. This application enables more granular business-based traffic distribution, making business rate limiting more reasonable.

[0087] In some optional implementations of this embodiment, the following steps are included before step S202:

[0088] Read the business path carried in the business request;

[0089] Based on the traffic volume of business requests along the same business path, business requests are divided into primary business requests and secondary business requests.

[0090] Build a unique business key for main business requests with the same business path;

[0091] Assign a unified business unique key to all secondary business requests.

[0092] In this embodiment, the unique key for the business component facilitates business classification, ensures that the business can be accurately matched with the business rate limiter, divides business requests into main business requests and secondary business requests, and enables the construction of a unique key for the business request in a targeted manner, reducing the need for token bucket rate limiters.

[0093] In some optional implementations of this embodiment, the token bucket rate limiter includes multiple sets of primary token buckets and secondary token buckets. The multiple sets of primary token buckets are used to limit primary service requests, and the secondary token buckets are used to limit secondary service requests. Before step S202 above, the following steps are also included:

[0094] Set the capacity b of the token bucket;

[0095] Set the number of tokens r added to the bucket per second based on the average rate of user business requests;

[0096] When there is a request of n bytes, subtract n tokens from the token bucket.

[0097] If the business request has already performed a token add operation, then determine whether the number of tokens in the token bucket is greater than n.

[0098] If the number of tokens in the token bucket is greater than n, the size of the token bucket is set according to the rate of business requests; otherwise, access is denied.

[0099] Specifically, when the number of tokens in the token bucket equals b, newly generated tokens will be discarded. The size of the token bucket capacity b is proportional to the average rate of business requests.

[0100] In this embodiment of the application, different rate limiters are set for different services, which can perform fine-grained rate limiting on services and prevent small-volume service requests from being blocked due to service rate limiting.

[0101] In some optional implementations of this embodiment, the rate limiting method of the token bucket rate limiter is as follows:

[0102] Retrieve the unique key of the business request;

[0103] Iterate through the Map collection and find the token bucket that matches the business unique key.

[0104] Send tokens to business requests via the token bucket;

[0105] Determine whether a business request carries a token, and rate-limit business requests that do not carry a token.

[0106] In this embodiment, the relationship between service requests and token buckets is stored to facilitate finding dedicated rate-limiting buckets for services, determining which services need rate limiting, responding accordingly, limiting the traffic of service requests, and ensuring the normal operation of the system.

[0107] In some optional implementations of this embodiment, step S204 specifically includes the following steps:

[0108] Rate limiting tokens are prioritized for business requests that have a delayed response time.

[0109] In some optional implementations of this embodiment, step S206 or step S209 includes the following steps:

[0110] Determine if there are any pending or unprocessed business requests;

[0111] If there are pending service requests, add them to the queue.

[0112] If there are no pending business requests, then determine whether the number of tokens in the token bucket is less than the number of bytes in the business request.

[0113] If the number of tokens in the token bucket is less than the number of bytes in the business request, then the business request will be rejected.

[0114] If the number of tokens in the token bucket is greater than or equal to the number of bytes in the business request, a normal response will be given, and a token will be matched for the business request.

[0115] In practical applications, requests are received through the company's external interface. The path of the business request is determined based on its IP address, and requests with the same path are assigned a unique key. A token bucket is then established based on the average request rate of different business requests, and each token bucket is associated with a unique business key. The token generation rate of the token bucket matches the average rate of business requests. A Map collection is also established, storing the key-value relationships between all unique business keys and business rate limiters. When a business request arrives, the unique key of the request is first obtained. Then, the rate limiter associated with the unique key is searched in the Map collection. A token matching the business request is then retrieved from the rate limiter. If the number of tokens in the token bucket is less than the number of bytes in the business request, the response to the business request is rejected; otherwise, a normal response is given. If no new requests are found at the average business request rate, the pending business requests are responded to. After a normal response to a business request, the database is accessed based on the request content, and the content reflected in the database is displayed at the business facade layer.

[0116] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by instructing related hardware with computer-readable instructions. These computer-readable instructions can be stored in a computer-readable storage medium, and when executed, they can include the processes of the embodiments of the methods described above. The aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, optical disk, or read-only memory (ROM), or random access memory (RAM).

[0117] It should be understood that although the steps in the flowcharts of the accompanying figures are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the accompanying figures may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.

[0118] Example 2

[0119] Further reference Figure 3 As a response to the above Figure 2 The implementation of the method shown in this application provides an embodiment of a service data rate limiting device based on a token bucket. This device embodiment is similar to... Figure 2 Corresponding to the method embodiments shown, this device can be specifically applied to various electronic devices.

[0120] like Figure 3 As shown, the token bucket-based service data rate limiting device 200 in this embodiment includes: a request receiving module 210, a Map collection reading module 220, a rate limiter acquisition module 230, a token allocation module 240, a request content judgment module 250, a first response module 260, a rate limiting condition judgment module 270, a delayed response module 280, and a second response module 290. Wherein:

[0121] The request receiving module 210 is used to receive service requests sent by user terminals, wherein the service request carries at least a service path;

[0122] Map collection reading module 220 is used to read a preset Map collection, wherein the Map collection includes a business unique key corresponding to each business path and a token bucket rate limiter corresponding to each business unique key;

[0123] The rate limiter acquisition module 230 is used to acquire the target business unique key corresponding to the business path and the target rate limiter corresponding to the target business unique key from a preset Map collection.

[0124] Token allocation module 240 is used to allocate a rate limiting token to a service request based on the target rate limiter;

[0125] The request content judgment module 250 is used to determine whether the business request has request content when a business request needs to be responded to.

[0126] The first response module 260 is used to respond to the business request if the requested content does not exist in the business request;

[0127] The rate limiting condition judgment module 270 is used to determine whether the rate limiting token of the business request meets the rate limiting condition if the business request contains request content, based on the token bucket algorithm and the token bucket rate limiter.

[0128] The delayed response module 280 is used to delay the response for a preset time if the rate limiting token meets the rate limiting conditions.

[0129] The second response module 290 is used to respond to the business request if the rate limiting token does not meet the rate limiting conditions.

[0130] In this application embodiment, a token bucket-based service data rate limiting method runs on electronic devices (e.g., Figure 1 The server / terminal device shown can receive access requests from terminal devices via wired or wireless connections. It should be noted that the wireless connection methods mentioned above may include, but are not limited to, 3G / 4G / 5G connections, WiFi connections, Bluetooth connections, WiMAX connections, Zigbee connections, UWB (ultra wideband) connections, and other currently known or future wireless connection methods.

[0131] In this embodiment of the application, service requests are received through an external interface, which can be a computing device, a network device, or a storage device. The path corresponding to each service request can be obtained through the IP address of the service request. Service requests with the same IP address are assigned the same unique key based on the IP address of the service request, and requests with the same path are sorted and classified.

[0132] In this embodiment of the application, a preset Map set can be used to match business requests carrying unique business keys with their corresponding token bucket rate limiters, so that the token bucket rate limiters can target and limit the business requests.

[0133] In this embodiment of the application, a token is obtained from the Map collection based on the business unique key. The Map collection can be used to set up different token buckets for business requests from different paths.

[0134] In this embodiment of the application, the received business requests may include requests with empty content. These requests are responded to normally.

[0135] In this embodiment, taking an insurance business scenario as an example, if insurance company A exposes an interface that both insurance company B and insurance company C need to call, insurance company B has a smaller call volume (QPS of 5) and the system load is not under pressure. However, insurance company C has a very large call volume (QPS of 1000), which may lead to excessive system load. In this case, insurance company A will obtain the business unique key B1 and business unique key C1 corresponding to insurance company B and insurance company C respectively, as well as the token bucket rate limiter B2 corresponding to business unique key B1 and the token bucket rate limiter C2 corresponding to business unique key C1, based on the preset Map set. Then, it will allocate rate limiting tokens B3 and C3 to insurance company B and insurance company C respectively based on the token bucket rate limiter B2 and token bucket rate limiter C2. When it is necessary to respond to the request of insurance company B or insurance company C, it first determines whether the request of insurance company B or insurance company C to call this interface has request content. If there is no request content, it responds directly. If there is request content, it is necessary to further determine whether the request needs to be rate limited based on the corresponding rate limiting token, thereby effectively distinguishing the source of the request interface (insurance company B or insurance company C) for rate limiting.

[0136] In this application embodiment, a service data rate limiting device 200 based on a token bucket is provided, including: a request receiving module 210, a Map collection reading module 220, a rate limiter acquisition module 230, a token allocation module 240, a request content judgment module 250, a first response module 260, a rate limiting condition judgment module 270, a delayed response module 280, and a second response module 290. Compared to existing technologies, this application accepts requests through the company's external interface, categorizes the request content and assigns unique keys to each, then establishes token buckets and assigns unique keys to them, associating the token bucket unique keys with business unique keys. The token generation speed of the token bucket matches the average rate of business requests. By establishing token buckets, business traffic can be rate-limited to prevent excessive traffic and protect the system. A Map collection is also established to store the key-value relationship between all business unique keys and business rate limiters, preserving the relationship between business requests and token buckets, facilitating the search for dedicated rate-limiting buckets for each business. By assigning unique keys to businesses, rate limiting can be applied separately to each business. This application enables more granular business-based traffic distribution, making business rate limiting more reasonable.

[0137] In some optional implementations of this embodiment, the apparatus 200 further includes: a business path reading module, a request partitioning module, a unique key construction module, and a unique key allocation module, wherein:

[0138] The business path reading module is used to read the business path carried in the business request;

[0139] The request segmentation module is used to divide business requests into main business requests and secondary business requests based on the traffic volume of business requests along the same business path.

[0140] The unique key building module is used to build a unique business key for main business requests with the same business path;

[0141] The unique key allocation module is used to assign a unified business unique key to all sub-business requests.

[0142] In some optional implementations of this embodiment, the token bucket rate limiter includes multiple sets of main token buckets and secondary token buckets. The multiple sets of main token buckets are used to limit primary service requests, and the secondary token buckets are used to limit secondary service requests. The device 200 further includes: a capacity setting module, a quantity setting module, a token deletion module, a quantity judgment module, and a quantity judgment result module, wherein:

[0143] The capacity setting module is used to set the capacity b of the token bucket;

[0144] The quantity setting module is used to set the number of tokens r put into the bucket per second based on the average rate of user business requests;

[0145] The token pruning module is used to subtract n tokens from the token bucket when there is a request of n bytes.

[0146] The quantity judgment module is used to determine whether the number of tokens in the token bucket is greater than n if the business request has previously performed a token addition operation.

[0147] The quantity judgment result module is used to set the size of the token bucket according to the rate of business requests if the number of tokens inside the token bucket is greater than n; otherwise, access is denied.

[0148] Specifically, when the number of tokens in the token bucket equals b, newly generated tokens will be discarded. The size of the token bucket capacity b is proportional to the average rate of business requests.

[0149] In some optional implementations of this embodiment, the rate limiting method of the token bucket rate limiter is as follows:

[0150] Retrieve the unique key of the business request;

[0151] Iterate through the Map collection and find the token bucket that matches the business unique key.

[0152] Send tokens to business requests via the token bucket;

[0153] Determine whether a business request carries a token, and rate-limit business requests that do not carry a token.

[0154] In some optional implementations of this embodiment, the token allocation module 240 includes: a token allocation submodule, wherein:

[0155] The token allocation submodule is used to prioritize allocating rate-limiting tokens to business requests that have a delayed response time.

[0156] In some optional implementations of this embodiment, the first response module or the second response module includes: a retention request judgment submodule, a join sequence submodule, a token quantity judgment submodule, a rejection response submodule, and a normal response submodule, wherein:

[0157] The delayed request judgment submodule is used to determine whether there are any delayed and unprocessed business requests;

[0158] Add a sequence submodule to add business requests to the queue if there are any pending requests.

[0159] The token quantity determination submodule is used to determine whether the number of tokens in the token bucket is less than the number of bytes in the business request if there are no pending business requests.

[0160] The Reject Response submodule is used to reject a business request if the number of tokens in the token bucket is less than the number of bytes in the business request.

[0161] The normal response submodule is used to provide a normal response and match tokens for the business request if the number of tokens in the token bucket is greater than or equal to the number of bytes in the business request.

[0162] To address the aforementioned technical problems, embodiments of this application also provide a computer device. Please refer to [link / reference needed]. Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.

[0163] Computer device 6 includes a memory 61, a processor 62, and a network interface 63 that are interconnected via a system bus. It should be noted that only computer device 6 with components 61-63 is shown in the figure; however, it should be understood that it is not required to implement all the shown components, and more or fewer components can be implemented alternatively. Those skilled in the art will understand that the computer device described herein is a device capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes, but is not limited to, microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.

[0164] Computer devices can include desktop computers, laptops, handheld computers, and cloud servers. These devices allow for human-computer interaction with users through keyboards, mice, remote controls, touchpads, or voice-activated devices.

[0165] The memory 61 includes at least one type of readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 61 may be an internal storage unit of the computer device 6, such as the hard disk or memory of the computer device 6. In other embodiments, the memory 61 may also be an external storage device of the computer device 6, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the computer device 6. Of course, the memory 61 may also include both the internal storage unit and the external storage device of the computer device 6. In this embodiment, the memory 61 is typically used to store the operating system and various application software installed on the computer device 6, computer-readable instructions for a token bucket-based business data rate limiting method, etc. In addition, memory 61 can also be used to temporarily store various types of data that have been output or will be output.

[0166] In some embodiments, processor 62 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip. This processor 62 is typically used to control the overall operation of the computer device 6. In this embodiment, processor 62 is used to execute computer-readable instructions stored in memory 61 or to process data, such as executing computer-readable instructions for a token bucket-based service data rate limiting method.

[0167] The network interface 63 may include a wireless network interface or a wired network interface, which is typically used to establish a communication connection between the computer device 6 and other electronic devices.

[0168] The computer equipment provided in this application accepts requests through the company's external interface, categorizes the request content and assigns unique keys to each, then establishes token buckets and assigns unique keys to them, associating the token bucket unique keys with business unique keys. The token generation speed of the token bucket matches the average rate of business requests. By establishing token buckets, business flow can be limited to prevent excessive business traffic and protect the system. A Map collection is also established to store the key-value relationship between all business unique keys and business flow limiters, saving the relationship between business requests and token buckets, facilitating the search for dedicated flow limit buckets for each business. By assigning unique keys to businesses, flow limit can be applied to each business separately, enabling finer-grained flow distribution and making business flow limiting more reasonable.

[0169] This application also provides another implementation, namely, a computer-readable storage medium storing computer-readable instructions that can be executed by at least one processor to cause the at least one processor to perform the steps of the token bucket-based service data rate limiting method described above.

[0170] The computer-readable storage medium provided in this application accepts requests through the company's external interface, then categorizes the request content and assigns each a unique key. A token bucket is then established and assigned a unique key, which is associated with a business unique key. The token generation speed of the token bucket matches the average rate of business requests. By establishing token buckets, business flow can be limited to prevent excessive business traffic and protect the system. A Map collection is also established to store the key-value relationship between all business unique keys and business flow limiters, saving the relationship between business requests and token buckets, facilitating the search for dedicated flow limit buckets for each business. By assigning unique keys to businesses, flow limit can be applied to each business separately, enabling finer-grained flow distribution and making business flow limiting more reasonable.

[0171] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods of the various embodiments of this application.

[0172] Obviously, the embodiments described above are only some embodiments of this application, not all embodiments. The accompanying drawings show preferred embodiments of this application, but do not limit the patent scope of this application. This application can be implemented in many different forms; rather, the purpose of providing these embodiments is to provide a more thorough and comprehensive understanding of the disclosure of this application. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing specific embodiments, or make equivalent substitutions for some of the technical features. Any equivalent structures made using the content of this application's specification and drawings, directly or indirectly applied to other related technical fields, are similarly within the scope of patent protection of this application.

Claims

1. A service data rate limiting method based on token bucket, characterized in that, Includes the following steps: Receive a service request sent by a user terminal, wherein the service request carries at least a service path; Read the business path carried in the business request; Based on the traffic volume of business requests along the same business path, the business requests are divided into primary business requests and secondary business requests. Build a unique business key for main business requests with the same business path; Assign a unified business-specific key to all secondary business requests; Read a preset Map set, wherein the Map set includes a business unique key corresponding to each business path and a token bucket rate limiter corresponding to each business unique key; Obtain the target business unique key corresponding to the business path and the target rate limiter corresponding to the target business unique key from the preset Map set; A rate limiting token is allocated to the service request according to the target rate limiter; When it is necessary to respond to the business request, it is determined whether the business request contains request content; If the requested content is not present in the business request, then the business request is responded to; If the requested content exists in the business request, then the token bucket algorithm and the token bucket rate limiter determine whether the rate limiting token of the business request meets the rate limiting conditions. If the rate limiting token meets the rate limiting conditions, the response will be delayed for a preset time. If the rate limiting token does not meet the rate limiting conditions, then the service request will be responded to.

2. The service data rate limiting method based on token bucket according to claim 1, characterized in that, The token bucket rate limiter includes multiple sets of primary token buckets and secondary token buckets. The primary token buckets are used to limit the rate of primary service requests, and the secondary token buckets are used to limit the rate of secondary service requests. Before the step of reading the preset Map collection, the following steps are also included: Set the capacity b of the token bucket; Set the number of tokens r added to the bucket per second based on the average rate of user business requests; When there is a request of n bytes, subtract n tokens from the token bucket. If the business request has already performed a token add operation, then determine whether the number of tokens in the token bucket is greater than n. If the number of tokens in the token bucket is greater than n, the size of the token bucket is set according to the rate of business requests; otherwise, access is denied. Specifically, when the number of tokens in the token bucket equals b, newly generated tokens will be discarded. The size of the token bucket capacity b is proportional to the average rate of service requests.

3. The service data rate limiting method based on token bucket according to claim 2, characterized in that: The current limiting method of the token bucket current limiter is as follows: Retrieve the unique key of the business request; Traverse the Map collection and find the token bucket that matches the business unique key in the Map collection; Send tokens to business requests via the token bucket; Determine whether a business request carries a token, and rate-limit business requests that do not carry a token.

4. The service data rate limiting method based on token bucket according to claim 1, characterized in that, The step of allocating a rate limiting token to the service request based on the target rate limiter specifically includes the following steps: The rate limiting token is preferentially allocated to service requests that have a delayed response time.

5. The service data rate limiting method based on token bucket according to claim 1, characterized in that, The steps for responding to the service request specifically include the following steps: Determine if there are any pending or unprocessed business requests; If there are pending service requests, then add those service requests to the queue. If there are no pending business requests, then determine whether the number of tokens in the token bucket is less than the number of bytes in the business request. If the number of tokens in the token bucket is less than the number of bytes in the service request, then the service request will be rejected. If the number of tokens in the token bucket is greater than or equal to the number of bytes in the business request, a normal response is given, and a token is matched for the business request.

6. A service data rate limiting device based on a token bucket, characterized in that, include: A request receiving module is used to receive service requests sent by user terminals, wherein the service request carries at least a service path; The business path reading module is used to read the business path carried in the business request; The request segmentation module is used to divide the business requests into main business requests and secondary business requests based on the traffic volume of business requests along the same business path. The unique key building module is used to build a unique business key for main business requests with the same business path; The unique key allocation module is used to assign a unified business unique key to all sub-business requests; The Map collection reading module is used to read a preset Map collection, wherein the Map collection includes a business unique key corresponding to each business path and a token bucket rate limiter corresponding to each business unique key; The rate limiter acquisition module is used to acquire the target business unique key corresponding to the business path and the target rate limiter corresponding to the target business unique key from the preset Map set; The token allocation module is used to allocate a rate limiting token to the service request according to the target rate limiter; The request content determination module is used to determine whether the business request contains request content when it is necessary to respond to the business request. The first response module is used to respond to the business request if the requested content does not exist in the business request. The rate limiting condition judgment module is used to determine whether the rate limiting token of the service request meets the rate limiting condition if the service request contains the request content, based on the token bucket algorithm and the token bucket rate limiter. The delayed response module is used to delay the response for a preset time if the rate limiting token meets the rate limiting condition. The second response module is used to respond to the service request if the rate limiting token does not meet the rate limiting conditions.

7. A computer device comprising a memory (61), a processor (62), and a network interface (63), wherein the memory stores computer-readable instructions, and the processor, when executing the computer-readable instructions, implements the steps of the flow limiting method as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the rate limiting method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Flow limiting method and device

    CN110611623A

  • Flow control method and device, equipment, storage medium and computer product

    CN115002033A