Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete
Site preparation description, it is clear that described embodiments are some of the embodiments of the present invention, instead of all the embodiments.Based on this hair
Embodiment in bright, every other implementation obtained by those of ordinary skill in the art without making creative efforts
Example, shall fall within the protection scope of the present invention.
It should be appreciated that ought use in this specification and in the appended claims, term " includes " and "comprising" instruction
Described feature, entirety, step, operation, the presence of element and/or component, but one or more of the other feature, whole is not precluded
Body, step, operation, the presence or addition of element, component and/or its set.
It is also understood that mesh of the term used in this description of the invention merely for the sake of description specific embodiment
And be not intended to limit the present invention.As description of the invention and it is used in the attached claims, unless on
Other situations are hereafter clearly indicated, otherwise " one " of singular, "one" and "the" are intended to include plural form.
It will be further appreciated that the term "and/or" used in description of the invention and the appended claims is
Refer to any combination and all possible combinations of one or more of associated item listed, and including these combinations.
As used in this specification and in the appended claims, term " if " can be according to context quilt
Be construed to " when ... " or " once " or " in response to determination " or " in response to detecting ".Similarly, phrase " if it is determined that " or
" if detecting [described condition or event] " can be interpreted to mean according to context " once it is determined that " or " in response to true
It is fixed " or " once detecting [described condition or event] " or " in response to detecting [described condition or event] ".
With the development of network technology, the continuous rapid growth of IP operation.Improving the quality that information is transmitted on ip networks is
The developing key point of IP network.The exploitation of IP QoS technology, purpose are exactly to provide to service end to end for user's request
Quality assurance, by packet classification, congestion management, it is crowded avoid, rate limit and flow shape technique realize Service Quality
Amount control has used token bucket algorithm mainly in its rate limit and traffic shaping to assess the logical of unit time interior request
Whether excessive be more than specified value.And the dispensing rate of token bucket capacity and token in traditional token bucket algorithm is fixed number
Value, this token bucket processing mode just seem weaker in the processing capacity of burst flow, that is to say, that when there are biggish prominent
When sending out flow, token bucket may can not handle request due to not enough tokens, and request processing flow is discontinuous, sometimes
Request is caused to abandon because of token lazy weight.Just seem when in face of a large amount of network request and extremely limit to, flexibility is poor.
In order to solve the poor technical problem of conventional token bucket algorithm flexibility, the invention proposes a kind of methods of elastic current limliting, ask
It is a kind of method implementation flow chart of elastic current limliting provided in an embodiment of the present invention referring to Fig. 1, Fig. 1.A kind of bullet as shown in Figure 1
The method of property current limliting includes:
S101 launches token to token bucket according to scheduled rate, and every the during launching token to token bucket
One preset duration counts the request response abnormality rate in first preset duration.
The token bucket is the storage inside pond of the network equipment, and for accommodating the token, the token is then with default
Rate pad to the token bucket virtual information packet.And the token that each request requires matching respective numbers could be sent out
It send to server.The length of time that the token bucket fills up is total to by the dispensing rate of the token bucket capacity and the token
With decision.
The scheduled rate, which refers to, launches token to token bucket with preset constant rate of speed.Such as: by the pre- of the token
It is if rate is set as 8000bit/s, i.e., per second that 8000 tokens are put into bucket, it just need to be from the order when often passing through a request
The token of corresponding number is removed in board bucket.When the token described in the token bucket exhausts, subsequent request is considered as surpassing
Outflow limitation, and the flow exceeded will take additional processing, the processing includes delay or discarding etc..
The request response abnormality is to cause server response abnormality since server access amount is excessive.And request is caused to ring
The reason of answering abnormal reason very much, response abnormality requested described in the embodiment of the present invention including but not limited to response timeout,
HTTP500 mistake etc..The request response abnormality need to be controlled by flow of the token bucket algorithm to request, and then alleviated and asked
The problem of seeking response abnormality.
In the present embodiment before adjusting the token and launching rate and the token bucket capacity, the request need to be responded different
Normal rate is counted, as the benchmark for adjusting the current dispensing rate of the token and the token bucket current capacities.It is described
Requesting response abnormality rate is the accounting of response abnormality quantity in the request number of responses in the first preset duration, wherein every section
Preset duration is continuous, and every section of preset duration requires respectively to the current dispensing rate of the token and the token
Bucket current capacities are adjusted, and first preset duration is exactly one section therein.
S102, according to the current dispensing rate for requesting response abnormality rate dynamic to adjust the token and the token
The current capacities of bucket.
Wherein, the dispensing rate of the token is adjusted for being requested in Units of Limitation duration through quantity, and adjusts institute
State token bucket capacity be used for limit momentary request by quantity, to guarantee that the load of server is in reasonable range.
The token launches rate and the capacity of the token bucket adjusts correlation.The same of rate is launched in dynamic adjustment token
When, token bucket capacity is limited.
Specifically, the current dispensing of the token is adjusted described in step S102 according to the request response abnormality rate dynamic
The current capacities of rate and the token bucket, specifically include: reducing working as the token according to the request response abnormality rate
The preceding current capacities for launching rate and the token bucket.
The request response abnormality rate is to generate such exception since the quantity requested in the unit time is too high.Therefore,
When can reduce unit by reducing the current dispensing rate of the token and the current capacities of the token bucket, and then passing through
The quantity of interior request alleviates response abnormality rate.And according to the response abnormality rate adjust the token dispensing rate and
The range of the capacity of the token bucket depending on needing according to actual needs, reduces request percent of pass, it is also possible to cause net simply
Network blocking.
Specifically, the current dispensing rate and the order that the token is reduced according to the request response abnormality rate
The current capacities of board bucket, specifically include: reducing the percentage of the current dispensing rate of the token and reduce the token bucket
Current capacities percentage, be equal to or be greater than the request response abnormality rate.
It, can be according to the current capacities for the percentage and the token bucket for launching rate in order to accurately adjust network flow
Percentage is accurately adjusted, such as: if first preset duration is 60s, count the total quantity of request response in 60s with
And the quantity of request response abnormality, calculate the request response abnormality rate.It is requested if one shares 6000 times, 1000 time-out,
1000 return 500 mistakes of http, then request response abnormality rate=(the 1000+1000)/6000=33%, according to described
It requests response abnormality rate to reduce the token and provides rate.If current 1s provides 100 tokens, by the throwing of the token
Putting speed adjust is 100 × (1-0.33)=67, that is, is adjusted to 67 tokens of granting per second, while the token bucket being held
Amount reduces by 2000.And the token is reduced in order to guarantee server in a normal loading range in actually adjustment
The percentage of the current capacities of the current percentage for launching rate and the token bucket is equal to or is greater than the request and responds
Abnormal rate.
Wherein, when a request is received, only when having enough tokens in the token bucket, request just allows to send out
It send to server.Token in the token bucket can be not only removed, and can also equally be added inward.Therefore, in order to protect
Card request can be transmitted to server, it is necessary to ceaselessly toward in bucket plus token.It can be seen that the dispensing speed of the token and
The token bucket capacity just determines that requests in the unit time passes through quantity.By adjusting the token and the token bucket
Capacity limits the use of flow and its resource, guarantees better network service.
In the present embodiment, response abnormality rate is requested in preset duration by counting, the dispensing speed of feedback regulation token
The capacity of rate and token bucket, and then control request in the unit time and pass through quantity, it prevents server overload and request is caused to ring
Should be abnormal, guarantee network service quality, compared with traditional token bucket algorithm, the present invention passes through the feedback regulation control unit time
Interior request realizes elasticity limitation request flow, improves the flexibility of token bucket algorithm by quantity.
Specifically, in the present embodiment, it is contemplated that reduce the throwing of the token by response abnormality rate in step s 102
The capacity of rate and the token bucket is put, and then controls request in the unit time and passes through quantity, although can prevent server from going out
The risk now overloaded.But when in face of burst big flow request, it may result in network blockage or request lost.Therefore this reality
It applies example and provides a kind of concrete implementation mode of step S102.It is counted in first preset duration every the first preset duration
Response abnormality rate is requested, after the request response abnormality rate in each section of the first preset duration that obtains, the request is rung
It answers the value of abnormal rate to be judged, when the response abnormality rate is greater than preset threshold, thens follow the steps S201, otherwise, execute
Step S202.Fig. 2 is referred to, Fig. 2 is that step S102 is specifically real in a kind of method of elastic current limliting provided in an embodiment of the present invention
Existing flow diagram.As shown in Fig. 2, step S102 in above-mentioned embodiment illustrated in fig. 1, especially by following steps S201 to S203
It realizes:
S201 reduces the order according to the request response abnormality rate when the response abnormality rate is greater than preset threshold
The current dispensing rate of board and the current capacities of the token bucket.
The threshold value can be arranged according to real network demand.When the response abnormality rate is greater than preset threshold, clothes are indicated
Device amount of access of being engaged in is excessive.It can be according to the current dispensing rate for requesting response abnormality rate reduce the token and the token
The current capacities of bucket, and then request is mitigated server burden, is made the response abnormality rate, reached by quantity in the unit time
In normal range (NR), i.e., the described response abnormality rate is less than or equal to the preset threshold.
S202 is then counted in the second preset duration when the response abnormality rate is less than or equal to the preset threshold
Request failure rate.
When the response abnormality rate is less than or equal to the preset threshold, indicate that current server request amount is in normal
Or reduced levels.If continuing according to the dispensing rate of the token at this time and the capacity of the token bucket in the unit time
When number of requests is limited, when number of requests increases suddenly in the unit time, then it may cause a large amount of requests and lost
It abandons or postpones, cause network blockage.In order to cope with the problem of causing network blockage when number of requests increases suddenly.Therefore this implementation
Example by the response abnormality rate be less than or equal to the preset threshold when, according to the request failure rate in the second preset duration
Judge whether to need to adjust the dispensing rate of the token and the capacity of the token bucket, adaptively control to the unit time
Interior request causes network blockage by quantity, to solve the problems, such as in the unit time that number of requests increases suddenly.
Specifically, the request failure rate in the second preset duration is counted described in step S202, is specifically included: pre- second
If in duration when a request is received, if the token quantity in the token bucket be unsatisfactory for the request needed for token quantity,
Then suspend or abandon the request, and labeled as request failure, request failure quantity is added 1.
A certain number of tokens are stored in the token bucket, are asked when the quantity of the token meets one or more
When asking, request continues to forward, while the token for corresponding number being deleted in the token bucket.Do not have when in the token bucket
When enough tokens, any request all can be dropped or postpone, and labeled as request failure, request failure quantity is added 1.
As an embodiment of the present invention, in the capacity for the dispensing rate and the token bucket for adjusting the token
Afterwards.When a request is received, token quantity of the token quantity in the token bucket needed for request is compared, if having foot
Enough tokens then request to be sent to server, abandon or cache if without enough tokens.Make the flow restriction of request one
It is a it is reasonable within the scope of.
As another embodiment of the invention, when receiving request, if there is token in the token bucket, no matter quantity is
No enough, the request all can be transmitted to server and can owe that is, when token quantity is less than the required token quantity of request
Debt forwarding.The debt forwarding refers to that after time forwarding is requested, token number is negative in the token bucket, adds token when next time
When, debt due is first paid off, forwarding request is further continued for.This processing method has compared with the former when handling burst request excellent
Gesture can guarantee the continuity that request is sent.
S203, according to the request failure rate dynamic adjust the token current dispensing rate and the token bucket
Current capacities.
Specifically, the current dispensing speed of the token is adjusted according to the request failure rate dynamic described in step S203
The current capacities of rate and the token bucket, specifically include: the current dispensing of the token is improved according to the request failure rate
The current capacities of rate and the token bucket.
Such as: second preset duration be 60s, then count do not have in 60s application arrive token number of requests, than if any
60.If current 1s provides 100 tokens, it is 100+ (60/60)=101 that token, which is provided speed adjust, i.e. 1s provides 101
A token.Token bucket capacity is increased by 60 simultaneously.
Specifically, described according to the current dispensing rate for requesting failure rate to improve the token and the token bucket
Current capacities, especially by following steps S301 to S302 realize, refer to Fig. 3, Fig. 3 is provided in an embodiment of the present invention one
Step S203 specific implementation flow schematic diagram in the method for the elastic current limliting of kind.As shown in figure 3, described according to the request failure rate
The current dispensing rate of the token and the current capacities of the token bucket are improved, are specifically included:
S301 improves the current of the token according to the default dispensing rate peak value of the token and the request failure rate
Launch rate.
The current dispensing rate of the token and the current appearance of the token bucket are being improved according to the request failure rate
When amount, in order to guarantee that the amount of access of server is in zone of reasonableness, it need to be limited by presetting the dispensing rate peak value of the token
It makes the maximum of the token and launches rate.
S302 improves the current of the token bucket according to the preset capacity peak value of the token bucket and the request failure rate
Capacity.
The current dispensing rate of the token and the current appearance of the token bucket are being improved according to the request failure rate
When amount, in order to guarantee that the amount of access of server is in zone of reasonableness, it need to be limited by presetting the capacity peak value of the token bucket
The maximum capacity of the token bucket, further control unit time interior request passes through quantity.
It in the present embodiment, is the current dispensing rate and the order for promoting the token according to the request failure rate
The current capacities of board bucket.Adaptive faculty when burst data request increases is not only increased, and request percent of pass control is existed
In reasonable range, the mode of elastic current limliting is realized, improves the flexibility of token bucket algorithm.
Preferably, on the one hand the embodiment of the present invention passes through the dispensing speed for counting the request response abnormality rate reduction token
Rate, to guarantee network service quality.On the other hand, in order to which the request of data for adapting to network burst increases, by being asked described in statistics
Failure rate is asked to improve the dispensing rate of token.The two is the relationship adjusted jointly, and specific implementation refers to Fig. 4, and Fig. 4 is the present invention
The implementation process schematic diagram of feedback regulation in a kind of method for elastic current limliting that embodiment provides.As shown in figure 4, by described
Response abnormality rate and the request failure rate feedback regulation token is requested to provide rate, comprising:
S401 launches token to token bucket according to scheduled rate.
The scheduled rate includes the dispensing rate of initial setting up and is lost by the request response abnormality rate, the request
It loses and launches rate made of rate feedback regulation.After the token launches token to token bucket according to scheduled rate, when receiving number
Token quantity needed for whether meeting the request according to the token quantity judged in token bucket when requesting, if meeting the request institute
The request is then sent to server by the token quantity needed, is abandoned or is prolonged if the token quantity needed for being unsatisfactory for the request
The slow request, and labeled as request failure.
S402, statistics is every request response abnormality rate in the first preset duration.
Step S401, S402 corresponds to current-limiting method as shown in Figure 1.By counting every asking in the first preset duration
Ask response abnormality rate, the dispensing speed of feedback regulation token.Especially by the dispensing speed for reducing token, and then when control unit
Interior request mitigates server stress by quantity, reduces the request response abnormality rate, guarantees network service quality.
S403 judges to request whether response abnormality rate is higher than threshold value.
When the request response abnormality rate is too low, indicate that server is in the state of low-load, if in face of a large amount of number
According to request, it may result in network blockage and cause the waste of hardware resource.So needing by judging that the request is abnormal loud
Should rate size, be further processed, to prevent network blockage.
S404, the second preset duration of statistics is interior to request failure rate.
Step S403, S404, corresponding to current-limiting method as shown in Figure 2.By too low in the request response abnormality rate
In the case where count and request failure rate in the second preset duration, improve the dispensing speed of token, and then increase and ask in the unit time
It asks through quantity, prevents the phenomenon that network blockage is led to by the request response abnormality rate feedback regulation.
The embodiment of the present invention adjusts token according to the request failure rate and the request response abnormality rate common feedback
Launch rate.It is shifting by the two, in face of different network transmission pressure states, the request in the unit time is passed through into number
Amount control realizes the mode of elastic current limliting in reasonable range.
It should be noted that the method for elasticity current limliting provided by the present invention is suitable for all kinds of token bucket algorithms, including color
Algorithm under blind mode: the algorithm under single speed list bucket algorithm, single speed twin-tub algorithm, double speed twin-tub algorithm and sense color state: single
Single barrel of double-colored algorithm of rate, single-rate twin-tub three color algorithm, dual rate twin-tub three color algorithm.In all kinds of twin-tub algorithms, each
The speed adjust of token bucket can unanimously can also be different, need to be depending on real network demand.
If the present invention provides a kind of devices 5 of elastic current limliting by Fig. 5, Fig. 5 is referred to, Fig. 5 is that the embodiment of the present invention provides
A kind of elastic current limliting device schematic diagram, as shown in Figure 5 a kind of device of elastic current limliting include:
Statistic unit 51, for counting described first every the first preset duration during launching token to token bucket
Request response abnormality rate in preset duration;
Control unit 52, for launching token to token bucket according to scheduled rate;It is dynamic according to the request response abnormality rate
State adjusts the current dispensing rate of the token and the current capacities of the token bucket.
A kind of device of elastic current limliting provided by the invention, requests response abnormality rate by counting, instead in preset duration
Feedback adjusts the dispensing rate of token and the capacity of token bucket, and then controls and request to prevent from servicing by quantity in the unit time
Device overloads and leads to request response abnormality, guarantees network service quality, and compared with traditional token bucket algorithm, the present invention passes through anti-
Feedback, which is adjusted, requests percent of pass in the control unit time, improve the flexibility of token bucket algorithm.
It should be understood that the size of the serial number of each step is not meant that the order of the execution order in above-described embodiment, each process
Execution sequence should be determined by its function and internal logic, the implementation process without coping with the embodiment of the present invention constitutes any limit
It is fixed.
Fig. 6 is a kind of schematic diagram of the terminal device for elastic current limliting that one embodiment of the invention provides.As shown in fig. 6, should
A kind of terminal device 6 of elastic current limliting of embodiment includes: processor 60, memory 61 and is stored in the memory 61
And the computer program 62 that can be run on the processor 60, such as a kind of program of elastic current limliting.The processor 60 is held
The step in a kind of above-mentioned each embodiment of the method for elastic current limliting is realized when the row computer program 62, such as shown in Fig. 1
Step S101 to S102.Alternatively, the processor 60 realizes above-mentioned each Installation practice when executing the computer program 62
The function of middle each unit, such as the function of unit 51 to 52 shown in Fig. 5.
Illustratively, the computer program 62 can be divided into one or more units, one or more of
Unit is stored in the memory 61, and is executed by the processor 60, to complete the present invention.One or more of lists
Member can be the series of computation machine program instruction section that can complete specific function, and the instruction segment is for describing the computer journey
Implementation procedure of the sequence 62 in a kind of terminal device 6 of elastic current limliting.For example, the computer program 62 can be divided
It is as follows at acquiring unit and computing unit each unit concrete function:
Statistic unit, for pre- every the first preset duration statistics described first during launching token to token bucket
If the request response abnormality rate in duration;
Control unit, for launching token to token bucket according to scheduled rate;According to the request response abnormality rate dynamic
Adjust the current dispensing rate of the token and the current capacities of the token bucket.
A kind of terminal device 6 of elastic current limliting can be desktop PC, notebook, palm PC and cloud clothes
Business device etc. calculates equipment.A kind of terminal device of elastic current limliting may include, but be not limited only to, processor 60, memory 61.
It will be understood by those skilled in the art that Fig. 6 is only a kind of example of the terminal device 6 of elastic current limliting, do not constitute to one kind
The restriction of the terminal device 6 of elastic current limliting may include components more more or fewer than diagram, or combine certain components, or
The different component of person, such as a kind of terminal device of elastic current limliting can also be set including input-output equipment, network insertion
Standby, bus etc..
Alleged processor 60 can be central processing unit (Central Processing Unit, CPU), can also be
Other general processors, digital signal processor (Digital Signal Processor, DSP), specific integrated circuit
(Application Specific Integrated Circuit, ASIC), ready-made programmable gate array (Field-
Programmable Gate Array, FPGA) either other programmable logic device, discrete gate or transistor logic,
Discrete hardware components etc..General processor can be microprocessor or the processor is also possible to any conventional processor
Deng.
The memory 61 can be a kind of internal storage unit of the terminal device 6 of elastic current limliting, such as a kind of
The hard disk or memory of the terminal device 6 of elastic current limliting.The terminal that the memory 61 is also possible to a kind of elastic current limliting is set
The plug-in type hard disk being equipped on standby 6 External memory equipment, such as a kind of terminal device 6 of elastic current limliting, intelligent storage
Block (Smart Media Card, SMC), secure digital (Secure Digital, SD) card, flash card (Flash Card) etc..
Further, the memory 61 can also both include a kind of terminal device 6 of elastic current limliting internal storage unit or
Including External memory equipment.The memory 61 is used to store the terminal of the computer program and a kind of elastic current limliting
Other programs and data needed for equipment.The memory 61, which can be also used for temporarily storing, have been exported or will export
Data.
It is apparent to those skilled in the art that for convenience of description and succinctly, only with above-mentioned each function
Can unit, module division progress for example, in practical application, can according to need and by above-mentioned function distribution by different
Functional unit, module are completed, i.e., the internal structure of described device is divided into different functional unit or module, more than completing
The all or part of function of description.Each functional unit in embodiment, module can integrate in one processing unit, can also
To be that each unit physically exists alone, can also be integrated in one unit with two or more units, it is above-mentioned integrated
Unit both can take the form of hardware realization, can also realize in the form of software functional units.In addition, each function list
Member, the specific name of module are also only for convenience of distinguishing each other, the protection scope being not intended to limit this application.Above system
The specific work process of middle unit, module, can refer to corresponding processes in the foregoing method embodiment, and details are not described herein.
In the above-described embodiments, it all emphasizes particularly on different fields to the description of each embodiment, is not described in detail or remembers in some embodiment
The part of load may refer to the associated description of other embodiments.
Those of ordinary skill in the art may be aware that list described in conjunction with the examples disclosed in the embodiments of the present disclosure
Member and algorithm steps can be realized with the combination of electronic hardware or computer software and electronic hardware.These functions are actually
It is implemented in hardware or software, the specific application and design constraint depending on technical solution.Professional technician
Each specific application can be used different methods to achieve the described function, but this realization is it is not considered that exceed
The scope of the present invention.
In embodiment provided by the present invention, it should be understood that disclosed terminal device and method can pass through it
Its mode is realized.For example, terminal device embodiment described above is only schematical, for example, the module or list
Member division, only a kind of logical function partition, there may be another division manner in actual implementation, for example, multiple units or
Component can be combined or can be integrated into another system, or some features can be ignored or not executed.Another point is shown
The mutual coupling or direct-coupling or communication connection shown or discussed can be through some interfaces, between device or unit
Coupling or communication connection are connect, can be electrical property, mechanical or other forms.
The unit as illustrated by the separation member may or may not be physically separated, aobvious as unit
The component shown may or may not be physical unit, it can and it is in one place, or may be distributed over multiple
In network unit.It can select some or all of unit therein according to the actual needs to realize the mesh of this embodiment scheme
's.
It, can also be in addition, the functional units in various embodiments of the present invention may be integrated into one processing unit
It is that each unit physically exists alone, can also be integrated in one unit with two or more units.Above-mentioned integrated list
Member both can take the form of hardware realization, can also realize in the form of software functional units.
If the integrated unit is realized in the form of SFU software functional unit and sells or use as independent product
When, it can store in a computer readable storage medium.Based on this understanding, the present invention realizes above-described embodiment side
All or part of the process in method can also instruct relevant hardware to complete, the computer by computer program
Program can be stored in a computer readable storage medium, and the computer program is when being executed by processor, it can be achieved that above-mentioned each
The step of a embodiment of the method.Wherein, the computer program includes computer program code, the computer program code
It can be source code form, object identification code form, executable file or certain intermediate forms etc..The computer-readable medium can
With include: can carry the computer program code any entity or device, recording medium, USB flash disk, mobile hard disk, magnetic disk,
CD, computer storage, read-only memory (Read-Only Memory, ROM), random access memory (Random
Access Memory, RAM), electric carrier signal, telecommunication signal and software distribution medium etc..It should be noted that the meter
The content that calculation machine readable medium includes can carry out increase and decrease appropriate according to the requirement made laws in jurisdiction with patent practice,
It such as does not include electric carrier signal and telecommunications according to legislation and patent practice, computer-readable medium in certain jurisdictions
Signal.
Embodiment described above is merely illustrative of the technical solution of the present invention, rather than its limitations;Although referring to aforementioned reality
Applying example, invention is explained in detail, those skilled in the art should understand that: it still can be to aforementioned each
Technical solution documented by embodiment is modified or equivalent replacement of some of the technical features;And these are modified
Or replacement, the spirit and scope for technical solution of various embodiments of the present invention that it does not separate the essence of the corresponding technical solution should all
Between protection scope of the present invention.