Current limiting method, current limiting device and electronic equipment based on token bucket algorithm

By adding tokens and adjusting token capacity in the token bucket algorithm, the access request accumulation problem caused by slowing server processing speed is solved, and the server's processing efficiency is improved.

CN115941610BActive Publication Date: 2025-02-25ZHONGLIAN SMART AGRI CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202211584492.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-09
Publication Date
2025-02-25
Estimated Expiration
2042-12-09

AI Technical Summary

Technical Problem

When the server processes access requests slower, the traditional token bucket algorithm will cause access requests to accumulate, further reducing server processing efficiency.

Method used

By comparing the number of tokens and capacity in the token bucket, if the number of tokens is less than the capacity, a new token is added to the token bucket and the access request is processed; if the number of tokens reaches or exceeds the capacity, the access request is discarded. In addition, the token capacity is adjusted every preset period in response to changes in the number of access requests.

Benefits of technology

This method effectively reduces the accumulation of access requests by the server, improves the efficiency of the server to process access requests, and avoids resource consumption and response delays caused by stacking.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115941610B_ABST
    Figure CN115941610B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention provides a current limiting method, current limiting device and electronic device based on a token bucket algorithm, which belongs to the technical field of access request current limiting control. The method comprises: first receiving an access request, then comparing the number of tokens in the token bucket and the token capacity, if the number of tokens is less than the token capacity, adding a token to the token bucket, and processing the access request based on the token in the token bucket; if the number of tokens is greater than or equal to the token capacity, discarding the access request. The method adds tokens to the token bucket by comparing the number of tokens in the token bucket and the token capacity, and processes the access request if the token can be added, and discards the access request if the token cannot be added. When there are many access requests being processed, the new access request will be directly discarded, thereby reducing the accumulation of access requests on the server and improving the efficiency of the server in processing access requests.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of access request current limiting control, and in particular to a current limiting method, a current limiting device and an electronic device based on a token bucket algorithm. Background Art

[0002] At present, the access request flow control is mainly carried out through the token bucket algorithm, which puts tokens into the token bucket at a uniform speed. When the number of tokens exceeds the token bucket capacity, the excess tokens are discarded. When there is an access request, a token is applied for from the token bucket. If the access request applies for a token, the access request is processed. If the access request does not apply for a token, the access request is discarded. When the server processes access requests slowly, access requests will accumulate. Since tokens are put into the token bucket at a uniform speed, the access request accumulation is more serious, resulting in low efficiency in the server's processing of access requests. Summary of the invention

[0003] Based on this, the first aspect of the present invention provides a current limiting method based on a token bucket algorithm, which effectively improves the processing efficiency of the server for access requests. The method includes:

[0004] receiving access requests;

[0005] Compare the number of tokens in the token bucket with the token capacity;

[0006] If the number of tokens is less than the token capacity, a new token is added to the token bucket and the access request is processed based on the tokens in the token bucket;

[0007] If the number of tokens is greater than or equal to the token capacity, the access request is discarded.

[0008] In the embodiment of the present invention, if the number of tokens is less than the token capacity, a token is added to the token bucket, and after the access request is processed based on the tokens in the token bucket, the following is further included:

[0009] After the access request is processed, a token is deleted from the token bucket.

[0010] In an embodiment of the present invention, the method further includes:

[0011] Obtain the number of access requests received by the token bucket within a preset time at every preset period;

[0012] Based on the number of access requests, the token capacity in the token bucket is adjusted.

[0013] In an embodiment of the present invention, adjusting the token capacity in the token bucket based on the number of access requests includes:

[0014] Compare the number of access requests in the current cycle with the number of access requests in the previous cycle;

[0015] If the number of access requests in the current cycle is greater than the number of access requests in the previous cycle, the token capacity is increased by a preset value to obtain an increased token capacity;

[0016] If the number of access requests in the current cycle is less than the number of access requests in the previous cycle, the token capacity is reduced by a preset value to obtain a reduced token capacity;

