CN114095444B - Current limiting method and device and electronic equipment - Google Patents

Current limiting method and device and electronic equipment Download PDF

Info

Publication number
CN114095444B
CN114095444B CN202010680118.9A CN202010680118A CN114095444B CN 114095444 B CN114095444 B CN 114095444B CN 202010680118 A CN202010680118 A CN 202010680118A CN 114095444 B CN114095444 B CN 114095444B
Authority
CN
China
Prior art keywords
tokens
token bucket
token
adjusted
preset
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010680118.9A
Other languages
Chinese (zh)
Other versions
CN114095444A (en
Inventor
陈新光
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Mobile Communications Group Co Ltd
China Mobile IoT Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
China Mobile IoT Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Mobile Communications Group Co Ltd, China Mobile IoT Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN202010680118.9A priority Critical patent/CN114095444B/en
Publication of CN114095444A publication Critical patent/CN114095444A/en
Application granted granted Critical
Publication of CN114095444B publication Critical patent/CN114095444B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • H04L47/215Flow control; Congestion control using token-bucket
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • H04L47/22Traffic shaping
    • H04L47/225Determination of shaping rate, e.g. using a moving window

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The invention relates to the technical field of communication, and provides a current limiting method, a device and electronic equipment, wherein the method comprises the following steps: obtaining the average token number in a token bucket in a sliding time window, wherein the sliding time window is a time window comprising a plurality of continuous time segments, and the window trailing edge of the sliding time window is the current moment; acquiring a first token number in the token bucket at the current moment; adjusting the number of tokens in the token bucket based on the average number of tokens and the first number of tokens; and carrying out flow limiting processing based on the adjusted number of tokens in the token bucket. The embodiment of the invention can improve the flexibility of current limiting.

Description

Current limiting method and device and electronic equipment
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a current limiting method, a device, and an electronic device.
Background
The token bucket algorithm is derived from a computer network, and when the network transmits data, in order to prevent the network from blocking, the flow out of the network needs to be limited, so that the flow is sent out at a relatively uniform speed. The token bucket algorithm may control the amount of data sent onto the network and allow for the transmission of bursty data. A token bucket of fixed size may itself continually generate tokens at a constant rate.
Currently, token buckets can only generate tokens at a constant rate, resulting in poor flexibility in throttling.
Disclosure of Invention
The embodiment of the invention provides a current limiting method, a device and electronic equipment, which are used for solving the problem that the current limiting flexibility is poor because a token bucket can only generate tokens at a constant speed in the prior art.
In order to solve the technical problems, the invention is realized as follows:
in a first aspect, an embodiment of the present invention provides a current limiting method, including:
obtaining the average token number in a token bucket in a sliding time window, wherein the sliding time window is a time window comprising a plurality of continuous time segments, and the window trailing edge of the sliding time window is the current moment;
acquiring a first token number in the token bucket at the current moment;
adjusting the number of tokens in the token bucket based on the average number of tokens and the first number of tokens;
and carrying out flow limiting processing based on the adjusted number of tokens in the token bucket.
In a second aspect, an embodiment of the present invention provides a current limiting device, including:
the first acquisition module is used for acquiring the average token number in the token bucket in a sliding time window, wherein the sliding time window is a time window comprising a plurality of continuous time segments, and the window trailing edge of the sliding time window is the current moment;
the second acquisition module is used for acquiring the first token number in the token bucket at the current moment;
an adjustment module for adjusting the number of tokens in the token bucket based on the average number of tokens and the first number of tokens;
and the current limiting module is used for carrying out current limiting processing based on the adjusted number of tokens in the token bucket.
In a third aspect, an embodiment of the present invention provides an electronic device, including: a processor, a memory, and a program stored on the memory and executable on the processor, which when executed by the processor, implements the steps of the current limiting method described in the first aspect.
In a fourth aspect, an embodiment of the present invention provides a computer readable storage medium, where a computer program is stored, where the computer program is executed by a processor to implement the steps of the current limiting method described in the first aspect.
In this embodiment, an average token number in a token bucket in a sliding time window is obtained, where the sliding time window is a time window including a plurality of continuous time slices, and a window trailing edge of the sliding time window is a current time; acquiring a first token number in the token bucket at the current moment; adjusting the number of tokens in the token bucket based on the average number of tokens and the first number of tokens; and carrying out flow limiting processing based on the adjusted number of tokens in the token bucket. Therefore, the number of tokens in the token bucket in the sliding time window is monitored according to the sliding time window, and the concurrency of the system is predicted, so that the rate of the token bucket for generating tokens is dynamically adjusted, the dynamic current limiting can be realized by combining the sliding time window with a token bucket algorithm, and the flexibility of the current limiting is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the description of the embodiments of the present invention will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort to a person of ordinary skill in the art.
FIG. 1 is a flow chart of a current limiting method according to an embodiment of the present invention;
FIG. 2 is a second flow chart of a current limiting method according to the embodiment of the invention;
FIG. 3 is a schematic diagram of a current limiting device according to an embodiment of the present invention;
FIG. 4 is a second schematic diagram of a current limiting device according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Referring to fig. 1, fig. 1 is a flowchart of a current limiting method according to an embodiment of the present invention, as shown in fig. 1, including the following steps:
step 101, obtaining the average number of tokens in a token bucket in a sliding time window, wherein the sliding time window is a time window containing a plurality of continuous time slices, and the window trailing edge of the sliding time window is the current moment.
The time represented by the time slice may be 0.5s, or may be 1s, or may be 2s, or the like, which is not limited in this embodiment. Taking the sliding time window as an example, the sliding time window comprises 6 time segments, each time segment is 0.5s, the time represented by each sliding time window is 3s, and the current time is 3s before in the sliding time window. Every time the sliding time window passes one time segment, the time window moves backwards by one time segment, and the smaller the time segment divided by the time window is, the more accurate the current limiting control is.
Additionally, the average number of tokens in the token bucket within the sliding time window may be an average of the number of tokens for the plurality of consecutive time segments. The number of tokens in the token bucket may be acquired once per time segment, or the number of tokens in the token bucket may be acquired multiple times per time segment. Taking the example of obtaining the number of tokens in the token bucket once in each time segment, the number of tokens in the token bucket can be obtained at the beginning time of the time segment, or the number of tokens in the token bucket can be obtained at the ending time of the time segment; or the number of tokens in the token bucket may be acquired at an intermediate time of the time slice, etc., which is not limited in this embodiment.
Taking the sliding time window as an example, the sliding time window includes 6 time slices, each time slice is 1s, if the current time is 08 h 00 min 06 s, the first time slice of the sliding time window is: the last time segment of the sliding time window is 08-08 minutes 00 seconds to 08-00 minutes 01 seconds: 08 time 00 minutes 05 seconds to 08 time 00 minutes 06 seconds. As one embodiment, the number of tokens in the token bucket may be acquired at the start time of the time slice, for example, the number of tokens in the token bucket at 08 time 00 minutes and 00 seconds, 08 time 00 minutes and 01 seconds, 08 time 00 minutes and 02 seconds, 08 time 00 minutes and 03 seconds, 08 time 00 minutes and 04 seconds, and 08 time 00 minutes and 05 seconds may be acquired, and the acquired six numbers of tokens may be averaged to obtain the average number of tokens in the token bucket within the sliding time window.
Further, the current limiting method can be applied to electronic equipment. The token bucket may be an internal memory pool of the electronic device for holding tokens.
Step 102, obtaining a first token number in the token bucket at the current moment.
The first token number may be the number of tokens in the token bucket at the current time.
Step 103, adjusting the number of tokens in the token bucket based on the average number of tokens and the first number of tokens.
Wherein the adjusting the number of tokens in the token bucket based on the average number of tokens and the first number of tokens may include: increasing the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket when the average number of tokens is less than the product of a first preset coefficient and the first number of tokens, and decreasing the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket when the average number of tokens is greater than the product of a second preset coefficient and the first number of tokens, wherein the first preset coefficient is less than the second preset coefficient; alternatively, it may further include: increasing the number of tokens in the token bucket when the difference between the average number of tokens and the first number of tokens is smaller than a first preset difference value, and reducing the number of tokens in the token bucket when the difference between the average number of tokens and the first number of tokens is larger than a second preset difference value, wherein the first preset difference value is smaller than the second preset difference value; etc., the present embodiment is not limited thereto.
And 104, performing flow limiting processing based on the adjusted number of tokens in the token bucket.
And after the number of tokens in the token bucket is adjusted, carrying out flow limiting processing on the adjusted number of tokens in the token bucket. And subtracting one token number in the token bucket from one token number in each time of allowing the access request until the token number in the token bucket reaches a third preset threshold, and rejecting the access request if the access request is received again at the moment, so as to achieve the purpose of limiting the flow.
The current limiting method in the embodiment can be applied to gateway equipment, the gateway equipment can be gateway equipment in a system, current limiting is performed through the gateway equipment, system resource blocking and even system breakdown caused by overlarge application access frequency are prevented, and healthy and stable operation of the system can be ensured. The gateway device may be a gateway device in a capability open platform, for example. Along with the increasing application of the access capability open platform, the access amount is increased rapidly, so as to prevent resource blocking and even system breakdown caused by the overlarge access frequency of the application, ensure that a service system operates healthily and stably, and the capability open platform introduces a gateway and realizes flow control through the gateway.
The current limiting method in the present embodiment may be applied to a gateway in a system, for example. After the system is started, the system starts a timing task, and the timing task is used for dynamically updating the number of tokens in the token bucket according to the current concurrence of the system after the timing time is reached. And the gateway receives the access request in real time and performs flow control filtering. Specifically, the gateway acquires the token from the token bucket, and if the token cannot be acquired, the gateway reaches the flow control condition and directly refuses the access request; otherwise, the current access request does not reach the flow control condition, the access request is allowed, and the subsequent processing is carried out on the access request.
At present, the token bucket algorithm is adopted to limit the flow, namely constant token generation rate is adopted, the rate of token generation by the token bucket in the embodiment can be dynamically adjusted according to the actual concurrency of the system, the constant token generation rate is prevented from being configured to be smaller, the higher concurrency cannot be adapted within the system capacity range, and the system resources are wasted; meanwhile, the constant token generation rate is prevented from being configured too high, and when the access request quantity is in a valley, the number of tokens in the token bucket is always in a high level, so that system resources are wasted. In the embodiment, the generation amount of the number of tokens in the token bucket can be dynamically adjusted, and the resource utilization rate is high.
In this embodiment, an average token number in a token bucket in a sliding time window is obtained, where the sliding time window is a time window including a plurality of continuous time slices, and a window trailing edge of the sliding time window is a current time; acquiring a first token number in the token bucket at the current moment; adjusting the number of tokens in the token bucket based on the average number of tokens and the first number of tokens; and carrying out flow limiting processing based on the adjusted number of tokens in the token bucket. Therefore, the number of tokens in the token bucket in the sliding time window is monitored according to the sliding time window, and the concurrency of the system is predicted, so that the rate of the token bucket for generating tokens is dynamically adjusted, the dynamic current limiting can be realized by combining the sliding time window with a token bucket algorithm, and the flexibility of the current limiting is improved.
Optionally, the adjusting the number of tokens in the token bucket based on the average number of tokens and the first number of tokens includes:
increasing the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket under the condition that the average number of tokens is smaller than the product of a first preset coefficient and the first number of tokens;
and under the condition that the average token number is larger than the product of a second preset coefficient and the first token number, reducing the token number in the token bucket to obtain the adjusted token number in the token bucket, wherein the first preset coefficient is smaller than the second preset coefficient.
The first preset coefficient may be 0.1, or 0.2, or 0.3, or the like, which is not limited in this embodiment. The second preset coefficient may be 0.7, or 0.8, or 0.9, or the like, which is not limited in this embodiment.
Additionally, the increasing the number of tokens in the token bucket may include: calculating the sum of the first token number and a first adjustment value to obtain the token number in the adjusted token bucket, wherein the first adjustment value is larger than 0; alternatively, it may further include: calculating the product of a first token number and a first adjustment coefficient to obtain the token number in the adjusted token bucket, wherein the first adjustment coefficient is larger than 1; etc., the present embodiment is not limited thereto. The reducing the number of tokens in the token bucket may include: calculating the difference between the first token number and a second adjustment value to obtain the token number in the adjusted token bucket, wherein the second adjustment value is greater than 0, and the first adjustment value can be the same as or different from the second adjustment value; alternatively, it may further include: calculating the product of the first token number and a second adjustment coefficient to obtain the token number in the adjusted token bucket, wherein the second adjustment coefficient is smaller than 1; etc., the present embodiment is not limited thereto.
Further, the number of tokens in the token bucket may be kept unchanged when the average number of tokens is greater than or equal to a product of a first preset coefficient and the first number of tokens and the average number of tokens is less than or equal to a product of a second preset coefficient and the first number of tokens.
In this embodiment, the average number of tokens is greater than the product of the first preset coefficient and the first number of tokens, which may be considered as a low system concurrence, so as to reduce the number of tokens in the token bucket and reduce the capacity of the token bucket; the average token number is smaller than the product of the second preset coefficient and the first token number, the concurrency of the system can be considered to be higher, the token number in the token bucket is increased, and the capacity of the token bucket can be increased. By reducing or increasing the capacity of the token bucket, flexible control of the number of tokens in the token bucket is realized, and the flow limiting effect is good.
Optionally, the increasing the number of tokens in the token bucket includes:
calculating the sum of the first token number and a preset adjustment value to obtain the token number in the adjusted token bucket;
the reducing the number of tokens in the token bucket includes:
and calculating the difference between the first token number and the preset adjustment value to obtain the adjusted token number in the token bucket.
Wherein the preset adjustment value may be obtained empirically, for example, the preset adjustment value may be determined according to a historical access amount; or, the current limiting effect can be achieved by debugging, and a proper value can be selected as a preset adjusting value through multiple times of debugging. When the number of tokens in the token bucket needs to be increased, the adjusted number of tokens in the token bucket can be the sum of the first number of tokens and a preset adjustment value; when the number of tokens in the token bucket needs to be reduced, the adjusted number of tokens in the token bucket may be a difference value between the first number of tokens and the preset adjustment value.
In this embodiment, the number of tokens in the token bucket is dynamically adjusted by the preset adjustment value, so that the tokens can be conveniently debugged and obtained to obtain a proper preset adjustment value for current limiting so as to achieve a better current limiting effect, and the problem that more parameters are introduced to increase debugging difficulty is avoided.
Optionally, after the increasing the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket, the method further includes:
updating the number of tokens in the adjusted token bucket to a first preset threshold value under the condition that the number of tokens in the adjusted token bucket is larger than the first preset threshold value;
after the reducing the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket, the method further includes:
and under the condition that the number of tokens in the adjusted token bucket is smaller than a second preset threshold value, updating the number of tokens in the adjusted token bucket to the second preset threshold value, wherein the first preset threshold value is larger than the second preset threshold value.
The first preset threshold and the second preset threshold may be obtained empirically, for example, a maximum value and a minimum value of the historical access amount may be respectively used as the first preset threshold and the second preset threshold.
In this embodiment, the maximum number of tokens and the minimum number of tokens in the token bucket after adjustment are limited by the first preset threshold value and the second preset threshold value, so that unrestricted increase or decrease of the token bucket capacity is avoided.
Optionally, the performing the current limiting processing based on the adjusted number of tokens in the token bucket includes:
receiving an access request in real time;
allowing the access request and subtracting one from the number of tokens in the token bucket if the number of tokens in the token bucket is greater than a third preset threshold;
and rejecting the access request under the condition that the number of tokens in the token bucket is smaller than or equal to the third preset threshold value.
The third preset threshold may be a smaller value, for example, may be 0. The number of tokens in the token bucket may be adjusted at intervals, for example, the number of tokens in the token bucket may be adjusted at intervals of one time segment, and the number of tokens in the token bucket may be adjusted at the beginning of each time segment.
In the embodiment, the access request received in real time is released or refused to be released based on the number of tokens in the token bucket, so that the purpose of limiting the current is achieved; and the dynamic current limiting is performed by combining the sliding time window and the token bucket algorithm, so that the accuracy of the flow control is higher.
As a specific embodiment, the current limiting method is applied to a gateway in the system. When the system is started, a first preset threshold max, a second preset threshold min and a preset adjustment value x are configured in an initialized mode. After the system is started, a timing task is started, and the timing task is periodically executed. As shown in fig. 2, the following operations are performed at each task cycle:
step 201: defining the size of a sliding time window, and calculating the average token number avg in a token bucket in each sliding time window;
step 202: acquiring the number count of tokens in a token bucket;
step 203: judging whether avg is more than 80% of count; if yes, go to step 204, otherwise go to step 207;
step 204: judging whether the min is smaller than the count-x; if yes, go to step 205, otherwise go to step 206;
step 205: adjusting the number of tokens count to count-x;
step 206: adjusting the number count of tokens to be min;
step 207: judging whether avg is less than count by 20%, if yes, executing step 208, otherwise executing step 211;
step 208: judging whether the count+x is larger than max or not; if yes, go to step 209, otherwise go to step 210;
step 209: adjusting the number of tokens count to be max;
step 210: adjusting the number of tokens count to count+x;
step 211: the number of tokens count is kept unchanged.
Wherein avg is greater than 80% of count, the number of tokens in the token bucket in a sliding time window can be considered to be always in a more state, the concurrency of the current system access request is not high, and partial concurrency resources can be released by reducing the number of tokens in the token bucket; the avg is smaller than count by 20%, and the number of tokens in the token bucket in a sliding time window can be considered to be always in a smaller state, the concurrency of the current system access request is higher, and more concurrency resources can be obtained by increasing the number of tokens in the token bucket.
Referring to fig. 3, fig. 3 is a schematic structural diagram of a current limiting device according to an embodiment of the present invention, and as shown in fig. 3, a current limiting device 300 includes:
a first obtaining module 301, configured to obtain an average number of tokens in a token bucket in a sliding time window, where the sliding time window is a time window including a plurality of continuous time slices, and a window trailing edge of the sliding time window is a current time;
a second obtaining module 302, configured to obtain a first number of tokens in the token bucket at a current time;
an adjustment module 303, configured to adjust the number of tokens in the token bucket based on the average number of tokens and the first number of tokens;
and the current limiting module 304 is configured to perform current limiting processing based on the adjusted number of tokens in the token bucket.
Optionally, as shown in fig. 4, the adjusting module 303 includes:
a first adjusting unit 3031, configured to increase the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket when the average number of tokens is less than a product of a first preset coefficient and the first number of tokens;
and a second adjusting unit 3032, configured to reduce the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket when the average number of tokens is greater than a product of a second preset coefficient and the first number of tokens, where the first preset coefficient is smaller than the second preset coefficient.
Optionally, the first adjusting unit 3031 is specifically configured to:
calculating the sum of the first token number and a preset adjustment value to obtain the number of tokens in the adjusted token bucket under the condition that the average token number is smaller than the product of a first preset coefficient and the first token number;
the second adjusting unit 3032 is specifically configured to:
and under the condition that the average token number is larger than the product of a second preset coefficient and the first token number, calculating the difference between the first token number and the preset adjustment value to obtain the adjusted token number in the token bucket.
Optionally, the first adjusting unit 3031 is further configured to:
determining the number of tokens in the adjusted token bucket as a first preset threshold value under the condition that the number of tokens in the adjusted token bucket is larger than the first preset threshold value;
the second adjusting unit 3032 is further configured to:
and under the condition that the number of tokens in the adjusted token bucket is smaller than a second preset threshold, determining the number of tokens in the adjusted token bucket as the second preset threshold, wherein the first preset threshold is larger than the second preset threshold.
Optionally, the current limiting module 304 is specifically configured to:
receiving an access request in real time;
allowing the access request and subtracting one from the number of tokens in the token bucket if the number of tokens in the token bucket is greater than a third preset threshold;
and rejecting the access request under the condition that the number of tokens in the token bucket is smaller than or equal to the third preset threshold value.
The current limiting device is capable of implementing the various processes in the method embodiment of fig. 1, and is not described here again to avoid repetition.
Referring to fig. 5, fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present invention, and as shown in fig. 5, an electronic device 400 includes: memory 402, processor 401, and a program stored on the memory 402 and executable on the processor 401, wherein:
the processor 401 reads a program in the memory 402 for executing:
obtaining the average token number in a token bucket in a sliding time window, wherein the sliding time window is a time window comprising a plurality of continuous time segments, and the window trailing edge of the sliding time window is the current moment;
acquiring a first token number in the token bucket at the current moment;
adjusting the number of tokens in the token bucket based on the average number of tokens and the first number of tokens;
and carrying out flow limiting processing based on the adjusted number of tokens in the token bucket.
Optionally, the adjusting, by the processor 401, the number of tokens in the token bucket based on the average number of tokens and the first number of tokens includes:
increasing the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket under the condition that the average number of tokens is smaller than the product of a first preset coefficient and the first number of tokens;
and under the condition that the average token number is larger than the product of a second preset coefficient and the first token number, reducing the token number in the token bucket to obtain the adjusted token number in the token bucket, wherein the first preset coefficient is smaller than the second preset coefficient.
Optionally, the increasing the number of tokens in the token bucket performed by the processor 401 includes:
calculating the sum of the first token number and a preset adjustment value to obtain the token number in the adjusted token bucket;
the reducing the number of tokens in the token bucket performed by the processor 401 includes:
and calculating the difference between the first token number and the preset adjustment value to obtain the adjusted token number in the token bucket.
Optionally, the processor 401 is further configured to perform:
updating the number of tokens in the adjusted token bucket to a first preset threshold value under the condition that the number of tokens in the adjusted token bucket is larger than the first preset threshold value;
after the reducing the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket, the method further includes:
and under the condition that the number of tokens in the adjusted token bucket is smaller than a second preset threshold value, updating the number of tokens in the adjusted token bucket to the second preset threshold value, wherein the first preset threshold value is larger than the second preset threshold value.
Optionally, the throttling processing performed by the processor 401 based on the adjusted number of tokens in the token bucket includes:
receiving an access request in real time;
allowing the access request and subtracting one from the number of tokens in the token bucket if the number of tokens in the token bucket is greater than a third preset threshold;
and rejecting the access request under the condition that the number of tokens in the token bucket is smaller than or equal to the third preset threshold value.
In fig. 5, a bus architecture may comprise any number of interconnected buses and bridges, with one or more processors, represented in particular by processor 401, and various circuits of memory, represented by memory 402, linked together. The bus architecture may also link together various other circuits such as peripheral devices, voltage regulators, power management circuits, etc., which are well known in the art and, therefore, will not be described further herein. The bus interface provides an interface.
The processor 401 is responsible for managing the bus architecture and general processing, and the memory 402 may store data used by the processor 401 in performing operations.
It should be noted that any implementation manner of the method embodiment of the present invention may be implemented by the electronic device in this embodiment, and achieve the same beneficial effects, which are not described herein.
The embodiment of the invention also provides a computer readable storage medium, on which a computer program is stored, which when executed by a processor, implements the processes of the above-mentioned current limiting method embodiment, and can achieve the same technical effects, and in order to avoid repetition, the description is omitted here. Wherein the computer readable storage medium is selected from Read-Only Memory (ROM), random access Memory (Random Access Memory, RAM), magnetic disk or optical disk.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) comprising instructions for causing a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the method according to the embodiments of the present invention.
The embodiments of the present invention have been described above with reference to the accompanying drawings, but the present invention is not limited to the above-described embodiments, which are merely illustrative and not restrictive, and many forms may be made by those having ordinary skill in the art without departing from the spirit of the present invention and the scope of the claims, which are to be protected by the present invention.

