A service flow limiting method, device, electronic equipment and storage medium

By building custom annotations and aspect logic in the service rate limiting method and creating a target token bucket, the problem of rate limiting differences between different interfaces is solved, flexible service rate limiting is achieved, and the normal operation of interface functions is guaranteed.

CN116366562BActive Publication Date: 2025-12-19PING AN BANK CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202211544903.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-02
Publication Date
2025-12-19
Estimated Expiration
2042-12-02

AI Technical Summary

Technical Problem

In existing technologies, service rate limiting methods cannot personalize rate limiting based on the differences in the complexity of business functions of different interfaces, resulting in the maximum traffic depending on the worst-performing interface, which affects the overall performance and availability of the service.

Method used

By constructing custom annotations and aspect logic, a target token bucket is created and integrated into the project source code. AOP technology is used to rate limit the interface. The target token bucket is created by constructing custom annotations and aspect logic, and the aspect logic containing the target token bucket is integrated into the target project source code so that each interface in the target project source code corresponds to the target token bucket. External requests are received, and tokens are retrieved from the target token bucket according to the target interface corresponding to the external request. The retrieval result is obtained, and rate limiting is applied to the target interface based on the retrieval result.

Benefits of technology

It enables flexible rate limiting for different interfaces in the service, improves the flexibility of service rate limiting, ensures the normal functioning of frequently used interfaces, and is suitable for scenarios that require limiting the average transmission rate while allowing a certain amount of burst transmission.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116366562B_ABST
    Figure CN116366562B_ABST
Patent Text Reader

Abstract

The application provides a service flow limiting method and device, electronic equipment and storage medium. The method comprises the following steps: in response to an annotation configuration operation, a custom annotation corresponding to the annotation configuration operation is constructed; in response to an aspect logic configuration operation, an aspect logic corresponding to the aspect logic configuration operation is created using the custom annotation; in response to a target token bucket creation operation, a target token bucket corresponding to the target token bucket creation operation is created in the aspect logic, and the aspect logic containing the target token bucket is integrated in a target project source code, so that each interface included in the target project source code corresponds to a target token bucket; an external request is received, a token is obtained from the target token bucket according to a target interface corresponding to the external request, an acquisition result is obtained, and the target interface is flow limited according to the acquisition result. The application can respectively limit the flow of different interfaces in the service, greatly improving the flexibility of the service flow limiting.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of service flow control, in particular to a service flow control method and device, electronic equipment and storage medium. BACKGROUND

[0002] In the software development process, in order to avoid the service being accessed by too many requests in the case of high concurrency, resulting in the service being unavailable after the service is online. In the case of insufficient service resources, in order to ensure that the core business can run normally, or based on business considerations, such as paying users can enjoy more traffic, ordinary users need to be limited in traffic, and some services need to be limited in flow.

[0003] Generally, the development or operation and maintenance personnel will configure service access threshold in the web server such as nginx or tomcat to limit the service access, but this way will have the following problems: the same threshold will be used to limit the flow of all interfaces in the service, but in the actual business scenario, different interfaces can have different thresholds due to the complexity of business functions. This will result in the maximum flow of the service depending on the interface with the worst performance. SUMMARY

[0004] Therefore, the purpose of the present application is to provide a service flow control method and device, electronic equipment and storage medium, which can realize limiting the flow of each interface in the service.

[0005] In a first aspect, the embodiments of the present application provide a service flow control method, which comprises:

[0006] In response to an annotation configuration operation, a custom annotation corresponding to the annotation configuration operation is constructed;

[0007] In response to an aspect logic configuration operation, an aspect logic corresponding to the aspect logic configuration operation is created using the custom annotation;

[0008] In response to a target token bucket creation operation, a target token bucket corresponding to the target token bucket creation operation is created in the aspect logic, and the aspect logic containing the target token bucket is integrated in the target project source code, so that each interface included in the target project source code corresponds to the target token bucket;

[0009] An external request is received, a token is obtained from the target token bucket according to the target interface corresponding to the external request, an acquisition result is obtained, and the target interface is limited in flow according to the acquisition result.

[0010] In some technical solutions of the present application, when the target token bucket corresponding to the target token bucket creation operation is created in the aspect logic, the method further comprises:

[0011] set the incoming production parameter; the transmission parameter represents the number of tokens generated in the target token bucket per unit time;

[0012] When the production requirement is met, the target token bucket produces a corresponding number of tokens according to the production parameter.

