CN111083062A - Weight mechanism-based current limiting method and device, computer equipment and storage medium - Google Patents
Weight mechanism-based current limiting method and device, computer equipment and storage medium Download PDFInfo
- Publication number
- CN111083062A CN111083062A CN201911302094.7A CN201911302094A CN111083062A CN 111083062 A CN111083062 A CN 111083062A CN 201911302094 A CN201911302094 A CN 201911302094A CN 111083062 A CN111083062 A CN 111083062A
- Authority
- CN
- China
- Prior art keywords
- token
- ratio
- token bucket
- tokens
- controlling
- 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.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 40
- 230000007246 mechanism Effects 0.000 title claims abstract description 22
- 238000004590 computer program Methods 0.000 claims description 10
- 230000006870 function Effects 0.000 abstract description 6
- 230000015556 catabolic process Effects 0.000 abstract description 4
- 230000008569 process Effects 0.000 description 4
- 230000009471 action Effects 0.000 description 3
- 238000004364 calculation method Methods 0.000 description 2
- 238000001514 detection method Methods 0.000 description 2
- 238000010586 diagram Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 238000004422 calculation algorithm Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000000750 progressive effect Effects 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L47/00—Traffic control in data switching networks
- H04L47/10—Flow control; Congestion control
- H04L47/215—Flow control; Congestion control using token-bucket
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a current limiting method and device based on a weight mechanism, computer equipment and a storage medium, and relates to the technical field of computers. The method comprises the following steps: setting a critical value for the token bucket in advance; setting different weights for different interfaces in advance; when the interface receives an access request, calculating the ratio of the number of the remaining tokens in the token bucket to the total number of the tokens; comparing the ratio to the threshold value; if the ratio is larger than the critical value, controlling access requests corresponding to all the interfaces to take out tokens from a token bucket; if the ratio is smaller than the critical value, controlling the access request corresponding to the interface with high weight to take out the token from the token bucket; and controlling the access request for taking out the token to execute corresponding business logic. The method can limit the current when a large number of high-concurrency access requests occur, avoid system breakdown and ensure the normal operation of important functions of the system.
Description
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for limiting current based on a weight mechanism, a computer device, and a storage medium.
Background
At present, because the processing capacity of the background server is limited, when the background server loads too much user access and the background server is not in time to expand the capacity, the background server can be overloaded, so that the system is crashed, and then important access requests cannot be processed in time.
Disclosure of Invention
The embodiment of the invention provides a current limiting method and device based on a weight mechanism, computer equipment and a storage medium, aiming at carrying out current limiting operation when a large number of high-concurrency access requests occur, avoiding system breakdown and ensuring normal operation of important functions of a system.
In a first aspect, an embodiment of the present invention provides a current limiting method based on a weight mechanism, including:
setting a critical value for the token bucket in advance;
setting different weights for different interfaces in advance;
when the interface receives an access request, calculating the ratio of the number of the remaining tokens in the token bucket to the total number of the tokens;
comparing the ratio to the threshold value;
if the ratio is larger than the critical value, controlling access requests corresponding to all the interfaces to take out tokens from a token bucket; if the ratio is smaller than the critical value, controlling the access request corresponding to the interface with high weight to take out the token from the token bucket;
and controlling the access request for taking out the token to execute corresponding business logic.
In a second aspect, an embodiment of the present invention provides a current limiting device based on a weight mechanism, including:
the input unit is used for setting a critical value for the token bucket in advance;
the setting unit is used for setting different weights for different interfaces in advance;
the computing unit is used for computing the ratio of the number of the remaining tokens in the token bucket to the total number of the tokens when the interface receives the access request;
the comparison unit is used for comparing the ratio with the critical value;
the judging unit is used for controlling the access requests corresponding to all the interfaces to take out the tokens from the token bucket when the ratio is larger than the critical value; if the ratio is smaller than the critical value, controlling the access request corresponding to the interface with high weight to take out the token from the token bucket;
and the output unit is used for controlling the access request for taking out the token to execute corresponding business logic.
In a third aspect, an embodiment of the present invention further provides a computer device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor, where the processor, when executing the computer program, implements the method for limiting current based on the weight mechanism according to the first aspect.
In a fourth aspect, the present invention further provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and the computer program, when executed by a processor, causes the processor to execute the method for limiting current based on a weight mechanism according to the first aspect.
The embodiment of the invention provides a current limiting method and device based on a weight mechanism, computer equipment and a storage medium. The method comprises the steps of setting a critical value for a token bucket in advance; then, different weights are set for different interfaces in advance; when the interface receives an access request, calculating the ratio of the number of the remaining tokens in the token bucket to the total number of the tokens; comparing the ratio to the threshold value; if the ratio is larger than the critical value, controlling access requests corresponding to all the interfaces to take out tokens from a token bucket; if the ratio is smaller than the critical value, controlling the access request corresponding to the interface with high weight to take out the token from the token bucket; and then controlling the access request for taking out the token to execute corresponding business logic. The embodiment of the invention selectively receives and processes the access request by combining the token bucket algorithm and setting the weight of the interface, and can ensure the normal operation of important functions of the system while avoiding system breakdown when a large number of highly-concurrent access requests occur.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a flowchart of a current limiting method based on a weight mechanism according to an embodiment of the present invention;
fig. 2 is a block diagram of a current limiting device based on a weighting mechanism according to an embodiment of the present invention;
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the specification of the present invention and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
Referring to fig. 1, fig. 1 is a flowchart of a current limiting method based on a weight mechanism according to an embodiment of the present invention.
The specific steps may include S110 to S160:
s110: setting a critical value for the token bucket in advance;
in one embodiment, the token bucket may itself continually generate tokens at a constant rate, and if tokens are not consumed (no access request currently), or are consumed less quickly than token generation, the tokens in the token bucket may continually increase until the bucket is filled, i.e., the maximum number of tokens that can be held in the token bucket is less than or equal to the capacity of the token bucket. The embodiment may set one or more threshold values for the token bucket in advance, and according to the threshold values, part of the access requests may be selectively discarded in the case that the number of the access requests is too large, so as to ensure that the system does not crash.
Preferably, the critical value is 3.
Specifically, in this embodiment, the number of the critical values is 3, where the critical value is a ratio of the number of tokens in the token bucket to the total number of tokens in the token bucket (capacity of the token bucket) in a critical state, and a high ratio indicates that the number of access requests is small, that is, the pressure of throttling is small; a low ratio indicates a large number of access requests and a high pressure for throttling. The critical state may be predetermined based on a constant rate in the token bucket and the capacity of the token bucket. For example, a constant rate of a token bucket is to put one token every 1ms, and the capacity of the token bucket is 10 ten thousand tokens, that is, the rate of generating tokens by the token bucket is large, so 3 critical states can be set for the token bucket, where the 3 critical states respectively correspond to 3 critical values: 30%, 15% and 5%. It should be noted that not only 3 critical values may be set, but also only 1 critical value may be set if the capacity of the token bucket is large; if the capacity of the token bucket is small, more thresholds may be set to ensure proper operation of the system.
S120: setting different weights for different interfaces in advance;
in this embodiment, in order to ensure service operation to the greatest extent when a large number of high-concurrency access requests are encountered, weight values corresponding to different interfaces may be set in advance, that is, a higher weight may be set for a more important interface. For example, in a loan system, applying for a quota and submitting a loan are core functions of the system, and corresponding interfaces belong to important interfaces; the core functions of the non-loan system such as inquiring and modifying enterprise information, modifying legal information and the like do not have too high importance, and the corresponding interfaces belong to common interfaces, so that when weights are preset, the weights can be set to an application limit interface and a loan submitting interface to be heavier, and meanwhile, the weights are set to a modifying enterprise information interface and a modifying legal information interface to be smaller. When the critical value is reached, different subsequent operations can be performed on the access requests corresponding to different interfaces according to different weight values. Preferably, after the weights corresponding to the interfaces are set for the interfaces, in order to more effectively perform different subsequent operations on different interfaces when the number of tokens in the token bucket reaches the threshold value, all the interfaces may be classified according to the number of preset threshold values. For example, if the number of the preset critical values is 1, the weight may be divided into two levels from high to low, all interfaces corresponding to the weight greater than or equal to 0.7 are divided into 1 level, and all interfaces corresponding to the remaining weight less than 0.7 are divided into 2 levels; if the number of the preset critical values is 2, the weight may be divided into 3 levels from high to low, all interfaces corresponding to the weight greater than or equal to 0.7 are divided into 1 level, all interfaces corresponding to the weight less than 0.7 and greater than or equal to 0.3 are divided into 2 levels, and all interfaces corresponding to the weight less than 0.3 are divided into 3 levels.
S130: when the interface receives an access request, calculating the ratio of the number of the remaining tokens in the token bucket to the total number of the tokens;
when an interface receives an access request, in order to prevent a large number of access requests from operating a token bucket at the same time and further prevent a system from being crashed, the number of tokens remaining in the token bucket needs to be inquired first, then whether the token bucket has the remaining tokens or not is judged, and if the token bucket has the remaining tokens is judged, the ratio of the number of the remaining tokens in the token bucket to the total number of the tokens is calculated; if no token is left in the token bucket, the ratio is 0, and then the step S140 is performed.
S140: comparing the ratio to the threshold value;
in this step, after calculating the ratio of the number of remaining tokens to the total number of tokens in the token bucket, the ratio needs to be compared with the critical value, and the comparison result changes according to the number of preset critical values, specifically, if only one preset critical value exists, the comparison result has: the ratio is greater than the critical value or less than the critical value; if the preset critical value is two or more, the comparison result is as follows: the ratio is greater than the maximum threshold, the ratio is less than the minimum threshold, and the ratio is between the thresholds, and then the step S150 is performed according to the comparison result.
S150: if the ratio is larger than the critical value, controlling access requests corresponding to all the interfaces to take out tokens from a token bucket; if the ratio is smaller than the critical value, controlling the access request corresponding to the interface with high weight to take out the token from the token bucket;
after all access requests reach the interface, firstly, the token in the token bucket needs to be acquired, and after the token in the token bucket is acquired, the subsequent business logic operation can be continued. In order to avoid system crash caused by excessive access requests for acquiring tokens and insufficient number of remaining tokens in the current token bucket, all access requests need to be compared before acquiring tokens in the token bucket, for example, 3 critical values are provided, which are respectively a first critical value of 30%, a second critical value of 15% and a third critical value of 5%, so that after a ratio of the number of remaining tokens in the token bucket to the total number of tokens is calculated, the ratio is compared with the critical values, and if the ratio is 35%, the comparison result is that the ratio is greater than the first critical value; if the ratio is 20%, the comparison result is that the ratio is smaller than a first critical value and larger than a second critical value; if the ratio is 10%, the comparison result is that the ratio is smaller than a second critical value and larger than a third critical value; if the ratio is 2%, the comparison result is that the ratio is smaller than a third critical value.
And then judging whether the current token bucket can receive a large number of access requests or not according to the comparison result. If the comparison result is that the ratio is greater than the critical value, that is, the number of the remaining tokens in the token bucket is sufficient, the access requests corresponding to all the interfaces can be controlled to simultaneously take out the tokens from the token bucket. If the comparison result is that the ratio is smaller than the critical value, it indicates that the number of remaining tokens in the token bucket is insufficient, and at this time, all access requests need to be screened according to the weight of different interfaces, and the access request corresponding to the interface with high weight is controlled to take out the token from the token bucket.
If the ratio is greater than the critical value, controlling access requests corresponding to all the interfaces to take out tokens from a token bucket; if the ratio is smaller than the critical value, controlling the access request corresponding to the interface with high weight to take out the token from the token bucket, including:
if the ratio is larger than the highest critical value, controlling access requests corresponding to all the interfaces to take out the tokens from the token bucket;
if the ratio is between the lowest critical value and the highest critical value, controlling the access request corresponding to the interface with high weight of part to take out the token from the token bucket;
and if the ratio is smaller than the lowest critical value, controlling the access request corresponding to the interface with the highest weight to take out the token from the token bucket.
Specifically, in this embodiment, it is assumed that there are 3 critical values, when the ratio is compared with the critical value, a comparison result may occur in which the ratio is greater than the highest critical value, which indicates that the number of remaining tokens in the token bucket is sufficient, that is, the system may receive all access requests, and at this time, may control the access requests corresponding to all interfaces to take out tokens from the token bucket; a comparison result of the ratio between the lowest critical value and the highest critical value may also occur, which indicates that the number of remaining tokens in the token bucket is not sufficient enough, and only part of the access requests can be allowed to take out tokens from the token bucket, and under the comparison result, the access requests corresponding to the interfaces with high weights of part of the access requests can be preferentially controlled to take out tokens from the token bucket; when the comparison result that the ratio is smaller than the lowest critical value occurs, it indicates that the system cannot load a large number of request accesses at this time, that is, the system is about to crash, and at this time, the remaining tokens still exist in the token bucket, but the tokens in the token bucket are about to be exhausted, so that only a very small number of access requests in the interface with the highest weight can be controlled to take out the tokens from the token bucket. Preferably, the weights may be classified from high to low according to the number of the critical values, and when the number of tokens in the token bucket reaches the critical value, different subsequent operations are performed on different interfaces according to the classified weight grades.
For example, the 3 critical values are 30%, 15%, and 5%, respectively, according to which the weight is divided into 4 levels from high to low, 1 level, 2 levels, 3 levels, and 4 levels, respectively, wherein an interface having a weight of greater than or equal to 0.7 is divided into 1 level, an interface having a weight of less than 0.7 and greater than or equal to 0.5 is divided into 2 levels, an interface having a weight of less than 0.5 and greater than or equal to 0.3 is divided into 3 levels, and an interface having a weight of less than 0.3 is divided into 4 levels. When the ratio is greater than 30%, the access requests corresponding to all the interfaces can be directly controlled to take out the tokens from the token bucket. When the ratio is less than or equal to 30% and greater than 15%, the access requests corresponding to the interfaces with most high weights can be preferentially controlled to take out the tokens from the token bucket, that is, the access requests corresponding to the interfaces with the weights of 1 level, 2 level and 3 level are preferentially controlled to take out the tokens from the token bucket. When the ratio is less than or equal to 15% and greater than 5%, the access requests corresponding to a small number of interfaces with high weights can be preferentially controlled to take out the tokens from the token bucket, that is, the access requests corresponding to the interfaces with the weights of level 1 and level 2 are preferentially controlled to take out the tokens from the token bucket. When the ratio is less than or equal to 5%, only controlling the extremely small number of access requests corresponding to the interface with the highest weight to take out the tokens from the token bucket, namely preferentially controlling the access requests corresponding to the interface with the 1-level weight to take out the tokens from the token bucket.
In an embodiment, after the access request corresponding to the interface with the higher control weight takes out the token from the token bucket if the ratio is smaller than the threshold, the method includes:
after the token is taken out from the access request corresponding to the interface with high weight, detecting whether the token bucket has residual tokens;
and if the token bucket has the remaining tokens, controlling the access request corresponding to the interface with low weight to take out the tokens from the token bucket.
In this embodiment, when the ratio is smaller than the highest critical value, the access request corresponding to the interface with the higher weight of the priority control part takes out the token from the token bucket, for example, when the preset critical value is only 1 and is equal to 30%, and when the ratio is smaller than 30% of the highest critical value, the access request corresponding to the interface with the weight greater than 0.7 may be preferentially controlled to take out the token from the token bucket; when the preset critical values are 2 and are respectively 30% and 10%, and when the ratio is smaller than the highest critical value by 30% and is larger than the lowest critical value by 10%, taking out the token from the token bucket by the access request corresponding to the interface with the priority control weight larger than 0.7; when the ratio is less than the lowest critical value by 10%, the access request corresponding to the interface with the weight greater than 0.85 can be controlled preferentially to take out the token from the token bucket. After the access request takes out the token, if the token bucket has the remaining tokens, the access requests corresponding to other interfaces can also perform token taking-out operation. Therefore, after the access request corresponding to the interface with high weight takes out the token, whether the token bucket has the remaining tokens or not can be detected, if the remaining tokens exist in the token bucket, the access requests corresponding to the relevant interfaces are sequentially controlled from high to low according to the weight to take out the tokens from the token bucket.
In an embodiment, the method for limiting current based on a weight mechanism further includes:
control discards access requests for which no token is fetched.
If the number of remaining tokens in the token bucket is smaller than the number of access requests, a situation that some access requests corresponding to interfaces with low weights cannot take out tokens from the token bucket occurs, and at this time, it is necessary to control to discard the access requests corresponding to interfaces which cannot respond to the access requests.
In an embodiment, the method for limiting current based on a weight mechanism further includes:
and if the ratio is equal to 0, controlling to discard the access requests corresponding to all the interfaces.
That is, if the ratio of the number of remaining tokens in the token bucket to the total number of tokens is 0, that is, there are no remaining tokens in the token bucket, it indicates that all interfaces cannot respond to the access request at this time, and therefore, it is necessary to control to discard the access requests corresponding to all interfaces, thereby avoiding system crash.
In one embodiment, the controlling discarding access requests for which no token is fetched includes:
detecting an access time of an access request without a token taken out;
and if the access time exceeds a time threshold value from the current time, controlling to discard the access request without the token.
In this embodiment, since the tokens in the token bucket will be continuously generating tokens at a constant rate, the calculation result is that the ratio is equal to 0, only indicating that the current ratio is equal to 0, so when the calculation result is that the ratio is equal to 0, all current access requests can not take out tokens from the token bucket, all the current access requests can enter a waiting stage (if the current ratio is not equal to 0, the access requests which can not acquire the tokens in time enter the waiting stage), continuously recalculating the value in the waiting stage, simultaneously detecting the access time of the access request without taking out the token, if the access time does not exceed the time threshold from the current time, continuing to maintain in the waiting stage, if the ratio is greater than 0 in the waiting stage, the access request corresponding to the interface can be controlled from high to low to take out the token from the token bucket according to the weight of the interface; if the access time of an access request exceeds a time threshold from the current time and a token has not been taken from a token bucket, then control is required to discard the access request.
In an embodiment, the time thresholds may be set uniformly, or different time thresholds may be set for different interfaces respectively according to the weight of the interface, where the time threshold corresponding to the interface with the larger weight is larger.
S160: and controlling the access request for taking out the token to execute corresponding business logic.
And when the access request takes out the token, corresponding business logic operation can be carried out according to the token. For example, after the access request for checking the commodity takes out the token, the business logic operation for checking the commodity can be performed, and after the access request for ordering payment takes out the token, the business logic operation for ordering payment can be performed.
In an embodiment, please refer to fig. 2, fig. 2 is a block diagram illustrating a current limiting device 200 based on a weighting mechanism according to an embodiment of the present invention;
the apparatus 200 may include:
an input unit 201 for setting a critical value for a token bucket in advance;
a setting unit 202, configured to set different weights for different interfaces in advance;
the calculating unit 203 is configured to calculate a ratio of the number of remaining tokens in the token bucket to the total number of tokens when the interface receives the access request;
a comparing unit 204, configured to compare the ratio with the critical value;
a determining unit 205, configured to control access requests corresponding to all interfaces to take out tokens from the token bucket when the ratio is greater than the critical value; if the ratio is smaller than the critical value, controlling the access request corresponding to the interface with high weight to take out the token from the token bucket;
and an output unit 206, configured to control the access request for fetching the token to execute a corresponding service logic.
The device can perform current limiting operation when a large number of high-concurrency access requests occur, so that normal operation of important functions of the system is guaranteed while system breakdown is avoided.
In one embodiment, the current limiting apparatus 200 based on the weighting scheme further includes:
and the first discarding unit is used for controlling to discard the access requests of which the tokens are not taken out.
In one embodiment, the current limiting apparatus based on the weighting mechanism further includes:
and the second discarding unit is used for controlling to discard the access requests corresponding to all the interfaces if the ratio is equal to 0.
In one embodiment, the determining unit 205 includes:
the first judgment unit is used for controlling the access requests corresponding to all the interfaces to take out the tokens from the token bucket when the ratio is larger than the highest critical value;
the second judgment unit is used for controlling the access request corresponding to the interface with high weight of part to take out the token from the token bucket when the ratio is between the lowest critical value and the highest critical value;
and the third judging unit is used for controlling the access request corresponding to the interface with the highest weight to take out the token from the token bucket when the ratio is smaller than the lowest critical value.
In one embodiment, the current limiting apparatus 200 based on the weighting scheme further includes:
the first detection unit is used for detecting whether the token bucket has residual tokens after the token is taken out by the access request with high weight;
and the fourth judging unit is used for controlling the access request corresponding to the interface with low weight to take out the token from the token bucket when the token bucket has the residual tokens.
In one embodiment, the first discarding unit includes:
a second detection unit configured to detect an access time of an access request for which the token is not taken out;
and the fifth judging unit is used for controlling to discard the access request without the token when the access time exceeds the time threshold from the current time.
In one embodiment, the threshold is 3.
Since the embodiments of the apparatus portion and the method portion correspond to each other, please refer to the description of the embodiments of the method portion for the embodiments of the apparatus portion, which is not repeated here.
The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed, can implement the method provided by the above-described embodiments.
The invention also provides a computer device, which may include a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the method provided by the above embodiments when executing the computer program.
The embodiments are described in a progressive manner in the specification, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description. It should be noted that, for those skilled in the art, it is possible to make various improvements and modifications to the present invention without departing from the principle of the present invention, and those improvements and modifications also fall within the scope of the claims of the present invention.
It is further noted that, in the present specification, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, 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 an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
Claims (10)
1. A current limiting method based on a weight mechanism is characterized by comprising the following steps:
setting a critical value for the token bucket in advance;
setting different weights for different interfaces in advance;
when the interface receives an access request, calculating the ratio of the number of the remaining tokens in the token bucket to the total number of the tokens;
comparing the ratio to the threshold value;
if the ratio is larger than the critical value, controlling access requests corresponding to all the interfaces to take out tokens from a token bucket; if the ratio is smaller than the critical value, controlling the access request corresponding to the interface with high weight to take out the token from the token bucket;
and controlling the access request for taking out the token to execute corresponding business logic.
2. The method for weight based throttling of claim 1, further comprising:
control discards access requests for which no token is fetched.
3. The method for weight based throttling of claim 1, further comprising:
and if the ratio is equal to 0, controlling to discard the access requests corresponding to all the interfaces.
4. The method according to claim 1, wherein if the ratio is greater than the threshold, controlling access requests corresponding to all interfaces to take out tokens from a token bucket; if the ratio is smaller than the critical value, controlling the access request corresponding to the interface with high weight to take out the token from the token bucket, including:
if the ratio is larger than the highest critical value, controlling access requests corresponding to all the interfaces to take out the tokens from the token bucket;
if the ratio is between the lowest critical value and the highest critical value, controlling the access request corresponding to the interface with high weight of part to take out the token from the token bucket;
and if the ratio is smaller than the lowest critical value, controlling the access request corresponding to the interface with the highest weight to take out the token from the token bucket.
5. The method for throttling current based on weight mechanism according to claim 1, wherein if the ratio is smaller than the threshold, after the access request corresponding to the interface with high control weight takes out the token from the token bucket, the method comprises:
after the token is taken out from the access request corresponding to the interface with high weight, detecting whether the token bucket has residual tokens;
and if the token bucket has the remaining tokens, controlling the access request corresponding to the interface with low weight to take out the tokens from the token bucket.
6. The method of throttling based on weight mechanism of claim 2, wherein the controlling discarding access requests for which no token is fetched comprises:
detecting an access time of an access request without a token taken out;
and if the access time exceeds a time threshold value from the current time, controlling to discard the access request without the token.
7. The method as claimed in claim 4, wherein the threshold is 3.
8. A current limiting apparatus based on a weighting scheme, comprising:
the input unit is used for setting a critical value for the token bucket in advance;
the setting unit is used for setting different weights for different interfaces in advance;
the computing unit is used for computing the ratio of the number of the remaining tokens in the token bucket to the total number of the tokens when the interface receives the access request;
the comparison unit is used for comparing the ratio with the critical value;
the judging unit is used for controlling the access requests corresponding to all the interfaces to take out the tokens from the token bucket when the ratio is larger than the critical value; if the ratio is smaller than the critical value, controlling the access request corresponding to the interface with high weight to take out the token from the token bucket;
and the output unit is used for controlling the access request for taking out the token to execute corresponding business logic.
9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the method for current limiting based on a weight mechanism according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, having stored thereon a computer program which, when being executed by a processor, implements the method for weight-based mechanism current limiting according to any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911302094.7A CN111083062A (en) | 2019-12-17 | 2019-12-17 | Weight mechanism-based current limiting method and device, computer equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911302094.7A CN111083062A (en) | 2019-12-17 | 2019-12-17 | Weight mechanism-based current limiting method and device, computer equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN111083062A true CN111083062A (en) | 2020-04-28 |
Family
ID=70315053
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201911302094.7A Pending CN111083062A (en) | 2019-12-17 | 2019-12-17 | Weight mechanism-based current limiting method and device, computer equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111083062A (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113726685A (en) * | 2021-08-23 | 2021-11-30 | 上海浦东发展银行股份有限公司 | Universal and special mixed flow control method, computer equipment and storage medium |
CN114095444A (en) * | 2020-07-15 | 2022-02-25 | 中移物联网有限公司 | Current limiting method and device and electronic equipment |
CN114979012A (en) * | 2022-05-31 | 2022-08-30 | 济南浪潮数据技术有限公司 | Network flow current limiting method, system, device and computer storage medium |
CN117294655A (en) * | 2023-11-27 | 2023-12-26 | 深圳市杉岩数据技术有限公司 | High-availability distributed gateway system and management method |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1601963A (en) * | 2003-09-26 | 2005-03-30 | 华为技术有限公司 | Access rate limiting method based on token pail algorithm |
US20050157723A1 (en) * | 2004-01-19 | 2005-07-21 | Bong-Cheol Kim | Controlling traffic congestion |
US20100085874A1 (en) * | 2008-10-05 | 2010-04-08 | Contextream Ltd. | Bandwidth allocation method and apparatus |
US20100177635A1 (en) * | 2009-01-09 | 2010-07-15 | Brocade Communications Systems, Inc. | Hierarchical rate color marker |
US20120147744A1 (en) * | 2010-12-14 | 2012-06-14 | Verizon Patent And Licensing, Inc. | Time and data rate policing |
CN104038434A (en) * | 2013-03-08 | 2014-09-10 | 中兴通讯股份有限公司 | Traffic policing method and apparatus |
-
2019
- 2019-12-17 CN CN201911302094.7A patent/CN111083062A/en active Pending
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1601963A (en) * | 2003-09-26 | 2005-03-30 | 华为技术有限公司 | Access rate limiting method based on token pail algorithm |
US20050157723A1 (en) * | 2004-01-19 | 2005-07-21 | Bong-Cheol Kim | Controlling traffic congestion |
US20100085874A1 (en) * | 2008-10-05 | 2010-04-08 | Contextream Ltd. | Bandwidth allocation method and apparatus |
US20100177635A1 (en) * | 2009-01-09 | 2010-07-15 | Brocade Communications Systems, Inc. | Hierarchical rate color marker |
US20120147744A1 (en) * | 2010-12-14 | 2012-06-14 | Verizon Patent And Licensing, Inc. | Time and data rate policing |
CN104038434A (en) * | 2013-03-08 | 2014-09-10 | 中兴通讯股份有限公司 | Traffic policing method and apparatus |
Non-Patent Citations (1)
Title |
---|
张根宝等: "基于工业以太网的工控领域流量管控设计", 《电脑知识与技术》 * |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114095444A (en) * | 2020-07-15 | 2022-02-25 | 中移物联网有限公司 | Current limiting method and device and electronic equipment |
CN114095444B (en) * | 2020-07-15 | 2023-11-10 | 中移物联网有限公司 | Current limiting method and device and electronic equipment |
CN113726685A (en) * | 2021-08-23 | 2021-11-30 | 上海浦东发展银行股份有限公司 | Universal and special mixed flow control method, computer equipment and storage medium |
CN113726685B (en) * | 2021-08-23 | 2024-01-23 | 上海浦东发展银行股份有限公司 | General and special mixed flow control method, computer equipment and storage medium |
CN114979012A (en) * | 2022-05-31 | 2022-08-30 | 济南浪潮数据技术有限公司 | Network flow current limiting method, system, device and computer storage medium |
CN117294655A (en) * | 2023-11-27 | 2023-12-26 | 深圳市杉岩数据技术有限公司 | High-availability distributed gateway system and management method |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111083062A (en) | Weight mechanism-based current limiting method and device, computer equipment and storage medium | |
CN105024933B (en) | The control method and device of request packet transmission frequency | |
CN106933650A (en) | load management method and system of cloud application system | |
CN106294206B (en) | Cache data processing method and device | |
CN105871983A (en) | Method and device for selecting servers | |
CN109597800B (en) | Log distribution method and device | |
CN109120548B (en) | Flow control method and device | |
US20160104125A1 (en) | Computing system and method for providing information relating to maintenance actions | |
US8677370B2 (en) | Generating resource consumption control limits | |
EP3885910A1 (en) | Dynamic quality of service management for deep learning training communication | |
JP2005128866A (en) | Computer unit and method for controlling computer unit | |
WO2018228323A1 (en) | Service level control method and system for on-line service system, and readable storage medium | |
US12050796B2 (en) | Managing deduplication operations based on a likelihood of duplicability | |
WO2019099929A1 (en) | Using a machine learning model in quantized steps for malware detection | |
CN112596880A (en) | Data processing method, device, equipment and storage medium | |
CN111737055A (en) | Service processing method, device, equipment and computer readable storage medium | |
CN107908555B (en) | SQL script abnormity detection method and terminal thereof | |
CN106547609A (en) | A kind of event-handling method and equipment | |
CN114827281A (en) | Method, system and device for sending and receiving network request | |
CN111047042B (en) | Operation method and device of reasoning service model | |
CN112631757B (en) | DDR4 multi-user access scheduling method and device | |
CN111193760B (en) | Information sending method, device and storage medium | |
CN108958902B (en) | Graph calculation method and system | |
CN113434735A (en) | Self-adaptive current limiting method, device, server and storage medium | |
CN110704461A (en) | Data verification method and device, computer equipment and readable storage medium |
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 | ||
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20200428 |