Flow control method and device based on OpenAPI, equipment and storage medium
By using OpenAPI-based traffic control method in high concurrency scenarios, combined with sliding windows and request counter technical means, the problem of difficult to achieve refined control and dynamic adjustment in the existing technology is solved, and effective guarantees for user experience and service quality are achieved.
Patent Information
- Application Number
- CN202510191213.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-20
- Publication Date
- 2025-05-23
AI Technical Summary
Existing flow control methods are difficult to achieve refined control and dynamic adjustment in high concurrency scenarios, resulting in system resource overload and network congestion.
Using the OpenAPI-based traffic control method, by obtaining access requests carrying user ID and service ID, the corresponding container data structure and traffic threshold are determined, the total access amount is counted using sliding windows and request counters, and the current limiting strategy is executed according to the threshold.
It realizes refined control and dynamic adjustment of characteristic services, improves user experience, and ensures service quality and system stability.
Smart Images

Figure CN120034494A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of flow control technology, and in particular to an OpenAPI-based flow control method, an OpenAPI-based flow control device, a computer device, and a computer-readable storage medium. Background Art
[0002] In high-concurrency application scenarios, in order to ensure system stability and avoid network congestion and resource overload, a variety of flow control methods are often used, such as the token bucket algorithm and the leaky bucket algorithm. However, these technologies also have shortcomings: for example, the token bucket algorithm needs to maintain the token bucket and token generation logic, which will increase the system's resource consumption, and the configuration parameters of the token bucket are usually fixed and lack dynamic adjustment capabilities; the existing technologies mostly perform unified flow limiting processing on requests and lack refined control. In actual business scenarios, some feature businesses may occupy a large amount of network resources and require differentiated flow control. Summary of the invention
[0003] Based on this, it is necessary to provide a flow control method, device, equipment and storage medium based on OpenAPI to address the above technical problems.
[0004] In the first aspect, the present application provides a flow control method based on OpenAPI, the method comprising: obtaining multiple access requests; each of the access requests carries a user identifier and a service identifier; determining the container data structure and flow threshold corresponding to each access request based on the user identifier and the service identifier; the container data structure is correspondingly configured with a sliding window and a request counter, and the sliding window is fixed in length with a set time period; each of the access requests is sent to the corresponding container data structure, and the number of access requests in the current sliding window is counted based on the request counter as the total number of accesses to the container data structure within the set time period; determining that the total number of accesses within the set time period exceeds the flow threshold, and executing a flow limiting strategy for the access requests that overflow within the set time period in the container data structure.
[0005] In one embodiment, the traffic threshold includes a user threshold, and the user threshold corresponds to the user identifier; the step of counting the number of access requests in the current sliding window as the total access amount includes: counting the number of access requests corresponding to the user identifier in the current sliding window as the total access amount; the step of determining that the total access amount for the set time period exceeds the traffic threshold, and executing a current limiting strategy for the access requests that overflow within the set time period in the container data structure, includes: determining that the total access amount exceeds the user threshold, and executing a current limiting strategy for the access requests corresponding to the user identifier that overflow within the set time period.
[0006] In one embodiment, the traffic threshold includes a service threshold, and the service threshold corresponds to the service identifier; the step of counting the number of access requests in the current sliding window as the total access amount includes: counting the number of access requests corresponding to the service identifier in the current sliding window as the total access amount; the step of determining that the total access amount for the set time period exceeds the traffic threshold, and executing a current limiting strategy for the access requests that overflow within the set time period in the container data structure, includes: determining that the total access amount exceeds the service threshold, and executing a current limiting strategy for the access requests corresponding to the service identifier that overflow within the set time period.
[0007] In one embodiment, the step of sending each of the access requests to the corresponding container data structure includes: counting the total number of accesses in the request counters corresponding to the multiple container data structures within the target time period to generate a concurrent access volume; determining that the concurrent access volume of the target time period exceeds a global threshold, and executing a corresponding current limiting strategy for the access requests that overflow the multiple container data structures within the set time period; and sending the access requests that do not overflow the multiple container data structures within the target time period to the corresponding container data structure.
[0008] In one embodiment, the step of counting the number of access requests in the current sliding window based on the request counter includes: removing the total number of accesses of the request counter before the start of the current sliding window; recording each access request obtained by the current sliding window to the request counter in timestamp order; counting the number of access requests in the request counter within the set time period, and generating the total number of accesses of the container data structure within the set time period.
[0009] In one embodiment, the access request carries a request permission; the step of executing a current limiting strategy on the access requests that overflow within the set time period in the container data structure includes: identifying the request permission corresponding to each overflow access request within the set time period in the container data structure; determining the current limiting strategy corresponding to each overflow access request according to the request permission, and executing the corresponding current limiting strategy on the overflow access requests respectively; the current limiting strategy includes delayed response and access denial.
[0010] In one embodiment, when the triggering frequency of the current limiting strategy exceeds a preset threshold, an alarm message is generated; the alarm message includes detailed information of the access request that triggers the current limiting strategy and the corresponding container data structure.
[0011] In the second aspect, the present application also provides a flow control device based on OpenAPI, including: an acquisition module, used to acquire multiple access requests; each of the access requests carries a user identifier and a service identifier; a processing module, used to determine the container data structure and flow threshold corresponding to each access request based on the user identifier and the service identifier; the container data structure is correspondingly configured with a sliding window and a request counter, and the sliding window is fixed in length with a set time period; a calculation module, used to send each of the access requests to the corresponding container data structure, and based on the request counter, count the number of access requests in the current sliding window as the total number of accesses to the container data structure within the set time period; a flow limiting module, used to determine that the total number of accesses within the set time period exceeds the flow threshold, and execute a flow limiting strategy for the access requests that overflow within the set time period in the container data structure.
[0012] In a third aspect, the present application provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of a flow control method based on OpenAPI when executing the computer program.
[0013] In a fourth aspect, the present application provides a computer-readable storage medium, on which a computer program is stored, and the computer program is used to enable a machine to execute any of the above methods of the present application.
[0014] One of the above technical solutions has the following advantages or beneficial effects: determining the corresponding container data structure and traffic threshold through the user identifier and service identifier carried by each access request; counting the number of access requests in the sliding window as the total number of accesses to the container data structure within a set time period, and then executing a flow limiting strategy for overflowing access requests based on the traffic threshold, thereby achieving refined control and dynamic adjustment of feature services, improving user experience while ensuring service quality; in addition, by controlling the flow to limit the number of requests processed simultaneously, it is ensured that resources are reasonably allocated and the stability and availability of the system are protected.
[0015] Other features and advantages of the embodiments of the present invention will be described in detail in the subsequent detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings are used to provide a further understanding of the embodiments of the present invention and constitute a part of the specification. Together with the following specific implementations, they are used to explain the embodiments of the present invention, but do not constitute a limitation on the embodiments of the present invention. In the accompanying drawings:
[0017] Figure 1 is an application environment diagram of a flow control method based on OpenAPI in an embodiment;
[0018] Figure 2 is a flow chart of a flow control method based on OpenAPI in an embodiment;
[0019] Figure 3 is a structural block diagram of a flow control device based on OpenAPI in an embodiment;
[0020] Figure 4 The figure is a diagram of the internal structure of a computer device in an embodiment. DETAILED DESCRIPTION
[0021] The specific implementation of the embodiment of the present invention is described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation described here is only used to illustrate and explain the embodiment of the present invention, and is not used to limit the embodiment of the present invention.
[0022] It should be noted that the acquisition, transmission, storage, use, and processing of data in the technical solution of this application are in compliance with the relevant provisions of national laws and regulations. In the embodiments of this application, some existing solutions in the industry such as certain software, components, and models may be mentioned, which should be considered as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of this application, but it does not mean that the applicant has or will necessarily use the solution.
[0023] In such Figure 1 The application environment shown includes a user terminal and an OpenAPI gateway server, wherein the user terminal can be run in device 101, device 102, and device 103, and devices 101, device 102, and device 103 include but are not limited to various personal computers, laptops, smart phones, vehicle-mounted terminals, etc.; the OpenAPI gateway server 104 can be implemented with an independent server or a server cluster composed of multiple servers. The user terminal and the server 104 can be connected to the network communication through a wired or wireless network, specifically through the Internet, local area network, Bluetooth, Wi-Fi or ZigBee protocol (ZigBee) and other communication methods. It should be understood that the OpenAPI gateway server can establish a communication relationship with multiple user terminals, and each user terminal has millions of users. The corresponding permissions of each user terminal are different, and the server interface and the number of interfaces accessed are also different. Therefore, it is necessary to propose a flow control method that ensures that all users use system resources fairly and guarantees service quality in a high concurrency scenario.
[0024] In one embodiment, Figure 2 As shown, a flow control method based on OpenAPI is provided, including:
[0025] S202, obtaining multiple access requests; each access request carries a user identifier and a service identifier.
[0026] Among them, the access request is a data set generated by the user through a program according to the interface rules provided by the gateway; the user identifier is usually used to distinguish and identify different users, and can be set to user name, signature, authentication code and other information; the service identifier is information used to distinguish and identify different services, which can be a separate identifier or string.
[0027] In this embodiment, the user needs to first register an account to obtain a user ID and associate it with the OpenAPI gateway, and send an access request to the OpenAPI server when using the API service. It should be understood that the user in this embodiment refers to an individual or enterprise with development capabilities.
[0028] S204, determining the container data structure and traffic threshold corresponding to each access request according to the user identifier and the service identifier; the container data structure is correspondingly configured with a sliding window and a request counter, and the sliding window has a fixed length of a set period of time.
[0029] Among them, the container data structure refers to a specific structure for storing and managing request-related data, which can be a queue, array, hash table, key-value pair in Redis, etc. The stored information can be the timestamp of the request, the number of requests, or the status of the request, etc. For example, when a user calls the service userRegister, the system will find a corresponding container data structure (such as a key in Redis) based on the user's user ID and service ID to record the timestamp of the user calling the userRegister service. It should be understood that the specific structure to be selected can be pre-configured according to the actual application scenario. For multiple access requests arriving within a certain period of time, multiple container data structures can be processed concurrently, which can achieve precise control of the request frequency of each user to each service, ensuring the stability and fairness of the system in high-concurrency scenarios.
[0030] Traffic threshold refers to the OpenAPI gateway's request limit on users, services, or requests within a certain time period, such as how many request responses are allowed per second for a user or service. It should be understood that the traffic threshold can be dynamically adjusted based on factors such as user identification, service category, and system load.
[0031] A sliding window refers to a time window mechanism that is used to record requests within a certain time period and is often used to implement traffic restrictions. The length of the window is fixed, such as 1 second, 1 minute, etc. As time goes by, the window will slide to discard old request records. In this embodiment, the sliding window is fixed in length based on a set time period. The fixed length of each sliding window and the fixed length of different time periods can be set according to actual business needs to achieve dynamic switching of flow control.
[0032] S206, sending each access request to the corresponding container data structure, and counting the number of access requests in the current sliding window based on the request counter as the total number of accesses to the container data structure within the set time period;
[0033] The request counter is used to count the number of requests in the current sliding window. When a new request arrives, the counter will increase; when an old request exceeds the window range, the counter will decrease. Based on the number of access requests counted in the request counter, as the total number of accesses to the container data structure within the set period, refined flow control can be achieved to protect the stability of the system.
[0034] S208, determining that the total amount of access within the set time period exceeds the flow threshold, and executing a flow limiting strategy for the access requests overflowing within the set time period in the container data structure.
[0035] Among them, when the total number of request accesses within the set time period exceeds the traffic threshold, the OpenAPI gateway recognizes that the number of requests in the container data structure exceeds the allowed range and needs to adopt corresponding flow limiting strategies, such as queuing, delaying processing or rejecting requests.
[0036] In one embodiment, the traffic threshold includes a user threshold, and the user threshold corresponds to a user identifier; the step of counting the number of access requests in the current sliding window as the total access amount includes: counting the number of access requests corresponding to the user identifier in the current sliding window as the total access amount; determining that the total access amount for a set time period exceeds the traffic threshold, and executing a flow limiting strategy for access requests that overflow within the set time period in the container data structure, includes: determining that the total access amount exceeds the user threshold, and executing a flow limiting strategy for access requests corresponding to the user identifier that overflows within the set time period.
[0037] Exemplarily, the access request carries a user identifier. The OpenAPI gateway finds the corresponding container data structure based on the user identifier, obtains the number of access requests corresponding to the user identifier from the container data structure, counts the number of access requests as the total access traffic and compares it with the user threshold. If it does not exceed the threshold, normal access is performed. If it exceeds the user threshold, a current limiting strategy is executed for the overflow access requests of the user in each container.
[0038] In one embodiment, the traffic threshold includes a service threshold, and the service threshold corresponds to a service identifier; the step of counting the number of access requests in the current sliding window as the total access amount includes: counting the number of access requests corresponding to the service identifier in the current sliding window as the total access amount; determining that the total access amount in a set time period exceeds the traffic threshold, and executing a current limiting strategy for the access requests that overflow in the set time period in the container data structure, includes: determining that the total access amount exceeds the service threshold, and executing a current limiting strategy for the access requests corresponding to the overflow service identifier within the set time period.
[0039] Exemplarily, the access request carries a service identifier. The OpenAPI gateway finds the corresponding container data structure based on the service identifier, obtains the number of access requests corresponding to the service identifier from the container data structure, counts the number of access requests as the total access traffic and compares it with the service threshold. If it does not exceed the threshold, it is accessed normally. If it exceeds the service threshold, the flow limiting strategy is executed for the overflow access requests of the service in each container. It should be understood that the system resources occupied by each service in the actual application scenario are different. To ensure that resources are reasonably allocated, the service threshold can be set by classifying the provided service interfaces.
[0040] In some embodiments, the step of sending each access request to the corresponding container data structure includes: counting the total number of accesses in the request counters corresponding to the multiple container data structures within the target time period to generate a concurrent access volume; determining that the concurrent access volume of the target time period exceeds the global threshold, and executing a corresponding current limiting strategy for the access requests that overflow the multiple container data structures within the set time period; and sending the access requests that do not overflow the multiple container data structures within the target time period to the corresponding container data structure.
[0041] Exemplarily, multiple container structures can be set, such as a container data structure corresponding to each combination of user and service. The concurrent access volume refers to the sum of the request counters corresponding to multiple container data structures within the target time period, and the global threshold can be set to the maximum concurrent access volume allowed. The values of all request counters are added to obtain the concurrent access volume, and compared with the global threshold. When the concurrent access volume exceeds the global threshold, it is possible to further check which container data structures overflow according to the user identifier or service identifier, and execute the flow limiting strategy for these overflowing requests, or directly limit all accesses exceeding the global threshold according to the timestamp. It should be understood that the target time period can be the same length as the sliding window and can also be set according to the actual application scenario. Whether to further check can be set according to the real-time and fairness of the business requirements. If the fairness and refined control requirements are higher, the container data structure overflow can be further checked in combination with the above-mentioned service identifier or user identifier; if the real-time requirements are high, the overflowing access request can be limited according to the timestamp, which can more comprehensively control the overall load of the system.
[0042] In one embodiment, the step of counting the number of access requests in the current sliding window based on the request counter includes: removing the total number of accesses of the request counter before the start of the current sliding window; recording each access request obtained by the current sliding window to the request counter in timestamp order; counting the number of access requests in the request counter within a set time period, and generating the total number of accesses of the container data structure within the set time period.
[0043] Exemplarily, the current timestamp of the access request is obtained, and all records with timestamps earlier than the start time of the current sliding window are removed from the sliding window. The value of the corresponding request counter is reduced. To record a new request, the current timestamp is added to the sliding window, and the value of the request counter is increased. The value of the statistical request counter is the total number of accesses in the current sliding window. The total number of accesses within a set time period is dynamically recorded in order to accurately control the number of access requests, which is suitable for various business situations.
[0044] In one embodiment, an access request carries a request permission; the step of executing a current limiting strategy for access requests that overflow within a set time period in a container data structure includes: identifying the request permission corresponding to each overflow access request within the set time period in the container data structure; determining the current limiting strategy corresponding to each overflow access request based on the request permission, and executing the corresponding current limiting strategy for the overflow access requests respectively; the current limiting strategy includes delayed response and access denial.
[0045] Among them, the request permission refers to the permission level corresponding to the priority of the identification request or the user identity. For example, the access request is divided into high-authorization request and ordinary permission request. The ordinary permission request can be directly rejected and the corresponding information can be returned. The high-authorization request is placed in a delay queue and waits for the resources to be released before processing to achieve differentiated services and balance the user experience and system load.
[0046] In one embodiment, when the triggering frequency of the current limiting strategy exceeds a preset threshold, an alarm message is generated; the alarm message includes detailed information of the access request that triggers the current limiting strategy and the corresponding container data structure.
[0047] Among them, in order to limit malicious access and reduce the system load, a preset threshold is set for the triggering frequency of the flow limiting strategy. When the triggering of the flow limiting strategy reaches a certain frequency, the corresponding alarm information will be generated, such as the detailed information of the access request that triggers the flow limiting strategy: user ID, service ID, request timestamp and specific content of the request; detailed information of the container data structure: the current state of the sliding window, the current value of the request counter, the configuration information of the flow threshold, etc.; the frequency statistics of the triggering of the flow limiting strategy, etc. It should be understood that the preset threshold can be configured according to the system's load capacity, business needs or background operation and maintenance experience. At the same time, the operation and maintenance personnel can understand the flow limiting situation of the system in real time, determine whether there is abnormal traffic or attack behavior, and optimize the system configuration according to the alarm information, and can adjust the flow threshold, optimize the flow limiting strategy or expand the system resources.
[0048] Based on the same inventive concept, the embodiment of the present application also provides an OpenAPI-based flow control device for implementing the above-mentioned method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above-mentioned method, so the specific limitations in one or more OpenAPI-based flow control device embodiments provided below can refer to the limitations on the API service access method above, and will not be repeated here.
[0049] In one embodiment, Figure 3 As shown, a flow control device 300 based on OpenAPI is provided, including:
[0050] The acquisition module 301 is used to acquire multiple access requests; each access request carries a user identifier and a service identifier.
[0051] The processing module 302 is used to determine the container data structure and traffic threshold corresponding to each access request according to the user identifier and the service identifier; the container data structure is correspondingly configured with a sliding window and a request counter, and the sliding window has a fixed length of a set period.
[0052] The calculation module 303 is used to send each access request to the corresponding container data structure, and count the number of access requests in the current sliding window based on the request counter as the total number of accesses to the container data structure in a set period of time.
[0053] The flow limiting module 304 is used to determine whether the total amount of access within a set time period exceeds a flow threshold, and to execute a flow limiting strategy on the access requests overflowing within the set time period in the container data structure.
[0054] In one embodiment, the processing module 302 can be specifically used to remove the total number of accesses of the request counter before the start of the current sliding window; record each access request obtained by the current sliding window to the request counter in timestamp order; count the number of access requests in the request counter within a set time period, and generate the total number of accesses to the container data structure within the set time period.
[0055] In one embodiment, the traffic threshold includes a user threshold, which corresponds to a user identifier; a calculation module 303, which can be specifically used to count the number of access requests corresponding to the user identifier in the current sliding window as the total access amount; a current limiting module 304, which can be specifically used to determine that the total access amount exceeds the user threshold, and execute a current limiting strategy for the access requests corresponding to the user identifier that overflows within a set time period.
[0056] In one embodiment, the traffic threshold includes a service threshold, which corresponds to a service identifier; a calculation module 303, which can be specifically used to count the number of access requests corresponding to the service identifier in the current sliding window as the total access amount; a current limiting module 304, which can be specifically used to determine whether the total access amount exceeds the service threshold, and execute a current limiting strategy for the access requests corresponding to the overflowed service identifier within a set time period.
[0057] In one embodiment, the calculation module 303 also includes a concurrent current limiting module, which can be specifically used to count the total number of accesses in the request counters corresponding to multiple container data structures within the target time period to generate concurrent access volume; determine that the concurrent access volume of the target time period exceeds the global threshold, and execute the corresponding current limiting strategy for the access requests that overflow the multiple container data structures within the set time period; send the access requests that do not overflow the multiple container data structures within the target time period to the corresponding container data structure.
[0058] In one embodiment, the access request carries a request permission; the current limiting module 304 also includes an execution module, which can be specifically used to identify the request permission corresponding to each overflowing access request within a set time period in the container data structure; determine the current limiting strategy corresponding to each overflowing access request according to the request permission, and execute the corresponding current limiting strategy for the overflowing access request respectively; the current limiting strategy includes delayed response and access denial.
[0059] In one embodiment, the OpenAPI-based traffic control device also includes an alarm module for generating alarm information when the triggering frequency of the current limiting strategy exceeds a preset threshold; the alarm information is used to trigger the access request of the current limiting strategy and detailed information of the corresponding container data structure.
[0060] In addition, in the implementation of the OpenAPI-based flow control device in the above-mentioned example, the logical division of each program module is only an example. In actual applications, the above-mentioned functions can be assigned to different program modules as needed, for example, for the configuration requirements of the corresponding hardware or the convenience of software implementation. That is, the internal structure of the OpenAPI-based flow control device is divided into different program modules to complete all or part of the functions described above.
[0061] In one embodiment, a computer device is provided. The computer device may be a mobile terminal. The internal structure diagram of the computer device may be as follows: Figure 4As shown. The computer device includes a processor, a memory, an input / output interface, and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the network interface is connected to the system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a flow control device based on OpenAPI is implemented.
[0062] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0063] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0064] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0065] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0066] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices, and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, 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 generate 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 flowchart and / or block diagram. 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.
[0067] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate 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 A function specified in one or more boxes.
[0068] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0069] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0070] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. A flow control method based on OpenAPI, characterized in that: include: Acquire multiple access requests, each of which carries a user identifier and a service identifier; Determine, according to the user identifier and the service identifier, a container data structure and a flow threshold corresponding to each access request; the container data structure is correspondingly configured with a sliding window and a request counter, and the sliding window has a fixed length of a set time period; Sending each of the access requests to a corresponding container data structure, and counting the number of access requests in the current sliding window based on the request counter as the total number of accesses to the container data structure within the set time period; It is determined that the total amount of access within the set time period exceeds the flow threshold, and a flow limiting strategy is executed on the access requests overflowing within the set time period in the container data structure.
2. The method according to claim 1, characterized in that The flow threshold includes a user threshold, and the user threshold corresponds to the user identifier; The step of counting the number of access requests in the current sliding window as the total number of access requests includes: Counting the number of access requests corresponding to the user identifier in the current sliding window as the total number of access requests; The step of determining that the total amount of accesses in the set time period exceeds the flow threshold, and executing a flow limiting strategy on the access requests overflowing within the set time period in the container data structure, comprises: It is determined that the total access amount exceeds the user threshold, and a flow limiting strategy is executed on the access requests corresponding to the user identifiers that overflow within the set time period.
3. The method according to claim 1, characterized in that: The traffic threshold includes a service threshold, and the service threshold corresponds to the service identifier; The step of counting the number of access requests in the current sliding window as the total number of access requests includes: Counting the number of access requests corresponding to the service identifier in the current sliding window as the total number of access requests; The step of determining that the total amount of accesses in the set time period exceeds the flow threshold, and executing a flow limiting strategy on the access requests overflowing within the set time period in the container data structure, comprises: It is determined that the total access amount exceeds the service threshold, and a flow limiting strategy is executed on the access requests corresponding to the overflowed service identifiers within the set time period.
4. The method according to claim 1, characterized in that The step of sending each of the access requests to the corresponding container data structure comprises: Count the total number of accesses in the request counters corresponding to multiple container data structures within the target time period to generate concurrent access volume; Determining that the concurrent access volume in the target time period exceeds a global threshold, and executing a corresponding current limiting strategy for access requests overflowing the multiple container data structures in the set time period; The access requests of the plurality of container data structures that have not overflowed within the target time period are sent to the corresponding container data structures.
5. The method according to claim 1, characterized in that The step of counting the number of access requests in the current sliding window based on the request counter comprises: Remove the total number of accesses to the request counter before the current sliding window starts; Record each access request currently acquired by the sliding window into the request counter in the order of timestamps; The number of the access requests in the request counter within the set time period is counted to generate the total number of accesses to the container data structure within the set time period.
6. The method according to any one of claims 1 to 5, characterized in that The access request carries a request permission; The step of executing a flow limiting strategy on the access requests overflowing within the set time period in the container data structure includes: Identifying the request authority corresponding to each overflow access request within the set time period in the container data structure; The current limiting strategy corresponding to each overflowing access request is determined according to the request authority, and the corresponding current limiting strategy is executed on the overflowing access request respectively; the current limiting strategy includes delayed response and access denial.
7. The method according to any one of claims 1 to 5, characterized in that Also includes: When the triggering frequency of the current limiting strategy exceeds a preset threshold, generating an alarm message; The alarm information includes detailed information of the access request that triggers the current limiting strategy and the corresponding container data structure.
8. A flow control device based on OpenAPI, characterized in that: include: An acquisition module, used to acquire multiple access requests; each of the access requests carries a user identifier and a service identifier; A processing module, configured to determine a container data structure and a flow threshold corresponding to each access request according to the user identifier and the service identifier; the container data structure is correspondingly configured with a sliding window and a request counter, and the sliding window has a fixed length of a set time period; a calculation module, configured to send each of the access requests to a corresponding container data structure, and to count the number of access requests in the current sliding window based on the request counter as the total number of accesses to the container data structure in the set time period; The flow limiting module is used to determine whether the total amount of access within the set time period exceeds the flow threshold, and to execute a flow limiting strategy on the access requests overflowing within the set time period in the container data structure.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.