Interface current limiting method and device, computer equipment and storage medium
By using the current limiting method of target timestamp and sliding window calculation in the medical system, the interface call request is dynamically controlled, which solves the problem of traffic surge during peak hours, improves the stability and response speed of the interface, and ensures the efficient operation of the system and the rational allocation of resources.
Patent Information
- Application Number
- CN202510626791.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-14
- Publication Date
- 2025-09-09
AI Technical Summary
The surge in interface call traffic in medical systems during peak hours leads to insufficient system carrying capacity, which may cause server overload, slow response, functional failure, and even affect patient safety. Existing flow-limiting components are complex and costly.
A current limiting method based on target timestamp and preset window information is adopted. The number of valid requests is calculated through a sliding window, and interface call requests are dynamically judged and controlled to allow valid requests to pass through and avoid excessive system load.
It improves the stability and response speed of the interface, flexibly adapts to the traffic requirements of the medical system, ensures efficient system operation and rational allocation of resources, and avoids the risk of system crash.
Smart Images

Figure CN120614301A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a current limiting method and device for an interface, computer equipment, and storage medium. Background Art
[0002] In the modern healthcare industry, with the continuous advancement of technology and the increasing level of informatization, medical system service interfaces are frequently called. As usage increases among patients and medical staff, interface traffic fluctuates significantly. Especially during peak hours, such as when emergency rooms are in operation, interface traffic can surge instantly, leading to insufficient system capacity. Without effective traffic control mechanisms, server overloads can occur, resulting in slow system response, functional failures, and even service downtime. This can negatively impact the patient experience and the normal operation of healthcare services, potentially threatening patients' lives.
[0003] To avoid such situations, medical systems need to adopt an efficient and flexible current limiting mechanism to balance traffic fluctuations and ensure that the system can still operate stably under high concurrency. In related technologies, many medical systems usually introduce complex distributed current limiting components, such as flow control mechanisms based on token buckets and leaky bucket algorithms. The integration of these components often requires large technical investment and maintenance costs. In large-scale medical platforms, such complex integration and management may bring certain operational pressures. Therefore, the use of a simple, efficient and low-cost current limiting device has become an urgent need in the medical industry. Summary of the Invention
[0004] The present invention provides a method, device, computer equipment and medium for limiting current of an interface, so as to solve the technical problems of complex and high-cost current limiting management of an interface in related technologies.
[0005] In a first aspect, a current limiting method based on an interface is provided, comprising:
[0006] Receive an interface call request and determine a target timestamp corresponding to the interface call request;
[0007] Determine a target sliding window according to the target timestamp and preset window information, and determine the number of valid requests within the target sliding window;
[0008] Determine whether the number of valid requests in the target sliding window is less than a preset request number threshold;
[0009] If the number of valid requests within the target sliding window is less than the preset request number threshold, the interface call request is determined to be a valid request and is allowed to pass.
[0010] In a second aspect, a current limiting device for an interface is provided, comprising:
[0011] A receiving module, configured to receive an interface call request and determine a target timestamp corresponding to the interface call request;
[0012] a determination module, configured to determine a target sliding window according to the target timestamp and preset window information, and determine the number of valid requests within the target sliding window;
[0013] A determination module, configured to determine whether the number of valid requests within the target sliding window is less than a preset request number threshold;
[0014] The current limiting module is used to determine the interface call request as a valid request and allow the valid request to pass if the number of valid requests in the target sliding window is less than the preset request number threshold.
[0015] In a third aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the current limiting method of the above-mentioned interface when executing the computer program.
[0016] In a fourth aspect, a computer-readable storage medium is provided, the computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the above-described interface current limiting method. In the scheme implemented by the above-described interface-based current limiting method, apparatus, computer device, and storage medium, an interface call request can be received and a target timestamp corresponding to the interface call request can be determined. Furthermore, a target sliding window can be determined based on the target timestamp and preset window information, and the number of valid requests within the target sliding window can be determined. Thus, it can be determined whether the number of valid requests within the target sliding window is less than a preset request threshold. If the number of valid requests within the target sliding window is less than the preset request threshold, the interface call request is determined as a valid request and allowed to pass. In the present invention, the number of valid requests within the target sliding window can be dynamically calculated by combining the target timestamp and preset window information, thereby achieving precise interface call request control. When the number of valid requests is less than the preset request threshold, the request is allowed to pass, effectively avoiding the risk of excessive system load or service crashes caused by excessive requests. This invention not only improves the stability and response speed of the interface but also flexibly adapts to the traffic demands of medical systemization scenarios, effectively ensuring the efficient operation of the medical system and the rational allocation of resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0018] Figure 1 This is a schematic diagram of an application environment of a current limiting method for an interface according to an embodiment of the present invention;
[0019] Figure 2 This is a flow chart of a method for limiting current on an interface according to an embodiment of the present invention;
[0020] Figure 3 yes Figure 1 A schematic flow chart of a specific implementation of step S10;
[0021] Figure 4 1 is a structural diagram of a current limiting device of an interface in one embodiment of the present invention;
[0022] Figure 5 is a structural diagram of a computer device in one embodiment of the present invention;
[0023] Figure 6 FIG. 2 is another structural diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0024] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0025] The interface-based current limiting method provided by the embodiment of the present invention can be applied in Figure 1In an application environment, a client communicates with a server via a network. The server can receive an interface call request from the client and determine a target timestamp corresponding to the interface call request. Furthermore, a target sliding window can be determined based on the target timestamp and preset window information, and the number of valid requests within the target sliding window can be determined. Thus, it can be determined whether the number of valid requests within the target sliding window is less than a preset request count threshold. If the number of valid requests within the target sliding window is less than the preset request count threshold, the interface call request is determined to be a valid request and allowed to proceed. The result is then fed back to the client. In the present invention, for complex medical systems such as those under medical services, the number of valid requests within the target sliding window can be dynamically calculated by combining the target timestamp and preset window information, thereby achieving precise interface call request control. When the number of valid requests is less than the preset request count threshold, the request is allowed to proceed, effectively avoiding the risk of excessive system load or service crashes caused by excessive requests. This invention not only improves the stability and response speed of the interface, but also flexibly adapts to the traffic requirements of medical systemization scenarios, effectively ensuring the efficient operation of the medical system and the rational allocation of resources. The client can include, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. The server side can be implemented by an independent server or a server cluster composed of multiple servers. The present invention will be described in detail below through specific embodiments.
[0026] See also Figure 2 As shown, Figure 2 A flow chart of an interface-based current limiting method provided in an embodiment of the present invention includes the following steps:
[0027] S10: Receive an interface call request, and determine a target timestamp corresponding to the interface call request.
[0028] The interface current limiting method provided by this invention can be applied to medical systems in various medical fields. In medical systems (such as medical service platforms), interface call requests can be initiated by users (such as patients, doctors, medical assistants, etc.) through various channels (such as online consultations, telephone consultations, health management apps, etc.). These requests typically include medical consultations, symptom descriptions, drug inquiries, appointment registrations, etc., so the medical system needs to process and respond according to preset rules or algorithms.
[0029] Specifically, when a user initiates a request, the medical system first receives the API call. Once the API call request is received, the medical system immediately assigns a target timestamp to the request. The target timestamp refers to the specific moment the API call request was received. It is typically generated from the server time and recorded in a standard format (such as timestamp or ISO 8601 format).
[0030] It's important to note that the target timestamp is more than just a simple time record; it plays multiple roles in traffic control, request scheduling, and data analysis within medical systems. For example, it accurately records the time a request is received, providing a foundation for traffic limiting algorithms and helping medical systems count and manage requests according to time windows. Alternatively, in high-concurrency scenarios, the target timestamp can ensure that requests are processed in order, avoiding request confusion or delays.
[0031] Through timestamps, the medical system can accurately record the time of each request and manage traffic according to the time window. When a large number of users submit requests at the same time, the target timestamp can help the medical system quickly identify which requests belong to the same time period and make flow control decisions based on this. In this way, the medical system can avoid wasting resources and performance degradation caused by processing too many requests, thereby ensuring stability. Figure 3 As shown, in step S10, that is, determining the target timestamp corresponding to the interface call request, includes the following steps:
[0032] S11: traverse and obtain the field delimiters in the interface call request.
[0033] S12: Splitting the fields in the interface call request according to the field delimiter to obtain a plurality of split fields.
[0034] S13: Extracting a timestamp field from the multiple split fields.
[0035] S14: Utilize a parser to parse the timestamp field to obtain the target timestamp of the interface call request.
[0036] For steps S11-S14, in the medical system, when a user initiates a request through the medical system, the medical system needs to receive a formatted interface call request. These requests usually consist of multiple fields, such as user information, problem description, request type, time, etc. Field separators refer to markers used to distinguish these fields (such as commas, semicolons, colons, spaces, etc.), which help the medical system identify the boundaries of different fields. Once the field separators are determined, the medical system will then split the interface call request into multiple fields based on these separators. Through this splitting, the medical system can separate different information in the request (such as user ID, problem content, timestamp, etc.) and perform subsequent processing.
[0037] Next, the medical system uses the field delimiter identified in the previous step to iterate over each character in the interface call request. When the medical system encounters a field delimiter, it treats the content at that location as a separate field. The delimited fields are typically stored in an array or list. The medical system then iterates over the delimited fields, searching for fields related to timestamps. Specifically, the medical system identifies the field as a timestamp based on the field name and extracts it. This step is a prerequisite for subsequent time parsing.
[0038] Finally, the extracted timestamp field can be parsed to obtain the precise target timestamp. The timestamp field typically contains date and time information. The medical system needs to use a time parser (e.g., a parser based on a standard time format) to convert it into an internally recognizable time format, typically Unix timestamp or ISO 8601 format.
[0039] Through steps S11 to S14, the medical system extracts and parses timestamps from interface call requests. The key to this process lies in accurately splitting the request fields using field delimiters, extracting the fields containing time information, and ultimately converting them into a standard time format through a parser. This process not only provides a basis for traffic throttling and request queuing, but also provides accurate time information for subsequent logging, data analysis, and other functions.
[0040] In step S10, that is, before determining the target timestamp corresponding to the interface call request, the method also includes: dividing the interface call request according to preset priority to obtain priority information of the interface call request; if the priority information of the interface call request is the first priority, allowing the interface call request to pass directly.
[0041] In the above embodiment, after the interface call request is divided according to the preset priority and the priority information of the interface call request is obtained, the method also includes: if the priority information of the interface call request is the second priority or the third priority, executing the step of determining the target timestamp corresponding to the interface call request, wherein the priority level of the first priority is greater than the level of the second priority, and the level of the second priority is greater than the level of the third priority.
[0042] For example, after the medical system receives an interface call request, it first prioritizes the request. This process assigns a priority to each interface call request based on preset rules or policies, which is usually divided into multiple levels (such as first priority, second priority, and third priority, etc.). The priority of each request determines its order in the processing queue and the priority of resource allocation. Priority rules: Different types of requests may have different business importance. For example, high-priority requests may be urgent or critical requests, while low-priority requests may be regular requests or non-urgent query requests. Preset priorities: Preset priorities are usually defined by business needs or service agreements. Typically, high-priority requests will be processed first, while low-priority requests will be processed when traffic is lower.
[0043] Once the priority information of the interface call request is divided, the medical system will first determine the priority of the request. First priority request: If the priority of the interface call request is first priority (i.e., the highest priority), the request will be allowed to pass immediately without the need to perform other subsequent flow limiting or timestamp judgment steps. This means that the medical system will give priority to these requests to ensure that they respond in a timely manner. For example, in an emergency medical service system, processing patients' emergency requests (such as rescue operation requests) should generally have the first priority to ensure that the requests can be processed in a timely manner without interference from other requests.
[0044] For requests with lower priority (i.e. second or third priority), the medical system needs to process them further. Second priority requests: These requests have a higher priority, but still lower than the first priority. Such requests will need to enter the current limiting mechanism and go through subsequent steps (such as timestamp determination, sliding window calculation, etc.) to decide whether to allow the request to pass. Third priority requests: These requests are usually non-urgent requests, which may be batch queries or scheduled tasks. If the load on the medical system is high, third priority requests may be postponed or processed only when there are fewer other requests. In second and third priority requests, the system will continue to execute the step of determining the target timestamp. This is because these requests are not high-priority requests that are executed immediately, but ordinary requests that require current limiting control and sliding window calculation.
[0045] S20: Determine a target sliding window according to the target timestamp and preset window information, and determine the number of valid requests within the target sliding window.
[0046] In S20, the medical system uses the target timestamp (obtained from the previous step) to calculate the sliding time window to which the current request belongs. The core idea of a sliding window is to divide a time period into multiple windows and slide them over time. For example, if the preset window is 5 minutes, the medical system will divide the request time into 5-minute intervals. Whenever a new request arrives, the medical system will locate the corresponding time window based on the request's timestamp.
[0047] Once the time window corresponding to the target timestamp is determined, the medical system will next calculate the number of valid requests that have been processed within the time window. A valid request is a request that meets certain conditions, such as: whether the request is legal and well-formed; whether the request meets business rules, such as whether a timely response is required, whether it involves an emergency, etc.; whether the request is in a processable state, such as not being rejected or restricted. The medical system will traverse all requests in the sliding window and count the number of valid requests that meet the conditions. For example, if 10 requests are received in a 5-minute window, and 7 of them are valid, then the number of valid requests is 7.
[0048] S30: Determine whether the number of valid requests in the target sliding window is less than a preset request number threshold.
[0049] When determining whether the number of valid requests within the target sliding window is less than the preset request threshold, the medical system performs the following operations: Comparison: This means the medical system first obtains the number of valid requests within the current time window and compares it with the preset request threshold. Judgment: If the number of valid requests is less than the preset request threshold, this means the system can process more valid requests within the current time window.
[0050] In some embodiments of the invention, that is, in S30, after determining whether the number of valid requests in the target sliding window is less than the preset request number threshold, it also includes: if the number of requests in the target sliding window is greater than or equal to the preset request number threshold, determining the interface call request as an invalid request, and refusing to pass the invalid request.
[0051] It's important to note that the preset request count threshold serves as the system's upper limit on the frequency of interface calls, ensuring the medical system can handle a certain number of requests within a certain timeframe. This threshold is typically set based on the system's processing capacity, load requirements, or performance optimization needs. Its purpose is to prevent the system from being overwhelmed by too many requests in a short period of time, leading to resource exhaustion or performance degradation, thereby maintaining the system's stability and responsiveness.
[0052] For example, in step S30, the medical system uses sliding window technology to count the number of valid interface call requests in the current time period (i.e., the target sliding window). Through this statistics, the medical system can monitor the request status in each time period in real time. Among them, the target sliding window is used to represent the time range determined by the target timestamp and the preset window value. The number of valid requests for each sliding window will be updated according to the timestamp of the request arrival. The number of valid requests refers to the number of requests that are successfully processed and meet the request conditions within the target sliding window.
[0053] For example, if the number of valid requests processed within the target sliding window reaches or exceeds the preset request count threshold, the medical system will determine that the current request volume has reached the upper limit, exceeding the maximum load the medical system can handle within that time period. Therefore, the medical system will determine that the current interface call request is invalid. If a request is deemed invalid, the medical system will adopt a rejection policy and not allow the request to proceed. This is to protect medical system resources and prevent excessive requests from causing performance degradation, system crashes, or other potential problems.
[0054] S40: If the number of valid requests in the target sliding window is less than the preset request number threshold, the interface call request is determined to be a valid request, and the valid request is allowed to pass.
[0055] In some embodiments, that is, in S40, after determining the interface call request as a valid request and allowing the valid request to pass, it also includes: updating the number of valid requests based on the target timestamp and number corresponding to the valid request to obtain an updated number of valid requests; and storing the updated number of valid requests in an ordered data structure.
[0056] It is understandable that the medical system has counted the number of valid requests within the target sliding window in the previous step. If this number is less than the preset request number threshold, the current request is deemed a valid request. At this point, the medical system will allow the request to continue into the processing flow for further processing (such as querying the database, calling external services, etc.). Once the request is determined to be valid, the medical system will allow it to pass and begin executing the corresponding business logic, such as returning the processing result of the request or executing the operation requested by the user. In the further step of S40, in addition to allowing the request to pass, the medical system also needs to update the number of valid requests to ensure that the number of requests in the current window can be accurately reflected in the next judgment.
[0057] For example, the specific steps of the update operation can be as follows: Update the number of valid requests based on the target timestamp and number: Whenever a request is allowed to pass, the system will update the target timestamp and valid number of requests corresponding to the request. The target timestamp refers to the actual timestamp of the request, and the valid number of requests refers to the number of valid requests that have been processed in the current sliding window. The updated valid number of requests is 1 plus the original valid number of requests, indicating that the current request has been successfully passed and added to the request count in the window. For example, if the number of valid requests in the current sliding window is 7 (the threshold is 10), and the current request is determined to be a valid request, then the updated number of valid requests becomes 8.
[0058] For example, to ensure the accuracy of request statistics and subsequent sliding window management, the medical system stores the updated valid request counts in an ordered data structure. The purpose of this data structure is to store the valid request counts within each time window and ensure sequential and efficient data access.
[0059] It can be seen that in the above scheme, by combining the target timestamp and the preset window information, the number of valid requests within the target sliding window can be dynamically calculated, thereby achieving accurate interface call request control. When the number of valid requests is less than the preset request number threshold, the request is allowed to pass, thereby effectively avoiding the risk of excessive system load or service crash caused by too many requests. This invention not only improves the stability and response speed of the interface, but also can flexibly adapt to the traffic requirements in the medical systemization scenario, effectively ensuring the efficient operation of the medical system and the rational allocation of resources.
[0060] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0061] In one embodiment, a current limiting device for an interface is provided, which corresponds one-to-one to the current limiting method based on the interface in the above embodiment. Figure 4 As shown, the current limiting device of the interface includes a receiving module 101, a determining module 102, a judging module 103, and a current limiting module 104. The functional modules are described in detail as follows:
[0062] The receiving module 101 is configured to receive an interface call request and determine a target timestamp corresponding to the interface call request;
[0063] A determination module 102 is configured to determine a target sliding window according to the target timestamp and preset window information, and determine the number of valid requests within the target sliding window;
[0064] A judging module 103 is configured to judge whether the number of valid requests in the target sliding window is less than a preset request number threshold;
[0065] The current limiting module 104 is configured to determine the interface call request as a valid request and allow the valid request to pass if the number of valid requests in the target sliding window is less than the preset request number threshold.
[0066] In one embodiment, the receiving module 101 is specifically configured to:
[0067] Traverse and obtain the field delimiters in the interface call request;
[0068] Splitting the fields in the interface call request according to the field delimiter to obtain multiple split fields;
[0069] extracting a timestamp field from the plurality of split fields;
[0070] The timestamp field is parsed using a parser to obtain a target timestamp of the interface call request.
[0071] In one embodiment, the determination module 102 is specifically configured to:
[0072] Determine the target timestamp as the time end point of the target sliding window, and determine the difference between the target timestamp and the preset window value as the time start point of the target sliding window;
[0073] A time range corresponding to the time start point and the time end point is determined as the target sliding window.
[0074] In one embodiment, the current limiting module 104 is specifically configured to:
[0075] Updating the number of valid requests based on the target timestamp and the number of times corresponding to the valid requests to obtain an updated number of valid requests;
[0076] The updated valid request times are stored in an ordered data structure.
[0077] In one embodiment, the determination module 103 is specifically configured to:
[0078] If the number of requests within the target sliding window is greater than or equal to the preset request number threshold, the interface call request is determined to be an invalid request and the invalid request is rejected.
[0079] In one embodiment, the determination module 102 is specifically configured to:
[0080] Dividing the interface call requests according to preset priorities to obtain priority information of the interface call requests;
[0081] If the priority information of the interface call request is the first priority, the interface call request is allowed to pass directly.
[0082] In one embodiment, the determination module 102 is specifically configured to:
[0083] If the priority information of the interface call request is the second priority or the third priority, the step of determining the target timestamp corresponding to the interface call request is executed, wherein the priority level of the first priority is greater than the level of the second priority, and the level of the second priority is greater than the level of the third priority.
[0084] The present invention provides an interface current limiting device that dynamically calculates the number of valid requests within a target sliding window by combining a target timestamp with preset window information, thereby achieving precise control of interface call requests. When the number of valid requests is less than the preset request threshold, the request is allowed to pass, effectively avoiding the risk of excessive system load or service crashes caused by excessive requests. This not only improves the stability and response speed of the interface, but also flexibly adapts to the traffic requirements in medical systematization scenarios, effectively ensuring the efficient operation of the medical system and the rational allocation of resources.
[0085] For the specific definition of the interface current limiting device, please refer to the definition of the interface current limiting method above and will not be repeated here. The various modules in the above-mentioned interface current limiting device can be implemented in whole or in part through software, hardware, or a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in hardware form, or can be stored in the memory of the computer device in software form, so that the processor can call and execute the corresponding operations of each of the above modules.
[0086] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a 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 and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external client via a network connection. When the computer program is executed by the processor, it implements the functions or steps of the server side of an interface-based current limiting method.
[0087] In one embodiment, a computer device is provided. The computer device may be a client, and its internal structure diagram may be as follows: Figure 6 As shown. The computer device includes a processor, memory, network interface, display screen and input device connected via a 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 computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server via a network connection. When the computer program is executed by the processor, it implements the functions or steps of the client side of a current limiting method based on an interface
[0088] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following steps are performed:
[0089] Receive an interface call request and determine a target timestamp corresponding to the interface call request;
[0090] Determine a target sliding window according to the target timestamp and preset window information, and determine the number of valid requests within the target sliding window;
[0091] Determine whether the number of valid requests in the target sliding window is less than a preset request number threshold;
[0092] If the number of valid requests within the target sliding window is less than the preset request number threshold, the interface call request is determined to be a valid request and is allowed to pass.
[0093] 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 following steps are implemented:
[0094] Receive an interface call request and determine a target timestamp corresponding to the interface call request;
[0095] Determine a target sliding window according to the target timestamp and preset window information, and determine the number of valid requests within the target sliding window;
[0096] Determine whether the number of valid requests in the target sliding window is less than a preset request number threshold;
[0097] If the number of valid requests within the target sliding window is less than the preset request number threshold, the interface call request is determined to be a valid request and is allowed to pass.
[0098] It should be noted that the above functions or steps that can be implemented by the computer-readable storage medium or computer device can be found in the relevant descriptions of the server side and the client side in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.
[0099] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchl ink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0100] Those skilled in the art will clearly understand that for the sake of convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0101] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention, and should all be included in the scope of protection of the present invention.
Claims
1. A current limiting method for an interface, characterized in that: The method comprises: Receive an interface call request and determine a target timestamp corresponding to the interface call request; Determine a target sliding window according to the target timestamp and preset window information, and determine the number of valid requests within the target sliding window; Determine whether the number of valid requests in the target sliding window is less than a preset request number threshold; If the number of valid requests within the target sliding window is less than the preset request number threshold, the interface call request is determined to be a valid request and is allowed to pass.
2. The method according to claim 1, characterized in that Determining a target timestamp corresponding to the interface call request includes: Traverse and obtain the field delimiters in the interface call request; Splitting the fields in the interface call request according to the field delimiter to obtain multiple split fields; extracting a timestamp field from the plurality of split fields; The timestamp field is parsed using a parser to obtain a target timestamp of the interface call request.
3. The method according to claim 1, characterized in that The preset window information includes a preset window value; and determining the target sliding window according to the target timestamp and the preset window information includes: Determine the target timestamp as the time end point of the target sliding window, and determine the difference between the target timestamp and the preset window value as the time start point of the target sliding window; A time range corresponding to the time start point and the time end point is determined as the target sliding window.
4. The method according to claim 1, wherein After determining the interface call request as a valid request and allowing the valid request to pass, the method further includes: Updating the number of valid requests based on the target timestamp and the number of times corresponding to the valid requests to obtain an updated number of valid requests; The updated valid request times are stored in an ordered data structure.
5. The method according to claim 1, wherein After determining whether the number of valid requests in the target sliding window is less than a preset request number threshold, the method further includes: If the number of requests within the target sliding window is greater than or equal to the preset request number threshold, the interface call request is determined to be an invalid request and the invalid request is rejected.
6. The method according to claim 1, characterized in that Before determining the target timestamp corresponding to the interface call request, the method further includes: Dividing the interface call requests according to preset priorities to obtain priority information of the interface call requests; If the priority information of the interface call request is the first priority, the interface call request is allowed to pass directly.
7. The method according to claim 6, characterized in that After dividing the interface call requests according to the preset priorities and obtaining the priority information of the interface call requests, the method further includes: If the priority information of the interface call request is the second priority or the third priority, the step of determining the target timestamp corresponding to the interface call request is executed, wherein the priority level of the first priority is greater than the level of the second priority, and the level of the second priority is greater than the level of the third priority.
8. A current limiting device for an interface, characterized in that: include: A receiving module, configured to receive an interface call request and determine a target timestamp corresponding to the interface call request; a determination module, configured to determine a target sliding window according to the target timestamp and preset window information, and determine the number of valid requests within the target sliding window; A judging module, configured to judge whether the number of valid requests in the target sliding window is less than a preset request number threshold; The current limiting module is used to determine the interface call request as a valid request and allow the valid request to pass if the number of valid requests in the target sliding window is less than the preset request number threshold.
9. A computer 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 steps of the current limiting method for the interface according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the current limiting method for an interface as claimed in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
API request flow control method, system and device and medium
CN121077980A
Method, system, device and medium for controlling API request traffic
CN121077980B
Load balancing method and system for registration system in high-concurrency scene
CN121964089A
