CN110213173A - Flow control methods and device, system, server, computer-readable medium - Google Patents

Flow control methods and device, system, server, computer-readable medium Download PDF

Info

Publication number
CN110213173A
CN110213173A CN201910491520.XA CN201910491520A CN110213173A CN 110213173 A CN110213173 A CN 110213173A CN 201910491520 A CN201910491520 A CN 201910491520A CN 110213173 A CN110213173 A CN 110213173A
Authority
CN
China
Prior art keywords
token
flow control
global
currently
local
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.)
Granted
Application number
CN201910491520.XA
Other languages
Chinese (zh)
Other versions
CN110213173B (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.)
Beijing Baidu Netcom Science and Technology Co Ltd
Original Assignee
Beijing Baidu Netcom Science and Technology 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 Beijing Baidu Netcom Science and Technology Co Ltd filed Critical Beijing Baidu Netcom Science and Technology Co Ltd
Priority to CN201910491520.XA priority Critical patent/CN110213173B/en
Publication of CN110213173A publication Critical patent/CN110213173A/en
Application granted granted Critical
Publication of CN110213173B publication Critical patent/CN110213173B/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

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

Present disclose provides a kind of flow control methods, are related to field of cloud calculation, comprising: when receiving service request, judge in local token bucket there is currently token quantity whether be greater than or equal to 1;If judge in local token bucket there is currently token quantity less than 1 when, excess flow control request is sent to global flow control node, so that the global flow control node is according to excess flow control request, judge in corresponding Global token bucket there is currently token quantity whether be greater than or equal to 1;Receive the global flow control node in judging corresponding Global token bucket there is currently token quantity be greater than or equal to 1 when the business processing instruction fed back;It is instructed based on the business processing, according to service request described in preset business logic processing.The disclosure additionally provides volume control device and system, server and computer-readable medium.

Description

Flow control methods and device, system, server, computer-readable medium
Technical field
The embodiment of the present disclosure is related to field of communication technology, in particular to flow control methods and device, system, server, Computer-readable medium.
Background technique
The service that product business externally provides is usually deployed on multiple servers, in order to avoid user's malicious attack, or Person avoids the usage amount of user from exceeding the range that system can carry, and usually requires to carry out flow control for service interface, When such as limiting single user's calling individual interface, it can only call within one second 10 times (10qps), especially pay in user according to flow Scene under.It realizes that flow control is very simple under stand-alone environment, but under distributed environment, takes into account performance, accurate Property and availability be realize flow control difficult point.
Currently, usually there are two types of the modes for realizing flow control under distributed environment: 1, being carried out by redis global Flow control calculates, and specifically executes lua script in redis and realizes sliding window or token bucket scheduling algorithm, divides to realize The flow control of cloth environment.2, by the stream on each Service Instance of number mean allocation of current service example (such as server) Limit is controlled, single machine problem is converted by distributed problem and carries out flow control.If the total flow control limit of current interface is 100qps, clothes Business is deployed with 5 Service Instances, then the flow control limit of corresponding interface is 100/5=20qps, each clothes on each Service Instance Pragmatic example is by being that limitation carries out flow control with 20qps in the sliding window algorithm or token bucket algorithm for locally using single machine System.
Summary of the invention
The embodiment of the present disclosure aims to solve at least one of the technical problems existing in the prior art, provides a kind of flow control Method and device, system, server, computer-readable medium.
In a first aspect, the embodiment of the present disclosure provides a kind of flow control methods, which includes:
When receiving service request, judge in local token bucket there is currently token quantity whether be greater than or equal to 1;
If judge in local token bucket there is currently token quantity less than 1 when, to global flow control node send excess Flow control request, so that the global flow control node is according to excess flow control request, judge in corresponding Global token bucket there is currently Token quantity whether be greater than or equal to 1;
Receive the global flow control node in judging corresponding Global token bucket there is currently token quantity be greater than Or the business processing instruction fed back when equal to 1;
It is instructed based on the business processing, according to service request described in preset business logic processing.
In some embodiments, described when receiving service request, judge in local token bucket there is currently token Whether quantity is greater than or equal to before 1, further includes:
When receiving service request, judge in the local Global token bucket cached in advance there is currently token quantity be It is no to be greater than or equal to 1;
If judge in the local Global token bucket cached in advance there is currently token quantity be greater than or equal to 1 when, hold Row judge local token bucket in there is currently token quantity whether be greater than or equal to 1 the step of;
If judge in the local Global token bucket cached in advance there is currently token quantity less than 1 when, return to business Request failure message.
In some embodiments, described when receiving service request, judge in local token bucket there is currently token Whether quantity is greater than or equal to after 1, further includes:
If judge in local token bucket there is currently token quantity be greater than or equal to 1 when, patrolled according to preset business Collect the processing service request;
By in local token bucket there is currently token quantity carry out subtracting 1 processing.
In some embodiments, it is described by local token bucket there is currently token quantity carry out subtracting 1 processing after, also Include:
The current count value of preset service request counter is carried out plus 1 is handled;
Judge whether the current count value of the service request counter is greater than or equal to the first preset threshold;
If judge that the current count value of the service request counter is greater than or equal to the first preset threshold, Xiang Suoshu Global flow control node sends that token is synchronous to deduct request, and the token is synchronous, and to deduct request include token number to be deducted, it is described to The current count value that token number is equal to the service request counter is deducted, so that the global flow control node base is synchronous in token Deduct request, according in corresponding Global token bucket there is currently token quantity and token number to be deducted difference, update complete Office token bucket in there is currently token quantity;
The current count value of the service request counter is zeroed out processing.
In some embodiments, the global flow control node is after feedback traffic process instruction, by corresponding global order In board bucket there is currently token quantity carry out subtracting 1 processing, with update in Global token bucket there is currently token quantity.
In some embodiments, in the global flow control node updates Global token bucket there is currently token quantity it Afterwards, the flow control methods further include:
Receive the global flow control node in updating Global token bucket there is currently token quantity after send it is complete Office token bucket in there is currently token quantity;
Update in the local Global token bucket cached in advance there is currently token quantity.
In some embodiments, after the synchronous deduction request to the overall situation flow control node transmission token, further includes:
The current count value of preset synchronization request counter is carried out plus 1 is handled;
Judge whether the current count value of the synchronization request counter is greater than or equal to the second preset threshold;
If judge that the current count value of the synchronization request counter is greater than or equal to the second preset threshold, obstruction is new Service request, until the global flow control node is completed, token is synchronous to be deducted.
Second aspect, the embodiment of the present disclosure provide a kind of volume control device, which includes:
Receiving module, for receiving service request;
Judgment module, for when the receiving module receives service request, judge in local token bucket there is currently Token quantity whether be greater than or equal to 1;
Sending module, if for judgment module judge in local token bucket there is currently token quantity less than 1 when, to Global flow control node sends excess flow control request, so that the global flow control node is according to excess flow control request, judges corresponding In Global token bucket there is currently token quantity whether be greater than or equal to 1;
Service Processing Module is currently deposited in judging corresponding Global token bucket for receiving the global flow control node Token quantity be greater than or equal to 1 when feed back business processing instruction;It is instructed based on the business processing, according to preset industry Service request described in logical process of being engaged in.
In some embodiments, the judgment module be also used in judging local token bucket there is currently token quantity Whether be greater than or equal to before 1, judge in the local Global token bucket cached in advance there is currently token quantity whether be greater than Or it is equal to 1;If judge in the local Global token bucket cached in advance there is currently token quantity be greater than or equal to 1 when, hold Row judge local token bucket in there is currently token quantity whether be greater than or equal to 1 the step of;
Judge in the local Global token bucket cached in advance currently if the Service Processing Module is also used to judgment module When existing token quantity is less than 1, service request failed message is returned.
In some embodiments, which further includes local token update module;
If the Service Processing Module be also used to judgment module judge in local token bucket there is currently token quantity When more than or equal to 1, according to service request described in preset business logic processing;
The local token update module is used in the Service Processing Module according to described in preset business logic processing After service request, by local token bucket there is currently token quantity carry out subtracting 1 processing.
In some embodiments, which further includes service request counting module;
The service request counting module be used for the local token update module by local token bucket there is currently Token quantity carry out subtracting 1 processing after, the current count value of preset service request counter is carried out plus 1 processing;
The judgment module is also used to the current of preset service request counter in the service request counting module Count value carries out after adding 1 processing, and it is pre- to judge whether the current count value of the service request counter is greater than or equal to first If threshold value;
If the sending module, which is also used to judgment module, judges that the current count value of the service request counter is greater than Or when being equal to the first preset threshold, the synchronous deduction request of token is sent to the global flow control node, the token is synchronous to be deducted Request includes token number to be deducted, and the token number to be deducted is equal to the current count value of the service request counter, for The overall situation flow control node base deducts request in token is synchronous, according in corresponding Global token bucket there is currently token quantity With the difference of token number to be deducted, update Global token bucket in there is currently token quantity;
The service request counting module is also used to send token to the global flow control node in the sending module same After step deducts request, the current count value of the service request counter is zeroed out processing.
In some embodiments, the global flow control node is after feedback traffic process instruction, by corresponding global order In board bucket there is currently token quantity carry out subtracting 1 processing, with update in Global token bucket there is currently token quantity.
In some embodiments, which further includes cache module, and the cache module is described for receiving Global flow control node in updating Global token bucket there is currently token quantity after currently deposit in the Global token bucket that sends Token quantity;Update in the local Global token bucket cached in advance there is currently token quantity.
In some embodiments, going back volume control device further includes synchronization request counting module and blocking module;
The synchronization request counting module is used to send the synchronous deduction of token to the global flow control node in sending module After request, the current count value of preset synchronization request counter is carried out plus 1 is handled;
The judgment module is also used to the current of preset synchronization request counter in the synchronization request counting module Count value carries out after adding 1 processing, and it is pre- to judge whether the current count value of the synchronization request counter is greater than or equal to second If threshold value;
If the blocking module for judgment module judge the current count value of the synchronization request counter be greater than or When equal to the second preset threshold, block new service request, token is synchronous to be deducted until the global flow control node is completed.
The third aspect, the embodiment of the present disclosure provide a kind of flow control system, which includes multiple services Example and global flow control node, the Service Instance includes volume control device provided by aforementioned any embodiment.
Fourth aspect, the embodiment of the present disclosure provide a kind of server, which includes:
One or more processors;
Storage device is stored thereon with one or more programs;
When one or more of programs are executed by one or more of processors, so that one or more of places It manages device and realizes flow control methods provided by aforementioned any embodiment.
5th aspect, the embodiment of the present disclosure provide a kind of computer-readable medium, are stored thereon with computer program, In, described program, which is performed, realizes flow control methods provided by aforementioned any embodiment.
The flow control methods and device, system, server, computer-readable medium that the embodiment of the present disclosure provides, are based on Token bucket algorithm carries out flow control by Service Instance and global flow control node, to realize higher flow control Performance and availability, meanwhile, improve the accuracy of flow control.
Detailed description of the invention
Attached drawing is used to provide to further understand the embodiment of the present disclosure, and constitutes part of specification, with this public affairs The embodiment opened is used to explain the disclosure together, does not constitute the limitation to the disclosure.By reference to attached drawing to detailed example reality It applies example to be described, the above and other feature and advantage will become apparent those skilled in the art, in the accompanying drawings:
Fig. 1 is a kind of flow chart for flow control methods that the embodiment of the present disclosure provides;
Fig. 2 is the flow chart for another flow control methods that the embodiment of the present disclosure provides;
Fig. 3 is the flow chart for another flow control methods that the embodiment of the present disclosure provides;
Fig. 4 is the flow chart for another flow control methods that the embodiment of the present disclosure provides;
Fig. 5 is the flow chart for another flow control methods that the embodiment of the present disclosure provides;
Fig. 6 is a kind of structural schematic diagram for volume control device that the embodiment of the present disclosure provides;
Fig. 7 is a kind of structural schematic diagram for flow control system that the embodiment of the present disclosure provides.
Specific embodiment
To make those skilled in the art more fully understand the technical solution of the disclosure, the disclosure is mentioned with reference to the accompanying drawing Flow control methods and device, system, server, the computer-readable medium of confession are described in detail.
Example embodiment will hereinafter be described more fully hereinafter with reference to the accompanying drawings, but the example embodiment can be with difference Form embodies and should not be construed as being limited to embodiment set forth herein.Conversely, the purpose for providing these embodiments is It is thoroughly and complete to make the disclosure, and those skilled in the art will be made to fully understand the scope of the present disclosure.
As it is used herein, term "and/or" includes any and all combinations of one or more associated listed entries.
Term as used herein is only used for description specific embodiment, and is not intended to limit the disclosure.As used herein , "one" is also intended to "the" including plural form singular, unless in addition context is expressly noted that.It will also be appreciated that Be, when in this specification use term " includes " and/or " by ... be made " when, specify there are the feature, entirety, step, Operation, element and/or component, but do not preclude the presence or addition of other one or more features, entirety, step, operation, element, Component and/or its group.
Embodiment described herein can be by the idealized schematic diagram of the disclosure and reference planes figure and/or sectional view are retouched It states.It therefore, can be according to manufacturing technology and/or tolerance come modified example diagram.Therefore, embodiment is not limited to reality shown in the drawings Apply example, but the modification of the configuration including being formed based on manufacturing process.Therefore, the area illustrated in attached drawing, which has, schematically to be belonged to Property, and the shape in area as shown in the figure instantiates the concrete shape in the area of element, but is not intended to restrictive.
Unless otherwise defined, the otherwise meaning of all terms (including technical and scientific term) used herein and this field The normally understood meaning of those of ordinary skill is identical.It will also be understood that such as those those of limit term in common dictionary and answer When being interpreted as having and its consistent meaning of meaning under the background of the relevant technologies and the disclosure, and will be not interpreted as having There are idealization or excessively formal meaning, unless clear herein so limit.
Flow control methods provided by the embodiment of the present disclosure can be executed by volume control device, which can be with It is realized by way of software and/or hardware, which can integrate in server, electronic equipment.
Flow control methods provided by the embodiment of the present disclosure, for realizing flow control under distributed environment.Dividing Under cloth environment, the service that product business externally provides is usually deployed on multiple Service Instances, for example, Service Instance is service Device.In the embodiments of the present disclosure, volume control device can integrate in Service Instance, to realize that the embodiment of the present disclosure is mentioned The flow control methods of confession.
Fig. 1 is a kind of flow chart for flow control methods that the embodiment of the present disclosure provides, as shown in Figure 1, the flow control Method includes:
Step 11 is directed to each Service Instance, which judges in local token bucket when receiving service request There is currently token quantity whether be greater than or equal to 1, if so, execute step 12, otherwise, execute step 13.
In the embodiments of the present disclosure, it under distributed environment, is cached on each Service Instance (such as server) corresponding Token bucket, the token bucket are referred to as local token bucket in the embodiments of the present disclosure;Correspondingly, being cached on global flow control node pair The token bucket answered, the token bucket are referred to as Global token bucket in the embodiments of the present disclosure.
Assuming that service interface is correspondingly arranged on n (n is more than or equal to 2 positive integer) a service under distributed environment Example, it is assumed that the flow control amount of service interface is Q, and the query rate per second (QPS) of service interface is Q, i.e. global flow control amount For Q, then the maximum token quantity in Global token bucket is Qa=Q, for example, Q is 100, then Qa=Q=100;For each service Example, the local flow control amount that can preset the correspondence of each Service Instance service interface is q=Q/n, each service reality The query rate per second (QPS) of example is q, then the maximum token quantity in local token bucket is qa=q, for example, Q is 100, n=5, Then q=100/5=20, qa=q=20.Under init state, the available token quantity in Global token bucket is Qa=Q, Available token quantity in local token bucket is qa=q.In the embodiments of the present disclosure, the flow control amount of service interface can manage Solution is the quantity of the service interface (such as per second in) manageable service request within a certain period of time, correspondingly, the service The local flow control amount of each Service Instance corresponding to interface is it can be appreciated that each Service Instance is (such as every within a certain period of time In second) quantity of manageable service request.
For example, service interface be short message service interface, service request be short message send service request, Service Instance be for Dispose the server of short message service.
In a step 11, for each Service Instance (such as server), which sentences when receiving service request Break in corresponding local token bucket there is currently token quantity whether be greater than or equal to 1, otherwise held if so, executing step 12 Row step 13.In other words, which judges that the flow control amount of local current residual is (initial when receiving service request The flow control amount of local current residual is q) whether to be greater than or equal to 1 under change state, if so, otherwise executing step 12 executes step Rapid 13.
In the embodiments of the present disclosure, global flow control node can be Redis server.
Step 12, the Service Instance are according to service request described in preset business logic processing.
In the embodiments of the present disclosure, for each Service Instance, which judges in corresponding local token bucket There is currently token quantity be greater than or equal to 1 when, show in local token bucket there are also available token, i.e., local flow control amount It does not run out also currently, the corresponding service interface of the Service Instance currently can still be called, and therefore, the Service Instance is according to pre- If the service request that is currently received of business logic processing.
Step 13, the Service Instance send excess flow control request to global flow control node.
In the embodiments of the present disclosure, for each Service Instance, if the Service Instance judges corresponding local token bucket In there is currently token quantity less than 1 when, show in local token bucket current without available token, i.e., local flow control volume Degree has currently run out, therefore requests excess flow control to global flow control node.
Step 14, global flow control node according to excess flow control request, judge in corresponding Global token bucket there is currently Whether token quantity is greater than or equal to 1, if so, executing step 15, otherwise global flow control node returns to industry by the Service Instance Business request failure message.
At step 14, which judges to correspond to after receiving the excess flow control request of the Service Instance Global token bucket in there is currently token quantity whether be greater than or equal to 1, that is, judge the flow control amount of global current residual Whether (the flow control amount of global current residual is Q under init state) is greater than or equal to 1, if the overall situation flow control node is judged In corresponding Global token bucket there is currently token quantity be greater than or equal to 1 when, show in Global token bucket it is current also Available token, i.e. global flow control amount do not run out also currently, even if without available token (this in local token bucket The flow control amount on ground has been used up), which still can be processed, therefore executes step 15, sends business to the Service Instance Process instruction, to handle the service request by the Service Instance.
If the overall situation flow control node judge in corresponding Global token bucket there is currently token quantity less than 1 when, table Current also without available token in bright Global token bucket, i.e. global flow control amount has currently also run out, therefore this is complete Office's flow control node can return to service request failed message by the Service Instance.
Step 15, global flow control node are to the Service Instance feedback traffic process instruction.
Step 16, the Service Instance are instructed based on business processing, according to the preset business logic processing service request.
Flow control methods provided by the embodiment of the present disclosure are based on token bucket algorithm, are combined by Service Instance global Flow control node carries out flow control, thus realize the performance and availability of higher flow control, meanwhile, improve flow The accuracy of control.
In some embodiments, which can incite somebody to action after according to the preset business logic processing service request A token in local token bucket abandons, and by local token bucket there is currently token quantity carry out subtracting 1 processing, update In local token bucket there is currently token quantity, that is, update the flow control amount of local current residual.Meanwhile updating local enable In board bucket there is currently token quantity after, can also request token is synchronous to deduct to global flow control node, so that entirely Office's flow control node can in its Global token bucket of synchronized update there is currently token quantity, that is, update the stream of global current residual Control amount, so as to guarantee the accuracy of flow control, the problem for avoiding the error of flow control excessive.Fig. 2 is the disclosure The flow chart for another flow control methods that embodiment provides, as shown in Fig. 2, the embodiment of the present disclosure and previous embodiment are not It is with place, after the step 12, further includes:
Step 121a, the Service Instance by local token bucket there is currently token quantity carry out subtracting 1 processing.
In step 121a, the Service Instance is after according to the preset business logic processing service request, by local order A token in board bucket abandons, and by local token bucket there is currently token quantity carry out subtracting 1 processing, update local enable In board bucket there is currently token quantity, that is, update the flow control amount of local current residual.
Step 122a, the Service Instance carries out the current count value of preset service request counter plus 1 is handled.
In step 122, which carries out the current count value of preset service request counter plus 1 is handled. Wherein, the current count value of preset service request counter is for indicating the current processed service request of the Service Instance Quantity.In the embodiments of the present disclosure, the count value of preset service request counter is 0 under init state.
Step 123a, it is pre- to judge whether the current count value of service request counter is greater than or equal to first for the Service Instance If threshold value, if so, executing step 124a, otherwise wait for receiving new service request.
In the embodiments of the present disclosure, the first preset threshold is threshold of the triggering to the synchronous deduction of global flow control node request token Value.
In step 123a, which judges the current count through the updated service request counter of step 122a Whether value is greater than or equal to the first preset threshold, if so, executing step 124a, otherwise waits for receiving new service request.Wherein, First preset threshold can be configured according to actual needs, and in some embodiments, the first preset threshold is equal to qa*0.1, In, qa is the maximum token quantity of the corresponding local token bucket of the Service Instance, and qa=q, q are the corresponding local of the Service Instance Flow control amount.In some embodiments, the first preset threshold may be arranged as qa*m, wherein 0 < m < 1, for example, m is 0.01. In the embodiments of the present disclosure, the first preset threshold is smaller, and the synchronous frequency deducted of request token is higher, the accuracy of flow control It is higher.
Step 124a, the Service Instance sends synchronous deduct of token to global flow control node and requests, and synchronous deduct of token is asked It asks including token number to be deducted.
In step 124a, when the Service Instance judge the current count value of service request counter up to or over When the threshold value, the step of deducting synchronous to global flow control node request token is triggered, i.e., it is same to send token to global flow control node Step deducts request.Wherein, synchronous deduct of token requests to include token number to be deducted, and token number to be deducted is counted equal to service request The current count value of device.
Step 125a, the current count value of service request counter is zeroed out processing by the Service Instance.
In step 125a, token is synchronous deduct after the completion of, the Service Instance is by the current meter of service request counter Numerical value is zeroed out processing, and waits new service request to be received.
Step 126a, global flow control node base is requested in synchronous deduct of token, according to current in corresponding Global token bucket The difference of existing token quantity and token number to be deducted, update Global token bucket in there is currently token quantity.
In step 126a, after global flow control node receives the synchronous deduction request of token, in corresponding Global token bucket The middle token for deducting identical with token number to be deducted quantity, and by corresponding Global token bucket there is currently token quantity Subtract token number to be deducted, with update in Global token bucket there is currently token quantity, that is, update the stream of global current residual Control amount.
In the embodiments of the present disclosure, each Service Instance is tactful by the synchronous deduction of token of step 121a to step 126a, So that global flow control node calculate update in Global token bucket there is currently token quantity (the flow control volume of global current residual Degree) error be able to maintain within 20%, to improve the accuracy of flow control, avoid the error of flow control excessive The problem of.
In some embodiments, after the step 12, further includes:
Step 121b, the Service Instance by local token bucket there is currently token quantity carry out subtracting 1 processing.
It can be found in the description of above-mentioned steps 121a about the specific descriptions of this step, details are not described herein again.
Step 122b, the Service Instance carries out the current count value of preset service request counter plus 1 is handled.
It can be found in the description of above-mentioned steps 122a about the specific descriptions of this step, details are not described herein again.
Step 123b, the Service Instance judge in local token bucket there is currently token quantity whether less than 1, if so, Step 124b is executed, otherwise waits for receiving new service request.
Step 124b, the Service Instance sends synchronous deduct of token to global flow control node and requests, and synchronous deduct of token is asked It asks including token number to be deducted.
It can be found in the description of above-mentioned steps 124a about the specific descriptions of this step 124b, details are not described herein again.
Step 125b, the current count value of service request counter is zeroed out processing by the Service Instance.
It can be found in the description of above-mentioned steps 125a about the specific descriptions of this step 125b, details are not described herein again.
Step 126b, global flow control node base is requested in synchronous deduct of token, according to current in corresponding Global token bucket The difference of existing token quantity and token number to be deducted, update Global token bucket in there is currently token quantity.
It can be found in the description of above-mentioned steps 126a about the specific descriptions of this step 126b, details are not described herein again.
Fig. 3 is the flow chart for another flow control methods that the embodiment of the present disclosure provides, as shown in figure 3, the disclosure is real Apply example and previous embodiment the difference is that, before step 11, further includes:
Step 10 is directed to each Service Instance, which judges local caching in advance when receiving service request Global token bucket in there is currently token quantity whether be greater than or equal to 1, if so, execute step 11, otherwise return to business Request failure message.
In the embodiments of the present disclosure, each Service Instance in the local Global token bucket of caching in advance there is currently token number Amount caches the flow control amount of global current residual in advance.Under init state, in Global token bucket there is currently token Quantity is the maximum token quantity Qa in Global token bucket, and the flow control amount of global current residual is that global flow control amount is Q, Qa=Q.
In step 10, for each Service Instance, which first determines whether local when receiving service request In the Global token bucket cached in advance there is currently token quantity whether be greater than or equal to 1, if so, execute step 11, into one Step judge in local token bucket there is currently token quantity whether be greater than or equal to 1, otherwise, show in Global token bucket currently Without available token, therefore return to service request failed message.
In some embodiments, after step 15, further includes:
Step 151, global flow control node by corresponding Global token bucket there is currently token quantity carry out subtracting 1 place Reason, with update in Global token bucket there is currently token quantity.
In step 151, global flow control node, can be by correspondence to after the Service Instance feedback traffic process instruction Global token bucket in a token abandon, and by corresponding Global token bucket there is currently token quantity subtract 1 Processing, with update in Global token bucket there is currently token quantity, that is, update the flow control amount of global current residual.
Fig. 4 is the flow chart for another flow control methods that the embodiment of the present disclosure provides, in some embodiments, in step After rapid 151, and after step 126a, as shown in figure 4, the flow control methods further include:
Step 1261, global flow control node to the Service Instance send in updated Global token bucket there is currently order Board quantity.
In step 1261, the Service Instance receive global flow control node in updating Global token bucket there is currently order In the Global token bucket sent after board quantity there is currently token quantity.
Step 1262, the Service Instance update in the local Global token bucket cached in advance there is currently token quantity.
In step 1262, the Service Instance in receiving Global token bucket there is currently token quantity after, will be In the Global token bucket received in step 1262 there is currently token quantity replace the local Global token cached in advance In bucket there is currently token quantity, thus update in the local Global token bucket cached in advance there is currently token quantity, And wait new service request to be received.
Above-mentioned steps 1261 and step are also executed after above-mentioned steps 126a it should be noted that illustrating only in Fig. 4 1262 the case where, the case where not showing that step 151 and execute above-mentioned steps 1261 and step 1262 after step 151.
In some embodiments, after step 124a, further includes:
Step 1241a, the Service Instance carries out the current count value of preset synchronization request counter plus 1 is handled.
In some embodiments, synchronization request counter is preset on each Service Instance, which uses It requests to count in synchronous deduct of the token for sending the Service Instance.In step 1241a, sent out to global flow control node After sending token is synchronous to deduct request, the current count value of preset synchronization request counter will add at 1 by Service Instance Reason.Wherein, the current count value of synchronization request counter is asked for indicating that the Service Instance has currently sent synchronous deduct of token The quantity asked.Under init state, the count value of the synchronization request counter is 0.
Step 1242a, the Service Instance judges whether the current count value of synchronization request counter is greater than or equal to second Preset threshold, if so, the service request that obstruction is new, until global flow control node is completed, token is synchronous to be deducted, and otherwise waits for receiving New service request.
Wherein, the second preset threshold can be configured according to actual needs, in some embodiments, the second preset threshold It can be set to 2, in some embodiments, the second preset threshold may be arranged as 1 etc., and the second preset threshold is usually no more than 2.In step 1242a, it is pre- which judges whether the current count value of synchronization request counter is greater than or equal to second If threshold value, if judge that the current count value of synchronization request counter is greater than or equal to the second preset threshold, block new industry Business request, until global flow control node is completed, token is synchronous to be deducted, that is, judges that the current count value of synchronization request counter is big When the second preset threshold, which will currently not receive and handle new service request, until global flow control section Point completes the synchronous deduction of token, and after global flow control node completion token is synchronous to be deducted, which counts synchronization request The nonce counter of device is zeroed out processing, then continues waiting for receiving new service request.
In extreme circumstances, in a short time, if the received service request amount of a Service Instance is very big, and other are serviced The received service request amount of example all very littles, it is assumed that the big Service Instance of received service request amount is practical have run out it is global Flow control amount, but other Service Instances carry out the synchronous deduction of token due to failing in time, so that the Global token bucket of local cache There is currently token quantity do not obtain timely updates, then the Global token bucket of local cache there is currently token quantity Value may be still very big, at this moment when other Service Instances receive a large number of services request, it will lead to global reception business The amount of request is up to twice of state of the flow control amount close to the overall situation, or even the flow control amount considerably beyond the overall situation.To keep away Exempt from this phenomenon to occur, the embodiment of the present disclosure is by executing step 1241a and step 1242a, thus after step 124a Can be obtained in time by global flow control node and update in the Global token bucket of local cache there is currently token quantity, keep away Exempt from a large amount of excess to occur using phenomenon.
To avoid above-mentioned phenomenon from occurring, in some embodiments, for each Service Instance, which can also be tieed up The synchronous state set for deducting request of a token is protected, when requesting token is synchronous to deduct every time, which all can be in state set Label in one request of middle record, removes label after the completion of request.If the quantity of the label in state Centralized requests is big When the second preset threshold (being usually no more than 2), then block the processing of new service request, global flow control node is waited to complete to enable It is discharged again after the synchronous deduction of board, thus can obtain by global flow control node in time and update the Global token of local cache Bucket in there is currently token quantity, avoid a large amount of excess from occurring using phenomenon.
In some embodiments, under distributed environment, excess token bucket, excess is being locally located in each Service Instance Maximum token quantity in token bucket is q*0.2.When the failure of global flow control node leads to unavailable, Service Instance is being connect When receiving service request, if judge in local token bucket there is currently token quantity less than 1 when, Service Instance passes through request The token obtained in excess token bucket carries out flow control.
In some embodiments, the health status that each Service Instance is monitored by external registration center, when service is real When delay machine occurs in example, each Service Instance and global flow control node survived by registration center to other issue the clothes currently survived Pragmatic example sum, notifies the Service Instance of survival to adjust the maximum token quantity of local token bucket.For example, it is assumed that global flow control Amount is Q, and the maximum token quantity in Global token bucket is Qa=Q, and the total quantity of Service Instance is n, when all Service Instances When normal, the local flow control amount of each Service Instance is q=Q/n, and the maximum token quantity in local token bucket is qa=q= Q/n;And when registration center has monitored 1 Service Instance delay machine, registration center issues to other Service Instances survived to work as The total quantity of the Service Instance of preceding survival is n-1, then the Service Instance respectively survived is according to the sum of the Service Instance currently survived It measures n-1 and updates local flow control amount q=Q/ (n-1), correspondingly, the maximum token quantity in local token bucket is qa=q=Q/ (n-1)。
Flow control methods provided by the embodiment of the present disclosure are less than in aspect of performance in flow (service request amount) (when local flow control amount q), the advantage that can make full use of local flow control carries out flow control to local flow control threshold value, to reach The performance of higher flow control;In terms of availability, flow control does not completely depend on (the redis service of global flow control node Device), either global flow control node (redis server) failure or Service Instance failure can have corresponding fault-tolerant measure, Effectively preventing global flow control node (redis server) failure leads to the unavailable phenomenon of operation system, and stream can be substantially improved Measure the availability of control;In terms of accuracy, beyond local flow control threshold value, (flow of local flow control amount q) will pass through global flow Control node, which carries out flow control, can will exceed about definite value (global flow control amount by the design of distributed token bucket algorithm Q part) controls within 20%, belongs to tolerance interval.Therefore, flow control methods provided by the embodiment of the present disclosure, It ensure that higher performance and availability, and by Accuracy control in reasonable range, can support service generation ring comprehensively Border uses.
Fig. 5 is the flow chart for another flow control methods that the embodiment of the present disclosure provides, as shown in figure 5, the flow control Method processed includes:
Step 20 is directed to each Service Instance, and whether which judges current time when receiving service request Next less than the local Global token bucket cached in advance starts to calculate the fiducial time for being put into token quantity, if so, returning Otherwise service request failed message executes step 21.
In the embodiments of the present disclosure, it under distributed environment, is cached on each Service Instance (such as server) corresponding Token bucket, the token bucket are referred to as local token bucket in the embodiments of the present disclosure;Correspondingly, being cached on global flow control node pair The token bucket answered, the token bucket are referred to as Global token bucket in the embodiments of the present disclosure.
In the embodiments of the present disclosure, before step 20, presetting global flow control amount is Q, initializes global enable Maximum token quantity in board bucket is Qa=Q, and the next of initialization Global token bucket starts to calculate the base for being put into token quantity (NextFreeTicketTime) is Gnt=0 between punctual, and chronomere is microsecond.
Assuming that service interface is correspondingly arranged on n (n is more than or equal to 2 positive integer) a service under distributed environment Example, before step 20, presetting the corresponding local flow control amount of each Service Instance is q=Q/n, initializes each clothes Maximum token quantity in the corresponding local token bucket of pragmatic example is qa=q, initializes local the next of token bucket and starts to count The fiducial time (NextFreeTicketTime) that calculation is put into token quantity is nt=Gnt, and chronomere is microsecond.
Before step 20, the current count value of the corresponding preset service request counter of each Service Instance is initialized C=0 sets the first preset threshold as s=q*0.1, sets the rate that each token is put into Global token bucket/local token bucket For r (a/microsecond).Wherein, the rate r that each token is put into Global token bucket/local token bucket can be set according to the actual situation It sets, the embodiment of the present disclosure is not construed as limiting this.
In the embodiments of the present disclosure, for each Service Instance, the Service Instance when receiving service request, pass through by The next of current time CurrentTime and pre-set Global token bucket starts to calculate when being put into the benchmark of token quantity Between Gnt be compared, if current time CurrentTime it is next start to calculate be put into fiducial time of token quantity After Gnt, then show have more tokens available, therefore can perform the next step suddenly, to obtain token;And if current time CurrentTime it is next start calculate be put into the fiducial time Gnt of token quantity before, then show do not have in Global token bucket There is available token, therefore directly returns to service request failed message.
Specifically, being directed to each Service Instance, which judges current time when receiving service request Whether CurrentTime, which is less than the next of the Global token bucket of local cache, starts to calculate when being put into the benchmark of token quantity Between, if so, show current time CurrentTime it is next start calculate be put into the fiducial time Gnt of token quantity before, Therefore return service request failed message, otherwise, show current time CurrentTime it is next start calculate be put into token number After the fiducial time Gnt of amount, therefore execute step 21.
Step 21, the Service Instance obtain since local token bucket it is next calculate be put into the benchmark of token quantity when Between to current time period in newly generated token quantity, and according to token quantity newly generated in the period update this In ground token bucket there is currently token quantity.
Specifically, which calculates current time CurrentTime and starts to calculate with local the next of token bucket The difference is put into Global token multiplied by pre-set each token by the difference being put between the fiducial time nt of token quantity Rate r in bucket/local token bucket, obtain since local token bucket it is next calculate and be put into fiducial time of token quantity Newly generated token quantity freshPermits1, i.e. freshPermits1=in the period of current time (CurrentTime-nt)*r。
After obtaining newly generated token quantity freshPermits1, in local token bucket there is currently token Quantity qa and newly generated token quantity freshPermits1 carries out summation process, obtains corresponding summed result, i.e. qa=qa + freshPermits1 takes the reckling in the maximum token quantity qa of the summed result and local token bucket as local token In bucket there is currently token quantity, and perform the next step rapid.
Step 22, the Service Instance judge in the local Global token bucket cached in advance there is currently token quantity whether More than or equal to 1, if so, executing step 23, service request failed message is otherwise returned to.
In the embodiments of the present disclosure, each Service Instance in the local Global token bucket of caching in advance there is currently token number Amount caches the flow control amount of global current residual in advance.Under init state, in Global token bucket there is currently token Quantity is the maximum token quantity Qa in Global token bucket, and the flow control amount of global current residual is that global flow control amount is Q, Qa=Q.
In step 22, the Service Instance first determine whether in the local Global token bucket cached in advance there is currently token Whether quantity Qa is greater than or equal to 1, if so, execute step 23, further judge in local token bucket there is currently token number Whether amount qa is greater than or equal to 1, otherwise, shows currently without available token in Global token bucket, therefore returns to service request and lose Lose message.
Step 23, the Service Instance judge in local token bucket there is currently token quantity whether be greater than or equal to 1, if It is to execute step 24, otherwise, executes step 34.
Description can be found in the description in above-described embodiment to step 11 as described in this step 23, and details are not described herein again.
Step 24, the Service Instance are according to service request described in preset business logic processing.
Description can be found in the description in above-described embodiment to step 12 as described in this step 24, and details are not described herein again.
Step 25, the Service Instance by local token bucket there is currently token quantity carry out subtracting 1 processing.
Specifically, which, will be in local token bucket after according to the preset business logic processing service request A token abandon, and by local token bucket there is currently token quantity qa carry out subtracting 1 processing, even qa=qa-1, Update in local token bucket there is currently token quantity qa, that is, update the flow control amount q of local current residual.
Step 26, the Service Instance carries out the current count value of preset service request counter plus 1 is handled.
In step 26, which carries out the current count value c of preset service request counter plus 1 is handled, Even c=c+1.Other descriptions about this step 26 can be found in the description in above-described embodiment to step 122a, herein no longer It repeats.
Step 27, the Service Instance update the next of local token bucket and start to calculate when being put into the benchmark of token quantity Between.
Specifically, in step 27, the Service Instance enable local token bucket it is next start to calculate be put into token quantity Fiducial time nt be equal to current time CurrentTime, with update local token bucket it is next start to calculate be put into token The fiducial time nt of quantity, while last service request time LastRequestTime is recorded as current time CurrentTime, i.e. LastRequestTime=CurrentTime.
It is default that step 28, the Service Instance judge whether the current count value of service request counter is greater than or equal to first Threshold value otherwise waits for receiving new service request if so, executing step 29, when new service request arrives, executes step 20。
In a step 28, which judges whether the current count value c of service request counter is greater than or equal to One preset threshold s otherwise waits for receiving new service request if so, executing step 29, when new service request arrives, holds Row step 20.Other descriptions about this step 28 can be found in the description in above-described embodiment to step 123a, no longer superfluous herein It states.
Step 29, the Service Instance send synchronous deduct of token to global flow control node and request, and token is synchronous to deduct request Including token number to be deducted.
Specifically, synchronous deduct of token requests to include token number to be deducted and synchronization request time RequestTime1.Its In, token number cs to be deducted is equal to the current count value c of service request counter, and the synchronization request time, RequestTime1 was equal to Last service request time LastRequestTime.It is right in above-described embodiment that other descriptions about this step 29 can be found in The description of step 124a, details are not described herein again.
The current count value of service request counter is zeroed out processing by step 30, the Service Instance, and is waited to be received New service request executes step 20 when new service request arrives.
In step 30, which is zeroed out processing for the current count value of service request counter, even industry The current count value c=0 of business request counter.
In some embodiments, synchronization request counter is preset on each Service Instance, which uses It requests to count in synchronous deduct of the token for sending the Service Instance.In the Service Instance working as service request counter After preceding count value is zeroed out processing, which add at 1 by the current count value of preset synchronization request counter Reason, then, judges whether the current count value of synchronization request counter is greater than or equal to the second preset threshold, if so, obstruction is new Service request, until global flow control node is completed, token is synchronous to be deducted, and otherwise waits for receiving new service request.In the part The specific descriptions of appearance can be found in the description in previous embodiment to step 126 and step 127, and details are not described herein again.
Step 31, global flow control node base are requested in synchronous deduct of token, are currently deposited according in corresponding Global token bucket Token quantity and token number to be deducted difference, update Global token bucket in there is currently token quantity.
Specifically, global flow control node base deducts request in token is synchronous, deducted in corresponding Global token bucket with to The token for deducting the identical quantity of token number cs, enable in Global token bucket there is currently token quantity Qa=Qa-cs, to update In Global token bucket there is currently token quantity, that is, update the flow control amount Q of global current residual, and update Global token bucket It is next start to calculate be put into the fiducial time Gnt of token quantity, enable Global token bucket it is next start to calculate be put into order The fiducial time Gnt of board quantity is equal to current time CurrentTime.
Step 32, global flow control node in updating Global token bucket there is currently token quantity after to service reality Example send Global token bucket in there is currently token quantity.
Specifically, in the step 32, global flow control node update Global token bucket in there is currently token quantity it Afterwards to the Service Instance send Global token bucket in there is currently token quantity Qa and the next of Global token bucket start to count Calculate the fiducial time Gnt for being put into token quantity.
Step 33, the Service Instance update in the local Global token bucket cached in advance there is currently token quantity, and Etc. new service request to be received, when new service request arrives, step 20 is executed.
Specifically, the Service Instance according in the Global token bucket received in the step 32 there is currently token quantity Qa and the next of Global token bucket start to calculate the fiducial time Gnt for being put into token quantity, and update locally caches complete in advance Office token bucket in there is currently token quantity and Global token bucket it is next start calculate be put into the benchmark of token quantity when Between, and new service request to be received is waited, when new service request arrives, execute step 20.
Step 34, the Service Instance send excess flow control request to global flow control node, and wherein excess flow control request includes Excess request time.
Wherein, excess request time RequestTime2 is equal to current time CurrentTime.In step 34, the clothes Pragmatic example in judging local token bucket there is currently token quantity qa less than 1 when, show in local token bucket it is current There is no available token, i.e., local flow control amount has not run out currently, therefore requests excess flow control to global flow control node.
Step 35, global flow control node judge whether excess request time is less than Global token according to excess flow control request The next of bucket starts to calculate the fiducial time for being put into token quantity, if so, returning to service request failure by the Service Instance Otherwise message executes step 36.
In step 35, global flow control node is by by excess request time RequestTime2 and the pre-set overall situation Token bucket it is next start to calculate be put into the fiducial time Gnt of token quantity and be compared, if excess request time RequestTime2 it is next start calculate be put into the fiducial time Gnt of token quantity after, then show have more tokens can To obtain, therefore can perform the next step suddenly, to obtain token;And if excess request time RequestTime2 is opened next Begin to calculate and be put into before the fiducial time Gnt of token quantity, then shows there is no available token in Global token bucket, therefore pass through The Service Instance directly returns to service request failed message.
Step 36, global flow control node obtain since Global token bucket it is next calculate and be put into the benchmark of token quantity Newly generated token quantity in time to the period of excess request time, and according to token quantity newly generated in the period Update Global token bucket in there is currently token quantity.
Specifically, global flow control node calculates excess request time RequestTime2 and opens with the next of Global token bucket Begin to calculate the difference being put between the fiducial time Gnt of token quantity, which is put into multiplied by pre-set each token Rate r in Global token bucket/local token bucket, obtain since Global token bucket it is next calculate be put into token quantity Newly generated token quantity freshPermits2 in the period of fiducial time Gnt to excess request time RequestTime2, That is freshPermits2=(RequestTime2-Gnt) * r.
After obtaining newly generated token quantity freshPermits2, in Global token bucket there is currently token Quantity Qa and newly generated token quantity freshPermits2 carries out summation process, obtains corresponding summed result, i.e. Qa=Qa + freshPermits2 takes the reckling in the maximum token quantity Qa of the summed result and Global token bucket as Global token In bucket there is currently token quantity, and perform the next step rapid.
Step 37, global flow control node according to excess flow control request, judge in corresponding Global token bucket there is currently Whether token quantity is greater than or equal to 1, if so, executing step 38, otherwise, returns to service request by the Service Instance and unsuccessfully disappears Breath.
In step 37, if the overall situation flow control node judge in corresponding Global token bucket there is currently token quantity When Qa is greater than or equal to 1, show current there are also available token in Global token bucket, i.e., global flow control amount is not currently also It runs out, even if the service request still may be used without available token (local flow control amount has been used up) in local token bucket With processed, therefore step 38 is executed, business processing instruction is sent to the Service Instance, to handle the business by the Service Instance Request.
If the overall situation flow control node judge in corresponding Global token bucket there is currently token quantity Qa less than 1 when, Show current also without available token in Global token bucket, i.e. global flow control amount has currently also run out, therefore should Global flow control node can return to service request failed message by the Service Instance.
Step 38, global flow control node are by the Service Instance according to the preset business logic processing service request.
Specifically, in step 38, global flow control node in judging corresponding Global token bucket there is currently order To the Service Instance feedback traffic process instruction when board quantity is greater than or equal to 1, so that the Service Instance is based on the business processing Instruction, according to the preset business logic processing service request.
Step 39, global flow control node by corresponding Global token bucket there is currently token quantity carry out subtracting 1 processing, With update in Global token bucket there is currently token quantity.
In step 39, global flow control node, can be by correspondence to after the Service Instance feedback traffic process instruction Global token bucket in a token abandon, and by corresponding Global token bucket there is currently token quantity Qa subtract 1 processing, even Qa=Qa-1, with update in Global token bucket there is currently token quantity, that is, update global current residual Flow control amount, and update the next of Global token bucket and start to calculate the fiducial time Gnt for being put into token quantity, enable Global token The next of bucket starts to calculate the fiducial time Gnt for being put into token quantity equal to excess request time RequestTime2.
Step 40, global flow control node in updating Global token bucket there is currently token quantity after to service reality Example send Global token bucket in there is currently token quantity.
Specifically, in step 40, global flow control node update Global token bucket in there is currently token quantity it Afterwards to the Service Instance send Global token bucket in there is currently token quantity Qa and the next of Global token bucket start to count Calculate the fiducial time Gnt for being put into token quantity.
Step 41, the Service Instance update in the local Global token bucket cached in advance there is currently token quantity, and Etc. new service request to be received, when new service request arrives, step 20 is executed.
Specifically, the Service Instance according in the Global token bucket received in step 40 there is currently token quantity Qa and the next of Global token bucket start to calculate the fiducial time Gnt for being put into token quantity, and update locally caches complete in advance Office token bucket in there is currently token quantity and Global token bucket it is next start calculate be put into the benchmark of token quantity when Between, and new service request to be received is waited, when new service request arrives, execute step 20.
Fig. 6 is a kind of structural schematic diagram for volume control device that the embodiment of the present disclosure provides, as shown in fig. 6, the flow For control device for realizing flow control methods provided by any of the above-described embodiment, which includes: reception mould Block 301, judgment module 302, sending module 303 and Service Processing Module 304.
Wherein, receiving module 301 is for receiving service request.
Judgment module 302 be used for when receiving module 301 receives service request, judge in local token bucket there is currently Token quantity whether be greater than or equal to 1.
If sending module 303 for judgment module 302 judge in local token bucket there is currently token quantity less than 1 When, excess flow control request, which is sent, to global flow control node judges corresponding so that global flow control node is according to excess flow control request In Global token bucket there is currently token quantity whether be greater than or equal to 1.
If Service Processing Module 304 for judgment module 302 judge in local token bucket there is currently token quantity When more than or equal to 1, according to service request described in preset business logic processing;Global flow control node is received to judge to correspond to Global token bucket in there is currently token quantity be greater than or equal to 1 when feed back business processing instruction;Based on business processing Instruction, according to service request described in preset business logic processing.
In some embodiments, judgment module 302 be also used in judging local token bucket there is currently token quantity Whether be greater than or equal to before 1, judge in the local Global token bucket cached in advance there is currently token quantity whether be greater than Or it is equal to 1;If judge in the local Global token bucket cached in advance there is currently token quantity be greater than or equal to 1 when, hold Row judge local token bucket in there is currently token quantity whether be greater than or equal to 1 the step of.
If Service Processing Module 304 be also used to judgment module 302 judge in the local Global token bucket cached in advance when When preceding existing token quantity is less than 1, service request failed message is returned.
In some embodiments, which further includes local token update module 305, and local token updates mould Block 305 is used for after Service Processing Module 304 is according to service request described in preset business logic processing, by local token bucket In there is currently token quantity carry out subtracting 1 processing.
In some embodiments, which further includes service request counting module 306, service request count module Block 306 be used for local token update module 305 by local token bucket there is currently token quantity carry out subtracting 1 processing it Afterwards, the current count value of preset service request counter is carried out plus 1 is handled;Judgment module 302 is also used in service request Counting module 306 carries out the current count value of preset service request counter after adding 1 processing, judges that service request counts Whether the current count value of device is greater than or equal to the first preset threshold;Judge if sending module 303 is also used to judgment module 302 When the current count value of service request counter is greater than or equal to the first preset threshold, it is synchronous that token is sent to global flow control node Request is deducted, synchronous deduct of token requests to include token number to be deducted, and token number to be deducted is equal to working as service request counter Preceding count value, so that global flow control node base deducts request in token is synchronous, according in corresponding Global token bucket there is currently Token quantity and token number to be deducted difference, update Global token bucket in there is currently token quantity;Service request meter After digital-to-analogue block 306 is also used to send the synchronous deduction request of token to global flow control node in sending module 303, by service request The current count value of counter is zeroed out processing.
In some embodiments, global flow control node is after feedback traffic process instruction, by corresponding Global token bucket In there is currently token quantity carry out subtracting 1 processing, with update in Global token bucket there is currently token quantity.
In some embodiments, which further includes cache module 307, and cache module 307 is complete for receiving Office's flow control node in updating Global token bucket there is currently token quantity after in the Global token bucket that sends there is currently Token quantity;Update in the local Global token bucket cached in advance there is currently token quantity.
In some embodiments, which further includes synchronization request counting module 308 and blocking module 309. Wherein, synchronization request counting module 308 is used to send the synchronous deduction request of token to global flow control node in sending module 303 Afterwards, the current count value of preset synchronization request counter is carried out plus 1 is handled;Judgment module 302 is also used in synchronization request Counting module carries out the current count value of preset synchronization request counter after adding 1 processing, judges synchronization request counter Current count value whether be greater than or equal to the second preset threshold;If blocking module 309 is judged to synchronize for judgment module 302 When the current count value of request counter is greater than or equal to the second preset threshold, block new service request, until global flow control Node completes the synchronous deduction of token.
In addition, volume control device provided by the embodiment of the present disclosure, for realizing provided by aforementioned any embodiment Flow control methods, other specifically describe the description that can be found in aforementioned any embodiment, and details are not described herein again.
Fig. 7 is a kind of structural schematic diagram for flow control system that the embodiment of the present disclosure provides, as shown in fig. 7, the flow For control system for realizing flow control methods provided by any of the above-described embodiment, which includes: multiple clothes Pragmatic example 401 and global flow control node 402, wherein Service Instance 401 includes the dress of flow control provided by above-described embodiment It sets.
Specific descriptions about the volume control device can be found in the description in above-described embodiment to volume control device, this Place repeats no more.
In addition, flow control system provided by the embodiment of the present disclosure is specifically used for realizing aforementioned flow control method, tool Body can be found in the description of aforementioned flow control method, and details are not described herein again.
The embodiment of the present disclosure additionally provides a kind of server, which includes: one or more processors and storage Device;Wherein, one or more programs are stored on storage device, when said one or multiple programs are by said one or multiple When processor executes, so that said one or multiple processors realize flow control methods above-mentioned.
The embodiment of the present disclosure additionally provides a computer readable storage medium, is stored thereon with computer program, wherein should Computer program, which is performed, realizes flow control methods above-mentioned.
It will appreciated by the skilled person that whole or certain steps, system, dress in method disclosed hereinabove Functional module/unit in setting may be implemented as software, firmware, hardware and its combination appropriate.In hardware embodiment, Division between the functional module/unit referred in the above description not necessarily corresponds to the division of physical assemblies;For example, one Physical assemblies can have multiple functions or a function or step and can be executed by several physical assemblies cooperations.Certain objects Reason component or all physical assemblies may be implemented as by processor, such as central processing unit, digital signal processor or micro process The software that device executes, is perhaps implemented as hardware or is implemented as integrated circuit, such as specific integrated circuit.Such software Can be distributed on a computer-readable medium, computer-readable medium may include computer storage medium (or non-transitory be situated between Matter) and communication media (or fugitive medium).As known to a person of ordinary skill in the art, term computer storage medium includes In any method or skill for storing information (such as computer readable instructions, data structure, program module or other data) The volatile and non-volatile implemented in art, removable and nonremovable medium.Computer storage medium includes but is not limited to RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storages, magnetic Box, tape, disk storage or other magnetic memory apparatus or it can be used for storing desired information and can be visited by computer Any other medium asked.In addition, known to a person of ordinary skill in the art be, communication media generally comprises computer-readable Other numbers in the modulated data signal of instruction, data structure, program module or such as carrier wave or other transmission mechanisms etc According to, and may include any information delivery media.
Example embodiment has been disclosed herein, although and use concrete term, they are only used for simultaneously only should It is interpreted general remark meaning, and is not used in the purpose of limitation.In some instances, aobvious to those skilled in the art and Be clear to, unless otherwise expressly stated, the feature that description is combined with specific embodiment that otherwise can be used alone, characteristic and/ Or element, or the feature, characteristic and/or element of description can be combined with other embodiments and be applied in combination.Therefore, art technology Personnel will be understood that, in the case where not departing from the scope of the present disclosure illustrated by the attached claims, can carry out various forms With the change in details.

Claims (17)

1. a kind of flow control methods, comprising:
When receiving service request, judge in local token bucket there is currently token quantity whether be greater than or equal to 1;
If judge in local token bucket there is currently token quantity less than 1 when, to global flow control node send excess flow control Request, so that the global flow control node is according to excess flow control request, judge in corresponding Global token bucket there is currently order Whether board quantity is greater than or equal to 1;
Receive the global flow control node in judging corresponding Global token bucket there is currently token quantity be greater than or wait The business processing instruction fed back when 1;
It is instructed based on the business processing, according to service request described in preset business logic processing.
2. flow control methods according to claim 1, wherein it is described when receiving service request, judge local token Bucket in there is currently token quantity whether be greater than or equal to before 1, further includes:
When receiving service request, judge in the local Global token bucket cached in advance there is currently token quantity it is whether big In or equal to 1;
If judge in the local Global token bucket cached in advance there is currently token quantity be greater than or equal to 1 when, execution is sentenced In disconnected local token bucket there is currently token quantity whether be greater than or equal to 1 the step of;
If judge in the local Global token bucket cached in advance there is currently token quantity less than 1 when, return to service request Failed message.
3. flow control methods according to claim 2, wherein it is described when receiving service request, judge local token Bucket in there is currently token quantity whether be greater than or equal to after 1, further includes:
If judge in local token bucket there is currently token quantity be greater than or equal to 1 when, at preset service logic Manage the service request;
By in local token bucket there is currently token quantity carry out subtracting 1 processing.
4. flow control methods according to claim 3, wherein it is described by local token bucket there is currently token number Amount carries out subtracting 1 after processing, further includes:
The current count value of preset service request counter is carried out plus 1 is handled;
Judge whether the current count value of the service request counter is greater than or equal to the first preset threshold;
If judge that the current count value of the service request counter is greater than or equal to the first preset threshold, to the overall situation Flow control node sends synchronous deduct of token and requests, and it includes token number to be deducted that the token, which synchronizes and deducts request, described wait deduct Token number is equal to the current count value of the service request counter, so that the global flow control node base is in the synchronous deduction of token Request, according in corresponding Global token bucket there is currently token quantity and token number to be deducted difference, update global enable In board bucket there is currently token quantity;
The current count value of the service request counter is zeroed out processing.
5. flow control methods according to claim 2, wherein the global flow control node is in feedback traffic process instruction Later, by corresponding Global token bucket there is currently token quantity carry out subtracting 1 processing, it is current in Global token bucket to update Existing token quantity.
6. flow control methods according to claim 4 or 5, wherein in the global flow control node updates Global token bucket In there is currently token quantity after, the flow control methods further include:
Receive the global flow control node in updating Global token bucket there is currently token quantity after send global enable In board bucket there is currently token quantity;
Update in the local Global token bucket cached in advance there is currently token quantity.
7. flow control methods according to claim 4, wherein described synchronous to the global flow control node transmission token It deducts after requesting, further includes:
The current count value of preset synchronization request counter is carried out plus 1 is handled;
Judge whether the current count value of the synchronization request counter is greater than or equal to the second preset threshold;
If judge that the current count value of the synchronization request counter is greater than or equal to the second preset threshold, block new industry Business request, until the global flow control node is completed, token is synchronous to be deducted.
8. a kind of volume control device, comprising:
Receiving module, for receiving service request;
Judgment module, for when the receiving module receives service request, judge in local token bucket there is currently order Whether board quantity is greater than or equal to 1;
Sending module, if for judgment module judge in local token bucket there is currently token quantity less than 1 when, to the overall situation Flow control node sends excess flow control request, so that the global flow control node is according to excess flow control request, judges the corresponding overall situation In token bucket there is currently token quantity whether be greater than or equal to 1;
Service Processing Module, for receive the global flow control node in judging corresponding Global token bucket there is currently Token quantity is greater than or equal to the business processing instruction fed back when 1;It is instructed based on the business processing, is patrolled according to preset business Collect the processing service request.
9. volume control device according to claim 8, wherein the judgment module is also used to judging local token bucket In there is currently token quantity whether be greater than or equal to 1 before, judge currently to deposit in the local Global token bucket cached in advance Token quantity whether be greater than or equal to 1;If judge in the local Global token bucket cached in advance there is currently token Quantity be greater than or equal to 1 when, execute judge local token bucket in there is currently token quantity whether be greater than or equal to 1 step Suddenly;
If the Service Processing Module be also used to judgment module judge in the local Global token bucket cached in advance there is currently Token quantity less than 1 when, return service request failed message.
10. volume control device according to claim 9, wherein further including local token update module;
If the Service Processing Module be also used to judgment module judge in local token bucket there is currently token quantity be greater than Or when being equal to 1, according to service request described in preset business logic processing;
The local token update module is used in the Service Processing Module according to business described in preset business logic processing After request, by local token bucket there is currently token quantity carry out subtracting 1 processing.
11. volume control device according to claim 10, wherein further including service request counting module;
The service request counting module be used for the local token update module by local token bucket there is currently order After board quantity carries out subtracting 1 processing, the current count value of preset service request counter is carried out plus 1 processing;
The judgment module is also used to the current count of preset service request counter in the service request counting module Value carries out after adding 1 processing, judges whether the current count value of the service request counter is greater than or equal to the first default threshold Value;
If the sending module, which is also used to judgment module, judges that the current count value of the service request counter is greater than or waits When the first preset threshold, synchronous deduct of token is sent to the global flow control node and is requested, the token is synchronous to deduct request Including token number to be deducted, the token number to be deducted is equal to the current count value of the service request counter, for described Global flow control node base deducts request in token is synchronous, according in corresponding Global token bucket there is currently token quantity with to Deduct token number difference, update Global token bucket in there is currently token quantity;
The service request counting module is also used to send the synchronous button of token to the global flow control node in the sending module After request, the current count value of the service request counter is zeroed out processing.
12. volume control device according to claim 9, wherein the global flow control node is in feedback traffic process instruction Later, by corresponding Global token bucket there is currently token quantity carry out subtracting 1 processing, it is current in Global token bucket to update Existing token quantity.
13. volume control device according to claim 11 or 12, wherein further including cache module, the cache module is used In receive the global flow control node in updating Global token bucket there is currently token quantity after the Global token that sends Bucket in there is currently token quantity;Update in the local Global token bucket cached in advance there is currently token quantity.
14. volume control device according to claim 11, wherein further including synchronization request counting module and blocking module;
The synchronization request counting module is used to send the synchronous deduction request of token to the global flow control node in sending module Later, the current count value of preset synchronization request counter is carried out plus 1 is handled;
The judgment module is also used to the current count of preset synchronization request counter in the synchronization request counting module Value carries out after adding 1 processing, judges whether the current count value of the synchronization request counter is greater than or equal to the second default threshold Value;
If the blocking module judges that the current count value of the synchronization request counter is greater than or equal to for judgment module When the second preset threshold, block new service request, token is synchronous to be deducted until the global flow control node is completed.
15. a kind of flow control system, including multiple Service Instances and global flow control node, the Service Instance includes that right is wanted Seek any volume control device in 8-14.
16. a kind of server, comprising:
One or more processors;
Storage device is stored thereon with one or more programs;
When one or more of programs are executed by one or more of processors, so that one or more of processors Realize the flow control methods as described in any in claim 1-7.
17. a kind of computer-readable medium, is stored thereon with computer program, wherein described program is performed realization as weighed Benefit requires any flow control methods in 1-7.
CN201910491520.XA 2019-06-06 2019-06-06 Flow control method and device, system, server and computer readable medium Active CN110213173B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910491520.XA CN110213173B (en) 2019-06-06 2019-06-06 Flow control method and device, system, server and computer readable medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910491520.XA CN110213173B (en) 2019-06-06 2019-06-06 Flow control method and device, system, server and computer readable medium

Publications (2)

Publication Number Publication Date
CN110213173A true CN110213173A (en) 2019-09-06
CN110213173B CN110213173B (en) 2023-03-24

Family

ID=67791423

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910491520.XA Active CN110213173B (en) 2019-06-06 2019-06-06 Flow control method and device, system, server and computer readable medium

Country Status (1)

Country Link
CN (1) CN110213173B (en)

Cited By (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111343102A (en) * 2020-02-03 2020-06-26 中国银联股份有限公司 Flow rate control method, server-side server, client-side server and system
CN111641563A (en) * 2020-05-28 2020-09-08 深圳壹账通智能科技有限公司 Flow self-adaption method and system based on distributed scene
CN112104567A (en) * 2020-09-03 2020-12-18 中国银联股份有限公司 Flow control method, device, equipment and medium
CN112202682A (en) * 2020-09-27 2021-01-08 平安国际智慧城市科技股份有限公司 Interface flow control method and device, computer equipment and storage medium
CN112564968A (en) * 2020-12-03 2021-03-26 腾讯科技(深圳)有限公司 Fault processing method, device and storage medium
CN112615795A (en) * 2020-12-25 2021-04-06 北京百度网讯科技有限公司 Flow control method and device, electronic equipment, storage medium and product
CN112637082A (en) * 2020-12-15 2021-04-09 银盛支付服务股份有限公司 Distributed current limiting method
CN112822080A (en) * 2020-12-31 2021-05-18 中国人寿保险股份有限公司上海数据中心 Bus system based on SOA architecture
CN112819624A (en) * 2021-02-01 2021-05-18 上交所技术有限责任公司 Low-delay distributed flow control method suitable for security trading system
CN113691461A (en) * 2021-08-23 2021-11-23 新华三信息安全技术有限公司 Token bucket management method and device for multi-core equipment
CN113742114A (en) * 2020-09-28 2021-12-03 北京沃东天骏信息技术有限公司 System current limiting method and device
CN113965519A (en) * 2021-09-06 2022-01-21 阿里巴巴(中国)有限公司 Flow control method, cluster resource guarantee method, equipment and storage medium
CN114745338A (en) * 2022-03-30 2022-07-12 Oppo广东移动通信有限公司 Flow control method, flow control device, storage medium and server
CN114745562A (en) * 2022-04-07 2022-07-12 深圳小鹅网络技术有限公司 Service request processing method and device
CN114745329A (en) * 2022-03-30 2022-07-12 青岛海尔科技有限公司 Flow control method and apparatus, storage medium, and electronic apparatus
CN114860334A (en) * 2022-04-24 2022-08-05 曙光信息产业(北京)有限公司 Method, device, equipment and medium for processing virtual machine start storm
CN115396377A (en) * 2022-07-29 2022-11-25 天翼云科技有限公司 Method, device and equipment for optimizing service quality of object storage and storage medium

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH08202640A (en) * 1995-01-27 1996-08-09 Mitsubishi Electric Corp Cyclic data transmission method for distributed processing system
CN103124439A (en) * 2011-11-18 2013-05-29 中国移动通信集团福建有限公司 GGSN (gateway GPRS support node) protection method and GGSN
CN103763208A (en) * 2014-01-29 2014-04-30 华为技术有限公司 Data flow limiting method and device
US9639398B1 (en) * 2015-03-31 2017-05-02 Amazon Technologies, Inc. Burst throttling with sequential operation detection
US9703602B1 (en) * 2015-03-31 2017-07-11 Amazon Technologies, Inc. Burst throttling for multi-tenant storage services
US20180083977A1 (en) * 2016-09-16 2018-03-22 Oracle International Corporation Distributed High Availability Agent Architecture
CN108494703A (en) * 2018-03-08 2018-09-04 腾讯科技(深圳)有限公司 A kind of access frequency control method, device and storage medium
CN109714268A (en) * 2019-01-23 2019-05-03 平安科技(深圳)有限公司 A kind of flow control methods and relevant apparatus of virtual private cloud

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH08202640A (en) * 1995-01-27 1996-08-09 Mitsubishi Electric Corp Cyclic data transmission method for distributed processing system
CN103124439A (en) * 2011-11-18 2013-05-29 中国移动通信集团福建有限公司 GGSN (gateway GPRS support node) protection method and GGSN
CN103763208A (en) * 2014-01-29 2014-04-30 华为技术有限公司 Data flow limiting method and device
US9639398B1 (en) * 2015-03-31 2017-05-02 Amazon Technologies, Inc. Burst throttling with sequential operation detection
US9703602B1 (en) * 2015-03-31 2017-07-11 Amazon Technologies, Inc. Burst throttling for multi-tenant storage services
US20180083977A1 (en) * 2016-09-16 2018-03-22 Oracle International Corporation Distributed High Availability Agent Architecture
CN108494703A (en) * 2018-03-08 2018-09-04 腾讯科技(深圳)有限公司 A kind of access frequency control method, device and storage medium
CN109714268A (en) * 2019-01-23 2019-05-03 平安科技(深圳)有限公司 A kind of flow control methods and relevant apparatus of virtual private cloud

Cited By (28)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111343102A (en) * 2020-02-03 2020-06-26 中国银联股份有限公司 Flow rate control method, server-side server, client-side server and system
CN111343102B (en) * 2020-02-03 2023-09-26 中国银联股份有限公司 Flow rate control method, server, client server and system
CN111641563B (en) * 2020-05-28 2022-11-01 深圳壹账通智能科技有限公司 Flow self-adaption method and system based on distributed scene
CN111641563A (en) * 2020-05-28 2020-09-08 深圳壹账通智能科技有限公司 Flow self-adaption method and system based on distributed scene
CN112104567A (en) * 2020-09-03 2020-12-18 中国银联股份有限公司 Flow control method, device, equipment and medium
CN112104567B (en) * 2020-09-03 2022-11-18 中国银联股份有限公司 Flow control method, device, equipment and medium
CN112202682A (en) * 2020-09-27 2021-01-08 平安国际智慧城市科技股份有限公司 Interface flow control method and device, computer equipment and storage medium
CN113742114A (en) * 2020-09-28 2021-12-03 北京沃东天骏信息技术有限公司 System current limiting method and device
CN112564968A (en) * 2020-12-03 2021-03-26 腾讯科技(深圳)有限公司 Fault processing method, device and storage medium
CN112637082A (en) * 2020-12-15 2021-04-09 银盛支付服务股份有限公司 Distributed current limiting method
CN112637082B (en) * 2020-12-15 2023-03-31 银盛支付服务股份有限公司 Distributed current limiting method
CN112615795A (en) * 2020-12-25 2021-04-06 北京百度网讯科技有限公司 Flow control method and device, electronic equipment, storage medium and product
CN112822080A (en) * 2020-12-31 2021-05-18 中国人寿保险股份有限公司上海数据中心 Bus system based on SOA architecture
CN112822080B (en) * 2020-12-31 2022-09-16 中国人寿保险股份有限公司上海数据中心 Bus system based on SOA architecture
CN112819624A (en) * 2021-02-01 2021-05-18 上交所技术有限责任公司 Low-delay distributed flow control method suitable for security trading system
CN112819624B (en) * 2021-02-01 2024-04-16 上交所技术有限责任公司 Low-delay distributed flow control method suitable for securities trading system
CN113691461B (en) * 2021-08-23 2023-03-24 新华三信息安全技术有限公司 Token bucket management method and device for multi-core equipment
CN113691461A (en) * 2021-08-23 2021-11-23 新华三信息安全技术有限公司 Token bucket management method and device for multi-core equipment
CN113965519A (en) * 2021-09-06 2022-01-21 阿里巴巴(中国)有限公司 Flow control method, cluster resource guarantee method, equipment and storage medium
CN113965519B (en) * 2021-09-06 2024-01-26 阿里巴巴(中国)有限公司 Flow control and cluster resource guarantee method, equipment and storage medium
CN114745338A (en) * 2022-03-30 2022-07-12 Oppo广东移动通信有限公司 Flow control method, flow control device, storage medium and server
CN114745329B (en) * 2022-03-30 2024-03-22 青岛海尔科技有限公司 Flow control method and device, storage medium and electronic device
CN114745329A (en) * 2022-03-30 2022-07-12 青岛海尔科技有限公司 Flow control method and apparatus, storage medium, and electronic apparatus
CN114745562A (en) * 2022-04-07 2022-07-12 深圳小鹅网络技术有限公司 Service request processing method and device
CN114860334A (en) * 2022-04-24 2022-08-05 曙光信息产业(北京)有限公司 Method, device, equipment and medium for processing virtual machine start storm
CN114860334B (en) * 2022-04-24 2024-01-26 曙光信息产业(北京)有限公司 Processing method, device, equipment and medium for virtual machine starting storm
CN115396377A (en) * 2022-07-29 2022-11-25 天翼云科技有限公司 Method, device and equipment for optimizing service quality of object storage and storage medium
CN115396377B (en) * 2022-07-29 2024-03-12 天翼云科技有限公司 Method, device, equipment and storage medium for optimizing service quality of object storage

Also Published As

Publication number Publication date
CN110213173B (en) 2023-03-24

Similar Documents

Publication Publication Date Title
CN110213173A (en) Flow control methods and device, system, server, computer-readable medium
CN110166376A (en) Flow control methods and device, system, server, computer-readable medium
CN105933444B (en) Based on the service discovery method that registration center and caching mechanism are cooperateed with
US10609176B2 (en) Method and system for real-time resource consumption control in a distributed computing environment
US8909783B2 (en) Managing multi-level service level agreements in cloud-based network
CN108768791A (en) A kind of information collection configuration management system and method
US20120131194A1 (en) Systems and methods for managing subscribed resource limits in cloud network using variable or instantaneous consumption tracking periods
CN102037681A (en) Method and apparatus for managing computing resources of management systems
KR20170024606A (en) Service orchestration method and apparatus in software-defined networking, and storage medium
CN110858808A (en) Method, system and device for realizing speed limit
CN106375102B (en) A kind of service registration method, application method and relevant apparatus
US11327767B2 (en) Increasing resources for partition to compensate for input/output (I/O) recovery event
CN110661824B (en) Flow control method of server in distributed cluster and storage medium
CN111625859A (en) Resource access control method and device, electronic equipment and storage medium
CN110191160A (en) A kind of concurrency control method and device
CN108574645A (en) A kind of array dispatching method and device
CN109173270A (en) A kind of game service system and implementation method
US7145995B2 (en) Method for server-assisted data processing for a plurality of clients
CN110795202B (en) Resource allocation method and device of virtualized cluster resource management system
WO2021045662A1 (en) Method and apparatus for dynamic realtime sharing of credit units for online charging
CN108763065A (en) A kind of mobile application gray scale delivery system and method
CN111818471B (en) Resource charging method, MEC management system and MEC host
CN115756847A (en) EPC memory resource management system, method, device, physical machine and medium
WO2018223944A1 (en) Phone bill generation method, device, mobile edge platform and storage medium
CN113112344B (en) Service processing method, device, storage medium and computer program product

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