[0013] In some technical solutions of the present application, the above method determines whether the production requirement is met by the following method:

[0014] Obtain the current production time and compare the current production time with the preset production time period. If the current production time is located within the preset production time period, the production requirement is met.

[0015] In some technical solutions of the present application, the above method further includes:

[0016] In response to the cache token bucket creation operation, a cache token bucket corresponding to the cache token bucket creation operation is created in the aspect logic.

[0017] In some technical solutions of the present application, the above receiving an external request, obtaining tokens from the target token bucket according to the target interface corresponding to the external request, obtaining a result, and limiting the target interface according to the result, includes:

[0018] Receiving an external request, obtaining tokens from the target token bucket and the cache token bucket according to the target interface corresponding to the external request, obtaining a result, and limiting the target interface according to the result.

[0019] In some technical solutions of the present application, the above obtaining tokens from the target token bucket and the cache token bucket according to the target interface corresponding to the external request includes:

[0020] Obtaining tokens from the target token bucket, and if tokens cannot be obtained and the acquisition requirement is met, obtaining tokens from the cache token bucket.

[0021] In some technical solutions of the present application, the above result includes obtaining tokens and not obtaining tokens.

[0022] If tokens are obtained, the target interface is not limited, and the business program corresponding to the target interface is executed.

[0023] If tokens are not obtained, the target interface is limited, and the business program corresponding to the target interface is not executed.

[0024] In a second aspect, the embodiments of the present application provide a service limiting device, which includes:

[0025] The first response module is configured to, in response to the annotation configuration operation, construct a custom annotation corresponding to the annotation configuration operation.

[0026] The second response module is configured to, in response to the aspect logic configuration operation, create aspect logic corresponding to the aspect logic configuration operation using the custom annotation.

[0027] The third response module is configured to, in response to the target token bucket creation operation, create a target token bucket corresponding to the target token bucket creation operation in the aspect logic, and integrate the aspect logic containing the target token bucket in a target project source code, so that each interface included in the target project source code corresponds to the target token bucket.

[0028] The processing module is configured to receive an external request, acquire a token from the target token bucket according to a target interface corresponding to the external request, obtain an acquisition result, and perform flow control on the target interface according to the acquisition result.

[0029] In a third aspect, an electronic device is provided, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the service flow control method when executing the computer program.

[0030] In a fourth aspect, a computer readable storage medium is provided, which stores a computer program, and the computer program implements the steps of the service flow control method when executed by a processor.

[0031] The technical scheme provided by the embodiments of the present application can have the following beneficial effects:

[0032] The method provided by the present application includes: in response to an annotation configuration operation, constructing a custom annotation corresponding to the annotation configuration operation; in response to an aspect logic configuration operation, creating aspect logic corresponding to the aspect logic configuration operation using the custom annotation; in response to a target token bucket creation operation, creating a target token bucket corresponding to the target token bucket creation operation in the aspect logic, and integrating the aspect logic containing the target token bucket in a target project source code, so that each interface included in the target project source code corresponds to the target token bucket; receiving an external request, acquiring a token from the target token bucket according to a target interface corresponding to the external request, obtaining an acquisition result, and performing flow control on the target interface according to the acquisition result. The present application can perform flow control on different interfaces in a service respectively, greatly improving the flexibility of service flow control, ensuring the normal function of frequently used interfaces, and the method is suitable for scenarios that require not only to limit the average transmission rate of data, but also to allow a certain degree of burst transmission.

[0033] In order to make the above objectives, characteristics and advantages of the present application more apparent, clear and easy to understand, the following will specifically describe a preferred embodiment in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF DRAWINGS

[0034] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments. It should be understood that the following drawings only show some of the embodiments of the present application, and therefore should not be considered as a limitation to the scope. For those skilled in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.

[0035] Figure 1 A flowchart of a method for service flow control provided by an embodiment of the present application is shown;

[0036] Figure 2 A schematic diagram of a device for service flow control provided by an embodiment of the present application is shown;

[0037] Figure 3 A schematic diagram of another device for service flow control provided by an embodiment of the present application is shown;

[0038] Figure 4 A schematic diagram of an electronic device provided by an embodiment of the present application is shown. DETAILED DESCRIPTION