Claims (7)

1. A method of limiting current, the method comprising:
obtaining the average token number in a token bucket in a sliding time window, wherein the sliding time window is a time window comprising a plurality of continuous time segments, and the window trailing edge of the sliding time window is the current moment;
acquiring a first token number in the token bucket at the current moment;
adjusting the number of tokens in the token bucket based on the average number of tokens and the first number of tokens;
performing flow limiting processing based on the adjusted number of tokens in the token bucket;
the adjusting the number of tokens in the token bucket based on the average number of tokens and the first number of tokens includes:
increasing the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket under the condition that the average number of tokens is smaller than the product of a first preset coefficient and the first number of tokens;
reducing the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket when the average number of tokens is greater than the product of a second preset coefficient and the first number of tokens, wherein the first preset coefficient is smaller than the second preset coefficient;
the flow limiting processing based on the adjusted number of tokens in the token bucket comprises the following steps:
receiving an access request in real time;
allowing the access request and subtracting one from the number of tokens in the token bucket if the number of tokens in the token bucket is greater than a third preset threshold;
and rejecting the access request under the condition that the number of tokens in the token bucket is smaller than or equal to the third preset threshold value.
2. The method of claim 1, wherein the increasing the number of tokens in the token bucket comprises:
calculating the sum of the first token number and a preset adjustment value to obtain the token number in the adjusted token bucket;
the reducing the number of tokens in the token bucket includes:
and calculating the difference between the first token number and the preset adjustment value to obtain the adjusted token number in the token bucket.
3. The method of claim 1, wherein after the increasing the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket, the method further comprises:
updating the number of tokens in the adjusted token bucket to a first preset threshold value under the condition that the number of tokens in the adjusted token bucket is larger than the first preset threshold value;
after the reducing the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket, the method further includes:
and under the condition that the number of tokens in the adjusted token bucket is smaller than a second preset threshold value, updating the number of tokens in the adjusted token bucket to the second preset threshold value, wherein the first preset threshold value is larger than the second preset threshold value.
4. A current limiting device, the current limiting device comprising:
the first acquisition module is used for acquiring the average token number in the token bucket in a sliding time window, wherein the sliding time window is a time window comprising a plurality of continuous time segments, and the window trailing edge of the sliding time window is the current moment;
the second acquisition module is used for acquiring the first token number in the token bucket at the current moment;
an adjustment module for adjusting the number of tokens in the token bucket based on the average number of tokens and the first number of tokens;
the flow limiting module is used for carrying out flow limiting processing based on the adjusted token number in the token bucket;
the adjustment module includes:
a first adjustment unit, configured to increase the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket when the average number of tokens is less than a product of a first preset coefficient and the first number of tokens;
a second adjustment unit, configured to reduce the number of tokens in the token bucket to obtain the adjusted number of tokens in the token bucket when the average number of tokens is greater than a product of a second preset coefficient and the first number of tokens, where the first preset coefficient is smaller than the second preset coefficient;
the current limiting module is specifically used for:
receiving an access request in real time;
allowing the access request and subtracting one from the number of tokens in the token bucket if the number of tokens in the token bucket is greater than a third preset threshold;
and rejecting the access request under the condition that the number of tokens in the token bucket is smaller than or equal to the third preset threshold value.
5. The current limiting device according to claim 4, wherein the first adjusting unit is specifically configured to:
calculating the sum of the first token number and a preset adjustment value to obtain the number of tokens in the adjusted token bucket under the condition that the average token number is smaller than the product of a first preset coefficient and the first token number;
the second adjusting unit is specifically configured to:
and under the condition that the average token number is larger than the product of a second preset coefficient and the first token number, calculating the difference between the first token number and the preset adjustment value to obtain the adjusted token number in the token bucket.
6. The current limiting device of claim 4, wherein the first adjustment unit is further configured to:
determining the number of tokens in the adjusted token bucket as a first preset threshold value under the condition that the number of tokens in the adjusted token bucket is larger than the first preset threshold value;
the second adjusting unit is further configured to:
and under the condition that the number of tokens in the adjusted token bucket is smaller than a second preset threshold, determining the number of tokens in the adjusted token bucket as the second preset threshold, wherein the first preset threshold is larger than the second preset threshold.
7. An electronic device, comprising: a processor, a memory and a program stored on the memory and executable on the processor, which when executed by the processor implements the steps of the current limiting method according to any one of claims 1 to 3.
CN202010680118.9A 2020-07-15 2020-07-15 Current limiting method and device and electronic equipment Active CN114095444B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010680118.9A CN114095444B (en) 2020-07-15 2020-07-15 Current limiting method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010680118.9A CN114095444B (en) 2020-07-15 2020-07-15 Current limiting method and device and electronic equipment

