Current limiting processing method, system, device and medium based on sliding event window
By dividing the sliding time window into multiple sliding unit windows, using the number of turns of the time wheel and the coordinate positioning request to update the window information and determine the current limit, the repeated calculation problem of the traditional sliding time window algorithm under large-scale concurrent requests is solved, and the system performance and stability are improved.
Patent Information
- Application Number
- CN202411622622.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-14
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2044-11-14
AI Technical Summary
Traditional sliding time window algorithms have duplicate calculation and performance issues when processing large-scale concurrent requests, resulting in unstable request processing, and especially in extreme cases, requests may be lost.
The sliding time window is divided into multiple sliding unit windows. Each unit window corresponds to the coordinate position of the time wheel. The current request is located by the number of turns and coordinates of the time wheel, the sliding unit window information is updated, and whether to limit the flow is determined based on the total number of requests and the threshold.
It reduces repeated processing of requests, improves system performance, ensures the stability and efficiency of request processing, and avoids expired data affecting calculations.
Smart Images

Figure CN119577264B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a current limiting processing method, system, device and medium based on a sliding event window. Background Art
[0002] With the development of Internet technology, major platforms, portals and other systems will face the problem of traffic overload. In most cases, the surge in system access traffic is unpredictable. Therefore, most systems will configure corresponding flow limiters during design. However, traditional flow limiting algorithms such as counter algorithm, leaky bucket algorithm, and token bucket algorithm all have drawbacks. The commonly used sliding time window algorithm needs to use the current request as the time node to calculate the time interval of the window forward when dynamically obtaining the window. The requests within the sub-interval may have been counted multiple times. Therefore, the traditional sliding time window algorithm has high requirements for time synchronization and window size adjustment, and performance problems caused by a large amount of repeated calculations.
[0003] At the same time, based on the existing sliding time window algorithm, the requirements for time synchronization and window size adjustment are high, especially when facing large-scale concurrent requests, which require processing a large number of duplicate requests. In extreme cases, request processing may be lost and performance problems may easily occur.
[0004] Therefore, how to reduce repeated processing of requests and improve system performance is a technical problem that needs to be solved urgently. Summary of the Invention
[0005] The technical task of the present invention is to provide a current limiting processing method, system, device and medium based on a sliding event window to solve the problem of how to reduce repeated processing of requests and improve system performance.
[0006] The technical task of the present invention is achieved in the following manner: a current limiting processing method based on a sliding event window, the method is specifically as follows:
[0007] Unit window division: a sliding time window is divided into multiple sliding unit windows, each sliding unit window corresponds to a coordinate position of the time wheel;
[0008] Locate the current sliding unit window: locate the time circle number and coordinates corresponding to the current request;
[0009] Update the sliding unit window information: Update the sliding unit window information according to the current request and the corresponding time circle number;
[0010] Determine whether to limit the flow: Count the relationship between the total number of requests in all sliding unit windows and the set threshold to determine whether to limit the flow.
[0011] Preferably, each sliding unit window records two parameters: the current number of laps and the current number of requests;
[0012] The current number of revolutions is used to record the time window to which the corresponding sliding unit window belongs, that is, the number of revolutions of the time wheel;
[0013] The current number of requests is used to record the number of requests received within the corresponding sliding unit window.
[0014] Preferably, after the time wheel is started, it rotates periodically according to a preset time interval;
[0015] Each time it rotates, the time wheel moves to the next coordinate position, corresponding to a new sliding unit window;
[0016] The number of circles on the time wheel indicates the current time window.
[0017] Preferably, the current sliding unit window is positioned as follows:
[0018] Calculate the number of time laps corresponding to the current request using the following formula:
[0019]
[0020] Calculate the time wheel coordinates corresponding to the current request. The formula is as follows:
[0021]
[0022] As a preference, updating the sliding unit window information is specifically as follows:
[0023] If the circle number of the target sliding unit window is inconsistent with the circle number of the current request, an initialization operation is performed, that is, the circle number is set to the circle number of the current request and the number of requests is reset to 0;
[0024] If the circle number of the target sliding unit window differs from the circle number of the current request by more than 1, the request number is reset to 0.
[0025] Preferably, the determination of whether to limit the current is as follows:
[0026] Count the sum of the number of requests in all sliding unit windows to obtain the total number of requests;
[0027] Determine the relationship between the total number of requests and the set threshold:
[0028] If the total number of requests is greater than the set threshold, the current request will be rejected;
[0029] If the total number of requests is not greater than the set threshold, the number of requests in the target sliding unit window is increased by 1, and the current request is allowed to pass.
[0030] A current limiting processing system based on a sliding event window, which is used to implement the current limiting processing method based on a sliding event window as described above, includes:
[0031] A division unit is used to divide a sliding time window into multiple sliding unit windows, each sliding unit window corresponds to a coordinate position of the time wheel;
[0032] Positioning unit, used to locate the time circle number and coordinates corresponding to the current request;
[0033] An updating unit, configured to update the sliding unit window information according to the current request and the corresponding time circle number;
[0034] The judgment unit is used to count the relationship between the total number of requests of all sliding unit windows and the set threshold to determine whether to limit the flow.
[0035] Preferably, the positioning unit includes:
[0036] The lap calculation module is used to calculate the number of time laps corresponding to the current request. The formula is as follows:
[0037]
[0038] The coordinate calculation module is used to calculate the time wheel coordinates corresponding to the current request. The formula is as follows:
[0039]
[0040] An electronic device comprising: a memory and at least one processor;
[0041] wherein the memory stores computer-executable instructions;
[0042] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the current limiting processing method based on the sliding event window as described above.
[0043] A computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the above-mentioned current limiting processing method based on the sliding event window is implemented.
[0044] The sliding event window-based current limiting processing method, system, device, and medium of the present invention have the following advantages:
[0045] (1) The present invention combines the time wheel algorithm to replace the traditional time window with a time wheel. The number of revolutions of the time wheel is used to determine the current time window. The time wheel coordinates record statistics, reducing repeated processing of requests and improving system performance.
[0046] (2) This invention replaces the traditional time window with a time wheel, dividing a sliding time window into several sliding unit windows. The number of rotations of the time wheel determines the current time window, and the time wheel coordinates record statistics. Compared with traditional time window algorithms, this design no longer uses the current request as the time node to calculate the time interval of the window. This can greatly reduce the repeated processing of requests and improve system performance.
[0047] (3) The present invention can not only ensure that the number of requests within any time window does not exceed the set threshold, but also ensure that in the scenario where a new request is received after an interval of more than one time window, outdated data will not affect the calculation. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The present invention will be further described below with reference to the accompanying drawings.
[0049] Attachment Figure 1 It is a flowchart of a current limiting processing method based on a sliding event window;
[0050] Attachment Figure 2 A schematic diagram of a complete time window cycle process. DETAILED DESCRIPTION
[0051] The current limiting processing method, system, device and medium based on the sliding event window of the present invention are described in detail below with reference to the drawings and specific embodiments of the specification.
[0052] Example 1:
[0053] As attached Figure 1 As shown, this embodiment provides a current limiting processing method based on a sliding event window, and the method is specifically as follows:
[0054] S1. Unit window division: Divide a sliding time window into multiple sliding unit windows, each sliding unit window corresponds to a coordinate position of the time wheel;
[0055] S2. Position the current sliding unit window: Position the time circle number and coordinates corresponding to the current request;
[0056] S3. Update sliding unit window information: Update sliding unit window information according to the current request and the corresponding time circle number;
[0057] S4. Determine whether to limit the flow: Count the relationship between the total number of requests of all sliding unit windows and the set threshold to determine whether to limit the flow.
[0058] In this embodiment, each sliding unit window records two parameters: the current number of circles and the current number of requests;
[0059] The current number of revolutions is used to record the time window to which the corresponding sliding unit window belongs, that is, the number of revolutions of the time wheel;
[0060] The current number of requests is used to record the number of requests received within the corresponding sliding unit window.
[0061] In this embodiment, after the time wheel is started, it rotates periodically according to a preset time interval;
[0062] Each time it rotates, the time wheel moves to the next coordinate position, corresponding to a new sliding unit window;
[0063] The number of circles on the time wheel indicates the current time window.
[0064] The positioning of the current sliding unit window in step S2 of this embodiment is specifically as follows:
[0065] S201. Calculate the number of time laps corresponding to the current request. The formula is as follows:
[0066]
[0067] S202. Calculate the time wheel coordinates corresponding to the current request. The formula is as follows:
[0068]
[0069] The updating of the sliding unit window information in step S3 of this embodiment is specifically as follows:
[0070] If the circle number of the target sliding unit window is inconsistent with the circle number of the current request, an initialization operation is performed, that is, the circle number is set to the circle number of the current request and the number of requests is reset to 0;
[0071] If the circle number of the target sliding unit window differs from the circle number of the current request by more than 1, the request number is reset to 0.
[0072] The determination of whether to limit the current in step S4 of this embodiment is as follows:
[0073] S401. Count the sum of the number of requests in all sliding unit windows to obtain the total number of requests;
[0074] S402: Determine the relationship between the total number of requests and the set threshold:
[0075] If the total number of requests is greater than the set threshold, the current request will be rejected;
[0076] If the total number of requests is not greater than the set threshold, the number of requests in the target sliding unit window is increased by 1, and the current request is allowed to pass.
[0077] Take a time window of 4 seconds and a request threshold of 2 as an example, that is, no more than 2 requests are allowed within any 4 seconds. Figure 2 As shown in the figure, within a complete time window cycle, each request arrival affects the counter of the sliding unit window at that moment. Similarly, each request arrival first requires summing the counters of all sliding unit windows to determine whether the threshold has been reached. Finally, as time passes, the next time window begins, overwriting the corresponding sliding unit window counter (resetting to 0) and the number of cycles (incrementing by 1).
[0078] Each large circle represents a time wheel, corresponding to a sliding time window, and a small circle represents a sliding unit window. The sliding unit window records the coordinates and access count of the current request. Whenever a new access arrives, the total number of requests within this time window is calculated to determine whether the threshold is reached, as shown in the attached figure. Figure 2 As shown in Ⅱ and Ⅲ, if the threshold is not reached, it is allowed to pass, as shown in the attached Figure 2 As shown in Ⅳ, the current is limited when the threshold is exceeded.
[0079] When the next time window begins, the counter (reset to 0) and the number of turns (+1) of the sliding unit window at the corresponding moment will be overwritten, as shown in the attached figure. Figure 2 As shown in V.
[0080] Example 2:
[0081] This embodiment provides a current limiting processing system based on a sliding event window. The system is used to implement the current limiting processing method based on a sliding event window in Example 1. The system includes:
[0082] A division unit is used to divide a sliding time window into multiple sliding unit windows, each sliding unit window corresponds to a coordinate position of the time wheel;
[0083] Positioning unit, used to locate the time circle number and coordinates corresponding to the current request;
[0084] An updating unit, configured to update the sliding unit window information according to the current request and the corresponding time circle number;
[0085] The judgment unit is used to count the relationship between the total number of requests of all sliding unit windows and the set threshold to determine whether to limit the flow.
[0086] In this embodiment, the positioning unit includes:
[0087] The lap calculation module is used to calculate the number of time laps corresponding to the current request. The formula is as follows:
[0088]
[0089] The coordinate calculation module is used to calculate the time wheel coordinates corresponding to the current request. The formula is as follows:
[0090]
[0091] Example 3:
[0092] This embodiment also provides an electronic device, including: a memory and at least one processor;
[0093] wherein the memory stores computer-executable instructions;
[0094] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the current limiting processing method based on the sliding event window according to any one of the present inventions.
[0095] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor may be a microprocessor or any conventional processor, etc.
[0096] The memory can be used to store computer programs and / or modules. The processor implements various functions of the electronic device by running or executing the computer programs and / or modules stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area. The program storage area can store an operating system, at least one application required for a function, etc.; the data storage area can store data created based on the use of the terminal, etc. In addition, the memory can also include high-speed random access memory and non-volatile memory, such as a hard disk, internal memory, a plug-in hard disk, a smart memory card (SMC), a secure digital (SD) card, a flash memory card, at least one disk storage period, a flash memory device, or other volatile solid-state memory devices.
[0097] Example 4:
[0098] This embodiment further provides a computer-readable storage medium storing a plurality of instructions, which are loaded by a processor to cause the processor to execute the current limiting method based on a sliding event window in any embodiment of the present invention. Specifically, a system or device equipped with a storage medium can be provided, wherein the storage medium stores software program code that implements the functions of any of the above-described embodiments, and a computer (or CPU or MPU) of the system or device reads and executes the program code stored in the storage medium.
[0099] In this case, the program code itself read from the storage medium can realize the function of any one of the above-mentioned embodiments, and thus the program code and the storage medium storing the program code constitute part of the present invention.
[0100] Examples of storage media for providing program code include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, the program code can be downloaded from a server computer via a communication network.
[0101] In addition, it should be clear that the functions of any of the above embodiments can be achieved not only by executing the program code read by the computer, but also by enabling the operating system operating on the computer to complete part or all of the actual operations based on the instructions of the program code.
[0102] In addition, it can be understood that the program code read from the storage medium is written into the memory provided in the expansion board inserted into the computer or into the memory provided in the expansion unit connected to the computer, and then based on the instructions of the program code, the CPU installed on the expansion board or expansion unit is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above embodiments.
[0103] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A current limiting processing method based on a sliding event window, characterized in that: The method is as follows: Unit window division: a sliding time window is divided into multiple sliding unit windows, each sliding unit window corresponds to a coordinate position of the time wheel; Locate the current sliding unit window: locate the time circle number and coordinates corresponding to the current request; Update the sliding unit window information: Update the sliding unit window information according to the current request and the corresponding time circle number; Determine whether to limit the flow: Count the relationship between the total number of requests in all sliding unit windows and the set threshold to determine whether to limit the flow; Each sliding unit window records two parameters: the current number of laps and the current number of requests; The current number of revolutions is used to record the time window to which the corresponding sliding unit window belongs, that is, the number of revolutions of the time wheel; The current number of requests is used to record the number of requests received within the corresponding sliding unit window; Positioning the current sliding unit window is as follows: Calculate the number of time laps corresponding to the current request using the following formula: ; Calculate the time wheel coordinates corresponding to the current request. The formula is as follows: ; Update the sliding unit window information as follows: If the circle number of the target sliding unit window is inconsistent with the circle number of the current request, an initialization operation is performed, that is, the circle number is set to the circle number of the current request and the number of requests is reset to 0; If the circle number of the target sliding unit window differs from the circle number of the current request by more than 1, the request number is reset to 0.
2. The current limiting processing method based on a sliding event window according to claim 1 is characterized in that: After the time wheel is started, it rotates periodically according to the preset time interval; Each time it rotates, the time wheel moves to the next coordinate position, corresponding to a new sliding unit window; The number of circles on the time wheel indicates the current time window.
3. The current limiting processing method based on a sliding event window according to claim 1 or 2, characterized in that: The specific methods for determining whether current limiting is required are as follows: Count the sum of the number of requests in all sliding unit windows to obtain the total number of requests; Determine the relationship between the total number of requests and the set threshold: If the total number of requests is greater than the set threshold, the current request will be rejected; If the total number of requests is not greater than the set threshold, the number of requests in the target sliding unit window is increased by 1, and the current request is allowed to pass.
4. A current limiting processing system based on a sliding event window, characterized in that: The system is used to implement the current limiting processing method based on a sliding event window as described in any one of claims 1 to 3, and the system includes: A division unit is used to divide a sliding time window into multiple sliding unit windows, each sliding unit window corresponds to a coordinate position of the time wheel; Positioning unit, used to locate the time circle number and coordinates corresponding to the current request; An updating unit, configured to update the sliding unit window information according to the current request and the corresponding time circle number; The judgment unit is used to count the relationship between the total number of requests of all sliding unit windows and the set threshold to determine whether to limit the flow.
5. An electronic device, characterized in that: include: memory and at least one processor; wherein the memory stores computer-executable instructions; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the current limiting processing method based on the sliding event window according to any one of claims 1 to 3.
6. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the current limiting processing method based on the sliding event window as described in any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Delay message processing method, device and equipment and readable storage medium
CN113037450A
Flow limiting method and device based on time window, server and storage medium
CN115174483A