[0039] In order to make the objectives, technical solutions and advantages of the embodiments of the present application more apparent, the following will clearly and completely describe the technical solutions in the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. It should be understood that the drawings in the present application only serve the purpose of illustration and description, and are not used to limit the scope of protection of the present application. In addition, it should be understood that the schematic drawings are not drawn according to the actual scale. The flowchart shows the operations implemented according to some embodiments of the present application. It should be understood that the operations of the flowchart can not be implemented in sequence, and the steps without logical context relationship can be reversed in sequence or implemented simultaneously. In addition, one or more other operations can be added to the flowchart or one or more operations can be removed from the flowchart under the guidance of the content of the present application.

[0040] In addition, the described embodiments are only some of the embodiments of the present application, not all. The components of the embodiments of the present application described and shown in the drawings herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the claimed application, but only represents selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.

[0041] It should be noted that the term "comprising" will be used in the embodiments of the present application to indicate the presence of the features declared thereafter, but does not exclude the addition of other features.

[0042] In the software development process, in order to avoid the service being accessed by too many requests in the case of high concurrency, resulting in the service being unavailable. In the case of insufficient service resources, in order to ensure that the core business can run normally, or based on business considerations, such as paid users can enjoy larger traffic, ordinary users need to be limited traffic, some services need to be limited.

[0043] Generally, the development or operation and maintenance personnel will configure service access threshold in the web server such as nginx or tomcat to limit the service access, but this way will have the following problems: the same threshold will be limited for all interfaces in the service, but in the actual business scenario, different interfaces can have different thresholds due to the complexity of business functions. This will result in the maximum traffic of the service depending on the interface with the worst performance.

[0044] Based on this, the embodiments of the present application provide a service limiting method, device, electronic equipment and storage medium, which are described below through embodiments.

[0045] Figure 1 A flowchart of a service limiting method provided by an embodiment of the present application is shown, wherein the method comprises steps S101-S104; specifically:

[0046] S101, in response to the annotation configuration operation, constructing a custom annotation corresponding to the annotation configuration operation;

[0047] S102, in response to the aspect logic configuration operation, creating aspect logic corresponding to the aspect logic configuration operation using the custom annotation;

[0048] S103, in response to the target token bucket creation operation, creating a target token bucket corresponding to the target token bucket creation operation in the aspect logic, and integrating the aspect logic containing the target token bucket in the target project source code, so that each interface included in the target project source code corresponds to the target token bucket;

[0049] S104, receiving an external request, obtaining a token from the target token bucket according to a target interface corresponding to the external request, obtaining a result, and limiting the target interface according to the result.

[0050] The application can limit the flow of different interfaces in the service respectively, greatly improving the flexibility of service flow limiting, ensuring the normal function of frequently used interfaces, and the method is suitable for scenes requiring to limit the average transmission rate of data and allowing a certain degree of burst transmission.

[0051] Some embodiments of the application will be described in detail below. In the case of no conflict, the following examples and features in the examples can be combined with each other.

[0052] S101, in response to the annotation configuration operation, constructing a custom annotation corresponding to the annotation configuration operation.

[0053] The application first acquires the target project source code from the project code management platform gitlab through the gitclone command. Source code (also known as source program) refers to a text file written in a certain programming language specification, which is a series of human-readable computer language instructions. In modern programming languages, source code can be in the form of books or tapes, but the most commonly used format is a text file. The purpose of this typical format is to compile computer programs. The ultimate goal of computer source code is to translate human-readable text into binary instructions that can be executed by computers. This process is called compilation, which is done through a compiler. A project's source code generally contains multiple interfaces, and the application needs to limit the flow of interfaces included in the target project source code respectively (some interfaces are limited, and some interfaces are not limited; the limit of the limited interface is different).

[0054] In the embodiment of the application, the user performs an annotation configuration operation through a terminal device such as a computer. After the background (server) receives the operation instruction corresponding to the configuration operation, a custom annotation corresponding to the annotation configuration operation is generated. Annotation is an important component technology in program development, and reasonable annotation can make our project maintenance more convenient. The essence of annotation is that the compiler will not compile the part containing the annotation when compiling the program.

[0055] Specifically, write a custom annotation: create a new Java class of type `@interface`, with the class name being the name of the custom annotation. Define a service degradation threshold variable `maxcount` in the class file and set a default value greater than 1. Include a service degradation handling method or class `failback` in the class file (this method or class is called when the number of service requests exceeds the set threshold).

[0056] S102. Respond to the aspect logic configuration operation by using the custom annotation to create aspect logic corresponding to the aspect logic configuration operation.