[0017] If the number of requests in the current cycle is equal to the number of requests in the previous cycle, the token capacity is not changed.

[0018] In the embodiment of the present invention, before obtaining the number of access requests received by the token bucket within a preset time at every preset period, the method further includes:

[0019] Set the maximum token capacity of the token bucket;

[0020] After increasing the token capacity by a preset value to obtain the increased token capacity, the method further includes:

[0021] If the increased token capacity is greater than the maximum token capacity, the increased token capacity is set to the maximum token capacity.

[0022] In the embodiment of the present invention, before obtaining the number of access requests received by the token bucket within a preset time at every preset period, the method further includes:

[0023] Set the minimum token capacity of the token bucket;

[0024] After reducing the token capacity by a preset value to obtain the reduced token capacity, it includes:

[0025] If the reduced token capacity is less than the minimum token capacity, the reduced token capacity is set to the minimum token capacity.

[0026] A second aspect of the present invention provides a current limiting device based on a token bucket algorithm, comprising:

[0027] A request receiving module, used for receiving an access request;

[0028] A comparison module, used for comparing the number of tokens in the token bucket and the token capacity;

[0029] A token processing module, used for adding a token to the token bucket if the number of tokens is less than the token capacity, and processing access requests based on the tokens in the token bucket;

[0030] The request discarding module is used to discard the access request if the number of tokens is greater than or equal to the token capacity.

[0031] In an embodiment of the present invention, the device further includes:

[0032] The token deletion module is used to delete a token from the token bucket after the access request processing is completed.

[0033] A third aspect of the present invention provides an electronic device, which includes a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement any of the above-mentioned current limiting methods based on the token bucket algorithm.

[0034] A fourth aspect of the present invention provides a machine-readable storage medium, on which instructions are stored, and when the instructions are executed by a processor, they implement any of the current limiting methods based on the token bucket algorithm as described above.

[0035] Through the above technical solution, an access request is first received, and then the number of tokens in the token bucket and the token capacity are compared. If the number of tokens is less than the token capacity, a new token is added to the token bucket, and the access request is processed based on the token in the token bucket; if the number of tokens is greater than or equal to the token capacity, the access request is discarded. This method adds tokens to the token bucket by comparing the number of tokens in the token bucket and the token capacity. If a new token can be added, the access request is processed; if a new token cannot be added, the access request is discarded. When there are many access requests being processed, the new access request will be directly discarded, thereby reducing the accumulation of access requests on the server and improving the efficiency of the server in processing access requests.

[0036] Other features and advantages of the embodiments of the present invention will be described in detail in the subsequent detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] The accompanying drawings are used to provide a further understanding of the embodiments of the present invention and constitute a part of the specification. Together with the following specific implementations, they are used to explain the embodiments of the present invention, but do not constitute a limitation on the embodiments of the present invention. In the accompanying drawings:

[0038] Figure 1 It is a flow chart of a current limiting method based on a token bucket algorithm provided by an embodiment of the present invention;

[0039] Figure 2 It is a structural schematic diagram of a current limiting device based on a token bucket algorithm provided by an embodiment of the present invention;

[0040] Figure 3 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0041] The specific implementation of the embodiment of the present invention is described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation described here is only used to illustrate and explain the embodiment of the present invention, and is not used to limit the embodiment of the present invention.

[0042] Currently, when a server receives an access request from a client, if the server's response to the access request becomes slow, and the access request continues to be sent, the server's access requests will accumulate, consuming the server's resources, making the server's response to the access request even slower, and eventually causing the server to crash. Therefore, it is necessary to solve the problem of slow server response by limiting the flow of access requests.

