Flow control method and device based on section
Through the aspect-based flow control method, aspect-oriented programming technology is used to extract the flow control logic from the business code, and the aspect strategy is dynamically adjusted to solve the performance and maintenance problems in high-concurrency scenarios, and achieve efficient and flexible flow control.
Patent Information
- Application Number
- CN202411183946.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-27
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2044-08-27
AI Technical Summary
The flow control method in the existing technology has high performance overhead and high latency in high-concurrency scenarios, and requires modification of business code, resulting in low system stability and maintenance efficiency.
Aspect-based flow control method is adopted. Through aspect-oriented programming technology, the flow control logic is extracted from the business code. Using efficient algorithms and data structures, the aspect strategy is dynamically adjusted to achieve decoupling of flow control and business code.
It achieves flexible, dynamic, low-intrusive and high-performance traffic control in high-concurrency scenarios, reduces latency, improves business efficiency, and ensures system stability and user experience.
Smart Images

Figure CN119094452B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of flow control technology and can be used in the field of financial technology, and in particular to a flow control method and device based on a slice. Background Art
[0002] With the rapid development of the Internet and the increase in business needs, high-concurrency traffic management has become a key issue in ensuring system stability and providing a good user experience. In related technologies, traffic control is usually implemented through the Nginx reverse proxy server according to the configuration file, but the traffic control function in related technologies is relatively basic and only suitable for simple static restriction scenarios. In high-concurrency scenarios, the traffic control methods in related technologies will introduce large performance overhead and delay; in addition, the traffic control methods in related technologies usually require embedding traffic control logic in the business code, making the code logic scattered and difficult to maintain. When the flow control logic needs to be adjusted or added, the original code needs to be modified and redeployed, which can easily introduce errors or cause system downtime, resulting in low business efficiency.
[0003] This section is intended to provide a background or context to the embodiments of the invention that are recited in the claims. No statement herein is admitted to be prior art by virtue of its inclusion in this section. Summary of the Invention
[0004] The embodiment of the present invention provides a section-based flow control method. This method implements high-concurrency flow control based on sections and can dynamically adjust section policies according to flow changes, thereby improving flexibility and dynamic adjustment capabilities. The section-based flow control method uses efficient algorithms and data structures to control flow with minimal performance overhead. It is decoupled from business code, eliminating the need to modify the original code, and achieves precise control of flow, thereby reducing latency and improving business efficiency. The method is characterized by low intrusion, dynamism, flexibility, and high performance. The method includes:
[0005] Get the business request sent by the user, which includes the request transaction code and flow control annotation;
[0006] Through the preset annotation section correspondence, according to the flow control annotation, the corresponding flow control section is determined;
[0007] Through the preset transaction attribution platform correspondence, according to the requested transaction code, the corresponding transaction attribution platform number is determined;
[0008] Through the preset corresponding relationship between the belonging platform aspects, according to the transaction belonging platform number, the parameters of the flow control aspect are adjusted to generate the target flow control aspect. The target flow control aspect is the flow control logic based on aspect-oriented programming technology;
[0009] Weave the target flow control aspect into the business request and perform flow control on the business request based on the target flow control logic in the target flow control aspect.
[0010] Preferably, the method further comprises:
[0011] Annotation definition operation that receives input;
[0012] Define operations based on annotations and construct flow control annotations. Flow control annotations are used to identify business requests for flow control.
[0013] Preferably, the method further comprises:
[0014] Aspect definition operations that receive input;
[0015] According to the aspect definition operation, a flow control aspect is constructed. The flow control aspect includes flow control strategies and flow restriction conditions.
[0016] Preferably, the target flow control logic includes a token limit quantity and a token limit rate, and the service request includes a token request quantity and a token request rate;
[0017] Weave the target flow control aspect into the business request and perform flow control on the business request based on the target flow control logic within the target flow control aspect, including:
[0018] Based on the token bucket algorithm, flow control is performed on the token request quantity and token request rate according to the token limit quantity and token limit rate to generate a flow control result.
[0019] Preferably, based on the token bucket algorithm, flow control is performed on the number of token requests and the token request rate according to the token limit number and the token limit rate, and a flow control result is generated, including:
[0020] Determine whether the number of token requests is less than or equal to the token limit, and whether the token request rate is less than or equal to the token limit rate;
[0021] If both are yes, a flow control result is generated for the service request to pass;
[0022] If at least one of the two is negative, query for service requests that exceed the token limit quantity and / or exceed the token limit rate;
[0023] Generate a flow control result of a failed business request based on the queried business request;
[0024] For business requests that do not exceed the token limit quantity and token limit rate, a flow control result is generated for the business request to pass.
[0025] Preferably, the target flow control logic includes a flow restriction condition, the flow restriction condition includes a threshold value of a maximum number of requests per second, and the service request includes a maximum number of requests per second;
[0026] Weave the target flow control aspect into the business request and perform flow control on the business request based on the target flow control logic within the target flow control aspect, including:
[0027] Determine whether the maximum number of requests per second in the business request is less than or equal to the maximum number of requests per second threshold;
[0028] If so, generate a flow control result indicating that the service request has passed;
[0029] If not, query the business requests that exceed the maximum number of requests per second threshold;
[0030] Generate a flow control result of a failed business request based on the queried business request;
[0031] For business requests that do not exceed the maximum number of requests per second, a flow control result is generated for the business request to pass.
[0032] Preferably, the target flow control logic includes a flow restriction condition, the flow restriction condition includes a concurrent connection number threshold, and the service request includes the concurrent connection number;
[0033] Weave the target flow control aspect into the business request and perform flow control on the business request based on the target flow control logic within the target flow control aspect, including:
[0034] Determine whether the number of concurrent connections in the service request is less than or equal to the concurrent connection threshold;
[0035] If so, generate a flow control result indicating that the service request has passed;
[0036] If not, a flow control result indicating that the service request failed is generated.
[0037] Preferably, the target flow control logic includes a flow restriction condition, the flow restriction condition includes a total request number threshold, and the service request includes a total request number;
[0038] Weave the target flow control aspect into the business request and perform flow control on the business request based on the target flow control logic within the target flow control aspect, including:
[0039] Determine whether the total number of requests in the service request is less than or equal to the total number of requests threshold;
[0040] If so, generate a flow control result indicating that the service request has passed;
[0041] If not, query the business requests that exceed the total request count threshold;
[0042] Generate a flow control result of a failed business request based on the queried business request;
[0043] For business requests that do not exceed the total request count threshold, a flow control result is generated for the business request to pass.
[0044] Preferably, the method further comprises:
[0045] Obtain monitoring data through the preset monitor list;
[0046] Determine whether the monitored data complies with the preset flow control section adjustment rules;
[0047] If yes, update the flow control section according to the flow control section adjustment rules and the monitoring data to generate an updated flow control section;
[0048] If not, repeat the steps of obtaining monitoring data through the preset monitor list.
[0049] Preferably, the listener list includes a system load listener, the monitoring data includes a CPU usage rate, and the flow control aspect adjustment rule includes a usage rate token coefficient correspondence;
[0050] According to the flow control section adjustment rules, the flow control section is updated according to the monitoring data to generate an updated flow control section, including:
[0051] Through the usage rate token coefficient correspondence relationship, the corresponding token coefficient is determined according to the CPU usage rate;
[0052] According to the determined token coefficient, the token parameters in the flow control section are updated to generate an updated flow control section.
[0053] Preferably, the listener list includes a configuration change listener, and the monitoring data includes configuration token parameters;
[0054] According to the flow control section adjustment rules, the flow control section is updated according to the monitoring data to generate an updated flow control section, including:
[0055] Update the token parameters in the flow control section to the monitored configuration token parameters and generate the updated flow control section.
[0056] Preferably, the listener list includes time listeners, the monitoring data includes monitoring time, and the flow control aspect adjustment rule includes a time token parameter correspondence;
[0057] According to the flow control section adjustment rules, the flow control section is updated according to the monitoring data to generate an updated flow control section, including:
[0058] Through the time token parameter correspondence, the corresponding token parameters are determined according to the monitoring time;
[0059] The token parameters in the flow control section are updated to the determined token parameters, and an updated flow control section is generated.
[0060] An embodiment of the present invention further provides a section-based flow control device, comprising:
[0061] A service request acquisition unit is used to acquire a service request sent by a user. The service request includes a request transaction code and a flow control annotation.
[0062] A section determination unit is used to determine a corresponding flow control section according to the flow control annotation through a preset annotation section correspondence relationship;
[0063] A platform number determination unit, configured to determine the corresponding transaction platform number according to the requested transaction code through a preset transaction platform correspondence relationship;
[0064] The target aspect determination unit is used to adjust the parameters of the flow control aspect according to the transaction belonging platform number through the preset corresponding relationship of the belonging platform aspect, and generate the target flow control aspect. The target flow control aspect is the flow control logic based on aspect-oriented programming technology;
[0065] The flow control unit is used to weave the target flow control aspect into the business request and perform flow control on the business request based on the target flow control logic in the target flow control aspect.
[0066] An embodiment of the present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned slice-based flow control method when executing the computer program.
[0067] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned slice-based flow control method is implemented.
[0068] An embodiment of the present invention further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the above-mentioned slice-based flow control method.
[0069] The aspect-based flow control method and device provided by the embodiment of the present invention obtains a business request sent by a user, the business request includes a request transaction code and a flow control annotation; through the preset annotation aspect correspondence relationship, according to the flow control annotation, the corresponding flow control aspect is determined; through the preset transaction attribution platform correspondence relationship, according to the request transaction code, the corresponding transaction attribution platform number is determined; through the preset attribution platform aspect correspondence relationship, according to the transaction attribution platform number, the flow control aspect parameters are adjusted to generate a target flow control aspect, which is a flow control aspect based on aspect-oriented programming technology. logic; weave the target flow control aspect into the business request, and perform flow control on the business request based on the target flow control logic in the target flow control aspect, implement high-concurrency flow control based on the aspect, and dynamically adjust the aspect strategy according to flow changes, thereby improving flexibility and dynamic adjustment capabilities; the aspect-based flow control method adopts efficient algorithms and data structures to achieve flow control with minimal performance overhead; it is decoupled from the business code and does not require modification of the original code, thereby achieving precise control of the flow, thereby reducing latency and improving business efficiency, with the characteristics of low intrusion, dynamism, flexibility and high performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for the embodiments or the description of the prior art. 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. In the drawings:
[0071] Figure 1 A flow chart of a flow control method based on a slice provided by an embodiment of the present invention;
[0072] Figure 2 A flow chart of another slice-based flow control method provided by an embodiment of the present invention;
[0073] Figure 3 A schematic structural diagram of a flow control device based on a section provided in an embodiment of the present invention;
[0074] Figure 4 A schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0075] To make the purpose, technical solutions and advantages of the embodiments of the present invention more clear, the embodiments of the present invention are further described in detail below with reference to the accompanying drawings. Here, the exemplary embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.
[0076] The information collected in the technical solution of this application is information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of relevant data comply with the relevant laws, regulations and standards of relevant countries and regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0077] The acquisition, transmission, storage, use, and processing of data in the technical solution of this application comply with the relevant provisions of national laws and regulations.
[0078] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned. They should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0079] It is worth noting that the technical solution provided in this application provides users with corresponding operation entrances for them to choose to agree or reject the automated decision-making results; if the user chooses to reject, the expert decision-making process will be entered.
[0080] In order to facilitate the understanding of the technical solution provided by this application, the relevant contents of the technical solution of this application are first explained below. In computer programming, aspect is a concept in aspect-oriented programming (AOP). Aspect-oriented programming is a programming paradigm that allows developers to separate cross-cutting concerns (such as logging, transaction management, security, etc.) from business logic, thereby improving the modularity and maintainability of the code. The aspect-based flow control method extracts the flow control logic from the business code and defines and manages it as a separate aspect. Aspect is a module that dynamically enhances requests and can be transparently woven into the request processing process at runtime.
[0081] The aspect-based high-concurrency flow control method combines aspect programming ideas and the characteristics of flow control, providing a flexible, scalable and low-coupling solution. It can effectively solve the performance impact and logic writing and maintenance problems in traditional flow control methods, and provide dynamic, flexible and high-performance flow control capabilities; it can ensure system stability, reliability and good user experience in high-concurrency scenarios.
[0082] The following uses a slice-based flow control device as an example to illustrate the implementation process of the slice-based flow control method provided by the embodiment of the present invention. It is understood that the implementation subject of the slice-based flow control method provided by the embodiment of the present invention includes but is not limited to the slice-based flow control device.
[0083] Figure 1 A flow chart of a flow control method based on a slice provided by an embodiment of the present invention is shown as follows: Figure 1 As shown, the method includes:
[0084] Step 101: Obtain a service request sent by a user, where the service request includes a request transaction code and a flow control annotation.
[0085] Step 102: Determine the corresponding flow control section according to the flow control annotation through the preset annotation section correspondence relationship.
[0086] Step 103: Determine the corresponding transaction platform number based on the requested transaction code through the preset transaction platform correspondence relationship.
[0087] Step 104: Adjust the parameters of the flow control aspect according to the transaction platform number through the preset corresponding relationship of the belonging platform aspect to generate the target flow control aspect. The target flow control aspect is the flow control logic based on aspect-oriented programming technology.
[0088] Step 105: Weave the target flow control aspect into the business request, and perform flow control on the business request based on the target flow control logic in the target flow control aspect.
[0089] In the technical solution provided by the embodiment of the present invention, a service request sent by a user is obtained, the service request including a request transaction code and a flow control annotation; a corresponding flow control aspect is determined according to the flow control annotation through a preset annotation aspect correspondence relationship; a corresponding transaction affiliation platform number is determined according to the request transaction code through a preset transaction affiliation platform correspondence relationship; parameters of the flow control aspect are adjusted according to the transaction affiliation platform number through a preset affiliation platform aspect correspondence relationship to generate a target flow control aspect, which is a flow control logic based on aspect-oriented programming technology; the target flow control aspect is woven into the service request, and flow control is performed on the service request based on the target flow control logic within the target flow control aspect, achieving high-concurrency flow control based on the aspect, and being able to dynamically adjust the aspect strategy according to flow changes, thereby improving flexibility and dynamic adjustment capabilities; the aspect-based flow control method adopts efficient algorithms and data structures to achieve flow control with minimal performance overhead; it is decoupled from the business code, and does not require modification of the original code, thereby achieving precise control of flow, thereby reducing latency and improving business efficiency, and has the characteristics of low intrusion, dynamism, flexibility, and high performance.
[0090] Figure 2 A flow chart of another aspect-based flow control method provided by an embodiment of the present invention is shown in FIG. Figure 2 As shown, the method includes:
[0091] Step 201: Receive input annotation definition operation.
[0092] In the embodiment of the present invention, each step is performed by a section-based flow control device.
[0093] In this embodiment of the present invention, annotation definitions are entered by developers when designing annotations. In programming, annotations are special tags used to provide metadata for program elements (such as classes, methods, and variables), such as the permitted request rate. Metadata is data that describes data and allows programs to obtain information about themselves at compile time or runtime.
[0094] Step 202: Construct a flow control annotation according to the annotation definition operation.
[0095] For example, the annotation definition operation includes the permitted request rate, and the custom-built flow control annotation is @RateLimited, which indicates that flow control is required.
[0096] In the embodiments of the present invention, annotations are a mechanism used by the Java language to provide metadata for code. They can be applied to classes, methods, variables, parameters, and so on. Flow control annotations are used to identify service requests that require flow control. These annotations can be attached to controller classes or methods to indicate the request codes that require flow control. The primary purpose of flow control annotations is to mark which methods require flow control logic.
[0097] It is worth noting that annotations are non-invasive and do not directly affect the logic of the program, but can be used by the compiler or runtime environment to change or enhance the behavior of the program.
[0098] Step 203: Receive the input slice definition operation.
[0099] In the embodiment of the present invention, the aspect definition operation is the flow control logic input by the developer when designing the flow control aspect. The aspect definition operation can define an aspect class, which will use the defined annotations to determine which methods require flow control.
[0100] Step 204: Construct a flow control aspect according to the aspect definition operation. The flow control aspect includes a flow control strategy and flow restriction conditions.
[0101] In the embodiment of the present invention, a section is created to implement flow control logic through section definition operation, and the flow control section is woven into the request processing process identified by the flow control annotation (@RateLimited).
[0102] In an embodiment of the present invention, the flow control aspect defines the flow control strategy and flow limitation conditions. The flow control strategy includes but is not limited to the leaky bucket algorithm, the token bucket algorithm or other suitable algorithms and their internal parameters; the flow limitation conditions include but are not limited to the maximum number of requests per second, the number of concurrent connections, and the total number of requests.
[0103] In the embodiment of the present invention, the flow control aspect is an application of aspect-oriented programming (AOP) and is used to manage and control the flow in an application program to ensure the stability and responsiveness of the system.
[0104] The present invention uses efficient algorithms and data structures to achieve flow control with minimal performance overhead. For example, it uses a leaky bucket algorithm or a token bucket algorithm to limit the request frequency without requiring additional locking operations, thereby improving system throughput and response time.
[0105] Step 205: Obtain the service request sent by the user.
[0106] In the embodiment of the present invention, a service request is a Hypertext Transfer Protocol (HTTP) request sent by a user. The service request includes, but is not limited to, a request transaction code and a flow control annotation. The request transaction code is used to uniquely identify a service request, and the flow control annotation is used to indicate that flow control is required for the service request.
[0107] It is worth noting that the system has a unified entry point and can automatically forward requests to the corresponding processing logic by requesting a transaction code. Even if the system entry point is not unified, aspects can customize the applied content and use exact matching and / or fuzzy matching to obtain the required application code.
[0108] Step 206: Determine the corresponding flow control section according to the flow control annotation through the preset annotation section correspondence relationship.
[0109] In the embodiment of the present invention, the annotation-face correspondence relationship is the correspondence relationship between annotations and facets, and the relationship between annotations and facets is many-to-many, that is, one annotation can correspond to multiple facets, and one facet can correspond to multiple annotations.
[0110] In the embodiment of the present invention, the aspect is applied to the annotated code, indicating that the code in this part uniformly performs the logic of this aspect.
[0111] For example: there are three aspects, namely Aspect A, Aspect B and Aspect C. Aspect A is used to record request time, Aspect B is used for flow control, and Aspect C is used for authentication; annotations are used to mark the relevant aspects used in this section of code. The corresponding annotation for Aspect A is defined as @TimeUsed, the corresponding annotation for Aspect B is defined as @RateLimited, and the corresponding annotation for Aspect C is defined as @RequestAuth. If the current business request requires flow control and recording of request time, the annotations @TimeUsed and @RateLimited can be added to the code of the business request to call the corresponding aspect to implement the corresponding function. At this time, this section of code has the function of recording time and flow control at the system level in a global and unified manner. It does not require repeated development to simplify labor costs, but also avoids errors such as omissions in repeated code copying.
[0112] For example, define an annotation @RequestProcess that includes three functions: the request time recording annotation @TimeUsed, the flow control annotation @RateLimited, and the authentication annotation @RequestAuth. If the annotation @RequestProcess is added to the business request code, the code will call and execute the flow control aspect, authentication aspect, and time-consuming aspect at the same time, thereby achieving functional enhancement.
[0113] It is worth noting that the specific content of the annotation aspect correspondence can be set according to actual needs and is not limited in this embodiment of the present invention. The embodiment of the present invention takes flow control as an example to design flow control annotations and flow control aspects. In actual applications, different functional enhancements can also be achieved based on the aspect concept.
[0114] Step 207: Determine the corresponding transaction platform number based on the requested transaction code through the preset transaction platform correspondence relationship.
[0115] In this embodiment of the present invention, the transaction attribution platform correspondence is a correspondence between a request transaction code and a transaction attribution platform. Specifically, the request transaction code of a service request is matched with the request transaction code in the transaction attribution platform correspondence to determine the corresponding transaction attribution platform number. The transaction attribution platform number uniquely identifies a transaction attribution platform.
[0116] In the embodiment of the present invention, the system distinguishes different tenants according to the transaction platform, and different users under the same tenant belong to the same traffic control aspect, so as to prevent individual tenants from monopolizing system resources for a long time.
[0117] It is worth noting that the specific content of the transaction-attribution platform correspondence relationship can be set according to actual needs, and the embodiment of the present invention does not limit this.
[0118] Step 208: Adjust the parameters of the flow control section according to the transaction belonging platform number through the preset corresponding relationship of the belonging platform section to generate the target flow control section.
[0119] In the embodiment of the present invention, the corresponding relationship between the belonging platform and the aspect is the corresponding relationship between the transaction belonging platform and the aspect. The transaction belonging platform corresponds to the aspect, and the aspect includes the traffic control aspect.
[0120] It is worth noting that the specific content of the corresponding relationship between the attribution platform aspects can be set according to actual needs and is not limited in this embodiment of the present invention. This embodiment of the present invention uses traffic control as an example to design the traffic control aspect, that is, the transaction attribution platform corresponds to the traffic control aspect. In actual applications, different functional enhancements can also be achieved based on the aspect concept.
[0121] In the embodiment of the present invention, the target flow control aspect is the flow control logic based on aspect-oriented programming technology, and the flow control logic can be set in a variety of ways, including but not limited to user level and system time. Specifically, a flow control aspect class (RateLimitAspect class) is defined, and multiple aspects with different business functions can be defined on the RateLimitAspect class, so that the flow control aspect can be parameter adjusted to generate the target flow control aspect. The parameters that need to be adjusted include but are not limited to the maximum number of requests per second, the number of concurrent connections, and the total number of requests. Specifically, based on the user level, the maximum number of requests per second corresponding to different user levels can be set; based on the system time, the maximum number of requests per second corresponding to different system time periods can be set. The system time period includes the low-peak time period at night and the peak time period during the day. The specific time points for dividing the system time periods can be set according to actual needs, and the embodiment of the present invention does not limit this.
[0122] For example, a default-level tenant is allowed to make 10 requests per second, while a high-level user is allowed to make 100 requests per second. The target flow control aspect can be determined by the transaction platform number corresponding to the business request. That is, the user level is judged to distinguish the number of requests per second allowed for this tenant.
[0123] In this embodiment of the present invention, the platform aspect corresponds to a mapping called RateLimiterMap maintained internally by the aspect, which stores the mapping between method names and rate limiter (RateLimiter) instances and uses a concurrent hash map (ConcurrentHashMap) to ensure thread safety. ConcurrentHashMap is a class in the Java Collection Framework that implements the ConcurrentMap interface and is a thread-safe implementation of Map. ConcurrentHashMap allows multiple threads to read and write simultaneously without the need for explicit synchronization measures.
[0124] Step 209: Weave the target flow control aspect into the service request, and perform flow control on the service request based on the target flow control logic in the target flow control aspect.
[0125] In this embodiment of the present invention, aspect weaving technology is used to bind the target flow control aspect to the business request code. When the aspect logic is subsequently executed, the target flow control aspect intercepts and processes the business request that requires flow control, and decides whether to allow the request to continue execution or queue it based on the control logic.
[0126] In the embodiment of the present invention, the aspect logic is executed before the service function code of the service request is executed. Taking flow control as an example, the embodiment of the present invention first executes the target flow control logic in the target flow control aspect before the service function code of the service request is executed.
[0127] In the embodiment of the present invention, taking the token bucket algorithm as an example, the target flow control logic includes a token limit quantity and a token limit rate, and the service request includes a token request quantity and a token request rate.
[0128] Step 209 specifically includes: based on the token bucket algorithm, according to the token limit quantity and the token limit rate, performing flow control on the token request quantity and the token request rate, and generating a flow control result.
[0129] Specifically, in step 2091, determine whether the number of token requests is less than or equal to the token limit number, and whether the token request rate is less than or equal to the token limit rate. If both are yes, execute step 2092; if at least one is no, execute step 2093.
[0130] In the embodiment of the present invention, the token limit quantity and token limit rate are preset in the target flow control logic, and the embodiment of the present invention does not limit this.
[0131] Specifically, if the number of token requests is less than or equal to the token limit number, and the token request rate is less than or equal to the token limit rate, it indicates that the business request has not met the flow control standard, and step 2092 is continued; if the number of token requests is greater than the token limit number, or the token request rate is greater than the token limit rate, it indicates that the business request has met the flow control standard, and step 2093 is continued.
[0132] For example: the token limit rate is that the platform can obtain 10 tokens per second. In the target flow control aspect, the platform obtains tokens based on its platform. If the platform obtains 9 tokens in this second, it does not exceed the token limit rate, indicating that the business request does not meet the flow control standard, and continue to execute step 2092; if the platform attempts to obtain the 11th token in this second, it exceeds the token limit rate, indicating that the business request has reached the flow control standard, and continue to execute step 2093.
[0133] Step 2092: Generate a flow control result for the service request. This step ends.
[0134] In the embodiment of the present invention, if the service request does not meet the flow control standard, the service request is allowed to pass, and a flow control result indicating that the service request passed is generated for subsequent execution of the service function code of the service request.
[0135] Step 2093: Query for service requests that exceed the token limit quantity and / or exceed the token limit rate.
[0136] For example, if the token limit rate is that the platform can obtain 10 tokens per second, and the platform attempts to obtain the 11th token in this second, the service request corresponding to the 11th token is a service request that exceeds the token limit rate.
[0137] Step 2094: Generate a flow control result of service request failure based on the queried service request.
[0138] In an embodiment of the present invention, if the token limit rate is that the platform can obtain 10 tokens per second, the business request corresponding to the 11th token is a business request that exceeds the token limit rate. The first 10 business requests are allowed to pass, the 11th business request is intercepted, and a flow control result of business request failure is generated for the 11th business request.
[0139] Step 2095: For service requests that do not exceed the token limit quantity and token limit rate, generate a flow control result for the service request to pass.
[0140] In an embodiment of the present invention, if the token limit rate is that the platform can obtain 10 tokens per second, the business request corresponding to the 11th token is a business request that exceeds the token limit rate. The first 10 business requests are allowed to pass, and a flow control result of the business request passing is generated for the first 10 business requests.
[0141] As another optional solution, the target flow control logic includes a flow restriction condition, the flow restriction condition includes a maximum request number threshold per second, and the service request includes a maximum request number per second.
[0142] Step 209 specifically includes:
[0143] Step 3091: Determine whether the maximum number of requests per second in the business request is less than or equal to the maximum number of requests per second threshold; if so, execute step 3092; if not, execute step 3093.
[0144] In the embodiment of the present invention, the maximum request number threshold per second is preset in the target flow control logic, and the embodiment of the present invention does not limit this.
[0145] Specifically, if the maximum number of requests per second in the business request is less than or equal to the maximum number of requests per second threshold, it indicates that the business request has not met the flow control standard, and step 3092 is continued to be executed; if the maximum number of requests per second in the business request is greater than the maximum number of requests per second threshold, it indicates that the business request has met the flow control standard, and step 3093 is continued to be executed.
[0146] For example, if the maximum number of requests per second is 8, and the number of requests in the service request in this second is 6, which does not exceed the maximum number of requests per second, it indicates that the service request does not meet the flow control standard, and step 3092 is continued. If the number of requests in the service request in this second is 10, which exceeds the maximum number of requests per second, it indicates that the service request has met the flow control standard, and step 3093 is continued.
[0147] Step 3092: Generate a flow control result for the service request. This step ends.
[0148] In the embodiment of the present invention, if the service request does not meet the flow control standard, the service request is allowed to pass, and a flow control result indicating that the service request passed is generated for subsequent execution of the service function code of the service request.
[0149] Step 3093: Query the business requests that exceed the maximum number of requests per second threshold.
[0150] For example, if the maximum request number threshold per second is 8, and the number of requests in the service request in this second is 10, then the 9th and 10th service requests are service requests that exceed the maximum request number threshold per second.
[0151] Step 3094: Generate a flow control result of service request failure based on the queried service request.
[0152] In an embodiment of the present invention, if the maximum number of requests per second threshold is 8, and the 9th and 10th business requests are business requests that exceed the maximum number of requests per second threshold, the first 8 business requests are allowed to pass, the 9th and 10th business requests are intercepted, and a flow control result of business request failure is generated for the 9th and 10th business requests.
[0153] Step 3095: For the service requests that do not exceed the maximum number of requests per second threshold, a flow control result is generated for the service requests passing through. This step ends.
[0154] In an embodiment of the present invention, if the maximum number of requests per second threshold is 8, the 9th and 10th service requests are service requests that exceed the maximum number of requests per second threshold, the first 8 service requests are allowed to pass, and a flow control result of the service request passing is generated for the first 8 service requests.
[0155] As another optional solution, the target flow control logic includes a flow restriction condition, the flow restriction condition includes a concurrent connection number threshold, and the service request includes the concurrent connection number.
[0156] Step 209 specifically includes:
[0157] Step 4091: Determine whether the number of concurrent connections in the service request is less than or equal to the concurrent connection number threshold. If so, execute step 4092; if not, execute step 4093.
[0158] In the embodiment of the present invention, the concurrent connection number threshold is pre-set in the target flow control logic, and the embodiment of the present invention does not limit this.
[0159] Specifically, if the number of concurrent connections in the service request is less than or equal to the concurrent connection number threshold, it indicates that the service request does not meet the flow control standard, and step 4092 is continued to be executed; if the number of concurrent connections in the service request is greater than the concurrent connection number threshold, it indicates that the service request has met the flow control standard, and step 4093 is continued to be executed.
[0160] Step 4092: Generate a flow control result for the service request. This step ends.
[0161] In the embodiment of the present invention, if the service request does not meet the flow control standard, the service request is allowed to pass, and a flow control result indicating that the service request passed is generated for subsequent execution of the service function code of the service request.
[0162] Step 4093: Generate a flow control result of service request failure, and this step ends.
[0163] In the embodiment of the present invention, if the service request has reached the flow control standard, the service request is intercepted and a flow control result of failure is given to the service request.
[0164] As another optional solution, the target flow control logic includes a flow restriction condition, the flow restriction condition includes a total request number threshold, and the service request includes the total request number.
[0165] Step 209 specifically includes:
[0166] Step 5091: Determine whether the total number of requests in the service request is less than or equal to the total number of requests threshold. If so, execute step 5092; if not, execute step 5093.
[0167] In the embodiment of the present invention, the total request number threshold is preset in the target flow control logic, and the embodiment of the present invention does not limit this.
[0168] Specifically, if the total number of requests in the business request is less than or equal to the total number of requests threshold, it indicates that the business request has not met the flow control standard, and step 5092 is continued; if the total number of requests in the business request is greater than the total number of requests threshold, it indicates that the business request has met the flow control standard, and step 5093 is continued.
[0169] Step 5092: Generate a flow control result for the service request. This step ends.
[0170] In the embodiment of the present invention, if the service request does not meet the flow control standard, the service request is allowed to pass, and a flow control result indicating that the service request passed is generated for subsequent execution of the service function code of the service request.
[0171] Step 5093: Query the service requests that exceed the total request count threshold.
[0172] For example, if the total request count threshold is 20 and the total request count in the service request is 22, then the 21st and 22nd service requests are service requests that exceed the total request count threshold.
[0173] Step 5094: Generate a flow control result of service request failure based on the queried service request.
[0174] In an embodiment of the present invention, if the total request number threshold is 20, the 21st and 22nd service requests are service requests that exceed the total request number threshold, the first 20 service requests are allowed to pass, the 21st and 22nd service requests are intercepted, and a flow control result of service request failure is generated for the 21st and 22nd service requests.
[0175] Step 5095: For the service requests that do not exceed the total request number threshold, a flow control result is generated for the service requests to pass. This step ends.
[0176] In an embodiment of the present invention, if the total request number threshold is 20, the 21st and 22nd service requests are service requests that exceed the total request number threshold, the first 20 service requests are allowed to pass, and a flow control result of the service request passing is generated for the first 20 service requests.
[0177] For example, if there are two methods, processRequest and processLimitedRequest, and the @RateLimited annotation is used on the processLimitedRequest method, then business requests with the request address processLimitedRequest will be subject to rate control. Whether the business request is allowed to execute will be determined according to the rate control logic within the rate control aspect. The rate control logic is implemented in the rate control aspect (RateLimitAspect). For example, regular requests require a token to be acquired. Successful token acquisition will allow the request to proceed. Failure to acquire a token will intercept the request and return a rate-controlled notification message.
[0178] This paper uses aspect-based programming to decouple flow control logic from business logic. By separating flow control-related code from business functions, developers can focus on developing and maintaining core business logic, improving code maintainability and scalability. This architectural pattern also facilitates horizontal expansion and collaborative development of the system.
[0179] Step 210: Obtain monitoring data through a preset monitor list.
[0180] In an embodiment of the present invention, the listener list (listeners) includes but is not limited to system load listeners, configuration change listeners, time listeners and rate change listeners (DynamicRateProvider). Among them, DynamicRateProvider is injected into the flow control aspect to obtain dynamically changing rate limit data. By marking the init method with the @PostConstruct annotation, it can be executed immediately after the object is created. The rate change listener (DynamicRateProvider) is registered through this method, and the onRateChange method is called for processing when the rate changes. The onRateChange method is used to update the rate limit of a specific method. When the new rate setting is received, the rate of the corresponding RateLimiter will be adjusted.
[0181] It is worth noting that each listener is registered with the configuration manager through the init method in order to monitor changes in the rate limit configuration.
[0182] Furthermore, the limitRequest method is marked as a method that checks for certain conditions (i.e., marked with the @RateLimited annotation) before execution. This method checks whether the request is allowed to proceed according to the dynamic rate limit and triggers an alert and throws an exception if the request exceeds the limit.
[0183] In an embodiment of the present invention, the monitoring data includes central processing unit (CPU) usage, configuration token parameters, monitoring time and dynamically changing rate limit data; the system load listener is used to monitor CPU usage, the configuration change listener is used to monitor configuration token parameters, the time listener is used to obtain the monitoring time, and the rate change listener is used to monitor dynamically changing rate limit data.
[0184] Step 211 : Determine whether the monitored data complies with the preset flow control section adjustment rule. If so, execute step 212 ; if not, execute step 210 .
[0185] In an embodiment of the present invention, the flow control aspect adjustment rule is a mechanism for dynamically adjusting and managing flow control, allowing developers to modify aspect definitions and restriction parameters at runtime, thereby flexibly adjusting the flow control strategy according to actual needs, such as: increasing or decreasing the number of requests per second, dynamically adjusting the number of concurrent connections, etc.
[0186] Specifically, the parameter values in the flow control logic are saved by dynamically refreshing the database. When the business request traffic undertaken by the system is too large, the parameter values in the flow control logic are reduced to reduce the pressure on the system. When the pressure on the system is reduced, the parameter values in the flow control logic are increased to make the flow control of the request system smoother.
[0187] In the embodiment of the present invention, the flow control aspect adjustment rules can be set according to actual needs, and the embodiment of the present invention does not limit this. If the monitored data meets the preset flow control aspect adjustment rules, it indicates that the parameter values in the flow control logic need to be adjusted and updated, and step 212 is continued; if the monitored data does not meet the preset flow control aspect adjustment rules, it indicates that the parameter values in the flow control logic do not need to be adjusted and updated, and step 210 is continued to monitor.
[0188] For example, if the parameter value in the flow control logic is a token parameter, as an optional solution, the flow control aspect adjustment rules include a usage token coefficient mapping relationship and a time token parameter mapping relationship. The usage token coefficient mapping relationship represents the relationship between CPU usage and token coefficients, while the time token parameter mapping relationship represents the relationship between system time and token parameters.
[0189] Specifically, the monitored CPU usage is matched with the CPU usage in the usage token coefficient correspondence. If the match is successful, it indicates that the flow control aspect adjustment rule is met, and step 212 is continued; if the match fails, it indicates that the flow control aspect adjustment rule is not met, and step 210 is continued.
[0190] Specifically, the monitored listening time is matched with the system time in the corresponding relationship of the time token parameter. If the match is successful, it indicates that the flow control aspect adjustment rules are met, and step 212 is continued; if the match fails, it indicates that the flow control aspect adjustment rules are not met, and step 210 is continued.
[0191] Step 212: Update the flow control section according to the flow control section adjustment rule and the monitored data to generate an updated flow control section.
[0192] In the embodiment of the present invention, the listener list includes system load listeners, the monitoring data includes central processing unit usage, and the flow control aspect adjustment rule includes a usage token coefficient correspondence.
[0193] Step 2121: Determine the corresponding token coefficient according to the CPU usage rate through the usage-token-coefficient correspondence.
[0194] Specifically, when the rate change listener (DynamicRateProvider) detects a rate change, the CPU usage detected by the system load listener is matched with the CPU usage in the usage token coefficient to determine the corresponding token coefficient.
[0195] As an optional solution, the corresponding relationship between the usage token coefficient is: if the CPU usage is greater than 50%, the corresponding token coefficient is 0.5; if the CPU usage is less than or equal to 50% and greater than 10%, the corresponding token coefficient is 0.8; if the CPU usage is continuously less than or equal to 10% within 1 minute, the corresponding token coefficient is 1.
[0196] Step 2122: Update the token parameters in the flow control section according to the determined token coefficient to generate an updated flow control section.
[0197] In an embodiment of the present invention, the token coefficient is multiplied by the token parameter in the flow control section to obtain an updated token parameter; the updated token parameter is applied to the flow control section to generate an updated flow control section.
[0198] For example: By default, the business request obtains 10 tokens per second. When the system CPU usage exceeds 50%, all token parameters are multiplied by the token coefficient 0.5. At this time, the business request is allowed to only 5 requests per second by default; when the system CPU usage drops below 20%, the token coefficient is 0.8. At this time, the business request is allowed to only 8 requests per second by default; when the system CPU usage is continuously below 10% for 1 minute, the token coefficient is 1. At this time, the business request can obtain 10 tokens per second by default.
[0199] Furthermore, the onRateChange method is configured to be called when the corresponding configuration item in the database changes. This method notifies all registered listeners of the rate change. When the system load listener detects a change in CPU usage that meets the flow control aspect's adjustment rules, it proactively calls the onRateChange method to notify the system of the change in flow control token parameters.
[0200] In an embodiment of the present invention, the listener list also includes a configuration change listener, and the monitored data includes configuration token parameters. The configuration change listener is used to monitor for manually updated token parameter configurations in the database and refresh the saved configuration token parameters. Step 212 specifically includes: when the rate change listener (DynamicRateProvider) monitors a rate change, that is, a change in the configuration token parameters, the token parameters in the flow control aspect are updated to the monitored configuration token parameters, and an updated flow control aspect is generated.
[0201] In an embodiment of the present invention, the database configuration is dynamically read and default values are set through a rate change listener (DynamicRateProvider), thereby realizing the ability of dynamic configuration update, so that the parameter values in the flow control logic such as rate limit value or token parameter can be changed without restarting the application.
[0202] Furthermore, the onRateChange method is configured to be called when the corresponding configuration item in the database changes. The onRateChange method is used to notify all registered listeners that the rate has changed. When the configuration change listener detects a change in the token parameter configuration, it actively calls the onRateChange method to notify the system of the change in the flow control token parameters.
[0203] In an embodiment of the present invention, the listener list also includes a time listener, the monitoring data includes the monitoring time, and the flow control aspect adjustment rules include the time token parameter correspondence. Time change monitoring can be triggered once per hour, and the token parameters are switched when the monitoring time corresponds to the night low peak period and the day high peak period corresponding to the preset system time.
[0204] Step 212 specifically includes:
[0205] Step 3121: Determine the corresponding token parameters according to the monitoring time through the time token parameter correspondence.
[0206] In the embodiment of the present invention, the monitoring time monitored by the system load monitor is matched with the system time in the time token parameter correspondence relationship to determine the corresponding token parameter.
[0207] Step 3122: Update the token parameters in the flow control section to the determined token parameters, and generate an updated flow control section.
[0208] In the embodiment of the present invention, the determined token parameters are applied to the flow control section to generate an updated flow control section.
[0209] This invention supports dynamic adjustment of flow control parameters and customizable flow control policies. System administrators can flexibly adjust limit parameters such as request frequency and number of concurrent connections based on actual needs, dynamically optimizing flow control without interrupting system operation. Developers can also customize flow control policies based on specific business scenarios and requirements to adapt to different business needs and provide greater flexibility and scalability.
[0210] Furthermore, the onRateChange method is configured to be called when the corresponding configuration item in the database changes. This method notifies all registered listeners of the rate change. When the time listener detects that the listening time change meets the flow control aspect adjustment rules, it proactively calls the onRateChange method to notify the system of the change in flow control token parameters.
[0211] Furthermore, an early warning condition for abnormal traffic is set in the traffic control aspect (RateLimitAspect). The early warning condition can be set according to actual needs, and the embodiment of the present invention does not limit this.
[0212] As an optional solution, a warning SMS message is sent when the CPU usage exceeds 80%.
[0213] As another option, if an event starts at 10 o'clock, the number of business requests allowed to pass through a specific interface per second can be set to 0. For such requests with a flow control of 0, the user who initiated the request can be analyzed before flow control, and the analyzed user can be added to the exception list to prohibit the user from participating in the event.
[0214] It is worth noting that in addition to sending warning SMS, the warning also needs to record the number of requests on each platform. For example, the request threshold configured by a high-level user is 200 times per second, but the business it requests is complex. In the future, you can consider reducing the number of interfaces allowed per second. In addition to targeting the platform, you can also target the interface, that is, reduce the number of tokens allowed to be obtained per second by the interface with complex business logic, and increase the number of tokens allowed to be obtained per second by the interface with simple business logic.
[0215] Furthermore, through traffic control strategies such as logging, indicator collection, and threshold setting, the request traffic in the system can be monitored in real time, abnormal traffic and abnormal behavior can be discovered in a timely manner, and early warnings can be triggered and countermeasures can be taken. While ensuring system performance, the traffic of business requests can be flexibly and accurately controlled and managed. It has the characteristics of decoupling from business code and dynamic adjustment, and has good scalability and is easy to maintain.
[0216] This application can effectively protect the system from sudden large traffic shocks by accurately limiting and controlling business requests in the system. When processing high-concurrency requests, the system's resource allocation can be more reasonable, ensuring that each request can be properly processed and responded to, thereby ensuring the stable operation of the system; aspect-based high-concurrency flow control uses high-performance flow control algorithms, such as implementing token bucket algorithms. These algorithms can quickly and accurately limit and process requests in high-concurrency scenarios, ensuring that the system has high throughput and low latency characteristics. By effectively managing system resources, common problems such as resource overload and performance degradation can be avoided. Therefore, this application has advantages in accurately limiting and controlling requests, decoupling business logic, high-performance flow control algorithms, and dynamically adjusting parameters. By providing stable, maintainable, and efficient solutions, it provides a powerful, reliable, and efficient technical foundation for processing high-concurrency request scenarios.
[0217] In the solution of the embodiment of the present invention, a business request sent by a user is obtained, and the business request includes a request transaction code and a flow control annotation; a corresponding flow control aspect is determined according to the flow control annotation through a preset annotation aspect correspondence relationship; a corresponding transaction attribution platform number is determined according to the request transaction code through a preset transaction attribution platform correspondence relationship; parameters of the flow control aspect are adjusted according to the transaction attribution platform number through a preset attribution platform aspect correspondence relationship to generate a target flow control aspect, which is flow control logic based on aspect-oriented programming technology; the target flow control aspect is woven into the business request, and flow control is performed on the business request based on the target flow control logic within the target flow control aspect, achieving high-concurrency flow control based on the aspect, and being able to dynamically adjust the aspect strategy according to flow changes, thereby improving flexibility and dynamic adjustment capabilities; the aspect-based flow control method adopts efficient algorithms and data structures to achieve flow control with minimal performance overhead; it is decoupled from the business code, and does not require modification of the original code, thereby achieving precise control of flow, thereby reducing latency and improving business efficiency, and has the characteristics of low intrusion, dynamism, flexibility, and high performance.
[0218] The present invention also provides a flow control device based on a slice, as described in the following embodiments. Since the principle of solving the problem of the device is similar to that of the flow control method based on a slice, the implementation of the device can refer to the implementation of the flow control method based on a slice.
[0219] Figure 3 A schematic structural diagram of a flow control device based on a slice according to an embodiment of the present invention is provided, wherein the device is used to execute the flow control method based on a slice, such as Figure 3 As shown, the device includes: a service request acquisition unit 11, a section determination unit 12, a platform number determination unit 13, a target section determination unit 14 and a traffic control unit 15.
[0220] The service request acquiring unit 11 is used to acquire the service request sent by the user, where the service request includes a request transaction code and a flow control annotation.
[0221] The section determination unit 12 is used to determine the corresponding flow control section according to the flow control annotation through the preset annotation section correspondence relationship.
[0222] The platform number determining unit 13 is configured to determine the corresponding transaction platform number according to the requested transaction code based on a preset transaction platform correspondence relationship.
[0223] The target aspect determination unit 14 is used to adjust the parameters of the flow control aspect according to the transaction platform number through the preset belonging platform aspect correspondence relationship, and generate a target flow control aspect. The target flow control aspect is the flow control logic based on aspect-oriented programming technology.
[0224] The flow control unit 15 is used to weave the target flow control aspect into the service request and perform flow control on the service request based on the target flow control logic in the target flow control aspect.
[0225] In the embodiment of the present invention, the device further includes: a receiving unit 16 and an annotation constructing unit 17 .
[0226] The receiving unit 16 is used to receive an input annotation definition operation.
[0227] The annotation construction unit 17 is used to construct a flow control annotation according to the annotation definition operation, and the flow control annotation is used to identify a service request for flow control.
[0228] In the embodiment of the present invention, the receiving unit 16 and the section construction unit 18.
[0229] The receiving unit 16 is further configured to receive an input slice definition operation.
[0230] The aspect construction unit 18 is used to construct a flow control aspect according to the aspect definition operation. The flow control aspect includes a flow control strategy and flow restriction conditions.
[0231] In an embodiment of the present invention, the target flow control logic includes a token limit number and a token limit rate, and the service request includes a token request number and a token request rate; the flow control unit 15 is specifically used to perform flow control on the token request number and the token request rate based on the token bucket algorithm and according to the token limit number and the token limit rate, and generate a flow control result.
[0232] In an embodiment of the present invention, the flow control unit 15 is specifically used to determine whether the number of token requests is less than or equal to the token limit number, and whether the token request rate is less than or equal to the token limit rate; if both are yes, a flow control result of the service request passing is generated; if at least one of them is no, the service requests that exceed the token limit number and / or exceed the token limit rate are queried; based on the queried service requests, a flow control result of the service request failure is generated; for the service requests that do not exceed the token limit number and the token limit rate, a flow control result of the service request passing is generated.
[0233] In an embodiment of the present invention, the target flow control logic includes flow limitation conditions, the flow limitation conditions include a maximum number of requests per second threshold, and the business request includes a maximum number of requests per second; the flow control unit 15 is specifically used to determine whether the maximum number of requests per second in the business request is less than or equal to the maximum number of requests per second threshold; if so, generate a flow control result for the business request to pass; if not, query the business request that exceeds the maximum number of requests per second threshold; based on the queried business request, generate a flow control result for the business request failure; for the business request that does not exceed the maximum number of requests per second threshold, generate a flow control result for the business request to pass.
[0234] In an embodiment of the present invention, the target flow control logic includes a flow limitation condition, the flow limitation condition includes a concurrent connection number threshold, and the service request includes the concurrent connection number; the flow control unit 15 is specifically used to determine whether the concurrent connection number in the service request is less than or equal to the concurrent connection number threshold; if so, generate a flow control result that the service request passes; if not, generate a flow control result that the service request fails.
[0235] In an embodiment of the present invention, the target flow control logic includes a flow limitation condition, the flow limitation condition includes a total request number threshold, and the service request includes the total request number; the flow control unit 15 is specifically used to determine whether the total request number in the service request is less than or equal to the total request number threshold; if so, generate a flow control result that the service request passes; if not, query the service requests that exceed the total request number threshold; based on the queried service requests, generate a flow control result that the service request fails; for the service requests that do not exceed the total request number threshold, generate a flow control result that the service request passes.
[0236] In the embodiment of the present invention, the device further includes: a monitoring data acquisition unit 19 , a rule judgment unit 20 and a slice updating unit 21 .
[0237] The monitoring data acquiring unit 19 is configured to acquire monitoring data through a preset monitor list.
[0238] The rule determination unit 20 is used to determine whether the monitoring data complies with the preset flow control section adjustment rule; if not, the monitoring data acquisition unit 19 is triggered to repeatedly execute the step of acquiring the monitoring data through the preset monitor list.
[0239] If yes, the section updating unit 21 is configured to update the flow control section according to the monitoring data and the flow control section adjustment rule to generate an updated flow control section.
[0240] In an embodiment of the present invention, the listener list includes a system load listener, the monitoring data includes the CPU usage rate, and the flow control aspect adjustment rule includes the usage rate token coefficient correspondence relationship; the aspect update unit 21 is specifically used to determine the corresponding token coefficient according to the CPU usage rate through the usage rate token coefficient correspondence relationship; according to the determined token coefficient, the token parameters in the flow control aspect are updated to generate an updated flow control aspect.
[0241] In an embodiment of the present invention, the listener list includes configuration change listeners, and the monitoring data includes configuration token parameters; the aspect update unit 21 is specifically used to update the token parameters in the flow control aspect to the monitored configuration token parameters to generate an updated flow control aspect.
[0242] In an embodiment of the present invention, the listener list includes a time listener, the monitoring data includes the monitoring time, and the flow control section adjustment rule includes the time token parameter correspondence; the section update unit 21 is specifically used to determine the corresponding token parameters according to the monitoring time through the time token parameter correspondence; the token parameters in the flow control section are updated to the determined token parameters to generate an updated flow control section.
[0243] In the solution of the embodiment of the present invention, a business request sent by a user is obtained, and the business request includes a request transaction code and a flow control annotation; a corresponding flow control aspect is determined according to the flow control annotation through a preset annotation aspect correspondence relationship; a corresponding transaction attribution platform number is determined according to the request transaction code through a preset transaction attribution platform correspondence relationship; parameters of the flow control aspect are adjusted according to the transaction attribution platform number through a preset attribution platform aspect correspondence relationship to generate a target flow control aspect, which is flow control logic based on aspect-oriented programming technology; the target flow control aspect is woven into the business request, and flow control is performed on the business request based on the target flow control logic within the target flow control aspect, achieving high-concurrency flow control based on the aspect, and being able to dynamically adjust the aspect strategy according to flow changes, thereby improving flexibility and dynamic adjustment capabilities; the aspect-based flow control method adopts efficient algorithms and data structures to achieve flow control with minimal performance overhead; it is decoupled from the business code, and does not require modification of the original code, thereby achieving precise control of flow, thereby reducing latency and improving business efficiency, and has the characteristics of low intrusion, dynamism, flexibility, and high performance.
[0244] It should be noted that the aspect-based flow control method provided in the embodiment of the present invention can be used in the field of financial technology, and can also be used in any technical field other than the field of financial technology. The embodiment of the present invention does not limit the application field of the virtual reality-based bank training system and its training method.
[0245] Figure 4 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present invention, such as Figure 4 As shown, the electronic device includes: a processor (processor) 501, a memory (memory) 502 and a bus 503.
[0246] The processor 501 and the memory 502 communicate with each other via a bus 503 .
[0247] The processor 501 is configured to call program instructions in the memory 502 to execute the methods provided by the above method embodiments.
[0248] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned slice-based flow control method is implemented.
[0249] An embodiment of the present invention further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the above-mentioned slice-based flow control method.
[0250] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0251] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0252] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0253] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 The steps for the function specified in one or more boxes.
[0254] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A flow control method based on a section, characterized in that: include: Obtaining a business request sent by a user, wherein the business request includes a request transaction code and a flow control annotation; Determine the corresponding flow control section according to the flow control annotation through the preset annotation section correspondence relationship; Determine the corresponding transaction platform number based on the requested transaction code through the preset transaction platform correspondence relationship; Through the preset corresponding relationship between the belonging platform aspects, according to the transaction belonging platform number, the parameters of the flow control aspect are adjusted to generate the target flow control aspect, and the target flow control aspect is the flow control logic based on aspect-oriented programming technology; Weaving the target flow control aspect into the service request, and performing flow control on the service request based on the target flow control logic in the target flow control aspect; The weaving the target flow control aspect into the service request specifically includes: Use aspect weaving technology to bind the target flow control aspect to the business request code.
2. The flow control method based on slices according to claim 1, characterized in that: The method further comprises: Annotation definition operation that receives input; A flow control annotation is constructed according to the annotation definition operation, and the flow control annotation is used to identify a service request for flow control.
3. The flow control method based on slices according to claim 1, characterized in that: The method further comprises: Aspect definition operations that receive input; According to the aspect definition operation, a flow control aspect is constructed, where the flow control aspect includes a flow control strategy and flow restriction conditions.
4. The flow control method based on slices according to claim 1, characterized in that: The target flow control logic includes a token limit quantity and a token limit rate, and the service request includes a token request quantity and a token request rate; The step of weaving the target flow control aspect into the service request and performing flow control on the service request based on the target flow control logic within the target flow control aspect includes: Based on the token bucket algorithm, flow control is performed on the token request quantity and the token request rate according to the token limit quantity and the token limit rate, and a flow control result is generated.
5. The flow control method based on section according to claim 4, characterized in that: The token bucket algorithm is based on which, according to the token limit quantity and the token limit rate, flow control is performed on the token request quantity and the token request rate to generate a flow control result, including: Determining whether the token request quantity is less than or equal to the token limit quantity, and whether the token request rate is less than or equal to the token limit rate; If both are yes, a flow control result is generated for the service request to pass; If at least one of the two is negative, querying for service requests that exceed the token limit quantity and / or exceed the token limit rate; Generate a flow control result of a failed business request based on the queried business request; For service requests that do not exceed the token limit quantity and token limit rate, a flow control result of the service request passing is generated.
6. The flow control method based on slices according to claim 1, characterized in that: The target flow control logic includes a flow restriction condition, the flow restriction condition includes a maximum request number threshold per second, and the service request includes a maximum request number per second; The step of weaving the target flow control aspect into the service request and performing flow control on the service request based on the target flow control logic within the target flow control aspect includes: Determine whether the maximum number of requests per second in the service request is less than or equal to the maximum number of requests per second threshold; If so, generate a flow control result indicating that the service request has passed; If not, query the service requests that exceed the maximum number of requests per second threshold; Generate a flow control result of a failed business request based on the queried business request; For service requests that do not exceed the maximum number of requests per second threshold, a flow control result of the service request passing is generated.
7. The flow control method based on slices according to claim 1, characterized in that: The target flow control logic includes a flow restriction condition, the flow restriction condition includes a concurrent connection number threshold, and the service request includes the concurrent connection number; The step of weaving the target flow control aspect into the service request and performing flow control on the service request based on the target flow control logic within the target flow control aspect includes: Determine whether the number of concurrent connections in the service request is less than or equal to the concurrent connection number threshold; If so, generate a flow control result indicating that the service request has passed; If not, a flow control result indicating that the service request failed is generated.
8. The flow control method based on slices according to claim 1, characterized in that: The target flow control logic includes a flow restriction condition, the flow restriction condition includes a total request number threshold, and the service request includes a total request number; The step of weaving the target flow control aspect into the service request and performing flow control on the service request based on the target flow control logic within the target flow control aspect includes: Determine whether the total number of requests in the service request is less than or equal to the total number of requests threshold; If so, generate a flow control result indicating that the service request has passed; If not, query the service requests that exceed the total request count threshold; Generate a flow control result of a failed business request based on the queried business request; For the service requests that do not exceed the total request number threshold, a flow control result of the service request passing is generated.
9. The flow control method based on slices according to claim 1, characterized in that: The method further comprises: Obtain monitoring data through the preset monitor list; Determining whether the monitored data complies with a preset flow control section adjustment rule; If yes, update the flow control section according to the flow control section adjustment rule and the monitoring data to generate an updated flow control section; If not, repeat the step of obtaining monitoring data through the preset monitor list.
10. The flow control method based on slices according to claim 9, characterized in that: The listener list includes a system load listener, the monitoring data includes a CPU usage rate, and the flow control aspect adjustment rule includes a usage rate token coefficient correspondence; The updating of the flow control section according to the monitoring data according to the flow control section adjustment rule to generate an updated flow control section includes: Determine the corresponding token coefficient according to the CPU usage rate through the usage rate-token coefficient correspondence relationship; According to the determined token coefficient, the token parameters in the flow control section are updated to generate an updated flow control section.
11. The flow control method based on slices according to claim 9, characterized in that: The listener list includes a configuration change listener, and the monitoring data includes a configuration token parameter; The updating of the flow control section according to the monitoring data according to the flow control section adjustment rule to generate an updated flow control section includes: Update the token parameters in the flow control section to the monitored configuration token parameters and generate the updated flow control section.
12. The flow control method based on slices according to claim 9, characterized in that: The listener list includes time listeners, the monitoring data includes monitoring time, and the flow control aspect adjustment rule includes a time token parameter correspondence; The updating of the flow control section according to the monitoring data according to the flow control section adjustment rule to generate an updated flow control section includes: Determine the corresponding token parameter according to the monitoring time through the time token parameter correspondence; The token parameters in the flow control section are updated to the determined token parameters, and an updated flow control section is generated.
13. A flow control device based on a section, characterized in that: include: A service request acquisition unit, configured to acquire a service request sent by a user, wherein the service request includes a request transaction code and a flow control annotation; A section determination unit, configured to determine a corresponding flow control section according to the flow control annotation through a preset annotation section correspondence relationship; A platform number determining unit, configured to determine a corresponding transaction platform number according to the requested transaction code through a preset transaction platform correspondence relationship; a target aspect determination unit, configured to adjust parameters of the flow control aspect according to the transaction belonging platform number through a preset corresponding relationship between the belonging platform aspects, and generate a target flow control aspect, wherein the target flow control aspect is flow control logic based on aspect-oriented programming technology; A flow control unit, configured to weave the target flow control aspect into the service request and perform flow control on the service request based on the target flow control logic within the target flow control aspect; The flow control unit is specifically used to bind the target flow control aspect with the code of the business request by using aspect weaving technology.
14. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the slice-based flow control method according to any one of claims 1 to 12 is implemented.
15. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements the slice-based flow control method according to any one of claims 1 to 12.
16. A computer program product, characterized in that The computer program product includes a computer program, and when the computer program is executed by a processor, it implements the slice-based flow control method according to any one of claims 1 to 12.
Citation Information
Patent Citations
System dynamic current limiting method and device, and storage medium
CN112333111A
Service request processing method and device, electronic equipment and storage medium
CN113179266A