[0057] After generating custom annotations, this application requires creating aspect logic based on those annotations. Aspect-Oriented Programming (AOP) is a technique that achieves unified maintenance of program functionality through pre-compilation and runtime dynamic proxies. AOP is a continuation of OOP, a hot topic in software development, and an important component of the Spring framework; it is a derivative paradigm of functional programming. AOP can isolate different parts of business logic, thereby reducing coupling between them, improving program reusability, and increasing development efficiency. This application uses aspect logic to isolate multiple interfaces in the target project, thereby enabling rate limiting for different interfaces.

[0058] Based on the user's configuration of the aspect logic, create the corresponding aspect logic. Specifically, write the aspect method using the @aspect annotation, implement it using @Around(value = "@annotation(custom service degradation annotation)"), and ensure that the aspect method is effective throughout the entire lifecycle of the loaded interface or method using @aroud.

[0059] S103. In response to the target token bucket creation operation, create a target token bucket corresponding to the target token bucket creation operation in the aspect logic, and integrate the aspect logic containing the target token bucket into the target project source code, so that each interface included in the target project source code corresponds to one target token bucket.

[0060] After creating the aspect logic, to achieve rate limiting, a target token bucket needs to be created based on the aspect logic. After creating the target token bucket, the aspect logic containing the target token bucket is integrated with the target project source code. This allows each interface in the target project source code to have its own target token bucket, thereby achieving rate limiting for each interface. The token bucket works as follows: the system adds tokens to the target token bucket at a fixed rate, for example, every 10ms. If the bucket is full, no more tokens are added. When a new request arrives, it takes one token; if no token is available, the service is rejected.

[0061] The application also sets the incoming production parameter when creating the target token bucket; the transmission parameter represents the number of tokens generated in the target token bucket per unit time; when the production requirement is met, the target token bucket produces tokens according to the production parameter. In order to avoid resource waste, the application sets certain requirements for token production when the target token bucket generates tokens, and only produces tokens when the production requirements are met.

[0062] In specific implementation, this production requirement is mainly reflected in the production time, that is, the application limits the generation time of the target token bucket. That is, the current production time is obtained before the token is produced, and the current production time is compared with the preset production time period, if the current production time is located in the preset production time period, the production requirement is met. In specific implementation, if tokens are always produced regardless of whether it is working time or not, resource waste will be caused, because tokens generated at non-working time will not be used by anyone.

[0063] Specifically, the token bucket is created based on the RateLimiter create method, and the permitsPerSecond parameter is set when creating the token bucket to set the number of tokens generated per second tokennum. It is judged whether the current time is (working time 8-18), if yes, the number of tokens generated per second tokennum is 10, if not, the number of tokens generated per second tokennum is set according to the parameter.

[0064] In the embodiment of the application, as an optional embodiment, a cache token bucket corresponding to the cache token bucket creation operation is created in the aspect logic in response to the cache token bucket creation operation.

[0065] As an embodiment of the application, the application also creates a cache token bucket when creating the target token bucket. The cache token bucket is used to take tokens from the target token bucket again when no tokens are taken.

[0066] The cache token bucket is created at the same time, and a specified token is added at 0 o'clock every day. The result / method is limited to logic: when the service request enters, before entering the business interface / method, first get the token from the token bucket, if it can be obtained, execute the business interface / method, and delete the token just obtained from the token bucket. If the token cannot be obtained from the token bucket, if it is in working time (working time 8-18), the token is obtained from the cache token bucket, if it can be obtained, the token business logic is executed, if it cannot be obtained, the failback method is executed.

[0067] S104, receiving an external request, obtaining a token from the target token bucket according to a target interface corresponding to the external request, obtaining an acquisition result, and performing flow control on the target interface according to the acquisition result.

[0068] After the above configuration is completed, an external request is received. After receiving the external request, a token is obtained from the target token bucket. If the token is obtained, the target interface is not flow controlled, and a business program corresponding to the target interface is executed. If the token is not obtained, the target interface is flow controlled, and the business program corresponding to the target interface is not executed.

[0069] Specifically, the service degradation configuration of the specified interface or method is implemented by marking the “@self-defined annotation” on the method or interface that needs to be flow controlled. If different service thresholds of different interfaces or methods need to be set, the “@self-defined annotation (maxcount = specified service threshold)” is marked. If the service threshold is not specified, the default configured service threshold is used to degrade the service.