Publications (2)

Publication Number Publication Date
CN114095444A CN114095444A (en) 2022-02-25
CN114095444B true CN114095444B (en) 2023-11-10

Family

ID=80294794

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010680118.9A Active CN114095444B (en) 2020-07-15 2020-07-15 Current limiting method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN114095444B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114785739A (en) * 2022-04-22 2022-07-22 天津中科曙光存储科技有限公司 Method, device, equipment and medium for controlling service quality of logical volume
CN115941610A (en) * 2022-12-09 2023-04-07 中联智慧农业股份有限公司 Token bucket algorithm-based current limiting method, current limiting device and electronic equipment

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101741603A (en) * 2008-11-11 2010-06-16 中兴通讯股份有限公司 Method and device for supervising traffic based on token bucket
CN102420773A (en) * 2012-01-05 2012-04-18 北京网御星云信息技术有限公司 Token-bucket-algorithm-based data transmission method and traffic control device
CN104734989A (en) * 2013-12-23 2015-06-24 腾讯数码(天津)有限公司 Data transmission flow scheduling method and system based on token buckets
WO2016086542A1 (en) * 2014-12-05 2016-06-09 中兴通讯股份有限公司 Message transmission method and device, and computer storage medium
CN106953812A (en) * 2016-01-07 2017-07-14 中兴通讯股份有限公司 A kind of data-message transmission control method and device
CN107493241A (en) * 2016-06-13 2017-12-19 中兴通讯股份有限公司 A kind of token distribution method and device
CN109714268A (en) * 2019-01-23 2019-05-03 平安科技(深圳)有限公司 A kind of flow control methods and relevant apparatus of virtual private cloud
CN109936511A (en) * 2017-12-19 2019-06-25 北京金山云网络技术有限公司 A kind of token acquisition methods, device, server, terminal device and medium
CN110545246A (en) * 2018-05-29 2019-12-06 北京京东尚科信息技术有限公司 Token bucket-based current limiting method and device
CN111083062A (en) * 2019-12-17 2020-04-28 深圳前海环融联易信息科技服务有限公司 Weight mechanism-based current limiting method and device, computer equipment and storage medium
CN111404836A (en) * 2020-03-30 2020-07-10 北京小米移动软件有限公司 Data transmission control method, device, control center, server and medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140112147A1 (en) * 2012-10-19 2014-04-24 Broadcom Corporation Refresh mechanism for a token bucket

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101741603A (en) * 2008-11-11 2010-06-16 中兴通讯股份有限公司 Method and device for supervising traffic based on token bucket
CN102420773A (en) * 2012-01-05 2012-04-18 北京网御星云信息技术有限公司 Token-bucket-algorithm-based data transmission method and traffic control device
CN104734989A (en) * 2013-12-23 2015-06-24 腾讯数码(天津)有限公司 Data transmission flow scheduling method and system based on token buckets
WO2016086542A1 (en) * 2014-12-05 2016-06-09 中兴通讯股份有限公司 Message transmission method and device, and computer storage medium
CN106953812A (en) * 2016-01-07 2017-07-14 中兴通讯股份有限公司 A kind of data-message transmission control method and device
CN107493241A (en) * 2016-06-13 2017-12-19 中兴通讯股份有限公司 A kind of token distribution method and device
CN109936511A (en) * 2017-12-19 2019-06-25 北京金山云网络技术有限公司 A kind of token acquisition methods, device, server, terminal device and medium
CN110545246A (en) * 2018-05-29 2019-12-06 北京京东尚科信息技术有限公司 Token bucket-based current limiting method and device
CN109714268A (en) * 2019-01-23 2019-05-03 平安科技(深圳)有限公司 A kind of flow control methods and relevant apparatus of virtual private cloud
CN111083062A (en) * 2019-12-17 2020-04-28 深圳前海环融联易信息科技服务有限公司 Weight mechanism-based current limiting method and device, computer equipment and storage medium
CN111404836A (en) * 2020-03-30 2020-07-10 北京小米移动软件有限公司 Data transmission control method, device, control center, server and medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Baihaqi Siregar ; Ardian Fadli ; Ainul Hizriadi.Controlling of Quality of Service in Campus Area Network Using OpenDaylight with Hierarchical Token Bucket Method.IEEE.2021,全文. *
一种基于多令牌桶的数据风暴抑制单元;马徐瀚;吴龙胜;赵坤鹏;陈庆宇;;微电子学与计算机(第09期);全文 *