[0043] In the prior art, the current limiting algorithms mainly include fixed window current limiting algorithm, sliding window current limiting algorithm, leaky bucket algorithm and token bucket method. When a large number of access requests are concentrated in a very short time range, the fixed window current limiting algorithm will cause other time windows in this unit time to be unable to respond to requests. In addition, if the access requests are concentrated at the end of the first time window and the beginning of the next time window, the server is likely to crash at this time. Although the sliding window current limiting algorithm can solve the problem of access requests concentrated at the end of the first time window and the beginning of the next time window, it cannot solve the problem of concentrated traffic surges in a short period of time. The leaky bucket algorithm can enable the server to process access requests at a uniform speed, ensuring that the server will not crash due to the short-term concentrated reception of access requests, but it cannot solve the normal traffic burst problem (such as various flash sale scenarios), affecting the user experience. The traditional token bucket method can solve the problem of traffic bursts, but when the server slows down the processing speed of access requests, it will cause the accumulation of access requests. The traditional token bucket method will also put tokens into the token bucket at a uniform speed, which will cause the accumulation of access requests to be more serious. The accumulation of a large number of access requests will consume server resources and extend the response time of the request.

[0044] Based on this, the present application provides a current limiting method based on a token bucket algorithm, which improves the traditional token bucket algorithm, thereby reducing the accumulation of server access requests and improving the efficiency of the server in processing access requests. Figure 1 A flow chart of a current limiting method based on a token bucket algorithm provided by an embodiment of the present invention is shown as follows: Figure 1 As shown, the method includes:

[0045] Step S101: receiving an access request.

[0046] In actual applications, access requests enter the server in the form of a queue, and the server receives and processes the access requests in sequence.

[0047] Step S102: Compare the number of tokens in the token bucket and the token capacity.

[0048] In actual applications, the token bucket is initialized, that is, the initial token capacity, maximum token capacity and minimum token capacity of the token bucket are set. When the server receives an access request, it compares the number of tokens in the current token bucket with the token capacity of the current token bucket.

[0049] Step S103: If the number of tokens is less than the token capacity, a new token is added to the token bucket, and the access request is processed based on the tokens in the token bucket.

[0050] In actual applications, if the current number of tokens is less than the current token capacity, the token bucket is not full of tokens and a new token can be added. The access request is processed based on the token in the token bucket, which can be an existing token in the token bucket or a newly added token.

[0051] Step S104: If the number of tokens is greater than or equal to the token capacity, the access request is discarded.

[0052] In actual applications, if the current number of tokens is greater than or equal to the current token capacity, the token bucket is full of tokens, no new tokens can be added, and the access request cannot be processed, so the access request is discarded.

[0053] Through the above embodiment, an access request is first received, and then the number of tokens in the token bucket and the token capacity are compared. If the number of tokens is less than the token capacity, a new token is added to the token bucket, and the access request is processed based on the token in the token bucket; if the number of tokens is greater than or equal to the token capacity, the access request is discarded. This method adds tokens to the token bucket by comparing the number of tokens in the token bucket and the token capacity. If a new token can be added, the access request is processed; if a new token cannot be added, the access request is discarded. When there are many access requests being processed, the new access request will be directly discarded, thereby reducing the accumulation of access requests on the server and improving the efficiency of the server in processing access requests.

[0054] In one embodiment, after step 103, the following steps are included:

[0055] After the access request is processed, a token is deleted from the token bucket.

[0056] In actual applications, after the server completes processing the access request, a token in the token bucket is deleted. This method can prevent the accumulation of access requests from the server by reducing the number of tokens in the token bucket after processing the access request.

[0057] In one embodiment, the current limiting method based on the token bucket algorithm further includes:

[0058] Obtain the number of access requests received by the token bucket within a preset time at every preset period;

[0059] Based on the number of access requests, the token capacity in the token bucket is adjusted.

[0060] In actual applications, the preset time can be set to 10 minutes, and the preset period can be set to 1 minute. It can be understood that the preset time and the preset period can be set as needed. Specifically, every minute, obtain the number of access requests received by the server within ten minutes before the current time point. For example, at 9:59, obtain the number of first access requests received by the server between 9:49 and 9:59, and at 10 o'clock, obtain the number of second access requests received by the server between 9:50 and 10 o'clock. Compare the number of access requests in the current cycle with the number of access requests in the previous cycle. For example, compare the number of second access requests at 10 o'clock with the number of first access requests at 9:59. Then, the token capacity of the token bucket can be adjusted according to the comparison result. The specific adjustment method will be introduced below.

[0061] In one embodiment, adjusting the token capacity in the token bucket based on the number of access requests includes:

[0062] Compare the number of access requests in the current cycle with the number of access requests in the previous cycle;

[0063] If the number of access requests in the current cycle is greater than the number of access requests in the previous cycle, the token capacity is increased by a preset value to obtain an increased token capacity;

[0064] If the number of access requests in the current cycle is less than the number of access requests in the previous cycle, the token capacity is reduced by a preset value to obtain a reduced token capacity;

[0065] If the number of requests in the current cycle is equal to the number of requests in the previous cycle, the token capacity is not changed.

[0066] In actual applications, the number of access requests within the preset time of the current cycle is compared with the number of access requests within the preset time of the previous cycle. If the number of access requests within the preset time of the current cycle is greater than the number of access requests within the preset time of the previous cycle, the server processing speed becomes faster, and the token capacity should be appropriately increased to increase the number of incoming requests. Specifically, the token capacity is increased by a preset value. For example, if the number of access requests within ten minutes of the current cycle is 15, and the number of access requests within ten minutes of the previous cycle is 10, the token capacity is increased by 2. It can be understood that the preset value can be set according to actual needs.

[0067] In actual applications, if the number of access requests within the preset time of the current cycle is less than the number of access requests within the preset time of the previous cycle, the server processing speed slows down, and the token bucket capacity should be appropriately reduced to reduce the number of incoming requests. Specifically, the token capacity is reduced by a preset value. For example, if the number of access requests within ten minutes of the current cycle is 15, and the number of access requests within ten minutes of the previous cycle is 20, the token capacity is reduced by 2.

[0068] In actual applications, if the number of access requests within the preset time of the current cycle is the same as the number of access requests within the preset time of the previous cycle, the token capacity is not changed.

[0069] Through the above embodiment, the process increases or decreases the token capacity based on the number of tokens by obtaining the number of tokens within a preset time every preset period. When the server processing speed is slow, the token capacity is reduced to reduce the number of incoming access requests, thereby reducing the occupation of server resources by new requests and improving the processing speed of access requests being processed. When the server processing speed is fast, the token capacity is increased to increase the number of incoming access requests and improve the server processing concurrency. And each time the token bucket capacity is increased or decreased by a fixed preset value, the preset value can be set as needed. Increasing the fixed preset value can prevent the server from consuming too much due to large differences in the adjustment of the token capacity. Dynamically adjusting the token capacity according to the processing speed of the server can also reduce the consumption of the server.

[0070] In one embodiment, before obtaining the number of access requests received by the token bucket within a preset time at every preset period, the method further includes:

[0071] Set the maximum token capacity of the token bucket;

[0072] After increasing the token capacity by a preset value to obtain the increased token capacity, the method further includes:

[0073] If the increased token capacity is greater than the maximum token capacity, the increased token capacity is set to the maximum token capacity.

[0074] In actual applications, before obtaining the number of access requests received by the token bucket within a preset time in each preset period, it is also necessary to set the maximum token capacity of the token bucket. When the increased token capacity is greater than the maximum token capacity, the increased token capacity is set to the maximum token capacity to prevent the token capacity from exceeding the maximum token capacity and causing the server to crash.

[0075] In one embodiment, before obtaining the number of access requests received by the token bucket within a preset time at every preset period, the method further includes:

[0076] Set the minimum token capacity of the token bucket;

[0077] After reducing the token capacity by a preset value to obtain the reduced token capacity, it includes:

[0078] If the reduced token capacity is less than the minimum token capacity, the reduced token capacity is set to the minimum token capacity.

[0079] In actual applications, in addition to setting the maximum token capacity, you also need to set the minimum token capacity. When the reduced token capacity is less than the minimum token capacity, set the token capacity to the minimum token capacity to prevent the server from crashing due to the token capacity being less than the minimum token capacity.

