Flow limiting processing method, system and equipment based on sliding event window and medium
By dividing the sliding time window into multiple sliding unit windows, and using the number of circles and coordinates of the time wheel to locate the current window, the repeated calculation and performance problems in the traditional sliding time window algorithm are solved, and more efficient current limiting processing is achieved.
Patent Information
- Application Number
- CN202411622622.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-14
- Publication Date
- 2025-03-07
- Estimated Expiration
- 2044-11-14
AI Technical Summary
When a traditional sliding time window algorithm dynamically obtains a window, it is necessary to calculate the time interval of the window with the current request as the time node, resulting in a large number of repeated calculations and performance problems, especially when large-scale concurrent requests are easily lost.
The sliding time window is divided into multiple sliding unit windows. Each sliding unit window corresponds to a coordinate position of the time wheel. The current sliding unit window is positioned through the number of circles and coordinates of the time wheel, and its information is updated to count the total number of requests and determine whether it is current limiting.
Reduces duplicate processing of requests, improves system performance, ensures that requests within any time window do not exceed the set threshold, and avoids the impact of expired data on calculations.
Smart Images

Figure CN119577264A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, 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, and 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 number 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, a large number of duplicate requests need to be processed. 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 sliding unit window information: Update sliding unit window information according to the current request and the corresponding time circle number;
[0010] Determine whether to limit the flow: Count the total number of requests for 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] Among them, 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 at 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, positioning the current sliding unit window is as follows:
[0018] Calculate the number of time laps corresponding to the current request. The formula is as follows:
[0019]
[0020] Calculate the time wheel coordinates corresponding to the current request. The formula is as follows:
[0021]
[0022] As a preferred method, the sliding unit window information is updated 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, whether to limit the current is determined 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, the system is used to implement the current limiting processing method based on a sliding event window as described above, the system comprising:
[0031] A division unit, used to divide a sliding time window into a plurality of sliding unit windows, each sliding unit window corresponding to a coordinate position of the time wheel;
[0032] A positioning unit, used to locate the time circle number and coordinates corresponding to the current request;
[0033] An updating unit, used 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 sliding unit window requests and the set threshold to determine whether to limit the flow.
[0035] Preferably, the positioning unit comprises:
[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 current limiting processing method based on the sliding event window as described above is implemented.
[0044] The current limiting processing method, system, device and medium based on the sliding event window of the present invention have the following advantages:
[0045] (I) The present invention combines the time wheel algorithm to change the traditional time window into a time wheel. The number of revolutions of the time wheel is used to locate the current time window. The time wheel coordinates record statistics, which reduces repeated processing of requests and improves system performance.
[0046] (ii) The present invention changes the traditional time window into a time wheel, divides a sliding time window into a number of sliding unit windows, and locates the current time window by the number of revolutions of the time wheel. The time wheel coordinates record statistics. Compared with the traditional time window algorithm, this design no longer uses the current request as the time node to calculate the time interval of the window, which can greatly reduce the repeated processing of requests and improve system performance.
[0047] (III) 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 is prevented from affecting the calculation. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The present invention is further described below in conjunction with the accompanying drawings.
[0049] Attached Figure 1 It is a flowchart of a current limiting processing method based on a sliding event window;
[0050] Attached 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] Embodiment 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: a sliding time window is divided 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, updating the sliding unit window information: updating the 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 laps and the current number of requests;
[0059] Among them, 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 circles 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 specific details of updating the sliding unit window information in step S3 of this embodiment are 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, counting the sum of the number of requests of 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, it is expressed that in a complete time window cycle, each time a request arrives, it will affect the counter of the sliding unit window at the corresponding moment. Similarly, each time a request arrives, it is necessary to first sum the counters of all sliding unit windows to determine whether the threshold has been reached. Finally, as time goes by, when the next time window starts, the counter of the sliding unit window at the corresponding moment will be overwritten (reset to 0) and the number of cycles (+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 in this time window is calculated to determine whether the threshold is reached, as shown in the attached figure. Figure 2 As shown in Ⅱ and Ⅲ in the figure, 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 starts, the counter (reset to 0) and the number of turns (+1) of the sliding unit window at the corresponding time will be overwritten, as shown in the attached figure. Figure 2 As shown in Ⅴ.
[0080] Embodiment 2:
[0081] This embodiment provides 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 in Embodiment 1. The system includes:
[0082] A division unit, used to divide a sliding time window into a plurality of sliding unit windows, each sliding unit window corresponding to a coordinate position of the time wheel;
[0083] A positioning unit, used to locate the time circle number and coordinates corresponding to the current request;
[0084] An updating unit, used 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 sliding unit window requests 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] Embodiment 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 executes the current limiting processing method based on the sliding event window described in any one of the present inventions.
[0095] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) 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 realizes 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, wherein 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 according to the use of the terminal, etc. In addition, the memory can also include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a 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 storage devices.
[0097] Embodiment 4:
[0098] This embodiment also provides a computer-readable storage medium, in which a plurality of instructions are stored, and the instructions are loaded by a processor, so that the processor executes the current limiting processing method based on the sliding event window in any embodiment of the present invention. Specifically, a system or device equipped with a storage medium can be provided, on which a software program code that implements the functions of any of the above embodiments is stored, 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 a part of the present invention.
[0100] The storage medium embodiments for providing the program code include a floppy disk, a hard disk, a magneto-optical disk, an optical disk (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), a magnetic tape, a non-volatile memory card, and a ROM. Alternatively, the program code can be downloaded from a server computer by a communication network.
[0101] In addition, it should be clear that the functions of any of the above embodiments can be implemented not only by executing the program code read by the computer, but also by enabling an operating system operating on the computer to complete part or all of the actual operations based on instructions from the program code.
[0102] In addition, it can be understood that the program code read from the storage medium is written to a memory provided in an expansion board inserted into the computer or written to a memory provided in an expansion unit connected to the computer, and then based on the instructions of the program code, a CPU installed on the expansion board or the expansion unit is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above-mentioned 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 aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned 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 sliding unit window information: Update sliding unit window information according to the current request and the corresponding time circle number; Determine whether to limit the flow: Count the total number of requests for all sliding unit windows and the set threshold to determine whether to limit the flow.
2. The current limiting processing method based on the sliding event window according to claim 1 is characterized in that: Each sliding unit window records two parameters: the current number of laps and the current number of requests; Among them, 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.
3. The current limiting processing method based on sliding event window according to claim 1 is characterized in that: After the time wheel is started, it rotates periodically at a 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.
4. The current limiting processing method based on a sliding event window according to claim 1 is characterized in that: Positioning the current sliding unit window is as follows: Calculate the number of time laps corresponding to the current request. The formula is as follows: Calculate the time wheel coordinates corresponding to the current request. The formula is as follows:
5. The current limiting processing method based on sliding event window according to claim 1 is characterized in that: 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.
6. The current limiting processing method based on a sliding event window according to any one of claims 1 to 5, 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.
7. 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 the sliding event window as described in any one of claims 1 to 6, and the system includes: A division unit, used to divide a sliding time window into a plurality of sliding unit windows, each sliding unit window corresponding to a coordinate position of the time wheel; A positioning unit, used to locate the time circle number and coordinates corresponding to the current request; An updating unit, used 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 sliding unit window requests and the set threshold to determine whether to limit the flow.
8. The current limiting processing system based on sliding event window according to claim 7 is characterized in that: The positioning unit comprises: The lap calculation module is used to calculate the number of time laps corresponding to the current request. The formula is as follows: The coordinate calculation module is used to calculate the time wheel coordinates corresponding to the current request. The formula is as follows:
9. 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 executes the current limiting processing method based on the sliding event window as described in any one of claims 1 to 6.
10. 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 6 is implemented.
Citation Information
Patent Citations
Order information obtaining method and device, computer equipment and storage medium
CA3129979A1
Flow control method based on time wheel
CN112015761A
Sliding window current limiting method and device based on double pointers, equipment and storage medium
CN112367269A
Delay message processing method, device and equipment and readable storage medium
CN113037450A
Method and device for controlling sending speed by using time wheels
CN113365084A