[0070] In the embodiment of the application, as an optional embodiment, when the buffer token bucket is constructed, an external request is received, a token is obtained from the target token bucket and the buffer token bucket according to a target interface corresponding to the external request, an acquisition result is obtained, and flow control is performed on the target interface according to the acquisition result. The token is obtained from the target token bucket. If the token cannot be obtained and the acquisition requirement is met, the token is obtained from the buffer token bucket.

[0071] Specifically, when a service request enters, before entering the business interface / method, a token is first obtained from the token bucket. If the token can be obtained, the business interface / method is executed, and the token just obtained is deleted from the token bucket. If the token cannot be obtained from the token bucket, if it is working time (working time 8-18), a token is obtained from the buffer token bucket. If the token can be obtained, the token business logic is executed. If the token cannot be obtained, the failback method is executed.

[0072] In this embodiment, as an optional implementation, the project source code is obtained from the project code management platform GitLab using the `git clone` command. Custom annotations are written (to facilitate the implementation of service degradation logic for specified interfaces or methods through annotations). A new Java class of type `@interface` is created, with the class name being the custom annotation name. A service degradation threshold variable `maxcount` is defined in the class file, with a default value greater than 1. A service degradation handling method or class `failback` is defined in the class file. (When the number of service requests exceeds the set threshold, this method or class is called to handle the situation). Aspect-Oriented Programming (AOP) logic is written: Aspect methods are written using the `@aspect` annotation and implemented using `@Around(value = "@annotation(custom service degradation annotation)")`. The `@aroud` annotation ensures that the aspect method is effective throughout the entire lifecycle of the loaded interface or method. A token bucket is created in the aspect: A token bucket is created based on the `RateLimiter create` method, and the `permitsPerSecond` parameter is set when creating the token bucket to determine the number of tokens generated per second. Rate limiting logic for results / methods: When a service request arrives, before entering the business interface / method, a token is first retrieved from the token bucket. If a token is obtained, the business interface / method is executed, and the previously retrieved token is removed from the token bucket. If a token cannot be retrieved from the token bucket, the failback method is executed. In practical use: The "@custom annotation" is used to annotate the method or interface that requires rate limiting to configure service degradation for that specific interface or method. If different service thresholds need to be set for different interfaces or methods, the annotation "@custom annotation(maxcount = specified service threshold)" is used. If no service threshold is specified, the default service threshold is used for service degradation.

[0073] In the embodiments of the present application, as an optional embodiment, project source code is obtained from a project code management platform gitlab through a gitclone command. A custom annotation is written (to facilitate service degradation of an interface or a method that needs to be implemented through an annotation method, to achieve service degradation logic of a specified interface or method), a new@interface type java class is created, the class name is the custom annotation name, a service degradation threshold variable maxcount is defined in the class file, and a default value greater than 1 is set, and a processing method or class failback after service degradation is set in the class file. An aspect method is written through an aspect annotation, which is implemented through an@Around(value@annotation(custom service degradation annotation)) method, which ensures that the aspect method is effective throughout the life cycle of the loaded interface or method. A token bucket is created in the aspect: a token bucket is created based on the RateLimiter create method, and the permitsPerSecond parameter is set when creating the token bucket to set the number of tokens generated per second tokennum. Determine whether the current time is (working hours 8-18), if so, generate 10 tokens per second. If not, generate tokens per second according to the parameter setting. At the same time, create a cache token bucket, and add a specified token at 0 o'clock every day. The result / method is limited: when the service request enters, before entering the business interface / method, first get the token from the token bucket, if you can get it, execute the business interface / method, and delete the token just obtained from the token bucket. If you can't get the token from the token bucket, if it's working hours (working hours 8-18), get the token from the cache token bucket, if you can get it, execute the token business logic, if you can't get it, execute the degradation method failback.

[0074] The method of the present application creates a token bucket (a specified number of tokens is added to the token bucket per unit time) when the interface method is initialized through AOP (aspect-oriented programming), when the external request reaches the interface, it is determined whether to limit the flow according to whether the token can be obtained from the token bucket, when the external request cannot obtain the token from the token bucket, the system will take some measures to achieve the purpose of limiting the flow, thereby greatly improving the flexibility of service flow limiting, ensuring the normal function of frequently used interfaces, and the method is suitable for scenes that require to limit the average transmission rate of data and allow a certain degree of burst transmission.

