Interface current limiting method, system, equipment and medium
By real-time parsing and processing of traffic information of HTTP service requests and processing requests based on preset flow limit rules, the problem of manually adding flow limit annotations in the existing technology is solved, which simplifies the development process and improves the maintainability of the system.
Patent Information
- Application Number
- CN202510403856.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-01
- Publication Date
- 2025-06-10
AI Technical Summary
When implementing traffic control of HTTP requests, developers need to manually add stream limit annotations on each interface, resulting in increased code complexity, reduced readability and maintainability, and decreased development efficiency.
By receiving HTTP service requests in real time, analyzing request characteristics, obtaining traffic information, and processing requests according to preset current limit rules, there is no need to manually add current limit annotations on each interface.
It simplifies the development process, improves development efficiency, avoids the accumulation of annotations and configurations in the entry-level code, and improves the maintainability of the system.
Smart Images

Figure CN120128535A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network traffic control, and particularly to an interface flow limiting method, system, device and medium. Background Art
[0002] In modern Internet applications, the Hypertext Transfer Protocol (HTTP) is one of the most commonly used communication protocols. However, due to system resource limitations and security considerations, it has become increasingly important to control the traffic of HTTP requests. The purpose of traffic control is to prevent server overload, ensure the availability and stability of services, and prevent malicious attacks and abuses. By limiting the speed and controlling HTTP requests, system resources can be effectively managed, and the reliability and security of the system can be improved.
[0003] Currently, when implementing traffic control for HTTP requests, it is usually done by adding flow limiting annotations to each interface. This method requires developers to manually add flow limiting annotations and configure corresponding parameters every time a new interface is added. In addition, as the number of interfaces increases, the code at the entry layer becomes more and more complex, filled with various annotations and configurations, resulting in a decrease in code readability and maintainability; moreover, it increases the workload of developers and reduces development efficiency. Summary of the Invention
[0004] To solve the above problems, the present invention provides an interface flow limiting method, system, device and medium.
[0005] The first aspect of the present invention discloses an interface flow limiting method, including:
[0006] Receiving an HTTP service request in real time;
[0007] Parsing the HTTP service request to obtain request characteristics;
[0008] Obtaining traffic information corresponding to the HTTP service request according to the request characteristics;
[0009] Judging whether the traffic information conforms to the flow limiting rules in the cache, and processing the HTTP service request according to the judgment result.
[0010] Further, the step of parsing the HTTP service request to obtain request characteristics includes:
[0011] Parsing the HTTP service request to obtain a target service identifier, a complete request path and a request operation type.
[0012] Further, the step of obtaining traffic information corresponding to the HTTP service request according to the request feature includes:
[0013] Generate an interface rate-limiting key according to the target service identifier, the complete request path, and the request operation type according to a preset rule;
[0014] Read the corresponding traffic information from the traffic statistics table according to the interface rate-limiting key.
[0015] Further, the step of determining whether the traffic information conforms to the rate-limiting rule in the cache and processing the HTTP service request according to the determination result includes:
[0016] Determine whether the traffic information conforms to the rate-limiting rule in the cache;
[0017] When it conforms, execute the HTTP service request;
[0018] When it does not conform, intercept the HTTP service request and return a predefined first status code.
[0019] Further, the step of executing the HTTP service request includes:
[0020] Process the HTTP service request and generate a second status code according to the processing result;
[0021] Reply to the HTTP service request according to the second status code;
[0022] Generate an interface rate-limiting key according to the target service identifier, the complete request path, and the request operation type according to a preset rule;
[0023] Update the traffic information corresponding to the interface rate-limiting key in the traffic statistics table according to the interface rate-limiting key.
[0024] Further, the interface rate-limiting method further includes:
[0025] Monitor the rate-limiting rule of the configuration center in real time;
[0026] When the rate-limiting rule changes, update the rate-limiting rule in the cache with the changed rate-limiting rule.
[0027] Further, the step of obtaining traffic information corresponding to the HTTP service request according to the request feature includes:
[0028] Judge whether the HTTP service request is a public request according to the request feature;
[0029] When it is a public request, obtain the traffic information corresponding to the HTTP service request;
[0030] When it is not a public request, execute the HTTP service request.
[0031] A second aspect of the present invention discloses an interface flow limiting system, including:
[0032] A receiving module, configured to receive HTTP service requests in real time;
[0033] A parsing module, configured to parse the HTTP service request to obtain request characteristics;
[0034] An obtaining module, configured to obtain traffic information corresponding to the HTTP service request according to the request characteristics;
[0035] A judging module, configured to judge whether the traffic information conforms to the flow limiting rules in the cache, and process the HTTP service request according to the judgment result.
[0036] A third aspect of the present invention discloses an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. The processor is characterized in that when the processor executes the computer program, the steps of any interface flow limiting method disclosed in the first aspect of the present invention are implemented.
[0037] A fourth aspect of the present invention discloses a storage medium, which stores a computer program. The computer program is characterized in that when the computer program is executed by a processor, the steps of any interface flow limiting method disclosed in the first aspect of the present invention are implemented.
[0038] Regarding the deficiencies of the existing methods, the present invention simplifies the development process and improves the development efficiency by monitoring real-time HTTP service requests, parsing and analyzing the HTTP service requests, obtaining the traffic information corresponding to the HTTP service requests, and processing the requests according to the preset flow limiting rules, without the need for developers to manually add flow limiting annotations to each interface; through centralized flow limiting processing, the present invention avoids the accumulation of a large number of annotations and configurations in the entrance layer code, making the code more concise and easy to maintain, and improving the maintainability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0040] Figure 1 It is a schematic flowchart of an interface flow limiting method disclosed in an embodiment of the present invention;
[0041] Figure 2 is a schematic structural diagram of an interface current limiting system disclosed in an embodiment of the present invention;
[0042] Figure 3 is a schematic structural diagram of an electronic device disclosed in an embodiment of the present invention. Detailed implementation manners
[0043] In order to enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0044] The terms "first", "second", etc. in the specification and claims of the present invention and the above drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, device, or product end that includes a series of steps or units is not limited to the listed steps or units, but optionally further includes steps or units not listed, or optionally further includes other steps or units inherent to these processes, methods, devices, or products.
[0045] Referring to "embodiment" herein means that a specific feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the present invention. The phrase appears in various places in the specification and does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.
[0046] Please refer to Figure 1 as shown in Figure 1 is a schematic flowchart of an interface current limiting method disclosed in an embodiment of the present invention, including the following operations:
[0047] S101. Receive HTTP service requests in real time;
[0048] In this optional embodiment, an HTTP service request refers to a service call request initiated by a client to a server through the HTTP protocol, usually including elements such as a request operation type (such as GET, POST), a complete request path, request headers, parameters, and a request body. In this optional embodiment, the server receives HTTP service requests in real time by listening on a specific network port.
[0049] S102. Parse the HTTP service request to obtain request features;
[0050] In an optional embodiment, the step of parsing the HTTP service request to obtain request features includes:
[0051] Parse the HTTP service request to obtain a target service identifier, a complete request path, and a request operation type.
[0052] In this optional embodiment, the target service identifier refers to the information used to uniquely identify an HTTP service in the HTTP service request, which can be a port number, and / or a virtual host name, and / or a URL (Uniform Resource Locator) path prefix, and / or a custom request header. In this optional embodiment, the target service identifier can be obtained through the following methods:
[0053] For the port number, the port number information can be extracted from the target address of the HTTP request. For example, if the requested URL is http: / / example.com:8080 / path, the target service identifier is 8080;
[0054] For the virtual host name, the virtual host name information can be extracted from the Host request header of the HTTP request. For example, if the request header contains Host: service-a.example.com, the target service identifier is service-a.example.com;
[0055] For the URL path prefix, a specified prefix can be extracted from the URL path of the HTTP request as the target service identifier. For example, if the requested URL is http: / / example.com / service-a / path, and it is agreed that / service-a / is the path prefix of service A, the target service identifier is service-a;
[0056] For the custom request header, the target service identifier can be extracted from the custom request header of the HTTP request. For example, if the request header contains X-Service-Name: service-b, the target service identifier is service-b.
[0057] In this optional embodiment, the complete request path refers to the complete URL path of the HTTP service request, including the requested resource path and query parameters. By parsing the request line of the HTTP request (such as GET / path / to / resource?key=value HTTP / 1.1), the complete request path can be extracted.
[0058] The request operation type refers to the method of the HTTP request, such as GET, POST, PUT, DELETE, etc. By parsing the request line of the HTTP request, the operation type of the request can be obtained. In the request line of the HTTP request, the first word represents the operation type of the request. For example, "GET / path / to / resource HTTP / 1.1" indicates that this is a GET request.
[0059] It can be seen that in this optional embodiment, by parsing the HTTP service request and based on the real-time parsing of the request characteristics, the flow limiting mechanism can be dynamically adjusted. According to the current system load situation and traffic conditions, more accurate traffic management can be implemented for specific services or interfaces. This fine-grained and dynamic flow limiting scheme helps to improve the reliability, performance, and maintainability of the system, and is of great significance for ensuring the stable operation of the system and providing high-quality services.
[0060] S103. Obtain the traffic information corresponding to the HTTP service request according to the request characteristics;
[0061] In an optional embodiment, the step of obtaining the traffic information corresponding to the HTTP service request according to the request characteristics includes:
[0062] Generate an interface flow limiting key according to the target service identifier, the complete request path, and the request operation type according to a preset rule;
[0063] Read the corresponding traffic information from the traffic statistics table according to the interface flow limiting key.
[0064] In this optional embodiment, the traffic statistics table is a data structure for storing and counting interface request traffic information. It organizes data in the form of key-value pairs, where the key is the interface flow limiting key generated according to the request characteristics, and the value is the traffic information corresponding to this key.
[0065] The key of the traffic statistics table is composed of the target service identifier, the complete request path, and the request operation type. For example, a key can be "service-a: / api / users / GET", indicating a GET request for the " / api / users" interface of service service-a. The value of the traffic statistics table contains the traffic information corresponding to the key. The traffic information includes the traffic information of a service interface, such as the real-time number of HTTP service requests of a service interface. The traffic information can also include: the cumulative number of bytes of the HTTP service request, and / or the average response time, and / or the timestamp of the most recent request, and / or the cumulative number of HTTP service requests, etc.
[0066] The traffic statistics table needs to support efficient read and write operations for real-time updating and querying of traffic information, which can be stored in memory, local file system, distributed cache, or distributed database. Since multiple requests may access and modify the traffic statistics table simultaneously, it is necessary to ensure that the read and write operations of the traffic statistics table are thread-safe. The embodiments of the present invention use concurrent data structures or locking mechanisms to ensure thread safety.
[0067] It can be seen that in this alternative embodiment, by generating an interface traffic limiting key based on the target service identifier, complete request path, and request operation type, and using this key to read the corresponding traffic information from the traffic statistics table, fine-grained traffic statistics and traffic limiting control can be achieved. This method associates traffic information with specific interface requests, making traffic limiting judgment more accurate and efficient. At the same time, it simplifies the design and maintenance of the traffic statistics table, improving the scalability and performance of the system.
[0068] In another alternative embodiment, the step of obtaining the traffic information corresponding to the HTTP service request according to the request characteristics includes:
[0069] Judging whether the HTTP service request is a public request according to the request characteristics;
[0070] When it is a public request, obtaining the traffic information corresponding to the HTTP service request;
[0071] When it is not a public request, executing the HTTP service request.
[0072] In this alternative embodiment, judging whether an HTTP service request is a public request can be achieved by identifying whether the request path conforms to the predefined open interface characteristics, by parsing the URI path of the HTTP request and matching the pre-configured open platform interface path rules. For example, it is predefined that an HTTP service request with a request path prefixed with / openapi / is a public request.
[0073] In this alternative embodiment, non-public requests usually come from trusted users or clients and have certain permissions and legality. These requests may involve important business logics or sensitive data operations. Directly executing the HTTP service request can ensure that these requests are processed promptly and correctly, avoiding the additional overhead and latency brought by unnecessary traffic limiting judgment. In contrast, public requests usually come from unknown or untrusted sources and may contain malicious attacks or high-frequency invalid requests. Obtaining traffic information and performing traffic limiting judgment on these requests can effectively identify and block potential attacks, protecting the system from overload and abuse. By treating public requests and non-public requests differently, the performance and response speed of the system can be improved while ensuring the security of the system.
[0074] It can be seen that in this optional embodiment, by determining whether the HTTP service request is a public request, different traffic limiting policies can be applied to public requests and non-public requests. This method can improve the security and availability of the system, prevent malicious users from exhausting system resources through a large number of public requests, and at the same time ensure that non-public requests are not affected by traffic limiting, guaranteeing the normal processing of legitimate user requests by the system, thereby providing a better user experience.
[0075] S104. Determine whether the traffic information conforms to the traffic limiting rules in the cache, and process the HTTP service request according to the determination result.
[0076] In an optional embodiment, the step of determining whether the traffic information conforms to the traffic limiting rules in the cache and processing the HTTP service request according to the determination result includes:
[0077] Determine whether the traffic information conforms to the traffic limiting rules in the cache;
[0078] When it conforms, execute the HTTP service request;
[0079] When it does not conform, intercept the received HTTP service request and return a predefined first status code.
[0080] In this optional embodiment, the traffic limiting rules refer to a set of rules and conditions for controlling the traffic of interface requests. These rules define restrictions such as the number of requests allowed within a certain time, request frequency, and concurrency, to prevent excessive requests from overloading the system or affecting the service quality of other users.
[0081] The traffic limiting rules can be time window traffic limiting, or token bucket traffic limiting, or concurrency traffic limiting, or leaky bucket traffic limiting, etc., and the embodiments of the present invention are not limited. Time window traffic limiting means that within a specified time window (e.g., 1 minute), the number of requests is restricted not to exceed a certain threshold; Token bucket traffic limiting means that tokens are generated at a fixed rate, and each HTTP service request needs to consume a certain number of tokens to pass, and the HTTP service request is rejected when the number of tokens is insufficient; Concurrency traffic limiting means that the number of concurrent requests at the same moment is restricted not to exceed a certain threshold, and the HTTP service request is rejected or queued when exceeded; Leaky bucket traffic limiting means that HTTP service requests enter the leaky bucket at a fixed rate, and the HTTP service request is rejected when the leaky bucket is full, and the leaky bucket releases HTTP service requests at a fixed rate.
[0082] For different traffic limiting rules, the corresponding traffic information in the traffic statistics table is different. For example, when the traffic limiting rule adopts time window traffic limiting, the traffic information needs to include the arrival time of each HTTP service request, for determining whether the HTTP service request is within the time window of the traffic limiting rule.
[0083] In this optional embodiment, intercepting an HTTP service request means terminating the execution of the HTTP service request in advance through a certain mechanism and returning a predefined response result before the HTTP service request reaches the actual service processing logic. Intercepting an HTTP service request can be achieved by adding an interceptor or a filter in the request processing flow.
[0084] When the request is intercepted, a predefined first status code is returned to indicate the reason and result of the interception. The first status code is an HTTP status code, which is a three-digit code returned by the server when responding to an HTTP service request and is used to indicate the processing result and status of the HTTP service request. In this embodiment, in the case where the HTTP service request is intercepted due to rate limiting, the status code 429 can be used to indicate that the client's request exceeds the limit allowed by the server; or the status code 503 can be used to indicate that the server is temporarily unable to process the request; or the status code 403 can be used to indicate that the server understands the request but refuses to execute it.
[0085] It can be seen that in this optional embodiment, by intercepting HTTP service requests that exceed the rate limiting rules and returning a predefined first status code, the server can be effectively protected from overload and abuse, ensuring the stability and availability of the system; quickly rejecting requests that exceed the limit, avoiding unnecessary resource consumption and response latency, and at the same time clearly informing the client of the reason for the request rejection through the status code, improving the controllability and maintainability of the system, and also providing clear feedback and guidance to the client, which helps to improve the user experience and the quality of system interaction.
[0086] In another optional embodiment, the step of executing the HTTP service request includes:
[0087] Processing the HTTP service request and generating a second status code according to the processing result;
[0088] Replying to the HTTP service request according to the second status code;
[0089] Generating an interface rate limiting key according to the target service identifier, the complete request path, and the request operation type according to a preset rule;
[0090] Updating the traffic information corresponding to the interface rate limiting key in the traffic statistics table according to the interface rate limiting key.
[0091] In this optional embodiment, the second status code refers to the HTTP status code generated according to the processing result of the HTTP service request after processing the HTTP service request. For example, when the HTTP service request has been successfully processed and the requested resource or result has been returned, the second status code can be set to 200; when the HTTP service request has been successfully processed and a new resource has been created, the second status code can be set to 201; when there is an error in the HTTP service request sent by the client and the server cannot process it, the second status code can be set to 400; when the resource requested by the HTTP service request does not exist and the server cannot find the requested resource, the second status code can be set to 404, etc.
[0092] The update of the traffic information is determined according to the data structure of the traffic statistics table. For example: increment the real-time HTTP service request count corresponding to the interface rate limit key. When the traffic statistics table includes the timestamp of the most recent request, the operation of updating the traffic information needs to update the last request time corresponding to the interface rate limit key to the current time.
[0093] It can be seen that in this optional embodiment, by updating the corresponding traffic information in the traffic statistics table after processing the HTTP service request, the request situation of each interface can be recorded and statistically analyzed in real time, providing an accurate data basis for subsequent rate limit judgment, finely controlling the traffic of each interface, setting appropriate rate limit rules according to the characteristics and requirements of different interfaces, and improving the flexibility and customizability of rate limiting. At the same time, by recording the processing results and status of requests, more comprehensive and detailed traffic monitoring and analysis can be realized, providing data support for system optimization and adjustment.
[0094] In yet another optional embodiment, the interface rate limiting method further includes:
[0095] Real-time monitoring of the rate limit rules in the configuration center;
[0096] When the rate limit rules change, update the rate limit rules in the cache with the changed rate limit rules.
[0097] In this optional embodiment, the configuration center is a system or service for centralized management of application / service configurations, used to store, manage, and distribute various configuration information required during the runtime of applications / services, such as database connection strings, service endpoints, rate limit rules, etc. By separating the configuration information from the application code, the configuration center realizes centralized management and dynamic update of configurations, improving the flexibility and maintainability of the system.
[0098] In this optional embodiment, the rate limit rules of the configuration center are monitored in real time through callbacks or event subscriptions.
[0099] It can be seen that in this alternative embodiment, by monitoring the rate limiting rules of the configuration center in real time and dynamically updating the cache when the rules change, dynamic adjustment and real-time effectiveness of the rate limiting rules can be achieved, improving the flexibility and adaptability of the system. This method allows for dynamic adjustment of the rate limiting rules according to the actual traffic conditions and business requirements without downtime or restarting the application, quickly responding to changes in traffic. At the same time, by centrally managing the rate limiting rules, the complexity of configuration and maintenance costs can be reduced, improving the operability and maintainability of the system.
[0100] Please refer to Figure 2 as shown in Figure 2 which is a schematic structural diagram of an interface rate limiting system disclosed in an embodiment of the present invention, including:
[0101] A receiving module 201, configured to receive HTTP service requests in real time;
[0102] A parsing module 202, configured to parse the HTTP service request to obtain request characteristics;
[0103] An obtaining module 203, configured to obtain traffic information corresponding to the HTTP service request according to the request characteristics;
[0104] A judging module 204, configured to judge whether the traffic information conforms to the rate limiting rules in the cache, and process the HTTP service request according to the judgment result.
[0105] For specific limitations on the interface rate limiting system, reference can be made to the limitations on the interface rate limiting method in the above text, which will not be elaborated here. Each module in the above interface rate limiting system can be implemented in whole or in part by software, hardware, and their combinations. The above modules can be embedded in the processor of the electronic device in a hardware format or independent of it, or stored in the memory of the electronic device in a software format, so that the processor can call the corresponding operations of the above modules.
[0106] It should be noted that, in order to highlight the innovative part of the present invention, modules not closely related to solving the technical problems proposed by the present invention are not introduced in this embodiment, but this does not mean that there are no other modules in this embodiment.
[0107] As Figure 3 shown, the electronic device 1 provided by the present invention may include a memory 11, a processor 12, and a bus, and may also include a computer program stored in the memory 11 and executable on the processor 12, such as an interface rate limiting program.
[0108] Among them, the memory 11 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, mobile hard disk, multimedia card, card-type memory (such as SD or DX memory, etc.), magnetic memory, magnetic disk, optical disc, etc. The memory 11 can be an internal storage unit of the electronic device 1 in some embodiments, such as the mobile hard disk of the electronic device 1. The memory 11 can also be an external storage device of the electronic device 1 in other embodiments, such as a plug-in mobile hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. equipped on the electronic device 1. Further, the memory 11 can also include both the internal storage unit and the external storage device of the electronic device 1. The memory 11 can be used not only to store application software installed on the electronic device 1 and various types of data, such as the code for interface current limiting, etc., but also to temporarily store data that has been output or will be output.
[0109] In some embodiments, the processor 12 can be composed of integrated circuits. For example, it can be composed of a single packaged integrated circuit, or can be composed of multiple integrated circuits with the same or different functions packaged, including a combination of one or more Central Processing Units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips, etc. The processor 12 is the control core (Control Unit) of the electronic device 1, connecting various components of the entire electronic device 1 through various interfaces and circuits, and by running or executing programs or modules (such as interface current limiting programs, etc.) stored in the memory 11, and calling data stored in the memory 11, to execute various functions of the electronic device 1 and process data.
[0110] The processor 12 executes the operating system of the electronic device 1 and various installed application programs. The processor 12 executes the application programs to implement the steps in the above interface current limiting method.
[0111] Exemplarily, the computer program can be divided into one or more modules, and the one or more modules are stored in the memory 11 and executed by the processor 12 to complete this application. The one or more modules can be a series of computer program instruction segments capable of completing specific functions, and these instruction segments are used to describe the execution process of the computer program in the electronic device 1. For example, the computer program can be divided into a receiving module 201, a parsing module 202, an obtaining module 203, and a judging module 204.
[0112] The integrated unit implemented in the form of software functional modules can be stored in a computer-readable storage medium, which can be non-volatile or volatile. The above software functional modules are stored in a storage medium and include several instructions for causing a computer device (which can be a personal computer, a computer device, or a network device, etc.) or a processor to execute some functions of the interface current limiting method described in various embodiments of the present application.
[0113] In summary, for an interface current limiting method, system, device, and medium disclosed by the present invention, by monitoring real-time HTTP service requests, parsing and analyzing the HTTP service requests, obtaining traffic information corresponding to the HTTP service requests, and processing the requests according to preset current limiting rules, it is not necessary for developers to manually add current limiting annotations to each interface, which simplifies the development process and improves the development efficiency; through centralized current limiting processing, the present invention avoids the accumulation of a large number of annotations and configurations in the entrance layer code, making the code more concise and easy to maintain, and improving the maintainability of the system. Therefore, the present invention effectively overcomes various disadvantages in the prior art and has high industrial utilization value.
[0114] The above embodiments merely exemplarily illustrate the principles and effects of the present invention, rather than limiting the present invention. Any person familiar with this technology can modify or change the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or changes completed by those with ordinary knowledge in the technical field without departing from the spirit and technical idea disclosed by the present invention should still be covered by the claims of the present invention.
Claims
1. An interface current limiting method, characterized in that: The method comprises: Receive HTTP service requests in real time; Parsing the HTTP service request to obtain request characteristics; According to the request characteristics, obtaining traffic information corresponding to the HTTP service request; Determine whether the traffic information complies with the current limiting rules in the cache, and process the HTTP service request based on the determination result.
2. An interface current limiting method according to claim 1, characterized in that: The steps of parsing the HTTP service request to obtain request characteristics include: Parse the HTTP service request to obtain the target service identifier, the complete request path and the request operation type.
3. An interface current limiting method according to claim 2, characterized in that: According to the request characteristics, the step of obtaining the flow information corresponding to the HTTP service request includes: Generate an interface current limiting key according to the target service identifier, the complete request path and the request operation type according to a preset rule; The corresponding flow information is read from the flow statistics table according to the interface flow limiting key.
4. The interface current limiting method according to claim 2, characterized in that: The steps of determining whether the traffic information complies with the current limiting rules in the cache and, based on the determination result, processing the HTTP service request include: Determine whether the traffic information complies with the current limiting rules in the cache; When the conditions are met, executing the HTTP service request; When it does not meet the requirements, the HTTP service request is intercepted and a predefined first status code is returned.
5. An interface current limiting method according to claim 4, characterized in that: The step of executing the HTTP service request comprises: Processing the HTTP service request, and generating a second status code according to the processing result; Replying to the HTTP service request according to the second status code; Generate an interface current limiting key according to the target service identifier, the complete request path and the request operation type according to a preset rule; According to the interface current limiting key, the flow information corresponding to the interface current limiting key in the flow statistics table is updated.
6. The interface current limiting method according to claim 1, characterized in that: The interface current limiting method further includes: Real-time monitoring of the current limiting rules of the configuration center; When the current limiting rule changes, the current limiting rule in the cache is updated using the changed current limiting rule.
7. The interface current limiting method according to claim 1, characterized in that: According to the request characteristics, the step of obtaining the flow information corresponding to the HTTP service request includes: Determining whether the HTTP service request is a public request according to the request characteristics; When it is a public request, obtain the traffic information corresponding to the HTTP service request; When it is not a public request, the HTTP service request is executed.
8. An interface current limiting system, characterized in that: include: A receiving module, used to receive HTTP service requests in real time; A parsing module, used to parse the HTTP service request to obtain request features; An acquisition module, used to acquire the flow information corresponding to the HTTP service request according to the request characteristics; The judgment module is used to judge whether the flow information complies with the flow limiting rules in the cache, and process the HTTP service request according to the judgment result.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the interface current limiting method according to any one of claims 1 to 7 are implemented.
10. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the interface current limiting method according to any one of claims 1 to 7 are implemented.