A service flow limiting method, device, computer equipment and storage medium
Through tangential programming technology, preset current limit execution policies and current limit parameters are written for each service interface, which solves the problem that current limiting strategies cannot be configured in personalized in the existing technology, and achieves the satisfaction of current limiting requirements and improvement of service capabilities of different interfaces.
Patent Information
- Application Number
- CN202211642690.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-20
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2042-12-20
AI Technical Summary
In the prior art, service flow limiting strategies cannot be personalized according to the business function complexity and traffic requirements of different service interfaces, resulting in the worst-performance interface limiting the maximum traffic of the entire service and affecting service capabilities.
Through the Oriented Programming (AOP) technology, preset current limit execution policies are pre-written, and interface-specific current limit parameters are set through the Aspect Annotation. The specific method includes using a leaky bucket queue or token bucket queue algorithm, determining whether the current limiting conditions are met based on the preset current limiting parameters, and performing current limiting processing.
Different service interfaces have different current limiting parameter configurations to meet the current limiting needs of each interface without affecting the overall service capability. At the same time, the adoption of section-oriented programming improves code reuse and development efficiency.
Smart Images

Figure CN115987902B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network communication technology, and in particular to a service current limiting method, device, computer equipment and storage medium. Background Art
[0002] During the software development process, in order to avoid service unavailability due to high concurrency after the service is launched, some flow limiting strategies are usually adopted to limit access to some requests, thereby ensuring that the core business can operate normally when service resources are insufficient.
[0003] In the prior art, a unified configuration is usually performed in a Web server such as Nginx or Tomcat, but this method will cause all interfaces of the service to use the same flow limiting parameters for flow limiting; in actual business scenarios, different interfaces have different corresponding service flows due to the different complexities of business functions. If the same flow limiting parameters are used for flow limiting, the setting of the flow limiting parameters needs to be based on the performance of the interface as a minimum, resulting in the maximum flow of the service depending on the interface with the worst performance, which seriously affects the service capability. Summary of the invention
[0004] In view of the deficiencies in the prior art, the present invention provides a service flow limiting method, device, computer equipment and storage medium.
[0005] In a first aspect, in one embodiment, the present invention provides a service flow limiting method, comprising:
[0006] Obtaining a first target service request received by the target service interface;
[0007] According to the aspect annotation of the target service interface, obtain the preset current limiting execution strategy and the preset current limiting parameters of the target service interface;
[0008] Determine, according to a preset current limiting execution strategy and preset current limiting parameters, whether the target service interface meets the first trigger result of the current limiting condition;
[0009] If the first trigger result indicates that the target service interface meets the current limiting condition, current limiting processing is performed on the first target service request.
[0010] In one embodiment, the preset current limiting execution strategy includes a leaky bucket queue, and the preset current limiting parameter includes a target request quantity corresponding to the leaky bucket queue; and the first trigger result of determining whether the target service interface meets the current limiting condition according to the preset current limiting execution strategy and the preset current limiting parameter includes:
[0011] Check the current number of requests in the leaky bucket queue;
[0012] If the current number of requests is not less than the target number of requests, a first trigger result is obtained, indicating that the target service interface meets the current limiting condition.
[0013] In one embodiment, after the step of determining whether the target service interface meets the first trigger result of the current limiting condition according to the preset current limiting execution strategy and the preset current limiting parameters, the service current limiting method further includes:
[0014] If the first trigger result indicates that the target service interface does not meet the current limiting condition, the first target service request is determined as a pending service request and added to the leaky bucket queue;
[0015] Get the first pending service request added to the leaky bucket queue;
[0016] Perform service processing on the pending service request that is added first.
[0017] In one embodiment, the preset current limiting execution strategy includes a token bucket queue, and the preset current limiting parameter includes a target token number corresponding to the token bucket queue; according to the preset current limiting execution strategy and the preset current limiting parameter, determining whether the target service interface meets the first trigger result of the current limiting condition includes:
[0018] Detect the number of remaining tokens in the token bucket queue; the tokens in the token bucket queue are used to indicate service processing for service requests;
[0019] If the number of remaining tokens is not greater than the target token data, a first trigger result is obtained, indicating that the target service interface meets the current limiting condition.
[0020] In one embodiment, the flow limiting process is performed on the first target service request, including:
[0021] Performing service downgrading on the first target service request to obtain a downgraded service request;
[0022] According to the downgraded service request, current limiting indication information is sent to a first user terminal corresponding to the first target service request.
[0023] In one embodiment, according to the downgraded service request, sending current limiting indication information to the first user terminal corresponding to the first target service request includes:
[0024] Adding the downgraded service request to the queue sequence;
[0025] Determine a target queue position of the downgraded service request in the queue sequence;
[0026] According to the target queue position of the degraded service request in the queue sequence, flow limiting indication information is sent to the first user terminal; the flow limiting indication information includes the target queue position.
[0027] In one embodiment, after the step of sending the target queuing position to the first user terminal, the service flow limiting method further includes:
[0028] Re-determine whether the target service interface meets the second trigger result of the current limiting condition;
[0029] If the second trigger result indicates that the target service interface does not meet the current limiting condition, determining the second user terminal corresponding to the downgraded service request with the highest queue position in the queue sequence;
[0030] A second target service request corresponding to the second user terminal is sent to the target service interface.
[0031] In a second aspect, in one embodiment, the present invention provides a service current limiting device, comprising:
[0032] A request acquisition module, used to acquire a first target service request received by the target service interface;
[0033] The strategy acquisition module is used to obtain the preset current limiting execution strategy and the preset current limiting parameters of the target service interface according to the aspect annotation of the target service interface;
[0034] A trigger determination module, used to determine whether the target service interface meets the first trigger result of the current limiting condition according to the preset current limiting execution strategy and preset current limiting parameters;
[0035] The current limiting processing module is used to perform current limiting processing on the first target service request if the first trigger result indicates that the target service interface meets the current limiting condition.
[0036] In a third aspect, in one embodiment, the present invention provides a computer device comprising a memory and a processor; the memory stores a computer program, and the processor is used to run the computer program in the memory to execute the steps in the service flow limiting method in any of the above embodiments.
[0037] In a fourth aspect, in one embodiment, the present invention provides a storage medium storing a computer program, and the computer program is loaded by a processor to execute the steps in the service flow limiting method in any of the above embodiments.
[0038] Through the above-mentioned service current limiting method, device, computer equipment and storage medium, the corresponding preset current limiting execution strategy is pre-written in an aspect-oriented programming manner, the preset current limiting execution strategy is associated with each service interface through aspect annotations, and the current limiting parameters of each service interface are set through aspect annotations; for the target service interface, when the first target service request is received, the content in the aspect annotation can be executed, that is, the preset current limiting execution strategy is obtained and executed. In the process of executing the preset current limiting execution strategy, the preset current limiting parameters are used, so that different service interfaces can have different current limiting parameters, which can meet the current limiting requirements of all interfaces and will not affect the service capabilities; in addition, due to the use of aspect-oriented programming, only one preset current limiting execution strategy needs to be written in advance, which improves code reuse, reduces the workload of developers, and improves development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0040] Figure 1 A schematic diagram of an application scenario of a current limiting service method in an embodiment of the present invention;
[0041] Figure 2 A schematic diagram of a flow chart of a current limiting service method in one embodiment of the present invention;
[0042] Figure 3 It is a structural schematic diagram of a current limiting service device in one embodiment of the present invention;
[0043] Figure 4 The figure is a schematic diagram of the internal structure of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0044] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0045] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the drawings, which are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first" and "second" are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present application, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined. In the present application, the word "exemplary" is used to mean "used as an example, illustration or description". Any embodiment described as "exemplary" in the present application is not necessarily interpreted as being more preferred or more advantageous than other embodiments. In order to enable any person skilled in the art to implement and use the present invention, the following description is given. In the following description, details are listed for the purpose of explanation. It should be understood that those of ordinary skill in the art will recognize that the present invention can be implemented without using these specific details. In other examples, well-known structures and processes will not be elaborated in detail to avoid unnecessary details that make the description of the present invention obscure. Therefore, the present invention is not intended to be limited to the embodiments shown, but is consistent with the widest range of principles and features disclosed in this application.
[0046] The service flow limiting method in the embodiment of the present invention is applied to a service flow limiting device, and the service flow limiting device is arranged in a computer device; the computer device can be a terminal, such as a mobile phone or a tablet computer, and the computer device can also be a server, or a service cluster composed of multiple servers.
[0047] like Figure 1 As shown, Figure 1 This is a schematic diagram of an application scenario of the service flow limiting method in an embodiment of the present invention. The application scenario of the service flow limiting method in an embodiment of the present invention includes a computer device 100 (a service flow limiting device is integrated in the computer device 100), and a computer-readable storage medium corresponding to the service flow limiting method is run in the computer device 100 to execute the steps of the service flow limiting method.
[0048] Understandably, Figure 1The computer devices in the application scenario of the service flow limiting method shown, or the devices included in the computer devices, do not constitute limitations on the embodiments of the present invention. That is, the number of devices and types of devices included in the application scenario of the service flow limiting method, or the number of devices and types of devices included in each device, do not affect the overall implementation of the technical solution in the embodiments of the present invention, and can all be regarded as equivalent replacements or derivatives of the technical solution claimed to be protected in the embodiments of the present invention.
[0049] The computer device 100 in the embodiment of the present invention may be an independent device, or a device network or device cluster composed of devices. For example, the computer device 100 described in the embodiment of the present invention includes but is not limited to a computer, a network host, a single network device, a plurality of network devices, or a cloud device composed of a plurality of devices. The cloud device is composed of a large number of computers or network devices based on cloud computing.
[0050] Those skilled in the art will understand that Figure 1 The application scenario shown in the figure is only an application scenario corresponding to the technical solution of the present invention, and does not constitute a limitation on the application scenario of the technical solution of the present invention. Other application scenarios may also include Figure 1 More or fewer computer devices shown in, or computer device network connection relationships, such as Figure 1 Only one computer device is shown. It can be understood that the scenario of the service flow limiting method can also include one or more other computer devices, which are not limited here. The computer device 100 can also include a memory for storing information related to the service flow limiting method.
[0051] In addition, in the application scenario of the service current limiting method in the embodiment of the present invention, the computer device 100 may be provided with a display device, or the computer device 100 may not be provided with a display device and may be communicated with an external display device 200, and the display device 200 is used to output the result of the execution of the service current limiting method in the computer device. The computer device 100 may access a backend database 300 (the backend database 300 may be a local memory of the computer device 100, and the backend database 300 may also be provided in the cloud), and the backend database 300 stores information related to the service current limiting method.
[0052] It should be noted that Figure 1 The application scenario of the service flow limiting method shown is only an example. The application scenario of the service flow limiting method described in the embodiment of the present invention is to more clearly illustrate the technical solution of the embodiment of the present invention, and does not constitute a limitation on the technical solution provided by the embodiment of the present invention.
[0053] Based on the application scenario of the above service current limiting method, an embodiment of the service current limiting method is proposed.
[0054] First, as Figure 2 As shown, in one embodiment, the present invention provides a service flow limiting method, comprising:
[0055] Step 201, obtaining a first target service request received by a target service interface;
[0056] Among them, service interface generally refers to Web service interface. Web service interface is a shared boundary between an automation system and another automation system or a person. It is based on Web service technology and provides syntax interoperability support for different applications on the Internet by using a series of standard specifications, making it possible for application interaction between enterprises to develop from a local scope to a global scope. Applications that interact using Web service technology only need to comply with the corresponding Web service interface without considering their internal implementation, which greatly reduces the coupling between interactive applications and increases the flexibility of enterprise applications.
[0057] Among them, the execution subject of the service current limiting method in this embodiment can be understood as a service device, the first target service request is sent by the corresponding first user terminal, the service device and the first user terminal can constitute a service system, in the service system, the service device can be used as the corresponding server, the first user terminal can be used as the corresponding client, and the client and the server can send and receive data through the HTTP protocol (Hypertext Transfer Protocol, which is an application layer transmission protocol based on the TCP protocol, in simple terms, it is a rule for the client and the server to perform data transmission); under the HTTP protocol, the first target service request sent by the first user terminal is an http request (the http request includes an http request line, an http request header, and an http request body);
[0058] Step 202, obtaining a preset current limiting execution strategy and preset current limiting parameters of the target service interface according to the aspect annotation of the target service interface;
[0059] Among them, developers can pre-complement and improve object-oriented programming (OOP) through aspect-oriented programming (AOP for short); it provides another way to think about program structure. The key in object-oriented programming (OOP) is the object, while the key in aspect-oriented programming (AOP) is the aspect. The aspect includes notification and pointcut. Notification refers to the specific function and usage scenario of the aspect. It defines what the specific function of the aspect is and when it is used. Pointcut refers to which connection points the notification acts on. This point can be called pointcut. From the above introduction to notification, we can see that notification defines "what" and "when to use" the aspect, while pointcut defines "where" the "aspect" is used. The aforementioned connection point indicates a point where the aspect notification can be inserted during the business logic execution process. In Spring, this point can be written in the form of when calling a method, after calling a method, or when throwing an exception) to obtain a preset current limiting execution strategy (that is, the notification in the aspect). The preset current limiting execution strategy is oriented to all service interfaces, and each service interface can call the preset current limiting execution strategy. For example, in this embodiment, after obtaining the first target service request received by the target service interface, the preset current limiting execution strategy can be called. The limitation of "after obtaining the first target service request received by the target service interface" is the connection point, that is, the tangent point in the aspect;
[0060] Among them, the determination of the tangent point can be achieved by means of aspect annotation, that is, a aspect annotation is pre-marked for the target service interface, which is executed after the first target service request received by the target service interface is obtained. The method of calling the preset current limiting execution strategy is defined in the aspect annotation. In addition, in this embodiment, since the preset current limiting execution strategy is a universal strategy that can be oriented to all service interfaces, in order to realize the difference in current limiting parameters of different service interfaces, it is also necessary to define the preset current limiting parameters of the corresponding target service interface in the aspect annotation, so that after executing "obtaining the first target service request received by the target service interface", After the step of "service request", the pre-annotated aspect annotation can be obtained, and then the content in the aspect annotation is executed, that is, the preset current limiting execution strategy is called and the current limiting judgment is made according to the preset current limiting parameters; the preset current limiting execution strategy also contains the corresponding current limiting parameters, but the current limiting parameters are default values. When the corresponding preset current limiting parameters are not defined in the aspect annotation of a service interface, the preset current limiting execution strategy makes current limiting judgment according to the default values; in this process, the current limiting strategy for the target service interface can be implemented through the general preset current limiting execution strategy and the preset current limiting parameters for the target service interface;
[0061] Among them, when developers define the above-mentioned cut points and preset current limiting parameters through annotations, they first enter the corresponding instructions to obtain the project source code corresponding to the target service interface, and then write the corresponding aspect annotations. Specifically, a new Java class of interface type is created, and the class name is the name of the aspect annotation. Then, the preset current limiting parameters are defined in the class file. The preset current limiting parameters can be determined according to the actual functions of the target service interface;
[0062] Step 203, determining whether the target service interface meets the first trigger result of the current limiting condition according to the preset current limiting execution strategy and the preset current limiting parameters;
[0063] Among them, as mentioned above, the general preset current limiting execution strategy and the exclusive preset current limiting parameters can constitute an exclusive current limiting execution strategy. By executing the current limiting execution strategy, it can be determined whether the target service interface meets the current limiting condition (the current limiting condition mainly depends on the preset current limiting parameter. For example, when executing the strategy, if the current parameter exceeds the preset current limiting parameter, the current limiting condition is met), and the corresponding first trigger result is obtained;
[0064] Step 204: If the first trigger result indicates that the target service interface meets the current limiting condition, current limiting processing is performed on the first target service request;
[0065] If the flow limiting condition is met, it means that the service corresponding to the current target service interface cannot bear more service requests and needs to be flow limited. The specific method of flow limiting can be data discarding, that is, directly discarding the first target service request. However, this method will make the first user terminal unable to know the current request status, causing it to frequently initiate new first target service requests, or directly give up, resulting in user loss;
[0066] Among them, if the flow limiting condition is not met, it means that the service corresponding to the current target service interface can continue to bear more service requests, and the service processing can be performed on the first target service request obtained; in different fields or scenarios, different service processing can be performed based on different service requests, such as services in the field of financial technology (including loan applications, financial product purchases, e-commerce, electronic payments, electronic transactions, securities transactions, online banking, tax processing, e-government, online shopping, online insurance applications, etc.), services in the field of digital medicine (including smart medicine, online diagnosis, online drug purchases, intelligent disease analysis, etc.), and services in the field of artificial intelligence (including computer vision, natural language processing, speech recognition, biometrics, semantic recognition, retinal recognition, iris recognition, palmprint recognition, machine translation, virtual assistants, character recognition, voice interaction, etc.);
[0067] Through the above-mentioned service current limiting method, the corresponding preset current limiting execution strategy is written in advance through aspect-oriented programming, the preset current limiting execution strategy is associated with each service interface through aspect annotation, and the current limiting parameters of each service interface are set through aspect annotation; for the target service interface, when the first target service request is received, the content in the aspect annotation can be executed, that is, the preset current limiting execution strategy is obtained and executed. In the process of executing the preset current limiting execution strategy, the preset current limiting parameters are used, so that different service interfaces can have different current limiting parameters, which can meet the current limiting requirements of all interfaces and will not affect the service capabilities; in addition, due to the use of aspect-oriented programming, only one preset current limiting execution strategy needs to be written in advance, which improves code reuse, reduces the workload of developers, and improves development efficiency.
[0068] In one embodiment, the preset current limiting execution strategy includes a leaky bucket queue, and the preset current limiting parameter includes a target request quantity corresponding to the leaky bucket queue; and the first trigger result of determining whether the target service interface meets the current limiting condition according to the preset current limiting execution strategy and the preset current limiting parameter includes:
[0069] Check the current number of requests in the leaky bucket queue;
[0070] Among them, the leaky bucket queue is a queue created based on the leaky bucket algorithm (Leaky Bucket is an algorithm often used in traffic shaping (Traffic Shaping) or rate limiting (Rate Limiting) in the network world. Its main purpose is to control the rate at which data is injected into the network and smooth out burst traffic on the network; the leaky bucket algorithm provides a mechanism through which burst traffic can be shaped to provide a stable flow for the network). Each service request needs to be passed to the subsequent processing module through the leaky bucket queue, and the leaky bucket queue can only provide a fixed rate output, that is, the service requests in the queue are passed to the subsequent processing modules at fixed time intervals, and the service interface may receive service requests at a higher rate. Since the leaky bucket queue has a storage limit, when the storage limit is exceeded, the service request will be sent to the subsequent processing module. After the restriction, subsequent service requests cannot be added to the leaky bucket queue, and then the flow control is performed; usually, the storage limit is the maximum storage space of the leaky bucket queue, and in this embodiment, it can be determined by the preset flow control parameters. For example, the preset flow control parameters define that the target number of requests that can be stored in the leaky bucket queue is 300, and the maximum number of requests that the leaky bucket queue can actually store is 1000. However, under the limitation of the preset flow control parameters, the storage limit of the leaky bucket queue is that it can only store service requests with a request number not exceeding 300. Therefore, when making flow control judgments based on the leaky bucket queue, it is first necessary to determine the current number of requests stored in the leaky bucket queue;
[0071] If the current number of requests is not less than the target number of requests, a first trigger result indicating that the target service interface meets the current limiting condition is obtained;
[0072] Among them, for example, taking the example in the above steps as an example, if the current number of requests determined is 280, it means that the current number of requests is less than the target number of requests, thereby obtaining the first trigger result indicating that the target service interface does not meet the flow limiting condition; if the current number of requests determined is 300, it means that the current number of requests is not less than the target number of requests, thereby obtaining the first trigger result indicating that the target service interface meets the flow limiting condition;
[0073] It should be noted that since the preset current limiting execution strategy is for all service interfaces, and the current limiting parameters of different service interfaces are different, when using the leaky bucket queue method, the actual storage space of the leaky bucket queue needs to be set as large as possible to ensure that the current limiting parameters can be applied to all service interfaces;
[0074] Among them, when using the leaky bucket queue method, developers can write a preset current limiting execution strategy by first creating a leaky bucket queue and then setting the target number of requests for the leaky bucket queue, that is, the queue size.
[0075] In one embodiment, after the step of determining whether the target service interface meets the first trigger result of the current limiting condition according to the preset current limiting execution strategy and the preset current limiting parameters, the service current limiting method further includes:
[0076] If the first trigger result indicates that the target service interface does not meet the current limiting condition, the first target service request is determined as a pending service request and added to the leaky bucket queue;
[0077] Among them, the above embodiment has mentioned that when the leaky bucket queue is used as the current limiting execution strategy, if it is determined that the current number of requests is not less than the target number of requests, the current limiting condition is met and current limiting processing is required; if it is determined that the current number of requests is less than the target number of requests, the current limiting condition is not met and current limiting processing is not required; specifically, the first target service request can be determined as a pending service request and added to the leaky bucket queue, and the leaky bucket queue can sequentially pass the stored pending service requests to the processing module in a first-in-first-out manner;
[0078] Get the first pending service request added to the leaky bucket queue;
[0079] Among them, when the time interval for request acquisition is met, the first pending service request added to the leaky bucket queue is acquired. When the acquisition is completed, the leaky bucket queue is equivalent to deleting the acquired request, and its current request quantity is reduced by 1. If the first trigger result that meets the current limiting condition is obtained before acquisition, the second trigger result that does not meet the current limiting condition can be obtained after acquisition. The first trigger result and the second trigger result represent the trigger results processed at different times;
[0080] Perform service processing on the pending service request added first;
[0081] After obtaining the pending service request, service processing can be performed on it. The specific processing method and content depend on the application scenario and service field of the service device. Please refer to the examples in the above embodiments and will not be repeated here.
[0082] In one embodiment, the preset current limiting execution strategy includes a token bucket queue, and the preset current limiting parameter includes a target token number corresponding to the token bucket queue; according to the preset current limiting execution strategy and the preset current limiting parameter, determining whether the target service interface meets the first trigger result of the current limiting condition includes:
[0083] Detect the number of remaining tokens in the token bucket queue; the tokens in the token bucket queue are used to indicate service processing for service requests;
[0084] Among them, the token bucket queue is a queue created based on the token bucket algorithm (which is the most commonly used algorithm in network traffic shaping (Traffic Shaping) and rate limiting (Rate Limiting); typically, the token bucket algorithm is used to control the amount of data sent to the network and allow the sending of burst data). The difference between the token bucket queue and the leaky bucket queue in the above embodiment is that there is no first-in-first-out method in the token bucket queue, and what is stored in the token bucket is tokens rather than requests. The incoming service request can only enter the subsequent processing module if the corresponding token is obtained in the token bucket. When the service processing of a service request is completed, the corresponding token will be returned to the token bucket queue. The tokens that can be obtained in the token bucket queue are limited. When all the tokens that can be obtained are obtained, subsequent service requests cannot be received. Tokens are obtained, and then current limiting processing is performed; usually, the tokens that can be obtained are all tokens in the token bucket queue, that is, the number of remaining tokens in the token bucket queue is allowed to be zero, and in this embodiment, it can be determined by the preset current limiting parameters. For example, the preset current limiting parameters can define the target number of tokens that can be remaining in the token bucket queue as 700, and the total number of tokens in the token bucket queue is 1000, but under the limitation of the preset current limiting parameters, the token acquisition of the token bucket queue is limited to only 300 tokens, that is, only service requests with a request number not exceeding 300 can be allowed to enter at the same time; therefore, when making current limiting judgments based on the token bucket queue, it is first necessary to determine the number of remaining tokens in the token bucket queue;
[0085] If the number of remaining tokens is not greater than the target token data, a first trigger result indicating that the target service interface meets the current limiting condition is obtained;
[0086] Among them, for example, taking the example in the above steps as an example, if the determined number of remaining tokens is 720, it means that the number of remaining tokens is greater than the target token data, thereby obtaining the first trigger result indicating that the target service interface does not meet the flow limiting condition; if the determined number of remaining tokens is 700, it means that the number of remaining tokens is not greater than the target token data, thereby obtaining the first trigger result indicating that the target service interface meets the flow limiting condition;
[0087] It should be noted that since the preset current limiting execution strategy is for all service interfaces, and the current limiting parameters of different service interfaces are different, when using the token bucket queue method, the total number of tokens in the token bucket queue needs to be set as large as possible to ensure that the current limiting parameters can be applied to all service interfaces;
[0088] Among them, both the leaky bucket algorithm and the token bucket algorithm can be used for current limiting, but they have different focuses. The leaky bucket algorithm focuses on controlling the processing rate to ensure the stability of the processing rate, while the token bucket algorithm focuses on controlling the degree of concurrency to ensure that the concurrency does not exceed the limit. In this application, the corresponding current limiting algorithm can be selected according to the actual scenario or needs.
[0089] In one embodiment, the flow limiting process is performed on the first target service request, including:
[0090] Performing service downgrading on the first target service request to obtain a downgraded service request;
[0091] Service degradation means that when the server pressure increases dramatically, some services (such as the first target service request in this embodiment) and pages are strategically not processed or processed in a simpler way according to the actual business situation and traffic, thereby releasing server resources to ensure the normal or efficient operation of core transactions;
[0092] Sending current limiting indication information to a first user terminal corresponding to the first target service request according to the downgrade service request;
[0093] Among them, after the first target service request is downgraded, although the service processing will not be performed, it will not be discarded directly. Instead, a current limiting indication information is fed back to the first user terminal corresponding to the first target service request to inform the user that the current server has triggered current limiting and the request cannot be processed by the service temporarily; specifically, the current limiting indication information can be "The current server has triggered current limiting, please try again later". After the user obtains the information, he can re-initiate a new first target service request to the target service interface through the first user terminal later.
[0094] Compared with the direct discarding method, the flow control through service degradation can prevent users from frequently initiating service requests or directly giving up without knowing the reason.
[0095] In one embodiment, according to the downgraded service request, sending current limiting indication information to the first user terminal corresponding to the first target service request includes:
[0096] Adding the downgraded service request to the queue sequence;
[0097] Among them, the queue sequence is used to count the downgrade order of downgrade service requests;
[0098] Determine a target queue position of the downgraded service request in the queue sequence;
[0099] The queue sequence is sorted according to the time of addition, for example, the queue position corresponding to the latest added downgrade service request is the last;
[0100] Sending flow limiting indication information to the first user terminal according to the target queue position of the downgraded service request in the queue sequence; the flow limiting indication information includes the target queue position;
[0101] After obtaining the target queue position, the user can know the number of downgraded service requests, and thus re-initiate the first target service request at an appropriate time;
[0102] It should be noted that when the user corresponding to the downgraded service request with a higher ranking re-initiates a service request, the downgraded service request will be cleared from the queue sequence, and the ranking and feedback of the remaining downgraded service requests will be updated.
[0103] In one embodiment, after the step of sending the target queuing position to the first user terminal, the service flow limiting method further includes:
[0104] Re-determine whether the target service interface meets the second trigger result of the current limiting condition;
[0105] Among them, the above embodiment has mentioned that the user can manually re-initiate the service request according to the real-time feedback ranking, but this method will still reduce the user experience; therefore, in this embodiment, in the presence of a downgraded service request, the second trigger result of continuously determining whether the target service interface meets the current limiting condition can be used;
[0106] If the second trigger result indicates that the target service interface does not meet the current limiting condition, determining the second user terminal corresponding to the downgraded service request with the highest queue position in the queue sequence;
[0107] If the flow limiting condition is not met, it means that a service request has been completed and the service processing is available, so the second user terminal corresponding to the front queue position in the queue sequence can be determined according to the queue sequence;
[0108] Sending a second target service request corresponding to the second user terminal to the target service interface;
[0109] Among them, after the second user terminal is determined, the corresponding second target service request can be automatically initiated in the name of the second user terminal, avoiding manual initiation by the user, improving the user experience, and then re-execute the steps of the service flow limiting method in the above embodiment. It should be noted that since it has been determined that the flow limiting conditions are not met, the re-initiated second target service request will not be subject to flow limiting processing again.
[0110] Second, as Figure 3 As shown, in one embodiment, the present invention provides a service current limiting device, comprising:
[0111] A request acquisition module 301 is used to acquire a first target service request received by a target service interface;
[0112] A strategy acquisition module 302 is used to acquire a preset current limiting execution strategy and preset current limiting parameters of the target service interface according to the aspect annotation of the target service interface;
[0113] A trigger determination module 303 is used to determine whether the target service interface meets the first trigger result of the current limiting condition according to the preset current limiting execution strategy and the preset current limiting parameters;
[0114] The current limiting processing module 304 is used to perform current limiting processing on the first target service request if the first trigger result indicates that the target service interface meets the current limiting condition.
[0115] Through the above-mentioned service current limiting device, the corresponding preset current limiting execution strategy is pre-written in an aspect-oriented programming manner, the preset current limiting execution strategy is associated with each service interface through aspect annotations, and the current limiting parameters of each service interface are set through aspect annotations; for the target service interface, when the first target service request is received, the content in the aspect annotation can be executed, that is, the preset current limiting execution strategy is obtained and executed. In the process of executing the preset current limiting execution strategy, the preset current limiting parameters are used, so that different service interfaces can have different current limiting parameters, which can meet the current limiting requirements of all interfaces and will not affect the service capabilities; in addition, due to the use of aspect-oriented programming, only one preset current limiting execution strategy needs to be written in advance, which improves code reuse, reduces the workload of developers, and improves development efficiency.
[0116] In one embodiment, the preset current limiting execution strategy includes a leaky bucket queue, and the preset current limiting parameters include a target number of requests corresponding to the leaky bucket queue; the trigger determination module is specifically used to detect the current number of requests in the leaky bucket queue; if the current number of requests is not less than the target number of requests, a first trigger result is obtained, indicating that the target service interface meets the current limiting condition.
[0117] In one embodiment, the service current limiting device further includes:
[0118] The service processing module is used to determine the first target service request as a pending service request and add it to the leaky bucket queue if the first trigger result indicates that the target service interface does not meet the current limiting condition; obtain the pending service request that is first added to the leaky bucket queue; and perform service processing on the pending service request that is first added.
[0119] In one embodiment, the preset current limiting execution strategy includes a token bucket queue, and the preset current limiting parameters include a target number of tokens corresponding to the token bucket queue; the trigger determination module is specifically used to detect the number of remaining tokens in the token bucket queue; the tokens in the token bucket queue are used to indicate service processing for service requests; if the number of remaining tokens is not greater than the target token data, a first trigger result is obtained, indicating that the target service interface meets the current limiting condition.
[0120] In one embodiment, the current limiting processing module is specifically used to perform service downgrade on the first target service request to obtain a downgraded service request; and send current limiting indication information to the first user terminal corresponding to the first target service request according to the downgraded service request.
[0121] In one embodiment, the flow limiting processing module is specifically used to add a downgraded service request to a queue sequence; determine a target queue position of the downgraded service request in the queue sequence; and send flow limiting indication information to the first user terminal according to the target queue position of the downgraded service request in the queue sequence; the flow limiting indication information includes the target queue position.
[0122] In one embodiment, the service current limiting device further includes:
[0123] A request initiation module is used to re-determine whether the target service interface meets the second trigger result of the flow limiting condition after the step of sending the target queue position to the first user terminal; if the second trigger result indicates that the target service interface does not meet the flow limiting condition, determine the second user terminal corresponding to the downgraded service request with the highest queue position in the queue sequence; send the second target service request corresponding to the second user terminal to the target service interface to obtain the second target service request received by the target service interface.
[0124] In a third aspect, in one embodiment, the present invention provides a computer device, such as Figure 4 As shown, it shows the structure of the computer device involved in the present invention, specifically:
[0125] The computer device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, and an input unit 404. Those skilled in the art will appreciate that Figure 4 The structure of the computer device shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. Among them:
[0126] The processor 401 is the control center of the computer device. It uses various interfaces and lines to connect various parts of the entire computer device. By running or executing software programs and / or modules stored in the memory 402 and calling data stored in the memory 402, it executes various functions of the computer device and processes data, thereby monitoring the computer device as a whole. Optionally, the processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and computer programs, etc., and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 401.
[0127] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, a computer program required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the server, etc. In addition, the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.
[0128] The computer device also includes a power supply 403 for supplying power to various components. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, so as to manage charging, discharging, and power consumption through the power management system. The power supply 403 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.
[0129] The computer device may further include an input unit 404, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0130] Although not shown, the computer device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 401 in the computer device will load the executable files corresponding to the processes of one or more computer programs into the memory 402 according to the following instructions, and the processor 401 will run the computer program stored in the memory 402 to perform the following steps:
[0131] Obtaining a first target service request received by the target service interface;
[0132] According to the aspect annotation of the target service interface, obtain the preset current limiting execution strategy and the preset current limiting parameters of the target service interface;
[0133] Determine, according to a preset current limiting execution strategy and preset current limiting parameters, whether the target service interface meets the first trigger result of the current limiting condition;
[0134] If the first trigger result indicates that the target service interface meets the current limiting condition, current limiting processing is performed on the first target service request.
[0135] Through the above-mentioned computer device, the corresponding preset current limiting execution strategy is pre-written in an aspect-oriented programming manner, the preset current limiting execution strategy is associated with each service interface through aspect annotations, and the current limiting parameters of each service interface are set through aspect annotations; for the target service interface, when the first target service request is received, the content in the aspect annotation can be executed, that is, the preset current limiting execution strategy is obtained and executed. In the process of executing the preset current limiting execution strategy, the preset current limiting parameters are used, so that different service interfaces can have different current limiting parameters, which can meet the current limiting requirements of all interfaces and will not affect the service capabilities; in addition, due to the use of aspect-oriented programming, only one preset current limiting execution strategy needs to be written in advance, which improves code reuse, reduces the workload of developers, and improves development efficiency.
[0136] A person of ordinary skill in the art will appreciate that all or part of the steps in any of the methods of the above embodiments may be completed by a computer program, or by controlling related hardware through a computer program. The computer program may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0137] In a fourth aspect, in one embodiment, the present invention provides a storage medium storing a plurality of computer programs, wherein the computer programs can be loaded by a processor to perform the following steps:
[0138] Obtaining a first target service request received by the target service interface;
[0139] According to the aspect annotation of the target service interface, obtain the preset current limiting execution strategy and the preset current limiting parameters of the target service interface;
[0140] Determine, according to a preset current limiting execution strategy and preset current limiting parameters, whether the target service interface meets the first trigger result of the current limiting condition;
[0141] If the first trigger result indicates that the target service interface meets the current limiting condition, current limiting processing is performed on the first target service request.
[0142] Through the above-mentioned storage medium, the corresponding preset current limiting execution strategy is pre-written in an aspect-oriented programming manner, the preset current limiting execution strategy is associated with each service interface through aspect annotations, and the current limiting parameters of each service interface are set through aspect annotations; for the target service interface, when the first target service request is received, the content in the aspect annotation can be executed, that is, the preset current limiting execution strategy is obtained and executed. In the process of executing the preset current limiting execution strategy, the preset current limiting parameters are used, so that different service interfaces can have different current limiting parameters, which can meet the current limiting requirements of all interfaces and will not affect the service capabilities; in addition, due to the use of aspect-oriented programming, only one preset current limiting execution strategy needs to be written in advance, which improves code reuse, reduces the workload of developers, and improves development efficiency.
[0143] It will be appreciated by those skilled in the art that any reference to memory, storage, database or other medium used in the embodiments provided by the present invention may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink), DRAM (SLDRAM), memory bus (Rambus), direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0144] Since the computer program stored in the storage medium can execute the steps in the service flow limiting method in any embodiment provided by the present invention, the beneficial effects that can be achieved by the service flow limiting method in any embodiment provided by the present invention can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0145] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0146] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the detailed description of other embodiments above, and will not be repeated here.
[0147] The above is a detailed introduction to a service flow limiting method, device, computer equipment and storage medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for technical personnel in this field, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
[0148] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
Claims
1. A service current limiting method, characterized in that: include: Acquire a first target service request sent by a first user terminal and received by a target service interface; According to the aspect annotation of the target service interface, a preset current limiting execution strategy and preset current limiting parameters of the target service interface are obtained, wherein the preset current limiting execution strategy is a common strategy for all service interfaces, the service interface and the aspect annotation are one-to-one corresponding, and each aspect annotation defines the preset current limiting parameters exclusive to the corresponding service interface; Determine, according to the preset current limiting execution strategy and the preset current limiting parameters, whether the target service interface meets the first trigger result of the current limiting condition; If the first trigger result indicates that the target service interface meets the current limiting condition, downgrading the first target service request to obtain a downgraded service request; adding the downgraded service request to a queue; Determine a target queue position of the downgraded service request in the queue sequence; Based on the target queue position of the degraded service request in the queue sequence, sending flow limiting indication information to the first user terminal, the flow limiting indication information including the target queue position; If the first user terminal re-initiates the first target service request, the degraded service request is cleared from the queuing sequence.
2. The service flow limiting method according to claim 1, characterized in that: The preset current limiting execution strategy includes a leaky bucket queue, and the preset current limiting parameter includes a target request quantity corresponding to the leaky bucket queue; The first trigger result of determining whether the target service interface meets the current limiting condition according to the preset current limiting execution strategy and the preset current limiting parameter includes: Detecting the current number of requests in the leaky bucket queue; If the current request quantity is not less than the target request quantity, a first trigger result is obtained, indicating that the target service interface meets the current limiting condition.
3. The service flow limiting method according to claim 2, characterized in that: After the step of determining, according to the preset current limiting execution strategy and the preset current limiting parameters, whether the target service interface satisfies the first trigger result of the current limiting condition, the method further includes: If the first trigger result indicates that the target service interface does not meet the current limiting condition, the first target service request is determined as a pending service request and added to the leaky bucket queue; Obtain the first pending service request added to the leaky bucket queue; Perform service processing on the to-be-processed service request that is added first.
4. The service flow limiting method according to claim 1, characterized in that: The preset current limiting execution strategy includes a token bucket queue, and the preset current limiting parameter includes a target token quantity corresponding to the token bucket queue; The first trigger result of determining whether the target service interface meets the current limiting condition according to the preset current limiting execution strategy and the preset current limiting parameter includes: Detecting the number of remaining tokens in the token bucket queue; the tokens in the token bucket queue are used to indicate service processing for the service request; If the remaining token quantity is not greater than the target token quantity, a first trigger result is obtained, indicating that the target service interface meets the current limiting condition.
5. The service flow limiting method according to claim 1, characterized in that: After the step of sending the target queuing position to the first user terminal, the method further includes: Re-determining whether the target service interface meets the second trigger result of the current limiting condition; If the second trigger result indicates that the target service interface does not meet the current limiting condition, determining a second user terminal corresponding to the degraded service request with the highest queue position in the queue sequence; Sending a second target service request corresponding to the second user terminal to the target service interface.
6. A service current limiting device, characterized in that: include: A request acquisition module, used to acquire a first target service request received by the target service interface; A strategy acquisition module, used to acquire a preset current limiting execution strategy and preset current limiting parameters of the target service interface according to the aspect annotation of the target service interface, wherein the preset current limiting execution strategy is a common strategy for all service interfaces, the service interface and the aspect annotation are one-to-one corresponding, and each aspect annotation defines the preset current limiting parameters exclusive to the corresponding service interface; A trigger determination module, configured to determine, according to the preset current limiting execution strategy and the preset current limiting parameters, whether the target service interface satisfies a first trigger result of a current limiting condition; Current limiting processing module, used for: If the first trigger result indicates that the target service interface meets the current limiting condition, downgrading the first target service request to obtain a downgraded service request; Adding the downgraded service request to a queue sequence; determining a target queue position of the downgraded service request in the queue sequence; Based on the target queue position of the degraded service request in the queue sequence, sending flow limiting indication information to the first user terminal, the flow limiting indication information including the target queue position; If the first user terminal re-initiates the first target service request, the degraded service request is cleared from the queuing sequence.
7. A computer device, characterized in that: It comprises a memory and a processor; the memory stores a computer program, and the processor is used to run the computer program in the memory to execute the steps in the service flow limiting method described in any one of claims 1 to 5.
8. A storage medium, characterized in that: The storage medium stores a computer program, and the computer program is loaded by a processor to execute the steps in the service flow limiting method described in any one of claims 1 to 5.
Citation Information
Patent Citations
Concurrent request processing method and device, server and storage medium
CN113342498A
Current limiting method, system and device and storage medium
CN114567507A