[0075] Figure 2 A structural schematic diagram of a service flow limiting device provided by an embodiment of the present application is shown, and the device comprises:

[0076] The first response module is configured to, in response to the annotation configuration operation, construct a custom annotation corresponding to the annotation configuration operation;

[0077] The second response module is configured to, in response to the aspect logic configuration operation, create aspect logic corresponding to the aspect logic configuration operation using the custom annotation;

[0078] The third response module is configured to, in response to the target token bucket creation operation, create a target token bucket corresponding to the target token bucket creation operation in the aspect logic, and integrate the aspect logic containing the target token bucket in a target project source code, so that each interface included in the target project source code corresponds to the target token bucket.

[0079] The processing module is configured to receive an external request, obtain a token from the target token bucket according to a target interface corresponding to the external request, obtain an acquisition result, and perform flow limiting on the target interface according to the acquisition result.

[0080] When the target token bucket corresponding to the target token bucket creation operation is created in the aspect logic, as shown in Figure 3 The device further includes:

[0081] The setting module is configured to set a production parameter transmitted; the transmission parameter represents a number of tokens generated in the target token bucket per unit time;

[0082] When the production requirement is met, the target token bucket produces a corresponding number of tokens according to the production parameter.

[0083] Whether the production requirement is met is determined by the following method:

[0084] The current production time is obtained, and the current production time is compared with a preset production time period; if the current production time is located within the preset production time period, the production requirement is met.

[0085] The device further includes a fourth response module configured to, in response to a cache token bucket creation operation, create a cache token bucket corresponding to the cache token bucket creation operation in the aspect logic.

[0086] The receiving of the external request, the obtaining of the token from the target token bucket according to the target interface corresponding to the external request, the obtaining of the acquisition result, and the flow limiting on the target interface according to the acquisition result include:

[0087] The receiving of the external request, the obtaining of the token from the target token bucket and the cache token bucket according to the target interface corresponding to the external request, the obtaining of the acquisition result, and the flow limiting on the target interface according to the acquisition result.

[0088] the target token bucket and the cache token bucket according to the target interface corresponding to the external request, comprising:

[0089] acquiring tokens from the target token, and acquiring tokens from the cache token if tokens cannot be acquired and the acquisition requirement is met.

[0090] the acquisition result comprises that tokens are acquired and tokens are not acquired;

[0091] if tokens are acquired, the target interface is not throttled, and a business program corresponding to the target interface is executed;

[0092] if tokens are not acquired, the target interface is throttled, and the business program corresponding to the target interface is not executed.

[0093] As shown in Figure 4 The embodiment of the present application provides an electronic device for executing the service throttling method in the present application, the device comprises a memory, a processor, a bus, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to realize the steps of the service throttling method.

[0094] Specifically, the memory and the processor can be general memory and processor, which are not limited here, and when the processor runs the computer program stored in the memory, the service throttling method can be executed.

[0095] Corresponding to the service throttling method in the present application, the embodiment of the present application further provides a computer readable storage medium, and the computer readable storage medium stores a computer program, and the computer program is executed by the processor to execute the steps of the service throttling method.

[0096] Specifically, the storage medium can be a general storage medium, such as a mobile disk, a hard disk, etc., and the computer program on the storage medium can be executed to execute the service throttling method.

[0097] In the embodiments provided in the present application, it should be understood that the disclosed system and method can be implemented in other ways. The system embodiments described above are only schematic, for example, the division of the units is only a logical function division, and another division mode can be used in actual implementation, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some communication interfaces, and the coupling or communication connection between systems or units can be electrical, mechanical or other forms.

[0098] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected to achieve the purpose of the embodiment according to actual needs.

[0099] In addition, the functional units in the embodiments provided in the present application can be integrated into one processing unit, or each unit can exist alone physically, or two or more units can be integrated into one unit.

[0100] The functions, if realized in the form of software functional units and sold or used as independent products, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or the parts of the prior art that make contributions or parts of the technical solutions can be embodied in the form of software products. The computer software product is stored in a storage medium, and includes a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.

[0101] It should be noted that: similar reference numerals and letters represent similar items in the following drawings, therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings, in addition, the terms "first", "second", "third" and the like are only used to distinguish description, and cannot be understood as indicating or implying relative importance.