[0080] Based on the above-mentioned current limiting method based on the token bucket algorithm, the embodiment of the present invention further provides a current limiting device 200 based on the token bucket algorithm. Figure 2 A schematic diagram of a current limiting device based on a token bucket algorithm provided in an embodiment of the present invention, the device 200 includes:

[0081] A request receiving module 201, used for receiving an access request;

[0082] A comparison module 202, used for comparing the number of tokens in the token bucket and the token capacity;

[0083] The token processing module 203 is used to add a token to the token bucket if the number of tokens is less than the token capacity, and process the access request based on the tokens in the token bucket;

[0084] The request discarding module 204 is configured to discard the access request if the number of tokens is greater than or equal to the token capacity.

[0085] In one embodiment, the device further comprises:

[0086] The token deletion module is used to delete a token from the token bucket after the access request processing is completed.

[0087] In one embodiment, the device further comprises:

[0088] An access request quantity acquisition module is used to acquire the number of access requests received by the token bucket within a preset time at every preset period;

[0089] The token capacity adjustment module is used to adjust the token capacity in the token bucket based on the number of access requests.

[0090] In one embodiment, the token capacity adjustment module includes:

[0091] A comparison unit, used to compare the number of access requests in the current cycle with the number of access requests in the previous cycle;

[0092] A token capacity increasing unit is used to increase the token capacity by a preset value to obtain an increased token capacity if the number of access requests in the current cycle is greater than the number of access requests in the previous cycle;

[0093] A token capacity reduction unit, used to reduce the token capacity by a preset value to obtain a reduced token capacity if the number of access requests in the current cycle is less than the number of access requests in the previous cycle;

[0094] The comparison unit is further configured to not change the token capacity if the number of requests in the current cycle is equal to the number of requests in the previous cycle.

[0095] In one embodiment, the device further comprises:

[0096] A maximum token capacity setting module is used to set the maximum token capacity of the token bucket;

[0097] The token capacity increasing unit is further used to set the increased token capacity as the maximum token capacity if the increased token capacity is greater than the maximum token capacity.

[0098] In one embodiment, the apparatus comprises:

[0099] A minimum token capacity setting module is used to set the minimum token capacity of the token bucket;

[0100] The token capacity reduction unit is further used to set the reduced token capacity as the minimum token capacity if the reduced token capacity is less than the minimum token capacity.

[0101] The current limiting device based on the token bucket algorithm provided in the embodiment of the present application can implement each process of the current limiting method based on the token bucket algorithm in the method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0102] The embodiment of the present invention further provides an electronic device, see Figure 3 As shown, the electronic device includes a processor 130 and a memory 131, wherein the memory 131 stores machine executable instructions that can be executed by the processor 130, and the processor 130 executes the machine executable instructions to implement the above-mentioned current limiting method based on the token bucket algorithm.

[0103] Further, Figure 3 The electronic device shown further includes a bus 132 and a communication interface 133 , and the processor 130 , the communication interface 133 and the memory 131 are connected via the bus 132 .

[0104] The memory 131 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 133 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 132 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0105] The processor 130 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 130. The above processor 130 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present invention can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 131, and the processor 130 reads the information in the memory 131 and completes the steps of the method of the above embodiment in combination with its hardware.

[0106] An embodiment of the present invention also provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the above-mentioned current limiting method based on the token bucket algorithm. The specific implementation can be found in the method embodiment, which will not be repeated here.

[0107] A token bucket algorithm-based current limiting method, current limiting device and electronic device provided in an embodiment of the present invention include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the method described in the previous method embodiment. The specific implementation can be found in the method embodiment, which will not be repeated here.

