CN115378656B - Token backfill method, storage medium and electronic device - Google Patents

Token backfill method, storage medium and electronic device Download PDF

Info

Publication number
CN115378656B
CN115378656B CN202210884966.0A CN202210884966A CN115378656B CN 115378656 B CN115378656 B CN 115378656B CN 202210884966 A CN202210884966 A CN 202210884966A CN 115378656 B CN115378656 B CN 115378656B
Authority
CN
China
Prior art keywords
token
token bucket
bucket
condition
acquisition
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210884966.0A
Other languages
Chinese (zh)
Other versions
CN115378656A (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.)
Qingdao Haier Technology Co Ltd
Haier Smart Home Co Ltd
Original Assignee
Qingdao Haier Technology Co Ltd
Haier Smart Home 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 Qingdao Haier Technology Co Ltd, Haier Smart Home Co Ltd filed Critical Qingdao Haier Technology Co Ltd
Priority to CN202210884966.0A priority Critical patent/CN115378656B/en
Publication of CN115378656A publication Critical patent/CN115378656A/en
Application granted granted Critical
Publication of CN115378656B publication Critical patent/CN115378656B/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
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/08Network architectures or network communication protocols for network security for authentication of entities
    • H04L63/0807Network architectures or network communication protocols for network security for authentication of entities using tickets, e.g. Kerberos
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/2803Home automation networks
    • 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)
  • Automation & Control Theory (AREA)
  • Computer Hardware Design (AREA)
  • Computer Security & Cryptography (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The application discloses a token backfilling method, a storage medium and an electronic device, and relates to the technical field of smart home/smart families, wherein the token backfilling method comprises the following steps: based on a token acquisition request input by a user terminal, carrying out token acquisition and outputting different acquisition results; collecting state information of a token bucket under each acquisition result condition, and collecting current limiting information of the token acquisition request under the condition that the acquisition result is failure; and carrying out token backfilling on the token bucket based on the state information and the current limit information. Under the condition that the token acquisition request of the user is limited, the application can confirm whether the token is excessively deducted according to the current limiting information and the state information, and timely backfill the token in the token bucket, thereby realizing correct token application.

Description

Token backfill method, storage medium and electronic device
Technical Field
The application relates to the technical field of smart home/smart home, in particular to a token backfilling method, a storage medium and an electronic device.
Background
The API, application programming interface (Application Program Interface, API) gateway serves as a traffic portal, assuming the most important responsibilities, and has extremely high requirements on its performance and stability. In the face of extremely complex traffic scenarios, high concurrent traffic, and potential attack threats, traffic control plays an important role.
Facing complex traffic throttling (ip, parameters, user, interface granularity, multiple throttling rules for the same interface-different priorities, different service interface groups throttling, multi-protocol throttling, etc.). When the API gateway performs service, the input request of the user is limited or the capacity of the token bucket is increased when the traffic is increased.
Since the API gateway can set different rules, and the period of generating tokens varies. In the prior art, after the input request of the user comes in, the input request of the user is limited because some rules acquire the tokens and some tokens are acquired. Since the incoming request is throttled, the corresponding rule should not deduct the token when the acquisition of the token is successful.
Therefore, how to avoid the phenomenon that the token is excessively deducted under the current limiting condition is a technical problem to be solved.
Disclosure of Invention
The application provides a token backfilling method, a storage medium and an electronic device, which are used for solving the defect that in the prior art, the token is excessively deducted under the current limiting condition, and realizing the backfilling of the excessively deducted token under the current limiting condition, thereby realizing the correct token application.
The application provides a token backfilling method, which comprises the following steps:
based on a token acquisition request input by a user terminal, carrying out token acquisition and outputting different acquisition results;
collecting state information of a token bucket under each acquisition result condition, and collecting current limiting information of the token acquisition request under the condition that the acquisition result is failure;
and carrying out token backfilling on the token bucket based on the state information and the current limit information.
According to the method for refilling the token, the method for refilling the token bucket with the token based on the state information and the current limit information comprises the following steps:
Confirming that the token acquisition request is in a current limiting condition based on the current limiting information, and acquiring token deduction information of the token bucket based on the current limiting information and the state information;
judging whether the token has redundant deduction or not based on the token deduction information;
and in the case that redundant deduction exists for the token, performing token backfilling on the token bucket based on the CAS atomic operation.
According to the method for refilling the token, under the condition that redundant deduction exists in the token, the token bucket is refilled with the token based on CAS atomic operation, and the method comprises the following steps:
Under the condition that excessive deduction exists in the token, acquiring a first target value and a second target value before and after token deduction based on the token deduction information;
And replacing the second target value with the first target value based on the CAS atomic operation to implement token backfilling of the token bucket under the condition that the target expected value is equal to the first target value.
According to the method for backfilling the token provided by the application, before confirming that the token acquisition request is in the current limiting condition based on the current limiting information, the method further comprises the following steps:
acquiring the flow increment of the API gateway in a target time period;
Comparing the flow increment with a preset threshold value to obtain a judging result of whether the API gateway is in the condition of flow surge;
and confirming whether the capacity of the token bucket is adjusted or not based on the judging result.
According to the method for refilling tokens provided by the application, the method for confirming whether to adjust the capacity of the token bucket based on the judging result comprises the following steps:
acquiring a dynamic capacity expansion threshold of the token bucket under the condition that the flow increment is larger than the preset threshold;
And adjusting the capacity of the token bucket based on the preset capacity threshold value and the dynamic capacity expansion threshold value of the token bucket.
According to the method for refilling tokens provided by the application, the method for confirming whether to adjust the capacity of the token bucket based on the judging result comprises the following steps:
adjusting a time confirmation time span based on the current time and the last token bucket capacity under the condition that the flow increment is less than or equal to the preset threshold value;
And judging whether the token bucket adjusts the capacity of the token bucket or not based on the time span and the token bucket refreshing period.
According to the method for refilling tokens provided by the application, the method for judging whether the token bucket adjusts the capacity of the token bucket or not based on the time span and the token bucket refreshing period comprises the following steps:
confirming that no token needs to be added to the token bucket in the condition that the time span is smaller than or equal to the token bucket refresh period;
and in the case that the time span is greater than the token bucket refresh period, confirming that a new token is added into the token bucket to adjust the capacity of the card bucket.
The application also provides a token backfilling device, which comprises:
The output module is used for carrying out token acquisition based on a token acquisition request input by the user side and outputting different acquisition results;
The acquisition module is used for acquiring state information of the token bucket under each acquisition result condition and acquiring current limiting information of the token acquisition request under the condition that the acquisition result is failure;
And the backfilling module is used for backfilling the token for the token bucket based on the state information and the current limiting information.
The application also provides an electronic device comprising a memory having stored therein a computer program and a processor arranged to implement a token backfill method as described in any of the above by execution of the computer program.
The present application also provides a computer readable storage medium comprising a stored program, wherein the program when run performs a method of implementing any one of the token backfill methods described above.
The application also provides a computer program product comprising a computer program which when executed by a processor implements a method of token backfilling as described in any one of the above.
According to the token backfilling method, the storage medium and the electronic device, token acquisition is performed based on the token acquisition request input by the user side, different acquisition results are output, then state information of the token bucket under each acquisition result condition is acquired, current limiting information of the token acquisition request under the condition that the acquisition result is failure is acquired, and finally token backfilling is performed on the token bucket based on the state information corresponding to each acquisition result and the current limiting information of the token acquisition request. Under the condition that the token acquisition request of the user is limited, the application can confirm whether the token is excessively deducted according to the current limiting information and the state information, and timely backfill the token in the token bucket, thereby realizing correct token application.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and together with the description, serve to explain the principles of the application.
In order to more clearly illustrate the embodiments of the application or the technical solutions of the prior art, the drawings which are used in the description of the embodiments or the prior art will be briefly described, and it will be obvious to a person skilled in the art that other drawings can be obtained from these drawings without inventive effort.
FIG. 1 is a flow chart of token deduction in the prior art;
FIG. 2 is a schematic flow chart of a method for backfilling tokens according to an embodiment of the present application;
FIG. 3 is a second flow chart of a method for token backfilling according to an embodiment of the present application;
FIG. 4 is a schematic diagram of a token backfill apparatus according to an embodiment of the present application;
FIG. 5 is a schematic diagram of a hardware environment of an interaction method of a smart device according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of an electronic device provided by the present application.
Detailed Description
In order that those skilled in the art will better understand the present application, a technical solution in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in which it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present application without making any inventive effort, shall fall within the scope of the present application.
It should be noted that the terms "first," "second," and the like in the description and the claims of the present application and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the application described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Referring to fig. 1, fig. 1 is a flow chart illustrating token deduction in the prior art. First, the user's input request goes into token acquisition according to three different rules: rule 1, rule 2, rule 3 perform token acquisition.
Wherein rule 1 obtains 500 tokens every three minutes, rule 2 obtains 1000 tokens every five minutes, and rule 3 obtains 2000 tokens every hour.
Under the conditions of rule 1 and rule 2, obtaining the token successfully; no token is acquired under rule 3 and the end user's input request is restricted.
In the above case, since the rule 1 and the rule 2 successfully acquire the token, but since the input request is limited, the rule 1 and the rule 2 unnecessarily deduct the token when acquiring the token, which causes the phenomenon of unnecessary deduction of the token, thereby causing the error of the token application.
In summary, the embodiment of the application provides a token backfilling method, a storage medium and an electronic device, which can backfill a token bucket according to a redundant deducted token when the token is redundant deducted, thereby realizing correct token application.
Referring to fig. 2, the method for backfilling tokens provided by the embodiment of the application comprises the following steps:
Step 210, performing token acquisition based on a token acquisition request input by the user terminal, and outputting different acquisition results.
The execution subject in this embodiment is a token backfill apparatus; the token backfill device can be a mobile electronic device or a non-mobile electronic device. By way of example, the mobile electronic device may be a mobile phone, a tablet computer, a notebook computer, a palm computer, a vehicle-mounted electronic device, etc., and the non-mobile electronic device may be an edge server, a cloud server, a network attached storage, a personal computer, etc., which are not particularly limited herein.
The definition of the API gateway is as follows: two mutually independent local area networks communicate through a router, and the middle route is called a gateway. Accordingly, any one application system, if it needs to be called by another system, needs to expose APIs that represent one functional point. If two systems communicate in between, an mediator is added between the systems to assist in the calling of the API, which mediator is the API gateway.
Firstly, under the API application scene, when a token acquisition request input by a user terminal is received, token acquisition is required to be confirmed. The rule of token acquisition can be set to be multiple, such as rule 1 is to acquire 500 tokens every three minutes, rule 2 is to acquire 1000 tokens every five minutes, and rule 3 is to acquire 2000 tokens every hour. According to a plurality of different rules, different acquisition results are acquired, wherein the acquisition results comprise success of token acquisition and failure of token acquisition.
Step 220, collecting the state information of the token bucket under each acquisition result condition, and collecting the flow limiting information of the token acquisition request under the condition that the acquisition result is failure.
Specifically, after the token is acquired, the state information of the token bucket under different rules is acquired according to different acquisition results. When the token acquisition is successful, it is indicated that the remaining tokens in the token bucket correspond to the input request, and the input request needs to be forwarded to other systems at this time. When the token acquisition fails, the token bucket is free of the remaining tokens corresponding to the input request, and the input request is required to be subjected to flow limiting processing, so that the input request is limited, and the situation that the request is discarded or queued for the tokens generated in the next period is effectively avoided
It should be further noted that, in this embodiment, when the token acquisition is successful, the state information of the token bucket is that the token is reduced, and when the token acquisition fails, the state of the token bucket is that the token is unchanged.
Further, when the token acquisition fails, it may be that: rule 1, rule 2 and rule 3 all fail to acquire; any two of rule 1, rule 2 and rule 3 fail to acquire; any one of rule 1, rule 2, and rule 3 fails to acquire. It is necessary to collect the current limit information in any possible case, i.e. the information that the input request of the user side is limited.
And step 230, performing token backfilling on the token bucket based on the state information and the current limit information.
Specifically, on the premise of limiting the flow information, that is, when confirming that the input request of the user is limited, whether the unnecessary deduction of the token exists or not can be confirmed according to the state information of the token bucket. Such as: the input request of the user side is limited, but the state information of the token bucket is the condition of deduction of the token, which indicates that the phenomenon of redundant deduction of the token exists at the moment, and the token bucket needs to be refilled with the token. By means of token backfilling, the number of tokens in the token bucket cannot be confused by requests caused by redundant deduction, and the possibility of error of token requests is reduced.
According to the token backfilling method provided by the embodiment of the application, token acquisition is performed based on the token acquisition request input by the user side, different acquisition results are output, then the state information of the token bucket under each acquisition result condition is acquired, the current limiting information of the token acquisition request under the condition that the acquisition result is failure is acquired, and finally the token bucket is backfilled based on the state information corresponding to each acquisition result and the current limiting information of the token acquisition request. Under the condition that the token acquisition request of the user is limited, the application can confirm whether the token is excessively deducted according to the current limiting information and the state information, and timely backfill the token in the token bucket, thereby realizing correct token application.
Based on the above embodiment, the performing token backfilling on the token bucket based on the state information and the current limit information includes:
Confirming that the token acquisition request is in a current limiting condition based on the current limiting information, and acquiring token deduction information of the token bucket based on the current limiting information and the state information;
judging whether the token has redundant deduction or not based on the token deduction information;
and in the case that redundant deduction exists for the token, performing token backfilling on the token bucket based on the CAS atomic operation.
Specifically, the embodiment provides a specific way for the situation of excessive deduction of the token and a process of backfilling the excessive deduction of the token. Firstly, the token acquisition request input by the user terminal can be confirmed to be in a limited state according to the current limiting information. Then, it is confirmed from the status information whether there is an unnecessary deduction of the token under each rule condition. For example, if either or both of rule 1, rule 2 and rule 3 succeed in obtaining the token, then there must be an unnecessary deduction of the token. Thus, token backfilling by CAS atomic operations is required.
It should be noted that CAS atomic operations (Compare And replace), colloquially speaking, replace old values with new values. In this embodiment, if the number of original tokens in the token bucket is assumed to be 100, it is necessary to subtract tokens in one token bucket every time it is acquired according to an input request. Let 2 be subtracted, at which time 98 tokens remain in the token bucket. But since the user-entered request is restricted, these 2 tokens are superfluously deducted. At this point, 100 is required to replace the old value 98 with the new value, thus supplementing the extra deducted token, i.e., realizing the backfilling of the token.
According to the token backfilling method provided by the embodiment of the application, the token bucket is timely replenished under the condition of redundant deduction of the token by utilizing CAS atomic operation, so that the token in the token bucket is timely backfilled, and the correct token application is realized.
Based on the above embodiment, in the case where there is an unnecessary deduction of the token, performing token backfilling on the token bucket based on CAS atomic operation includes:
Under the condition that excessive deduction exists in the token, acquiring a first target value and a second target value before and after token deduction based on the token deduction information;
And replacing the second target value with the first target value based on the CAS atomic operation to implement token backfilling of the token bucket under the condition that the target expected value is equal to the first target value.
In particular, the present embodiment provides a specific way of performing token backfilling based on CAS atomic operations. And under the condition that the excessive deduction exists in the token, acquiring a first target value and a second target value before and after the deduction of the token. For example, the number of tokens is 100 before deduction, and 98 after deduction. When the target expected value and the first target value are equal, i.e., the target expected value is also 100, then the second target value is replaced with the first target value, i.e., 98 is replaced with 100 to achieve token backfill.
According to the token backfilling method provided by the embodiment of the application, under the condition of redundant deduction of the token, the first target value before redundant deduction of the token is used for replacing the second target value after redundant deduction of the token, so that the token bucket is timely replenished with the token, and the token backfilling in the token bucket is timely realized, thereby realizing correct token application.
Based on the above embodiment, before the confirming that the token acquisition request is in the current limit condition based on the current limit information, the method further includes:
acquiring the flow increment of the API gateway in a target time period;
Comparing the flow increment with a preset threshold value to obtain a judging result of whether the API gateway is in the condition of flow surge;
and confirming whether the capacity of the token bucket is adjusted or not based on the judging result.
Specifically, in this embodiment, if each system of the API gateway is in a flow surge, that is, the flow increase in the target period is greater than the preset target threshold, the capacity of the token bucket needs to be adjusted. The adjustment mode is to increase the capacity of the token bucket according to a preset capacity threshold and a dynamic capacity expansion threshold, namely, the size of the source bucket (the size of the bucket before adjustment) and the dynamic capacity expansion threshold are added to obtain the size of the bucket after adjustment.
The method for determining the dynamic capacity expansion threshold is as follows:
first, the flow average of a plurality of systems is calculated as shown in the following formula (1):
then, performing aggregation analysis according to the number of systems, the flow data and the flow average value to obtain an analysis result delta, namely a target standard deviation, wherein the calculation mode is shown in the following formula (2):
wherein x i is the flow data for each system, Is the flow average value, n is the system number.
And finally, forming a capacity expansion base line which is three times of standard deviation according to the target standard deviation delta and the target multiple, and generating a dynamic capacity expansion threshold value by combining the flow average value, wherein the calculation mode is shown in the following formula (3):
Wherein p is a dynamic capacity expansion threshold value, Is the flow average value, and 3 delta is the expansion baseline.
According to the token backfilling method provided by the embodiment of the application, when the flow surge condition is faced, the capacity of the token bucket is adjusted through the dynamic capacity expansion threshold value, so that the accuracy, controllability and intellectualization of token capacity adjustment are realized.
Based on the above embodiment, the determining whether to adjust the capacity of the token bucket based on the determination result includes:
acquiring a dynamic capacity expansion threshold of the token bucket under the condition that the flow increment is larger than the preset threshold;
And adjusting the capacity of the token bucket based on the preset capacity threshold value and the dynamic capacity expansion threshold value of the token bucket.
In particular, the present embodiment provides one of the implementations in the case of different flow surges. If the API gateway is in the flow surge, that is, the flow increment in the target time period is greater than the preset target threshold, the capacity of the token bucket needs to be dynamically adjusted.
Note that, the present invention is not limited to the above-described embodiments. The dynamic capacity expansion threshold in this embodiment is determined according to the flow information of each system, that is, the dynamic capacity expansion threshold is dynamically changed in real time, so that the capacity adjustment of the token bucket is also dynamically adjusted.
According to the token backfilling method provided by the embodiment of the application, the flow information of the system is changed in real time, so that the dynamic capacity expansion threshold value is also changed dynamically, the capacity of the token bucket can be adjusted according to the flow information of a plurality of systems, the accuracy of the capacity adjustment of the token bucket is ensured, intelligent coping with the flow surge is realized through dynamic adjustment, and the system is not crushed.
Based on the above embodiment, the determining whether to adjust the capacity of the token bucket based on the determination result includes:
adjusting a time confirmation time span based on the current time and the last token bucket capacity under the condition that the flow increment is less than or equal to the preset threshold value;
And judging whether the token bucket adjusts the capacity of the token bucket or not based on the time span and the token bucket refreshing period.
In particular, the present embodiment provides a second implementation in the case of a different flow surge. If the API gateway is not in the flow surge, that is, the flow increment in the target time period is less than or equal to the preset target threshold, timing adjustment is needed for the capacity of the token bucket.
And confirming whether the capacity of the token bucket is adjusted or not according to the time span and the refresh period of the token bucket by acquiring the current time and the time confirmation time span of the previous token adding to the token bucket.
According to the token backfilling method provided by the embodiment of the application, the adjustment of the capacity of the token bucket is not required to be carried out every time, so that the resource waste caused by redundant addition of tokens is reduced.
Based on the above embodiment, the determining whether the token bucket adjusts the capacity of the token bucket based on the time span and the token bucket refresh period includes:
confirming that no token needs to be added to the token bucket in the condition that the time span is smaller than or equal to the token bucket refresh period;
and in the case that the time span is greater than the token bucket refresh period, confirming that a new token is added into the token bucket to adjust the capacity of the card bucket.
In particular, the present embodiment provides a specific implementation procedure for timing adjustment of the capacity of a token bucket.
In one aspect, in the event that the time span is less than or equal to the token bucket refresh period, the confirmation is made without adding tokens to the token bucket. That is, when the current time is not one period from the last time of adding a token, and the token adding condition is not satisfied, a new token is not added to the token bucket.
On the other hand, in the case where the time span is greater than the token bucket refresh period, it is confirmed that a token needs to be added to the token bucket. That is, the current time has reached one period of token addition since the last time token was added, satisfying the token addition condition, a new token needs to be added to the token bucket.
When the number of tokens in the token bucket reaches a target threshold, namely the number of tokens reaches the required number or the capacity of the token bucket reaches the maximum, the token adding is stopped, an instruction is generated to confirm that the adding is completed, and an input request of a user side is input into other systems.
According to the token backfilling method, the time span is compared with the preset token refreshing period to determine whether the token bucket adds a new token, a timing task is not required to be set, and the token addition is not required to be executed every time, so that resource waste caused by redundant addition of the token can be effectively reduced.
Referring to fig. 3, fig. 3 is a flow chart of a token backfill method according to an embodiment of the present application, including:
step 310, a request is entered.
Step 320, obtain tokens based on rule 1, rule 2, and rule 3. Wherein, rule 1 is to obtain 500 tokens every three minutes, rule 2 is to obtain 1000 tokens every five minutes, and rule 3 is to obtain 2000 tokens every hour.
Step 330, the acquisition of the token based on rule 1 and rule 2 succeeds, and the acquisition of the token based on rule 3 fails.
Step 340, record token bucket status under each rule.
And step 350, performing token backfilling on the token buckets corresponding to the rule 1 and the rule 2.
Step 360, limiting the incoming request.
The token backfill device provided by the application is described below, and the token backfill device described below and the token backfill method described above can be referred to correspondingly.
Referring to fig. 4, an apparatus for backfilling a token according to an embodiment of the present application includes: an output module 410, an acquisition module 420, and a backfill module 430;
The output module 410 is configured to perform token acquisition based on a token acquisition request input by the user side, and output different acquisition results;
The acquisition module 420 is configured to acquire status information of the token bucket under each acquisition result condition, and acquire current limit information of the token acquisition request when the acquisition result is failure;
and a backfilling module 430, configured to backfill the token bucket with tokens based on the state information and the current limit information.
According to the token backfilling device provided by the embodiment of the application, token acquisition is performed based on the token acquisition request input by the user side, different acquisition results are output, then the state information of the token bucket under each acquisition result condition is acquired, the current limiting information of the token acquisition request under the condition that the acquisition result is failure is acquired, and finally the token bucket is backfilled based on the state information corresponding to each acquisition result and the current limiting information of the token acquisition request. Under the condition that the token acquisition request of the user is limited, the application can confirm whether the token is excessively deducted according to the current limiting information and the state information, and timely backfill the token in the token bucket, thereby realizing correct token application.
Based on the above embodiments, the backfill module is specifically configured to:
Confirming that the token acquisition request is in a current limiting condition based on the current limiting information, and acquiring token deduction information of the token bucket based on the current limiting information and the state information;
judging whether the token has redundant deduction or not based on the token deduction information;
and in the case that redundant deduction exists for the token, performing token backfilling on the token bucket based on the CAS atomic operation.
Based on the above embodiment, the backfill module is further configured to:
Under the condition that excessive deduction exists in the token, acquiring a first target value and a second target value before and after token deduction based on the token deduction information;
And replacing the second target value with the first target value based on the CAS atomic operation to implement token backfilling of the token bucket under the condition that the target expected value is equal to the first target value.
Based on the above embodiment, further comprising:
the acquisition module is used for acquiring the flow increment of the API gateway in the target time period;
The comparison module is used for comparing the flow increment with a preset threshold value to obtain a judgment result of whether the API gateway is in the flow surge condition;
and the confirming module is used for confirming whether the capacity of the token bucket is adjusted or not based on the judging result.
Based on the above embodiments, the confirmation module is specifically configured to:
acquiring a dynamic capacity expansion threshold of the token bucket under the condition that the flow increment is larger than the preset threshold;
And adjusting the capacity of the token bucket based on the preset capacity threshold value and the dynamic capacity expansion threshold value of the token bucket.
Based on the above embodiments, the confirmation module is specifically configured to:
adjusting a time confirmation time span based on the current time and the last token bucket capacity under the condition that the flow increment is less than or equal to the preset threshold value;
And judging whether the token bucket adjusts the capacity of the token bucket or not based on the time span and the token bucket refreshing period.
Based on the above embodiment, the confirmation module is further configured to:
confirming that no token needs to be added to the token bucket in the condition that the time span is smaller than or equal to the token bucket refresh period;
and in the case that the time span is greater than the token bucket refresh period, confirming that a new token is added into the token bucket to adjust the capacity of the card bucket.
According to one aspect of an embodiment of the present application, a method for token backfilling is provided. The token backfilling method is widely applied to full-house intelligent digital control application scenes such as intelligent Home (Smart Home), intelligent Home equipment ecology, intelligent Home (INTELLIGENCE HOUSE) ecology and the like. Alternatively, in the present embodiment, the token backfilling method described above may be applied to a hardware environment constituted by the terminal device 502 and the server 504 as shown in fig. 5. As shown in fig. 5, the server 504 is connected to the terminal device 502 through a network, and may be used to provide services (such as application services and the like) for a terminal or a client installed on the terminal, a database may be set on the server or independent of the server, to provide data storage services for the server 504, and cloud computing and/or edge computing services may be configured on the server or independent of the server, to provide data computing services for the server 504.
The network may include, but is not limited to, at least one of: wired network, wireless network. The wired network may include, but is not limited to, at least one of: a wide area network, a metropolitan area network, a local area network, and the wireless network may include, but is not limited to, at least one of: WIFI (WIRELESS FIDELITY ), bluetooth. The terminal device 502 may not be limited to a PC, a mobile phone, a tablet computer, an intelligent air conditioner, an intelligent smoke machine, an intelligent refrigerator, an intelligent oven, an intelligent cooking range, an intelligent washing machine, an intelligent water heater, an intelligent washing device, an intelligent dish washer, an intelligent projection device, an intelligent television, an intelligent clothes hanger, an intelligent curtain, an intelligent video, an intelligent socket, an intelligent sound box, an intelligent fresh air device, an intelligent kitchen and toilet device, an intelligent bathroom device, an intelligent sweeping robot, an intelligent window cleaning robot, an intelligent mopping robot, an intelligent air purifying device, an intelligent steam box, an intelligent microwave oven, an intelligent kitchen appliance, an intelligent purifier, an intelligent water dispenser, an intelligent door lock, and the like.
Fig. 6 illustrates a physical schematic diagram of an electronic device, as shown in fig. 6, which may include: processor 610, communication interface (Communications Interface) 620, memory 630, and communication bus 640, wherein processor 610, communication interface 620, memory 630 communicate with each other via communication bus 640. The processor 610 may invoke logic instructions in the memory 630 to perform a token backfill method comprising: based on a token acquisition request input by a user terminal, carrying out token acquisition and outputting different acquisition results; collecting state information of a token bucket under each acquisition result condition, and collecting current limiting information of the token acquisition request under the condition that the acquisition result is failure; and carrying out token backfilling on the token bucket based on the state information and the current limit information.
Further, the logic instructions in the memory 630 may be implemented in the form of software functional units and stored in a computer-readable storage medium when sold or used as a stand-alone product. Based on this understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a usb disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
In another aspect, the present application also provides a computer program product, the computer program product including a computer program, the computer program being storable on a computer readable storage medium, the computer program, when executed by a processor, being capable of executing the token backfilling method provided by the above methods, the method comprising: based on a token acquisition request input by a user terminal, carrying out token acquisition and outputting different acquisition results; collecting state information of a token bucket under each acquisition result condition, and collecting current limiting information of the token acquisition request under the condition that the acquisition result is failure; and carrying out token backfilling on the token bucket based on the state information and the current limit information.
In still another aspect, the present application further provides a computer readable storage medium, where the computer readable storage medium includes a stored program, where the program executes a method for backfilling tokens provided by the above methods, the method comprising: based on a token acquisition request input by a user terminal, carrying out token acquisition and outputting different acquisition results; collecting state information of a token bucket under each acquisition result condition, and collecting current limiting information of the token acquisition request under the condition that the acquisition result is failure; and carrying out token backfilling on the token bucket based on the state information and the current limit information.
The apparatus embodiments described above are merely illustrative, wherein the elements illustrated as separate elements may or may not be physically separate, and the elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
From the above description of the embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus necessary general hardware platforms, or of course may be implemented by means of hardware. Based on this understanding, the foregoing technical solution may be embodied essentially or in a part contributing to the prior art in the form of a software product, which may be stored in a computer readable storage medium, such as ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method described in the respective embodiments or some parts of the embodiments.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present application, and are not limiting; although the application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims (10)

1. A method of token backfilling comprising:
based on a token acquisition request input by a user terminal, carrying out token acquisition and outputting different acquisition results;
collecting state information of a token bucket under each acquisition result condition, and collecting current limiting information of the token acquisition request under the condition that the acquisition result is failure;
And under the condition that the input request of the user side is limited and the state information of the token bucket is token deduction, carrying out token backfilling on the token bucket based on the state information and the current limiting information.
2. The method of claim 1, wherein the step of token backfilling the token bucket based on the state information and the current limit information comprises:
Confirming that the token acquisition request is in a current limiting condition based on the current limiting information, and acquiring token deduction information of the token bucket based on the current limiting information and the state information;
judging whether the token has redundant deduction or not based on the token deduction information;
and in the case that redundant deduction exists for the token, performing token backfilling on the token bucket based on the CAS atomic operation.
3. The method of claim 2, wherein the step of refilling the token bucket with tokens based on CAS atomic operations in the presence of redundant deductions of tokens comprises:
Under the condition that excessive deduction exists in the token, acquiring a first target value and a second target value before and after token deduction based on the token deduction information;
And replacing the second target value with the first target value based on the CAS atomic operation to implement token backfilling of the token bucket under the condition that the target expected value is equal to the first target value.
4. The method of claim 1, wherein the confirming that the token acquisition request is in a current limit condition based on the current limit information further comprises:
acquiring the flow increment of the API gateway in a target time period;
Comparing the flow increment with a preset threshold value to obtain a judging result of whether the API gateway is in the condition of flow surge;
and confirming whether the capacity of the token bucket is adjusted or not based on the judging result.
5. The method of claim 4, wherein the determining whether to adjust the capacity of the token bucket based on the determination result comprises:
acquiring a dynamic capacity expansion threshold of the token bucket under the condition that the flow increment is larger than the preset threshold;
And adjusting the capacity of the token bucket based on the preset capacity threshold value and the dynamic capacity expansion threshold value of the token bucket.
6. The method of claim 4, wherein the determining whether to adjust the capacity of the token bucket based on the determination result comprises:
adjusting a time confirmation time span based on the current time and the last token bucket capacity under the condition that the flow increment is less than or equal to the preset threshold value;
And judging whether the token bucket adjusts the capacity of the token bucket or not based on the time span and the token bucket refreshing period.
7. The method of claim 6, wherein the determining whether the token bucket adjusts the capacity of the token bucket based on the time span and a token bucket refresh period comprises:
confirming that no token needs to be added to the token bucket in the condition that the time span is smaller than or equal to the token bucket refresh period;
and in the case that the time span is greater than the token bucket refresh period, confirming that a new token is added into the token bucket to adjust the capacity of the card bucket.
8. A token backfill apparatus, comprising:
The output module is used for carrying out token acquisition based on a token acquisition request input by the user side and outputting different acquisition results;
The acquisition module is used for acquiring state information of the token bucket under each acquisition result condition and acquiring current limiting information of the token acquisition request under the condition that the acquisition result is failure;
and the backfilling module is used for backfilling the token bucket based on the state information and the current limiting information under the condition that the input request of the user side is limited and the state information of the token bucket is token deduction.
9. A computer-readable storage medium, characterized in that the computer-readable storage medium comprises a stored program, wherein the program when run performs the token backfill method of any one of claims 1 to 7.
10. An electronic device comprising a memory and a processor, wherein the memory has stored therein a computer program, the processor being arranged to perform the token backfill method of any one of claims 1 to 7 by means of the computer program.
CN202210884966.0A 2022-07-26 2022-07-26 Token backfill method, storage medium and electronic device Active CN115378656B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210884966.0A CN115378656B (en) 2022-07-26 2022-07-26 Token backfill method, storage medium and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210884966.0A CN115378656B (en) 2022-07-26 2022-07-26 Token backfill method, storage medium and electronic device

Publications (2)

Publication Number Publication Date
CN115378656A CN115378656A (en) 2022-11-22
CN115378656B true CN115378656B (en) 2024-07-19

Family

ID=84064651

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210884966.0A Active CN115378656B (en) 2022-07-26 2022-07-26 Token backfill method, storage medium and electronic device

Country Status (1)

Country Link
CN (1) CN115378656B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106385377A (en) * 2015-07-29 2017-02-08 腾讯科技(深圳)有限公司 Information processing method and system thereof
CN110932994A (en) * 2019-12-31 2020-03-27 深圳云天励飞技术有限公司 Data traffic processing method and device, electronic equipment and storage medium

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7327682B2 (en) * 2003-06-27 2008-02-05 Cisco Technology, Inc. Methods and devices for flexible bandwidth allocation
US7805382B2 (en) * 2005-04-11 2010-09-28 Mkt10, Inc. Match-based employment system and method
CN100574278C (en) * 2006-12-26 2009-12-23 华为技术有限公司 The method of refreshing token bucket and device in the flow limiting technology
US20140359112A1 (en) * 2013-05-31 2014-12-04 Broadcom Corporation Burst Access to Memory in Optical Line Terminal
CN111901174B (en) * 2020-07-30 2024-04-26 腾讯科技(深圳)有限公司 Service state notification method, related device and storage medium
CN113765820A (en) * 2020-10-30 2021-12-07 北京沃东天骏信息技术有限公司 Token bucket-based current limiting method, token bucket-based current limiting device, token bucket-based computing equipment and token bucket-based current limiting medium
CN114024908A (en) * 2021-11-03 2022-02-08 蚂蚁胜信(上海)信息技术有限公司 Real-time self-adaptive current limiting method, current limiting service system and current limiter
CN114143265A (en) * 2021-11-26 2022-03-04 杭州安恒信息技术股份有限公司 Network flow current limiting method, device, equipment and storage medium

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106385377A (en) * 2015-07-29 2017-02-08 腾讯科技(深圳)有限公司 Information processing method and system thereof
CN110932994A (en) * 2019-12-31 2020-03-27 深圳云天励飞技术有限公司 Data traffic processing method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN115378656A (en) 2022-11-22

Similar Documents

Publication Publication Date Title
JP6457447B2 (en) Data center network traffic scheduling method and apparatus
JP7568354B2 (en) Flow Control for Probabilistic Relaying in Blockchain Networks
US11159376B2 (en) System and method for network infrastructure analysis and convergence
JP7398000B2 (en) Blockchain-based data detection method and device, computer device and program
US8695079B1 (en) Allocating shared resources
CN115460153B (en) Dynamic adjustment method and device for token bucket capacity, storage medium and electronic device
CN107402851B (en) Data recovery control method and device
CN107797859B (en) Scheduling method of timing task and scheduling server
CN107102889B (en) Virtual machine resource adjusting method and device
CN103595736B (en) Access request treating method and apparatus in video monitoring system
CN115955332A (en) Abnormal traffic filtering method and device for authentication system and electronic equipment
CN117950862A (en) Dynamic capacity expansion and contraction method and related equipment
CN108200185B (en) Method and device for realizing load balance
CN115378656B (en) Token backfill method, storage medium and electronic device
CN113469811A (en) Block chain transaction processing method and device
US11736299B2 (en) Data access control for edge devices using a cryptographic hash
CN114697150B (en) Command issuing method and device, storage medium and electronic device
Kancharla et al. Dependable Industrial Crypto Computing
CN116450229A (en) Pre-starting method and device of application software, storage medium and electronic device
CN110781500A (en) Data wind control system and method
CN115658290A (en) Message processing method, device, equipment and storage medium
CN113300966B (en) Flow control method, device, system and electronic equipment
CN114780565A (en) Cache updating method and device, storage medium and electronic device
CN111371675B (en) Intelligent addressing method, device, equipment and storage medium thereof
CN112148551B (en) Method, apparatus and computer program product for determining a rate of change of usage of a storage system

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