[0102] Finally, it should be noted that: the above-described embodiments are only specific embodiments of the present application, used to illustrate the technical solutions of the present application, and not to limit them, the protection scope of the present application is not limited thereto, although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any skilled person in the art can modify or easily think of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed by the present application, or make equivalent replacements to some of the technical features; and these modifications, changes or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application. All should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be limited by the protection scope of the claims.

Claims

1. A method for service rate limiting, characterized in that, The method includes: In response to annotation configuration operations, a custom annotation corresponding to the annotation configuration operation is constructed; wherein, the custom annotation includes a service degradation threshold variable for defining the interface rate limiting threshold and a processing method after service degradation; In response to the aspect logic configuration operation, the custom annotation is used to create aspect logic corresponding to the aspect logic configuration operation; wherein, the aspect logic is used to isolate multiple interfaces in the target project; In response to the target token bucket creation operation, a target token bucket corresponding to the target token bucket creation operation is created in the aspect logic, and the aspect logic containing the target token bucket is integrated into the target project source code, so that each interface included in the target project source code corresponds to one target token bucket; Receive an external request, retrieve a token from the target token bucket according to the target interface corresponding to the external request, obtain the retrieval result, and rate limit the target interface according to the retrieval result; The results obtained include whether a token was obtained or not. If a token is obtained, no rate limiting is applied to the target interface, and the business program corresponding to the target interface is executed; If no token is obtained and the number of external requests exceeds the rate limiting threshold defined by the service degradation threshold variable, the post-service degradation processing method shall be executed.

2. The method according to claim 1, characterized in that, When creating the target token bucket corresponding to the target token bucket creation operation in the aspect logic, the method further includes: Set the input production parameters; the production parameters represent the number of tokens generated in the target token bucket per unit time. When production requirements are met, the target token bucket produces the corresponding number of tokens according to the production parameters.

3. The method according to claim 2, characterized in that, The method determines whether production requirements are met using the following approach: Obtain the current production time and compare it with a preset production time period. If the current production time is within the preset production time period, the production requirements are met.

4. The method according to claim 1, characterized in that, The method further includes: In response to the cache token bucket creation operation, a cache token bucket corresponding to the cache token bucket creation operation is created in the aspect logic.

5. The method according to claim 4, characterized in that, The process of receiving an external request, retrieving a token from the target token bucket based on the target interface corresponding to the external request, obtaining the retrieval result, and rate limiting the target interface based on the retrieval result includes: Receive an external request, retrieve a token from the target token bucket and the cache token bucket according to the target interface corresponding to the external request, obtain the retrieval result, and rate limit the target interface according to the retrieval result.

6. The method according to claim 5, characterized in that, The step of retrieving a token from the target token bucket and the cached token bucket based on the target interface corresponding to the external request includes: Obtain a token from the target token; if a token cannot be obtained but the acquisition requirements are met, obtain a token from the cached token.

7. A service rate limiting device, characterized in that, The device includes: The first response module is used to respond to annotation configuration operations and construct a custom annotation corresponding to the annotation configuration operation; wherein, the custom annotation includes a service degradation threshold variable for defining the interface rate limiting threshold and a processing method after service degradation; The second response module is used to respond to aspect logic configuration operations, and uses the custom annotation to create aspect logic corresponding to the aspect logic configuration operation; wherein, the aspect logic is used to isolate multiple interfaces in the target project; The third response module is used to respond to the target token bucket creation operation, create a target token bucket corresponding to the target token bucket creation operation in the aspect logic, and integrate the aspect logic containing the target token bucket into the target project source code, so that each interface included in the target project source code corresponds to one target token bucket; The processing module is used to receive external requests, retrieve tokens from the target token bucket according to the target interface corresponding to the external request, obtain the retrieval result, and perform rate limiting on the target interface according to the retrieval result; The results obtained include whether a token was obtained or not. If the processing module obtains the token, it will not rate-limit the target interface and will execute the business program corresponding to the target interface. If no token is obtained and the number of external requests exceeds the rate limiting threshold defined by the service degradation threshold variable, the post-service degradation processing method shall be executed.

8. An electronic device, characterized in that, include: The device includes a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor communicates with the memory via the bus. When the machine-readable instructions are executed by the processor, they perform the steps of the service rate limiting method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the steps of the service rate limiting method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Flow limiting method and device based on Zuul, equipment and storage medium

    CN110380986A

  • System dynamic current limiting method and device, and storage medium

    CN112333111A

  • Network traffic limiting method and device, equipment and storage medium

    CN114143265A