Also Published As

Publication number Publication date
CN114095444A (en) 2022-02-25

Similar Documents

Publication Publication Date Title
CN114095444B (en) Current limiting method and device and electronic equipment
US20170331705A1 (en) Resource Scaling Method on Cloud Platform and Cloud Platform
CN112003795B (en) Method, system, equipment and storage medium for dynamically preventing traffic attack
CN110138756B (en) Current limiting method and system
CN110505105B (en) Method, device, equipment and storage medium for controlling network service quality
US20130332516A1 (en) Polling protocol for automatic load limiting
US20090010155A1 (en) Network communication control methods and systems
CN110831038B (en) Network slice resource scheduling method and device
CN107204858B (en) mobile terminal flow reminding method and device
CN109121196B (en) Terminal transmitting power control method and device based on NB-IoT system
CN106464733A (en) Method and device for adjusting virtual resources in cloud computing
CN111147395A (en) Network resource adjusting method and device
US9281960B2 (en) Estimating processing workloads
CN110780986A (en) Internet of things task scheduling method and system based on mobile edge computing
US6717932B1 (en) Method for sharing capacity in a CDMA mobile radiocommunication system
CN106603215B (en) ZigBee-based non-fair network channel resource sharing method
CN112035249A (en) Application program network proportion adjusting method and device and storage medium
CN113453285B (en) Resource adjusting method, device and storage medium
CN109428901B (en) Message processing method and message processing device
CN112783641A (en) Service interface flow control method and device
CN115498735A (en) Fuel cell monomer voltage monitoring method and fuel cell controller
CN115515188A (en) Flow control method and device, electronic equipment and storage medium
CN115175245A (en) Method, device and equipment for adjusting data throughput and storage medium
CN113873003A (en) Data transmission control method and system between storage end and communication end in Internet of things
CN114860397B (en) Task scheduling method, device and equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant