CN114844838A - Flow control method and device - Google Patents
Flow control method and device Download PDFInfo
- Publication number
- CN114844838A CN114844838A CN202210385644.1A CN202210385644A CN114844838A CN 114844838 A CN114844838 A CN 114844838A CN 202210385644 A CN202210385644 A CN 202210385644A CN 114844838 A CN114844838 A CN 114844838A
- Authority
- CN
- China
- Prior art keywords
- request
- flow control
- target
- service request
- control rule
- 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
Links
- 238000000034 method Methods 0.000 title claims abstract description 43
- 238000004364 calculation method Methods 0.000 claims description 14
- 230000003247 decreasing effect Effects 0.000 claims description 3
- 230000004044 response Effects 0.000 description 19
- 238000010586 diagram Methods 0.000 description 11
- 230000008569 process Effects 0.000 description 11
- 238000004422 calculation algorithm Methods 0.000 description 8
- 238000004891 communication Methods 0.000 description 7
- 238000011144 upstream manufacturing Methods 0.000 description 6
- 230000006870 function Effects 0.000 description 5
- 230000009471 action Effects 0.000 description 3
- 238000004806 packaging method and process Methods 0.000 description 3
- 230000008859 change Effects 0.000 description 2
- 238000004590 computer program Methods 0.000 description 2
- 238000005538 encapsulation Methods 0.000 description 2
- 230000000903 blocking effect Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000000750 progressive effect Effects 0.000 description 1
- 238000004064 recycling Methods 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L47/00—Traffic control in data switching networks
- H04L47/10—Flow control; Congestion control
- H04L47/215—Flow control; Congestion control using token-bucket
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/66—Arrangements for connecting between networks having differing types of switching systems, e.g. gateways
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The application provides a flow control method and a flow control device, wherein the method comprises the following steps: when a service request for accessing a target module is received, determining a flow control rule matched with the service request from a preset flow control rule set as a target flow control rule; determining current limiting basis information corresponding to the service request according to the target flow control rule and the service request; obtaining a count value of a target counter corresponding to the current limiting basis information from a buffer database, and calculating a request allowance according to the count value and a request upper limit value; and processing the service request according to the request allowance. The method and the device can use the gateway cluster to control the flow.
Description
Technical Field
The present application relates to the field of gateway control, and in particular, to a method and an apparatus for controlling traffic.
Background
With the rapid rise of the fields of e-commerce, internet finance and the like, transaction scenes of high-performance pressure such as second killing, promotion, double 11 and 618 and the like appear in succession, and in order to ensure that systems such as a mobile palm bank and the like can run stably under the scenes, the mobile-end micro-service must have flow control capacity. For a micro service cloud platform, flow control is made to be the most popular solution at present by using a micro service gateway, and with the increasing amount of micro services, cluster deployment is already a necessary choice for the micro service gateway. How to use the gateway cluster for flow control is a problem that needs to be solved at present.
Disclosure of Invention
In view of this, the present application provides a flow control method and device, which are used for performing flow control, and the technical scheme is as follows:
a flow control method is applied to any gateway node in a gateway cluster, and comprises the following steps:
when a service request for accessing a target module is received, determining a flow control rule matched with the service request from a preset flow control rule set as the target flow control rule, wherein the target flow control rule comprises a request upper limit value corresponding to the target module, and the request upper limit value refers to the maximum request quantity capable of accessing the target module in unit time;
determining current limiting basis information corresponding to the service request according to the target flow control rule and the service request;
obtaining a count value of a target counter corresponding to the current limiting basis information from a buffer database, and calculating a request allowance according to the count value and a request upper limit value, wherein the target counter is used for counting requests needing to access a target module;
and processing the service request according to the request allowance.
Optionally, processing the service request according to the request margin includes:
if the request allowance is not 0, performing asynchronous counting according to the service request, and after rewriting the service request according to request rewriting data, forwarding the rewritten service request, wherein the request rewriting data comprises a count value, the request allowance, a request upper limit value and the time for placing the token into a token bucket next time;
and if the request allowance is 0, the service request is arranged in a waiting queue, after waiting for a set time length, the request retry number is added by 1, the execution is returned to obtain the count value of a target counter corresponding to the current limiting basis information from the buffer database until the request retry number reaches the preset retry number upper limit value, or the newly calculated request allowance is not 0, wherein the initial request retry number is 0, and the set time length is determined according to the time for placing the token into the token bucket next time.
Optionally, performing asynchronous counting according to the service request includes:
the count value is increased by 1 or the request margin is decreased by 1.
Optionally, determining a traffic control rule matching the service request from a preset traffic control rule set includes:
determining a target scope according to key parameters contained in the service request;
and determining the flow control rule set containing the flow control rule of the target scope as the flow control rule matched with the service request.
Optionally, determining, according to the target traffic control rule and the service request, current limiting basis information corresponding to the service request, including:
determining a flow limiting basis field corresponding to the service request from the target flow control rule;
analyzing the service request to obtain a current limiting basis parameter corresponding to a current limiting basis field;
and using the current limiting basis field and the current limiting basis parameter as current limiting basis information.
Optionally, calculating the request margin according to the count value and the request upper limit value includes:
and subtracting the count value from the request upper limit value, and taking the difference value as the request margin.
A flow control device is applied to any gateway node in a gateway cluster, and comprises: the flow control system comprises a target flow control rule determining module, a flow limiting basis information determining module, a request allowance calculating module and a service request processing module;
the target flow control rule determining module is used for determining a flow control rule matched with a service request from a preset flow control rule set as a target flow control rule when the service request for accessing the target module is received, wherein the target flow control rule comprises a request upper limit value corresponding to the target module, and the request upper limit value is the maximum request quantity capable of accessing the target module in unit time;
the flow limiting basis information determining module is used for determining flow limiting basis information corresponding to the service request according to the target flow control rule and the service request;
the request allowance calculation module is used for acquiring a count value of a target counter corresponding to the current limiting basis information from the buffer database and calculating a request allowance according to the count value and a request upper limit value, wherein the target counter is used for counting requests needing to access the target module;
and the service request processing module is used for processing the service request according to the request allowance.
Optionally, the service request processing module includes: the device comprises a first processing module and a second processing module;
the first processing module is used for asynchronously counting according to the service request if the request allowance is not 0, and forwarding the rewritten service request after rewriting the service request according to the request rewriting data, wherein the request rewriting data comprises a count value, the request allowance, a request upper limit value and the time for placing the token into a token bucket next time;
and the second processing module is used for queuing the service request into a waiting queue if the request margin is 0, adding 1 to the request retry times after waiting for the set time length, returning to the execution request margin calculation module until the request retry times reach the preset retry time upper limit value, or, the newly calculated request margin is not 0, wherein the initial request retry times are 0, and the set time length is determined according to the time for placing the token into the token bucket next time.
Optionally, the target flow control rule determining module includes: the target scope determining module and the target flow control rule matching module;
the target scope determining module is used for determining a target scope according to the key parameters contained in the service request;
and the target flow control rule matching module is used for determining the flow control rule set containing the target scope as the flow control rule matched with the service request.
Optionally, the current limit determining module includes: a current limiting basis field determining module, a current limiting basis parameter determining module and a current limiting basis information determining submodule;
the flow limiting basis field determining module is used for determining a flow limiting basis field corresponding to the service request from the target flow control rule;
the current-limiting basis parameter determining module is used for analyzing the service request to obtain a current-limiting basis parameter corresponding to a current-limiting basis field;
and the current limiting basis information determining submodule is used for taking the current limiting basis field and the current limiting basis parameter as current limiting basis information.
According to the technical scheme, when a service request for accessing a target module is received, a flow control rule matched with the service request is determined from a preset flow control rule set and is used as a target flow control rule, then current limiting basis information corresponding to the service request is determined according to the target flow control rule and the service request, then a count value of a target counter corresponding to the current limiting basis information is obtained from a cache database, a request margin is calculated according to the count value and a request upper limit value, and finally the service request is processed according to the request margin. Therefore, the gateway cluster can be used for flow control.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, it is obvious that the drawings in the following description are only embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
Fig. 1 is a schematic flow chart of a flow control method according to an embodiment of the present application;
FIG. 2 is a schematic structural diagram of a flow control device according to an embodiment of the present disclosure;
fig. 3 is a schematic diagram of a flow control architecture according to an embodiment of the present application;
fig. 4 is a schematic diagram of an operating process of a policy management module according to an embodiment of the present application;
fig. 5 is a schematic diagram of an operating process of a count management module according to an embodiment of the present application;
fig. 6 is a schematic overall workflow diagram of a flow control method according to an embodiment of the present application;
fig. 7 is a block diagram of a hardware structure of a flow control device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments in the present application without making any creative effort belong to the protection scope of the present application.
Because the prior art does not have a method for controlling flow by using a gateway cluster, the inventor of the present application has conducted an in-depth study, and in the idea of the initial stage, two flow control algorithms used by the gateway cluster are provided, wherein the first flow control algorithm is a leaky-bucket algorithm, i.e., a cache queue is used to handle short-time burst flow, and the second flow control algorithm is a token-bucket algorithm, i.e., a token bucket is used to handle short-time burst flow. Meanwhile, the inventor provides two counting modes for providing flow control capacity by gateway clusters, wherein the first counting mode is to equally divide the cluster flow limiting rule to each node so that the nodes can respectively count requests; the second way of counting is to use a relational database for request counting.
The inventor finds that the first flow control algorithm can ensure the stability of request forwarding when flow control is carried out based on the flow control algorithm and the counting mode, but the waiting time of a request arriving at a gateway is long, and short-time unavailability of service is easily caused in a high-transaction-volume scene; the second flow control algorithm can ensure that the service part is available in a high-transaction scene, but can directly discard the overrun request and cannot realize flow peak clipping and valley filling; the first counting mode can ensure that the maximum number of requests passing through the gateway in unit time does not exceed a specified upper limit, but when the number of nodes is large and the flow is inclined, the conditions that the cluster flow does not reach the upper limit of the current limit and part of the nodes limit the current in advance easily occur, so that inaccurate counting is caused; the second counting method can avoid flow inclination, but each time the gateway cluster processes a request, database reading operation and database writing operation must be completed once, and database reading and writing are frequent, which seriously affects the performance of the gateway cluster.
In summary, the flow control method proposed in the idea of the initial stage cannot give consideration to both performance and counting accuracy during counting, and cannot realize flow peak clipping and valley filling under the condition of ensuring that the service is continuously available.
In view of the above problems, the inventors of the present invention further studied and finally proposed a flow control method, which can be applied to any gateway node in a gateway cluster, and then detailed descriptions are provided for the flow control method provided in the present application through the following embodiments.
Referring to fig. 1, a schematic flow chart of a flow control method according to an embodiment of the present application is shown, where the flow control method may include:
step S101, when a service request for accessing a target module is received, a flow control rule matched with the service request is determined from a preset flow control rule set and is used as a target flow control rule.
The target flow control rule includes a request upper limit value corresponding to the target module, where the request upper limit value is the maximum request quantity that can access the target module in unit time.
The target module refers to a module to which the service request requests access, and optionally, the target module may be a target system (also referred to as a target service or an upstream service, and the target system may include at least one target interface) or a target interface.
In this embodiment, at least one flow control rule may be preset for each module, for example, at least one flow control rule may be preset for system a, and at least one flow control rule may be preset for interface B.
Optionally, when each flow control rule is preset, a rule scope and/or a life cycle may be configured for each flow control rule. Here, the rule scope, i.e., the flow control rule, is set for which module, for example, for a target flow control rule, the rule scope is a target module; the life cycle refers to the effective time of the flow control rule, for example, a certain flow control rule is set to be effective only on a holiday, which is the life cycle of the flow control rule.
Optionally, when each flow control rule is preset, a corresponding request upper limit value may also be configured for each flow control rule. Here, the request upper limit value refers to the maximum request amount that can access the target module per unit time.
Of course, this embodiment may also configure other information for each flow control rule, which is not limited in this application.
After the flow control rules are preset for all modules, the flow control rules preset for all modules form a flow control rule set in the step.
After the flow control rule set is preset, the step can monitor whether a service request is received in real time, and when the service request is received, the flow control rule matched with the service request is determined from the preset flow control rule set.
It should be noted that, in this step, only one flow control rule may be matched from a preset flow control rule set, or multiple flow control rules may be matched from a preset flow control rule set, which is determined according to actual conditions, and this is not limited in this application.
In an alternative embodiment, the implementation process of this step may include: and determining a target scope according to the key parameters contained in the service request, and determining the flow control rule containing the target scope in the flow control rule set as the flow control rule matched with the service request. Optionally, the key parameter included in the service request may be a service parameter, a routing parameter, or the like.
Specifically, as introduced above, each flow control rule in the flow control rule set may be configured with a rule scope, and in this step, a target scope corresponding to the service request may be determined according to key parameters included in the service request, such as key parameters of service, routing, and the like, and then a target flow control rule matched with the service request is determined according to the target scope.
Optionally, the counter name may also be generated according to the target flow control rule.
And step S102, determining the current limiting basis information corresponding to the service request according to the target flow control rule and the service request.
Optionally, the specific implementation process of this step may include: and determining a current limiting basis field corresponding to the service request from the target flow control rule, analyzing the service request to obtain a current limiting basis parameter corresponding to the current limiting basis field, and using the current limiting basis field and the current limiting basis parameter as current limiting basis information.
Specifically, it is understood that the target flow control rule usually further includes more detailed flow restriction dependency field information for performing flow control, and the target flow control rule includes: limiting 3 times of access of the IP 1-4 every second, and determining that the current limiting basis field is an IP field; after the current limit basis field is determined, the step may parse the service request to parse a current limit basis parameter in the service request, where the current limit basis parameter refers to a specific field value of the current limit basis field, for example, if an IP address that the service request wants to access is IP1, then "1" in IP1 is the current limit basis parameter; based on this, the current limit basis information is "IP 1".
Step S103, obtaining a count value of a target counter corresponding to the current limiting basis information from the buffer database, and calculating a request margin according to the count value and the request upper limit value.
The target counter is used for counting the requests needing to access the target module.
In this step, the cache database includes at least one counter, and each counter of the at least one counter corresponds to the limited flow basis information.
Because the target flow control rule includes the request upper limit value, the request margin can be calculated according to the acquired count value and the request upper limit value. Specifically, the difference value obtained by subtracting the count value from the request upper limit value is the request margin, and the target module can be known to be accessed again several times in the current unit time according to the request margin.
It should be noted that the cache database mentioned in this step refers to a remote dictionary service, and optionally, the cache database may be a Redis database. Because the cache database has high performance and the capability of asynchronous counting without blocking gateway threads, the counter sharing can be realized with lower performance loss.
And step S104, processing the service request according to the request allowance.
Optionally, the specific implementation process of this step may include: if the request margin is not 0, performing asynchronous counting according to the service request, and after rewriting the service request according to the request rewriting data, forwarding the rewritten service request, where the request rewriting data includes but is not limited to the following data: counting value, request allowance, request upper limit value and time for putting the token into the token bucket next time; if the request allowance is 0, the service request is refused to be forwarded, and the current limiting response message is packaged and returned.
Specifically, if the request margin is not 0, which indicates that the request margin has not reached the request upper limit value specified by the target traffic control rule, the service request may be processed continuously, and the processing procedure includes: on one hand, an asynchronous task is used for interacting with a cache database to count requests according to service requests, for example, the count value is increased by 1, or the request margin is decreased by 1; on the other hand, according to the configuration of the target flow control rule, the request rewriting data is written into a request head or a request body, then the rewritten service request is forwarded to the upstream service, and if the upstream service returns a response message, the response message is received and returned to the client.
If the request margin is 0, it indicates that the current request has reached the request upper limit value specified by the target traffic control rule, at this time, the service request is not processed any more, but the service request is rejected to be forwarded, and a current limiting response message is encapsulated and returned to the client.
In an optional embodiment, when the request margin is insufficient (that is, the request margin is 0), the service request is directly rejected from processing, so that traffic peak clipping and valley filling cannot be realized, and the user experience is poor. In order to solve the problem, in this step, when the request margin is 0, the service request may be queued in a wait queue, and after waiting for a set time length, the execution is returned to obtain the count value of the target counter corresponding to the current limiting basis information from the buffer database until the newly calculated request margin is not 0, where the set time length is determined according to the time when the token is next placed in the token bucket.
Specifically, if the request margin is 0, the limited service request is queued in a wait queue, and after waiting for a set duration, that is, after the token is put into a token bucket next time so that the counter margin is increased, the count value of the target counter is obtained again from the cache database, and a new request margin is calculated according to the newly obtained count value and the request upper limit value, and then the service request is processed according to the new request margin.
When the service request is processed according to the new request allowance, if the new request allowance is 0, the service request is queued again in the waiting queue to retry the request again, and when the new request allowance is not 0, asynchronous counting is performed according to the service request, and after the service request is rewritten according to the request rewriting data, the rewritten service request is forwarded.
It is noted that when processing a service request according to a new request margin, the request overwrite data includes, but is not limited to, the following data: the newly acquired count value, the newly calculated request margin, the request upper limit value and the time for the next token to be put into the token bucket.
In another optional embodiment, considering that the time for the client to wait for the request retry is long and the experience is poor, in this embodiment, the number of request retries may be increased when the request retry occurs, and when the number of request retries reaches the preset upper limit of the number of retries, the request retry is not continued regardless of whether the calculated new request margin is 0, so as to reduce the waiting time of the client.
That is, in a preferred case, when the request margin is 0, the process of this step may include: and queuing the service request into a waiting queue, adding 1 to the retry number of the request after waiting for a set time length, returning to execute the count value of a target counter corresponding to the current-limiting basis information obtained from the buffer database until the retry number of the request reaches the upper limit value of the preset retry number, or, the newly calculated request margin is not 0, wherein the initial retry number of the request is 0, and the set time length is determined according to the time when the token is put into a token bucket next time.
And when the retry number of the request reaches the preset retry number upper limit value, if the newly calculated request allowance is also 0, rejecting to forward the service request, packaging and returning a current-limiting response message.
Optionally, the preset upper limit of the retry number may be 1, that is, the application may retry only once automatically, and if the retry is successful (that is, the new request margin is not 0), forward the service request, receive the response message and return the response message to the client, and if the retry fails (that is, the new request margin is still 0), discard the service request, and encapsulate the current-limiting response message (that is, generate the response code and the message content of the current-limiting response message according to the target flow control rule).
The flow control method applied to any gateway node in a gateway cluster includes the steps of firstly determining a flow control rule matched with a service request from a preset flow control rule set when the service request for accessing a target module is received, using the flow control rule as a target flow control rule, then determining current-limiting basis information corresponding to the service request according to the target flow control rule and the service request, then obtaining a count value of a target counter corresponding to the current-limiting basis information from a cache database, calculating request allowance according to the count value and the request upper limit value, and finally processing the service request according to the request allowance. Therefore, the gateway cluster can be used for flow control.
When the gateway cluster is used for flow control, the counting value of the counter is stored by the cache database, and the gateway nodes in the gateway cluster can share the counter in the cache database to count requests, so that the performance of the gateway cluster is better, and the counting accuracy is improved by sharing the counter. Meanwhile, when the request margin is 0, the service request cannot be directly rejected, but the service request can be queued into a waiting queue, and the request is retried after a short delay, so that the traffic peak clipping and valley filling can be realized under the condition that the service is continuously available; when the request allowance is not 0, the data rewriting service request can be rewritten according to the request, so that the upstream service can timely acquire the current request condition based on the request rewriting data contained in the rewritten service request.
The embodiment of the present application further provides a flow control device, where the flow control device may be applied to any gateway node in a gateway cluster, and the flow control device provided in the embodiment of the present application is described below, and the flow control device described below and the flow control method described above may be referred to in a corresponding manner.
Referring to fig. 2, a schematic structural diagram of a flow control device according to an embodiment of the present application is shown, and as shown in fig. 2, the flow control device may include: a target flow control rule determining module 201, a flow limit basis information determining module 202, a request margin calculating module 203 and a service request processing module 204.
The target traffic control rule determining module 201 is configured to determine, when a service request for accessing a target module is received, a traffic control rule matched with the service request from a preset traffic control rule set, as the target traffic control rule, where the target traffic control rule includes a request upper limit value corresponding to the target module, and the request upper limit value is a maximum request amount capable of accessing the target module in unit time.
And a current limiting basis information determining module 202, configured to determine, according to the target flow control rule and the service request, current limiting basis information corresponding to the service request.
And the request margin calculation module 203 is configured to obtain a count value of a target counter corresponding to the current limiting basis information from the buffer database, and calculate the request margin according to the count value and the request upper limit value, where the target counter is configured to count requests that need to access the target module.
And the service request processing module 204 is configured to process the service request according to the request margin.
In a possible implementation manner, the service request processing module 204 may include: the device comprises a first processing module and a second processing module.
The first processing module is used for carrying out asynchronous counting according to the service request if the request allowance is not 0, and forwarding the rewritten service request after rewriting the service request according to request rewriting data, wherein the request rewriting data comprises a counting value, a request allowance, a request upper limit value and the time for placing the token into the token bucket next time.
And the second processing module is configured to, if the request margin is 0, queue the service request, add 1 to the request retry number after waiting for a set time length, return to the execution request margin calculation module 203 until the request retry number reaches a preset retry number upper limit value, or determine that the newly calculated request margin is not 0, where the initial request retry number is 0, and the set time length is determined according to the time when the token is next put into the token bucket.
In a possible implementation manner, when performing asynchronous counting according to a service request, the first processing module may specifically be configured to add 1 to a count value, or subtract 1 from a request margin.
In a possible implementation manner, the target flow control rule determining module 201 may include: the system comprises a target scope determining module and a target flow control rule matching module.
And the target scope determining module is used for determining the target scope according to the key parameters contained in the service request.
And the target flow control rule matching module is used for determining the flow control rule set containing the target scope as the flow control rule matched with the service request.
In a possible implementation manner, the above current limit dependency information determining module 202 may include: the device comprises a current limiting basis field determining module, a current limiting basis parameter determining module and a current limiting basis information determining submodule.
And the flow limiting basis field determining module is used for determining a flow limiting basis field corresponding to the service request from the target flow control rule.
And the current limiting basis parameter determining module is used for analyzing the service request to obtain a current limiting basis parameter corresponding to the current limiting basis field.
And the current limiting basis information determining submodule is used for taking the current limiting basis field and the current limiting basis parameter as current limiting basis information.
In a possible implementation manner, when the request margin calculation module 203 calculates the request margin according to the count value and the request upper limit value, the request upper limit value may be specifically used to subtract the count value from the request upper limit value, and the difference is used as the request margin.
In order to make those skilled in the art understand the present application more clearly, a specific flow control scenario is taken as an example, and it should be noted that the following embodiment is only an example and is not a limitation to the present application.
Optionally, the flow control method and apparatus provided in this application may be applied to the flow control architecture shown in fig. 3. As shown in fig. 3, the flow control architecture includes a flow control module, a count management module, and a policy management module.
Optionally, the target flow control rule determining module 201 and the flow limit basis information determining module 202 provided in the present application may also be arranged in a unit, and in this step, the unit is defined as a request parsing unit, that is, the request parsing unit may be configured to determine, when receiving a service request for accessing the target module, a flow control rule matching the service request from a preset flow control rule set, as the target flow control rule, and determine, according to the target flow control rule and the service request, the flow limit basis information corresponding to the service request. As shown in fig. 3, the request parsing unit may be disposed on the flow control module.
Optionally, the request margin calculation module 203 provided in the present application may be separately arranged in a unit, and in this step, the unit is defined as a margin calculation unit, that is, the margin calculation unit may be configured to obtain a count value of a target counter corresponding to the current limiting basis information from the cache database (that is, obtain the count value by calling the count management module), and calculate the request margin according to the count value and a request upper limit value (the request upper limit value may be obtained by calling the policy management module). As shown in fig. 3, the margin calculating unit may be disposed on the flow control module.
Optionally, the service request processing module 204 provided in the present application is arranged in a plurality of units, where the units are respectively defined as a counting unit, a request rewriting unit, a request retry unit, and a response encapsulation unit, and functions of each unit are as follows:
if the allowance calculation unit judges that the request allowance is not 0, asynchronous counting is carried out through the counting unit according to the service request, the service request is rewritten through the request rewriting unit according to the request rewriting data, and the rewritten service request is forwarded out; if the margin calculation unit judges that the request margin is 0, the request retry unit maintains a waiting queue, service requests are arranged in the waiting queue, after waiting for a set time length (the set time length is determined by calling the time for obtaining the next time for putting the token into the token bucket), the request retry number is added with 1, and the margin calculation unit is called to obtain the count value again and calculate new request margin again until the request retry number reaches the preset retry number upper limit value, or the newly calculated request margin is not 0. And when the retry number of the request reaches the upper limit value of the preset retry number, if the newly calculated request allowance is 0, packaging the current-limiting response message through a response packaging unit.
As shown in fig. 3, the counting unit may be disposed on the count management module, and the request rewriting unit, the request retrying unit, and the response encapsulating unit may be disposed on the flow control module.
In addition to the above units, as shown in fig. 3, the flow control architecture further includes a policy management module, where the policy management module is composed of a policy management unit, a policy lifecycle management unit, and a policy storage unit. The strategy management module provides a flow control rule management interface, and specifically comprises a strategy management unit and a management interface exposed to the outside by the strategy life cycle management unit; the strategy storage unit is responsible for storing the flow control rule set; the policy life cycle management unit is responsible for managing the flow control policy effective state.
Referring to FIG. 4, a schematic diagram of the operation of the policy management module is shown. As shown in fig. 4, when the traffic control module needs to query the target traffic control rule, the policy management unit may provide a management interface for querying (corresponding to the query policy); when the counting management module needs to inquire the request upper limit value contained in the target flow control rule, the request upper limit value can be inquired (corresponding to the strategy flow limiting upper limit inquiry) through a management interface provided by the strategy management unit; when the counting management module needs to query the life cycle of the target flow control rule, the counting management module can query through a management interface provided by the policy life cycle management unit (corresponding to the query policy life cycle).
Therefore, the policy management module enables the application to customize the flow control rule in a personalized way.
As shown in fig. 3, the flow control architecture further includes a count management module, and the count management module is composed of a counting unit and a storage space management unit. The storage space management unit is used for interacting with a remote dictionary service and managing the storage space of the counter, and comprises initializing a new counter and recycling an expired or unused counter for a long time; the counting unit provides a request counting and counting inquiry interface for the flow control module to use.
Referring to FIG. 5, a diagram of the operation of the count management module is shown. As shown in fig. 5, the counters are stored in a remote dictionary service (i.e., a cache database); when the flow control architecture is operated, the storage space management unit monitors the change of the flow control rule in the policy management module, and initializes a new counter or deletes a failed counter in the remote dictionary according to the change condition of the flow control rule; when the flow control module calls a counting query or request counting interface, the counting unit packages a remote dictionary service query request or an update request to realize reading or increasing of the counting of the counter.
In summary, the policy management module is composed of a policy management unit, a policy lifecycle management unit, and a policy storage unit, and is configured to configure and store the flow control policy and manage the lifecycle of the flow control policy; the flow control module consists of a request analysis unit, a margin calculation unit, a request retry unit, a request rewrite unit and a response encapsulation unit and is used for processing a service request, calculating a current-limiting margin and temporarily fusing a flow overrun service; the counting management module consists of a storage space management unit and a counting unit and is used for distributing counting space, requesting counting and recovering expired counting space.
Optionally, the policy management module may be a policy manager, the flow control module may be a flow manager, and the count management module may be a count manager, as shown in fig. 6, which shows an overall workflow diagram of the flow control method.
After the policy manager configures the set of flow control rules, the flow controller may monitor whether a service request is received, and if the service request is received, match a target flow control rule, and determine current limiting basis information according to the target flow control rule and the service request; then the counting manager can access a target counter in the cache database according to the current limiting basis information and read the counting value of the target counter; then the flow controller calculates a request allowance according to the count value and the request upper limit value, and judges whether the allowance is sufficient (namely, judges whether the request allowance is 0), if the allowance is insufficient, judges whether the request retry is performed for the first time (namely, the preset retry time upper limit value is 1), if the request retry is performed for the first time, the service request is put into a waiting queue for waiting retry, and if the request retry is not performed for the first time, a current-limiting response message is packaged and returned to the client; if the allowance is sufficient, the counting manager performs asynchronous counting according to the service request, the flow controller rewrites the data to rewrite the service request based on the request and forwards the rewritten service request to the upstream service, and when the upstream service returns a response message aiming at the service request, the flow controller receives the response message and returns the response message to the client.
The embodiment of the application also provides a flow control device, which can be applied to any gateway node in a gateway cluster. Optionally, fig. 7 shows a block diagram of a hardware structure of the flow control device, and referring to fig. 7, the hardware structure of the flow control device may include: at least one processor 701, at least one communication interface 702, at least one memory 703 and at least one communication bus 704;
in the embodiment of the present application, the number of the processor 701, the communication interface 702, the memory 703 and the communication bus 704 is at least one, and the processor 701, the communication interface 702 and the memory 703 complete mutual communication through the communication bus 704;
the processor 701 may be a central processing unit CPU, or an application Specific Integrated circuit (asic), or one or more Integrated circuits configured to implement embodiments of the present invention, or the like;
the memory 703 may include a high-speed RAM memory, and may further include a non-volatile memory (non-volatile memory) or the like, such as at least one disk memory;
wherein the memory 703 stores a program, and the processor 701 may call the program stored in the memory 703, the program being configured to:
when a service request for accessing a target module is received, determining a flow control rule matched with the service request from a preset flow control rule set as the target flow control rule, wherein the target flow control rule comprises a request upper limit value corresponding to the target module, and the request upper limit value refers to the maximum request quantity capable of accessing the target module in unit time;
determining current limiting basis information corresponding to the service request according to the target flow control rule and the service request;
obtaining a count value of a target counter corresponding to the current limiting basis information from a buffer database, and calculating a request allowance according to the count value and a request upper limit value, wherein the target counter is used for counting requests needing to access a target module;
and processing the service request according to the request allowance.
Alternatively, the detailed function and the extended function of the program may be as described above.
The embodiment of the application also provides a readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the flow control method is realized.
Alternatively, the detailed function and the extended function of the program may be as described above.
Finally, it is further noted that, herein, relational terms such as, for example, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
In the present specification, the embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims (10)
1. A flow control method is applied to any gateway node in a gateway cluster, and comprises the following steps:
when a service request for accessing a target module is received, determining a flow control rule matched with the service request from a preset flow control rule set as the target flow control rule, wherein the target flow control rule comprises a request upper limit value corresponding to the target module, and the request upper limit value refers to the maximum request quantity capable of accessing the target module in unit time;
determining current limiting basis information corresponding to the service request according to the target flow control rule and the service request;
obtaining a count value of a target counter corresponding to the current limiting basis information from a buffer database, and calculating a request allowance according to the count value and the request upper limit value, wherein the target counter is used for counting requests needing to access the target module;
and processing the service request according to the request allowance.
2. The traffic control method according to claim 1, wherein processing the service request according to the request margin comprises:
if the request allowance is not 0, asynchronously counting according to the service request, and after rewriting the service request according to request rewriting data, forwarding the rewritten service request, wherein the request rewriting data comprises the count value, the request allowance, the request upper limit value and the time for placing the token into the token bucket next time;
and if the request allowance is 0, queuing the service request into a waiting queue, adding 1 to the retry number of the request after waiting for a set time length, returning to execute the count value of the target counter corresponding to the current limiting basis information obtained from the buffer database until the retry number of the request reaches the preset retry number upper limit value, or, the newly calculated request allowance is not 0, wherein the initial retry number of the request is 0, and the set time length is determined according to the time for placing the token into the token bucket next time.
3. The traffic control method according to claim 2, wherein said asynchronously counting according to the service request comprises:
the count value is increased by 1 or the request margin is decreased by 1.
4. The method according to claim 1, wherein the determining the traffic control rule matching the service request from a preset traffic control rule set includes:
determining a target scope according to key parameters contained in the service request;
and determining the flow control rule set containing the flow control rule of the target scope as the flow control rule matched with the service request.
5. The method of claim 1, wherein the determining, according to the target traffic control rule and the service request, the flow limitation reference information corresponding to the service request comprises:
determining a current limiting basis field corresponding to the service request from the target flow control rule;
analyzing the service request to obtain a current limiting basis parameter corresponding to the current limiting basis field;
and using the current limiting basis field and the current limiting basis parameter as the current limiting basis information.
6. The flow control method according to claim 1, wherein the calculating a request margin based on the count value and the request upper limit value includes:
and subtracting the count value from the request upper limit value, and taking the difference value as the request allowance.
7. The flow control device is applied to any gateway node in a gateway cluster, and includes: the flow control system comprises a target flow control rule determining module, a flow limiting basis information determining module, a request allowance calculating module and a service request processing module;
the target flow control rule determining module is configured to determine, when a service request for accessing a target module is received, a flow control rule matched with the service request from a preset flow control rule set, as the target flow control rule, where the target flow control rule includes a request upper limit value corresponding to the target module, and the request upper limit value is a maximum request amount capable of accessing the target module in unit time;
the flow limiting basis information determining module is used for determining flow limiting basis information corresponding to the service request according to the target flow control rule and the service request;
the request allowance calculation module is used for acquiring a count value of a target counter corresponding to the current limiting basis information from a buffer database and calculating a request allowance according to the count value and the request upper limit value, wherein the target counter is used for counting requests needing to access the target module;
and the service request processing module is used for processing the service request according to the request allowance.
8. The flow control device of claim 7, wherein the service request processing module comprises: a first processing module and a second processing module;
the first processing module is configured to, if the request margin is not 0, perform asynchronous counting according to the service request, and forward the rewritten service request after rewriting the service request according to request rewriting data, where the request rewriting data includes the count value, the request margin, the request upper limit value, and a time when the token is next placed in the token bucket;
and the second processing module is configured to, if the request margin is 0, queue the service request, add 1 to the request retry number after waiting for a set time length, return to the execution of the request margin calculation module until the request retry number reaches a preset retry number upper limit value, or determine that the newly calculated request margin is not 0, where the initial request retry number is 0, and the set time length is determined according to the time for placing the token into the token bucket next time.
9. A flow control device according to claim 7, wherein said target flow control rules determination module comprises: the target scope determining module and the target flow control rule matching module;
the target scope determining module is used for determining a target scope according to the key parameters contained in the service request;
and the target flow control rule matching module is used for determining the flow control rule set containing the target scope as the flow control rule matched with the service request.
10. A flow control device according to claim 7, wherein said flow restriction dependency information determination module comprises: a current limiting basis field determining module, a current limiting basis parameter determining module and a current limiting basis information determining submodule;
the flow limiting basis field determining module is used for determining a flow limiting basis field corresponding to the service request from the target flow control rule;
the current-limiting basis parameter determining module is used for analyzing the service request to obtain a current-limiting basis parameter corresponding to the current-limiting basis field;
and the current limiting basis information determining submodule is used for taking the current limiting basis field and the current limiting basis parameter as the current limiting basis information.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210385644.1A CN114844838B (en) | 2022-04-13 | 2022-04-13 | Flow control method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210385644.1A CN114844838B (en) | 2022-04-13 | 2022-04-13 | Flow control method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN114844838A true CN114844838A (en) | 2022-08-02 |
CN114844838B CN114844838B (en) | 2024-07-09 |
Family
ID=82563005
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210385644.1A Active CN114844838B (en) | 2022-04-13 | 2022-04-13 | Flow control method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114844838B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115665074A (en) * | 2022-10-08 | 2023-01-31 | 广州市玄武无线科技股份有限公司 | Message flow limiting sending method, device, equipment and storage medium |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105281981A (en) * | 2015-11-04 | 2016-01-27 | 北京百度网讯科技有限公司 | Data traffic monitoring method and device for network service |
KR20160015670A (en) * | 2014-07-31 | 2016-02-15 | 에스케이텔레콤 주식회사 | Method and apparatus for managing policy of mobile communition service |
US20190372899A1 (en) * | 2016-12-26 | 2019-12-05 | New H3C Technologies Co., Ltd. | Processing packet |
CN111447150A (en) * | 2020-02-29 | 2020-07-24 | 中国平安财产保险股份有限公司 | Access request current limiting method, server and storage medium |
CN114189478A (en) * | 2021-12-01 | 2022-03-15 | 浪潮云信息技术股份公司 | Distributed current limiting implementation method and system based on sliding window algorithm |
CN114244525A (en) * | 2021-12-13 | 2022-03-25 | 中国农业银行股份有限公司 | Request data processing method, device, equipment and storage medium |
-
2022
- 2022-04-13 CN CN202210385644.1A patent/CN114844838B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
KR20160015670A (en) * | 2014-07-31 | 2016-02-15 | 에스케이텔레콤 주식회사 | Method and apparatus for managing policy of mobile communition service |
CN105281981A (en) * | 2015-11-04 | 2016-01-27 | 北京百度网讯科技有限公司 | Data traffic monitoring method and device for network service |
US20190372899A1 (en) * | 2016-12-26 | 2019-12-05 | New H3C Technologies Co., Ltd. | Processing packet |
CN111447150A (en) * | 2020-02-29 | 2020-07-24 | 中国平安财产保险股份有限公司 | Access request current limiting method, server and storage medium |
CN114189478A (en) * | 2021-12-01 | 2022-03-15 | 浪潮云信息技术股份公司 | Distributed current limiting implementation method and system based on sliding window algorithm |
CN114244525A (en) * | 2021-12-13 | 2022-03-25 | 中国农业银行股份有限公司 | Request data processing method, device, equipment and storage medium |
Non-Patent Citations (1)
Title |
---|
贾蓓;李倩茹;吴静怡;: "信息管理系统在用户使用和系统安全策略中的应用", 信息通信, no. 07, 15 September 2013 (2013-09-15) * |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115665074A (en) * | 2022-10-08 | 2023-01-31 | 广州市玄武无线科技股份有限公司 | Message flow limiting sending method, device, equipment and storage medium |
CN115665074B (en) * | 2022-10-08 | 2023-09-15 | 广州市玄武无线科技股份有限公司 | Message flow-limiting sending method, device, equipment and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN114844838B (en) | 2024-07-09 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Apostolopoulos et al. | QoS routing mechanisms and OSPF extensions | |
CN106202505B (en) | Data processing method and its system | |
US8208403B2 (en) | Defining an end-to-end path for a network service | |
US9998532B2 (en) | Computer-based, balanced provisioning and optimization of data transfer resources for products and services | |
CN104601696B (en) | Service processing method, service calling system, device and system | |
CN108881348B (en) | Service quality control method and device and storage server | |
US11320998B2 (en) | Method for assuring quality of service in distributed storage system, control node, and system | |
US8577008B2 (en) | Asynchronous calls using intermittent callback for delay sensitive applications | |
US10567504B2 (en) | Protecting in-flight transaction requests | |
CN108683695A (en) | Hot spot access processing method, cache access agent equipment and distributed cache system | |
JP2003303052A (en) | Method and system for operation and management of storage | |
CN103312624A (en) | Message queue service system and method | |
US10642585B1 (en) | Enhancing API service schemes | |
CN112615793A (en) | Data current limiting method and device | |
US20190327138A1 (en) | System and method for network provisioning | |
CN114844838A (en) | Flow control method and device | |
US20190266081A1 (en) | Chronologically ordered out-of-place update key-value storage system | |
CN107181773A (en) | Data storage and data managing method, the equipment of distributed memory system | |
CN113656178B (en) | Data processing method, device, equipment and readable storage medium | |
CN109284311B (en) | Method and device for acquiring database connection | |
CN110019372A (en) | Data monitoring method, device, server and storage medium | |
Apostolopoulos et al. | rfc2676: QoS routing mechanisms and OSPF extensions | |
CN108718285A (en) | Flow control methods, device and the server of cloud computing cluster | |
JPWO2020081224A5 (en) | ||
US20240054018A1 (en) | Reducing network overhead |
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 |