[0108] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0109] In addition, in the description of the embodiments of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, and it can be the internal communication of two components. For those skilled in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0110] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for enabling a computer device (which can be a personal computer, electronic device, or network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, and other media that can store program codes.

[0111] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.

[0112] Finally, it should be noted that the above embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above embodiments, those skilled in the art should understand that any person skilled in the art can still modify the technical solutions recorded in the above embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A current limiting method based on a token bucket algorithm, characterized in that: include: receiving access requests; Compare the number of tokens in the token bucket with the token capacity; If the number of tokens is less than the token capacity, adding a token to the token bucket, and processing the access request based on the tokens in the token bucket; If the number of tokens is greater than or equal to the token capacity, discarding the access request; Obtaining the number of access requests received by the token bucket within a preset time at every preset period; Based on the number of access requests, adjusting the token capacity in the token bucket; Wherein, adjusting the token capacity in the token bucket based on the number of access requests includes: Compare the number of access requests in the current cycle with the number of access requests in the previous cycle; If the number of access requests in the current cycle is greater than the number of access requests in the previous cycle, the token capacity is increased by a preset value to obtain an increased token capacity; If the number of access requests in the current cycle is less than the number of access requests in the previous cycle, reducing the token capacity by the preset value to obtain a reduced token capacity; If the number of requests in the current cycle is equal to the number of requests in the previous cycle, the token capacity is not changed; Before obtaining the number of access requests received by the token bucket within a preset time at every preset period, the method further includes: Set the maximum token capacity of the token bucket; After increasing the token capacity by a preset value to obtain the increased token capacity, the method further includes: If the increased token capacity is greater than the maximum token capacity, the increased token capacity is set as the maximum token capacity.

2. The method according to claim 1, characterized in that If the number of tokens is less than the token capacity, a token is added to the token bucket, and after processing the access request based on the tokens in the token bucket, the method further includes: After the access request processing is completed, a token is deleted from the token bucket.

3. The method according to claim 1, characterized in that Before obtaining the number of access requests received by the token bucket within a preset time at every preset period, the method further includes: Setting the minimum token capacity of the token bucket; After reducing the token capacity by the preset value to obtain the reduced token capacity, the method includes: If the reduced token capacity is less than the minimum token capacity, the reduced token capacity is set as the minimum token capacity.

4. A current limiting device based on a token bucket algorithm, characterized in that: include: A request receiving module, used for receiving an access request; A comparison module, used for comparing the number of tokens in the token bucket and the token capacity; A token processing module, configured to add a token to the token bucket if the number of tokens is less than the token capacity, and process the access request based on the tokens in the token bucket; a request discarding module, configured to discard the access request if the number of tokens is greater than or equal to the token capacity; An access request quantity acquisition module is used to acquire the number of access requests received by the token bucket within a preset time at every preset period; A token capacity adjustment module, used to adjust the token capacity in the token bucket based on the number of access requests; A maximum token capacity setting module is used to set the maximum token capacity of the token bucket; The token capacity adjustment module includes: A comparison unit, used to compare the number of access requests in the current cycle with the number of access requests in the previous cycle; A token capacity increasing unit is used to increase the token capacity by a preset value to obtain an increased token capacity if the number of access requests in the current cycle is greater than the number of access requests in the previous cycle; A token capacity reduction unit, used to reduce the token capacity by a preset value to obtain a reduced token capacity if the number of access requests in the current cycle is less than the number of access requests in the previous cycle; The comparison unit is further configured to not change the token capacity if the number of requests in the current cycle is equal to the number of requests in the previous cycle; The token capacity increasing unit is further configured to set the increased token capacity as the maximum token capacity if the increased token capacity is greater than the maximum token capacity.

5. The device according to claim 4, characterized in that Also includes: The token discarding module is used to delete a token from the token bucket after the access request processing is completed.

6. An electronic device, characterized in that: The electronic device includes a processor and a memory, the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the current limiting method based on the token bucket algorithm as described in any one of claims 1 to 3.

7. A machine-readable storage medium having instructions stored thereon, characterized in that: When the instruction is executed by the processor, the current limiting method based on the token bucket algorithm as described in any one of claims 1 to 3 is implemented.

Citation Information

Patent Citations

  • Flow limiting method and device, and electronic equipment

    CN114095444A

  • Message transmission method and system and storage medium

    CN115174486A

  • Data processing method and device, computer equipment and computer readable storage medium

    CN115277577A