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
acquisition
information
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 present application discloses a token backfilling method, a storage medium and an electronic device, and relates to the field of smart home/intelligent home technology. The token backfilling method includes: acquiring tokens based on a token acquisition request input by a user end, and outputting different acquisition results; collecting status information of a token bucket under each acquisition result condition, and collecting flow limiting information of the token acquisition request when the acquisition result is a failure; and backfilling the token bucket with tokens based on the status information and flow limiting information. In the case where the user's token acquisition request is flow limited, the present application can confirm whether the token is deducted in excess according to the flow limiting information and the status information, and timely backfill the token in the token bucket, thereby realizing the correct token application.

Description

令牌回填方法、存储介质及电子装置Token backfill method, storage medium and electronic device

技术领域Technical Field

本申请涉及智能家居/智慧家庭技术领域,尤其涉及一种令牌回填方法、存储介质及电子装置。The present application relates to the field of smart home/intelligent family technology, and in particular to a token backfill method, storage medium and electronic device.

背景技术Background technique

API,应用程序接口(Application Program Interface,API)网关作为流量入口,承担着最重要的责任,对其性能和稳定性有着极高的要求。面对极其复杂的业务场景,高并发的流量,以及潜在的攻击威胁,流量控制担任了重要角色。API, Application Program Interface (API) gateway as the traffic entrance, bears the most important responsibility, and has extremely high requirements for its performance and stability. Faced with extremely complex business scenarios, high concurrent traffic, and potential attack threats, traffic control plays an important role.

面对复杂的业务限流(ip、参数、用户、接口粗细粒度、同一接口多种限流规则-不同优先级、不同服务接口组限流、多协议限流等)。在API网关进行服务时,在流量激增时会对用户的输入请求进行限流或者增大令牌桶容量。Faced with complex business flow control (IP, parameters, users, interface coarse and fine granularity, multiple flow control rules for the same interface - different priorities, flow control for different service interface groups, multi-protocol flow control, etc.), when the API gateway provides services, it will limit the user's input requests or increase the token bucket capacity when the traffic surges.

由于API网关可以设置不同的规则,且生成令牌的周期长短不一。现有的做法在用户的输入请求进来后,尝试获取令牌,有些规则获取到令牌,有些令牌为获取到令牌,因此用户的输入请求会被限流。由于输入请求被限流,那么获取令牌成功时对应的规则就不应该扣除令牌。Since the API gateway can set different rules and the token generation cycle varies in length, the existing approach is to try to obtain a token after the user's input request comes in. Some rules obtain the token, while some tokens do not obtain the token, so the user's input request will be limited. Since the input request is limited, the corresponding rule should not deduct the token when the token is successfully obtained.

因此,如何避免在限流情况下出现令牌被多余扣除的现象,是当前亟需解决的技术问题。Therefore, how to avoid the phenomenon of unnecessary token deductions under current limiting conditions is a technical problem that needs to be solved urgently.

发明内容Summary of the invention

本申请提供一种令牌回填方法、存储介质及电子装置,用以解决现有技术中在限流情况下出现令牌被多余扣除的缺陷,实现在限流情况下对多余扣除的令牌进行回填,从而实现正确的令牌申请。The present application provides a token backfilling method, a storage medium and an electronic device, which are used to solve the defect of the prior art that tokens are excessively deducted under current limiting conditions, and to backfill the excess deducted tokens under current limiting conditions, thereby achieving correct token application.

本申请提供一种令牌回填方法,包括:The present application provides a token backfill method, comprising:

基于用户端输入的令牌获取请求进行令牌获取,输出不同的获取结果;Acquire tokens based on the token acquisition request input by the user, and output different acquisition results;

采集令牌桶在每种获取结果条件下的状态信息,以及采集在获取结果为失败情况下所述令牌获取请求的限流信息;Collecting status information of the token bucket under each acquisition result condition, and collecting current limiting information of the token acquisition request when the acquisition result is a failure;

基于所述状态信息和限流信息对所述令牌桶进行令牌回填。The token bucket is backfilled with tokens based on the state information and the current limiting information.

根据本申请提供的一种令牌回填方法,所述基于所述状态信息和限流信息对所述令牌桶进行令牌回填,包括:According to a token backfilling method provided by the present application, the token backfilling of the token bucket based on the state information and the current limiting information includes:

基于所述限流信息确认所述令牌获取请求处于限流情况,基于所述限流信息结合所述状态信息获取所述令牌桶的令牌扣除信息;Confirming that the token acquisition request is in a current limiting state based on the current limiting information, and acquiring token deduction information of the token bucket based on the current limiting information combined with the state information;

基于令牌扣除信息判断令牌是否存在多余扣除的情况;Based on the token deduction information, determine whether there is any excess deduction of the token;

在令牌存在多余扣除的情况下,基于CAS原子操作对所述令牌桶进行令牌回填。In the case where there is excess deduction of tokens, the token bucket is backfilled with tokens based on the CAS atomic operation.

根据本申请提供的一种令牌回填方法,所述在令牌存在多余扣除的情况下,基于CAS原子操作对所述令牌桶进行令牌回填,包括:According to a token backfilling method provided by the present application, in the case where there is excess deduction of tokens, the token bucket is backfilled with tokens based on a CAS atomic operation, including:

在令牌存在多余扣除的情况下,基于所述令牌扣除信息获取令牌扣除前后的第一目标数值和第二目标数值;In the case where there is excess deduction of the token, obtaining the first target value and the second target value before and after the token deduction based on the token deduction information;

在目标期望值等于所述第一目标值的情况下,基于所述CAS原子操作,利用所述第一目标数值替换所述第二目标数值以实现对所述令牌桶进行令牌回填。When the target expected value is equal to the first target value, based on the CAS atomic operation, the first target value is used to replace the second target value to achieve token backfilling of the token bucket.

根据本申请提供的一种令牌回填方法,所述基于所述限流信息确认所述令牌获取请求处于限流情况之前,还包括:According to a token backfill method provided by the present application, before confirming that the token acquisition request is in a current limiting situation based on the current limiting information, the method further includes:

获取API网关在目标时间段内的流量增加量;Get the traffic increase of the API gateway during the target time period;

对所述流量增加量和预设阈值进行比较,得到所述API网关是否处于流量激增情况的判断结果;Compare the traffic increase with a preset threshold to determine whether the API gateway is experiencing a traffic surge;

基于所述判断结果确认是否对所述令牌桶的容量进行调整。Determine whether to adjust the capacity of the token bucket based on the determination result.

根据本申请提供的一种令牌回填方法,所述基于所述判断结果确认是否对所述令牌桶的容量进行调整,包括:According to a token backfill method provided by the present application, the step of confirming whether to adjust the capacity of the token bucket based on the judgment result includes:

在所述流量增加量大于所述预设阈值的情况下,获取所述令牌桶的动态扩容阈值;When the traffic increase is greater than the preset threshold, obtaining a dynamic expansion threshold of the token bucket;

基于所述令牌桶的预设容量阈值和所述动态扩容阈值对所述令牌桶的容量进行调整。The capacity of the token bucket is adjusted based on the preset capacity threshold of the token bucket and the dynamic capacity expansion threshold.

根据本申请提供的一种令牌回填方法,所述基于所述判断结果确认是否对所述令牌桶的容量进行调整,包括:According to a token backfill method provided by the present application, the step of confirming whether to adjust the capacity of the token bucket based on the judgment result includes:

在所述流量增加量小于或等于所述预设阈值的情况下,基于当前时间和上次令牌桶容量调整时间确认时间跨度;In the case where the traffic increase is less than or equal to the preset threshold, confirming the time span based on the current time and the last token bucket capacity adjustment time;

基于所述时间跨度和令牌桶刷新周期判断所述令牌桶是否对所述令牌桶的容量进行调整。The token bucket is judged whether to adjust the capacity of the token bucket based on the time span and the token bucket refresh period.

根据本申请提供的一种令牌回填方法,所述基于所述时间跨度和令牌桶刷新周期判断所述令牌桶是否对所述令牌桶的容量进行调整,包括:According to a token backfill method provided by the present application, judging whether the token bucket adjusts the capacity of the token bucket based on the time span and the token bucket refresh cycle includes:

在所述时间跨度小于或等于所述令牌桶刷新周期的情况下,确认无需向所述令牌桶中添加令牌;When the time span is less than or equal to the token bucket refresh period, confirming that there is no need to add tokens to the token bucket;

在所述时间跨度大于所述令牌桶刷新周期的情况下,确认向所述令牌桶中添加新的令牌以调整所述牌桶的容量。In the case where the time span is greater than the token bucket refresh period, it is confirmed to add new tokens to the token bucket to adjust the capacity of the card bucket.

本申请还提供一种令牌回填装置,包括:The present application also provides a token backfilling device, comprising:

输出模块,用于基于用户端输入的令牌获取请求进行令牌获取,输出不同的获取结果;The output module is used to obtain the token based on the token acquisition request input by the user end and output different acquisition results;

采集模块,用于采集令牌桶在每种获取结果条件下的状态信息,以及采集在获取结果为失败情况下所述令牌获取请求的限流信息;A collection module, used to collect status information of the token bucket under each acquisition result condition, and to collect current limiting information of the token acquisition request when the acquisition result is a failure;

回填模块,用于基于所述状态信息和限流信息对所述令牌桶进行令牌回填。A backfill module is used to backfill the token bucket with tokens based on the state information and current limiting information.

本申请还提供一种电子装置,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器被设置为通过所述计算机程序执行实现如上述任一种所述令牌回填方法。The present application also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute and implement any of the token backfill methods described above through the computer program.

本申请还提供一种计算机可读的存储介质,所述计算机可读的存储介质包括存储的程序,其中,所述程序运行时执行实现如上述任一种所述令牌回填方法。The present application also provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored program, wherein the program is executed to implement any of the token backfilling methods described above when it is run.

本申请还提供一种计算机程序产品,包括计算机程序,所述计算机程序被处理器执行时实现如上述任一种所述令牌回填方法。The present application also provides a computer program product, including a computer program, wherein when the computer program is executed by a processor, the token backfilling method described above is implemented.

本申请提供的令牌回填方法、存储介质及电子装置,通过基于用户端输入的令牌获取请求进行令牌获取,输出不同的获取结果,然后采集令牌桶在每种获取结果条件下的状态信息,以及采集在获取结果为失败情况下令牌获取请求的限流信息,最后基于每种获取结果对应的状态信息和对令牌获取请求的限流信息对令牌桶进行令牌回填。本申请在用户的令牌获取请求被限流的情况下,根据限流信息和状态信息能够确认令牌是否被多余扣除,以及时地对令牌桶内进行令牌回填,从而实现正确的令牌申请。The token backfill method, storage medium and electronic device provided by the present application acquire tokens based on the token acquisition request input by the user end, output different acquisition results, then collect the status information of the token bucket under each acquisition result condition, and collect the flow limiting information of the token acquisition request when the acquisition result is a failure, and finally backfill the token bucket with tokens based on the status information corresponding to each acquisition result and the flow limiting information of the token acquisition request. In the case where the user's token acquisition request is flow limited, the present application can confirm whether the token is deducted in excess according to the flow limiting information and status information, and timely backfill the token in the token bucket, thereby realizing the correct token application.

附图说明BRIEF DESCRIPTION OF THE DRAWINGS

此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本申请的实施例,并与说明书一起用于解释本申请的原理。The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,对于本领域普通技术人员而言,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

图1是现有技术中令牌扣除的流程示意图;FIG1 is a schematic diagram of a flow chart of token deduction in the prior art;

图2是本申请实施例提供的令牌回填方法的流程示意图之一;FIG2 is a flow chart of a token backfill method according to an embodiment of the present application;

图3是本申请实施例提供的令牌回填方法的流程示意图之二;FIG3 is a second flow chart of a token backfill method provided in an embodiment of the present application;

图4是本申请实施例提供的令牌回填装置的结构示意图;FIG4 is a schematic diagram of the structure of a token backfill device provided in an embodiment of the present application;

图5是根据本申请实施例的一种智能设备的交互方法的硬件环境示意图;FIG5 is a schematic diagram of a hardware environment of an interaction method of a smart device according to an embodiment of the present application;

图6是本申请提供的电子装置的结构示意图。FIG. 6 is a schematic diagram of the structure of the electronic device provided in the present application.

具体实施方式Detailed ways

为了使本技术领域的人员更好地理解本申请方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分的实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于本申请保护的范围。In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.

需要说明的是,本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的本申请的实施例能够以除了在这里图示或描述的那些以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

参照图1,图1是现有技术中的令牌扣除的流程示意图。首先,用户的输入请求进入进行令牌获取,根据三种不同的规则:规则1、规则2、规则3进行令牌获取。Referring to Figure 1, Figure 1 is a flow chart of token deduction in the prior art. First, the user's input request enters to obtain a token, and the token is obtained according to three different rules: Rule 1, Rule 2, and Rule 3.

其中,规则1为每三分钟获取500个令牌,规则2为每五分钟获取1000个令牌,规则3为每一小时获取2000个令牌。Among them, 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.

在规则1和规则2的条件下,获取令牌成功;在规则3的条件下未获取到令牌,最终用户的输入请求被限制。Under the conditions of rules 1 and 2, the token is obtained successfully; under the conditions of rule 3, the token is not obtained and the end user's input request is restricted.

上述情况下,由于规则1和规则2获取令牌成功,但是由于输入请求被限制,因此规则1和规则2在获取令牌时多余扣除了令牌,便造成了令牌多余扣除的现象,从而导致令牌申请出现错误。In the above case, since rules 1 and 2 successfully obtained the token, but because the input request was restricted, rules 1 and 2 deducted excess tokens when obtaining the token, resulting in excess token deduction, which led to an error in the token application.

综上所述,本申请实施例提出一种令牌回填方法、存储介质及电子装置,达到在令牌被多余扣除时,根据多余扣除的令牌对令牌桶进行回填,从而实现正确的令牌申请。In summary, the embodiments of the present application provide a token backfill method, a storage medium, and an electronic device, so that when tokens are deducted in excess, a token bucket is backfilled according to the excess tokens, thereby achieving correct token application.

参照图2,本申请实施例提供的令牌回填方法,包括以下步骤:Referring to FIG. 2 , the token backfill method provided in the embodiment of the present application includes the following steps:

步骤210,基于用户端输入的令牌获取请求进行令牌获取,输出不同的获取结果。Step 210: Token acquisition is performed based on the token acquisition request input by the user end, and different acquisition results are output.

本实施例中的执行主体是令牌回填装置;令牌回填装置可以是移动电子设备,也可以为非移动电子设备。示例性的,移动电子设备可以为手机、平板电脑、笔记本电脑、掌上电脑、车载电子设备等,非移动电子设备可以为边缘服务器、云服务器、网络附属存储器、个人计算机等,在此不作具体限定。The execution subject in this embodiment is a token backfill device; the token backfill device can be a mobile electronic device or a non-mobile electronic device. For example, the mobile electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted electronic device, etc., and the non-mobile electronic device can be an edge server, a cloud server, a network attached storage, a personal computer, etc., which are not specifically limited here.

其中,API网关的释义为:两个相互独立的局域网之间通过路由器进行通信,中间的路由即被称之为网关。相应地,任何一个应用系统如果需要被其他系统调用,就需要暴露API,这些API代表着一个一个的功能点。如果两个系统中间通信,在系统之间加上一个中介者协助API的调用,这个中介者就是API网关。The definition of API gateway is: two independent LANs communicate through a router, and the router in the middle is called a gateway. Accordingly, if any application system needs to be called by other systems, it needs to expose APIs, which represent functional points one by one. If two systems communicate in the middle, a mediator is added between the systems to assist in API calls. This mediator is the API gateway.

首先需要确认在API应用场景下,当接收到用户端输入的令牌获取请求时,进行令牌获取。其中,令牌获取的规则可设置为多种,如上述的规则1为每三分钟获取500个令牌,规则2为每五分钟获取1000个令牌,规则3为每一小时获取2000个令牌。根据多种不同的规则,获取不同的获取结果,获取结果包括令牌获取成功和令牌获取失败。First, it is necessary to confirm that in the API application scenario, when a token acquisition request is received from the user, token acquisition is performed. Among them, the rules for token acquisition can be set to multiple, such as the above rule 1 to obtain 500 tokens every three minutes, rule 2 to obtain 1000 tokens every five minutes, and rule 3 to obtain 2000 tokens every hour. According to a variety of different rules, different acquisition results are obtained, including successful token acquisition and token acquisition failure.

步骤220,采集令牌桶在每种获取结果条件下的状态信息,以及采集在获取结果为失败情况下所述令牌获取请求的限流信息。Step 220 , collect the status information of the token bucket under each acquisition result condition, and collect the current limiting information of the token acquisition request when the acquisition result is a failure.

具体地,本步骤在令牌获取之后,根据不同的获取结果采集令牌桶在不同规则下状态信息。当令牌获取成功时,说明令牌桶中有剩余令牌与输入请求对应,此时则需要将输入的请求转发至其他系统中。当令牌获取失败时,说明令牌桶中没有与输入请求相对应的剩余令牌,此时则需要对输入请求进行限流处理,限制输入请求的进入,从而有效地避免请求将会被丢弃或者排队等待下个周期生成的令牌的情况Specifically, after the token is acquired, this step collects the status information of the token bucket under different rules according to different acquisition results. When the token is acquired successfully, it means that there are remaining tokens in the token bucket corresponding to the input request. At this time, the input request needs to be forwarded to other systems. When the token acquisition fails, it means that there are no remaining tokens in the token bucket corresponding to the input request. At this time, the input request needs to be current-limited to limit the entry of the input request, thereby effectively avoiding the situation where the request will be discarded or queued to wait for the token generated in the next cycle.

需要进一步说明的是,在本实施例中令牌获取成功时,令牌桶的状态信息为令牌减少,令牌获取失败时,令牌桶的状态为令牌不变。It should be further explained that, in this embodiment, when the token is successfully acquired, the status information of the token bucket is that the token is reduced, and when the token is failed to be acquired, the status of the token bucket is that the token remains unchanged.

更进一步地,当令牌获取失败时,可能情况为:规则1、规则2和规则3均获取失败;规则1、规则2和规则3任两个规则获取失败;规则1、规则2和规则3任一个获取失败。则需要采集在任一可能情况下的限流信息,即用户端的输入请求被限制的信息。Furthermore, when the token acquisition fails, the possible situations are: all of rules 1, 2, and 3 fail to acquire; any two of rules 1, 2, and 3 fail to acquire; any one of rules 1, 2, and 3 fails to acquire. It is necessary to collect the current limiting information in any possible situation, that is, the information that the input request of the user end is restricted.

步骤230,基于所述状态信息和限流信息对所述令牌桶进行令牌回填。Step 230: backfill the token bucket with tokens based on the state information and current limiting information.

具体地,在限流信息的前提下,即确认用户的输入请求被限制时,根据令牌桶的状态信息便可以确认是否存在令牌多余扣除的情况。如:用户端的输入请求被限制,但是令牌桶的状态信息还是出现令牌扣除的情况,便说明此时存在令牌多余扣除的现象,便需要对令牌桶进行令牌回填。通过令牌回填,使得令牌桶内的令牌数量不会因多余扣除而造成请求混乱,减少了令牌请求出错的可能性。Specifically, under the premise of current limiting information, that is, when it is confirmed that the user's input request is restricted, it can be confirmed whether there is a situation of excess token deduction based on the status information of the token bucket. For example, if the input request of the user end is restricted, but the status information of the token bucket still shows the situation of token deduction, it means that there is a phenomenon of excess token deduction at this time, and the token bucket needs to be backfilled with tokens. By backfilling tokens, the number of tokens in the token bucket will not cause request confusion due to excess deductions, reducing the possibility of token request errors.

本申请实施例提供的令牌回填方法,通过基于用户端输入的令牌获取请求进行令牌获取,输出不同的获取结果,然后采集令牌桶在每种获取结果条件下的状态信息,以及采集在获取结果为失败情况下令牌获取请求的限流信息,最后基于每种获取结果对应的状态信息和对令牌获取请求的限流信息对令牌桶进行令牌回填。本申请在用户的令牌获取请求被限流的情况下,根据限流信息和状态信息能够确认令牌是否被多余扣除,以及时地对令牌桶内进行令牌回填,从而实现正确的令牌申请。The token backfill method provided in the embodiment of the present application performs token acquisition based on the token acquisition request input by the user end, outputs different acquisition results, then collects the status information of the token bucket under each acquisition result condition, and collects the flow limiting information of the token acquisition request when the acquisition result is a failure, and finally backfills the token bucket with tokens based on the status information corresponding to each acquisition result and the flow limiting information of the token acquisition request. In the case where the user's token acquisition request is flow limited, the present application can confirm whether the token is deducted in excess according to the flow limiting information and status information, and timely backfill the token in the token bucket, thereby realizing the correct token application.

基于以上实施例,所述基于所述状态信息和限流信息对所述令牌桶进行令牌回填,包括:Based on the above embodiment, the token backfilling of the token bucket based on the state information and the current limiting information includes:

基于所述限流信息确认所述令牌获取请求处于限流情况,基于所述限流信息结合所述状态信息获取所述令牌桶的令牌扣除信息;Confirming that the token acquisition request is in a current limiting state based on the current limiting information, and acquiring token deduction information of the token bucket based on the current limiting information combined with the state information;

基于令牌扣除信息判断令牌是否存在多余扣除的情况;Based on the token deduction information, determine whether there is any excess deduction of the token;

在令牌存在多余扣除的情况下,基于CAS原子操作对所述令牌桶进行令牌回填。In the case where there is excess deduction of tokens, the token bucket is backfilled with tokens based on the CAS atomic operation.

具体地,本实施例提供了令牌多余扣除情况的具体方式,以及对令牌多余扣除进行回填的过程。首先,根据限流信息便可以确认用户端输入的令牌获取请求处于被限制状态。然后,根据状态信息确认在每个规则条件下,是否存在令牌多余扣除的情况。比如,规则1、规则2和规则3中的任一个或两个获取令牌成功,那么必然会出现令牌多余扣除的情况。因此,则需要通过CAS原子操作进行令牌回填。Specifically, the present embodiment provides a specific method for the situation of excess token deduction, and a process for backfilling the excess token deduction. First, according to the current limiting information, it can be confirmed that the token acquisition request input by the user end is in a restricted state. Then, according to the status information, it is confirmed whether there is a situation of excess token deduction under each rule condition. For example, if any one or two of Rule 1, Rule 2 and Rule 3 successfully obtain the token, then there will inevitably be a situation of excess token deduction. Therefore, it is necessary to backfill the token through CAS atomic operation.

需要说明的是,CAS原子操作(Compare And Swap,比较和替换),通俗的讲便是用新值替换旧值。在本实施例中,如果将令牌桶内的原本的令牌数假定为100个,那么每根据输入的请求获取一次,便需要减去一个令牌桶中的令牌。假设减去2个,此时令牌桶中还剩下98个令牌。但是由于用户输入的请求是被限制的,所以这2个令牌便是多余扣除的。此时,便需要将100作为新值替换旧值98,这样便对多余扣除的令牌进行了补充,即实现了令牌的回填。It should be noted that the CAS atomic operation (Compare And Swap) is, in layman's terms, replacing the old value with the new value. In this embodiment, if the original number of tokens in the token bucket is assumed to be 100, then each time a token is obtained based on an input request, it is necessary to subtract a token from the token bucket. Assuming that 2 tokens are subtracted, there are 98 tokens left in the token bucket. However, since the request input by the user is restricted, these 2 tokens are redundant. At this time, it is necessary to replace the old value 98 with 100 as the new value, so that the redundant tokens are supplemented, that is, the backfill of tokens is achieved.

本申请实施例提供的令牌回填方法,通过利用CAS原子操作,在令牌多余扣除的情况下,对令牌桶及时进行令牌补充,实现及时地对令牌桶内进行令牌回填,从而实现正确的令牌申请。The token backfill method provided in the embodiment of the present application utilizes the CAS atomic operation to replenish tokens in the token bucket in a timely manner when excess tokens are deducted, thereby achieving timely token backfilling in the token bucket and realizing correct token application.

基于以上实施例,所述在令牌存在多余扣除的情况下,基于CAS原子操作对所述令牌桶进行令牌回填,包括:Based on the above embodiment, in the case where there is excess deduction of tokens, the token bucket is backfilled with tokens based on the CAS atomic operation, including:

在令牌存在多余扣除的情况下,基于所述令牌扣除信息获取令牌扣除前后的第一目标数值和第二目标数值;In the case where there is excess deduction of the token, obtaining the first target value and the second target value before and after the token deduction based on the token deduction information;

在目标期望值等于所述第一目标值的情况下,基于所述CAS原子操作,利用所述第一目标数值替换所述第二目标数值以实现对所述令牌桶进行令牌回填。When the target expected value is equal to the first target value, based on the CAS atomic operation, the first target value is used to replace the second target value to achieve token backfilling of the token bucket.

具体地,本实施例提供了基于CAS原子操作进行令牌回填的具体方式。在令牌存在多余扣除的情况下,获取在令牌扣除前后的第一目标数值和第二目标数值。例如,令牌扣除前为100个,扣除后为98个。当目标期望值和第一目标数值相等时,即目标期望值也为100时,则利用第一目标数值替换第二目标数值,即用100替换98以实现令牌回填。Specifically, this embodiment provides a specific method for token backfilling based on CAS atomic operation. In the case of redundant token deduction, the first target value and the second target value before and after the token deduction are obtained. For example, the number of tokens before deduction is 100 and the number of tokens after deduction is 98. When the target expected value is equal to the first target value, that is, the target expected value is also 100, the second target value is replaced by the first target value, that is, 98 is replaced by 100 to achieve token backfilling.

本申请实施例提供的令牌回填方法,通过利用CAS原子操作,在令牌多余扣除的情况下,用令牌多余扣除之前的第一目标数值替换令牌多余扣除之后的第二目标数值,以对令牌桶及时进行令牌补充,实现及时地对令牌桶内进行令牌回填,从而实现正确的令牌申请。The token backfill method provided in the embodiment of the present application utilizes the CAS atomic operation. In the case of excess token deduction, the second target value after the token deduction is replaced with the first target value before the token deduction, so as to replenish the token bucket with tokens in time, realize timely token backfilling in the token bucket, and thus realize correct token application.

基于以上实施例,所述基于所述限流信息确认所述令牌获取请求处于限流情况之前,还包括:Based on the above embodiment, before confirming that the token acquisition request is in a current limiting situation based on the current limiting information, the method further includes:

获取API网关在目标时间段内的流量增加量;Get the traffic increase of the API gateway during the target time period;

对所述流量增加量和预设阈值进行比较,得到所述API网关是否处于流量激增情况的判断结果;Compare the traffic increase with a preset threshold to determine whether the API gateway is experiencing a traffic surge;

基于所述判断结果确认是否对所述令牌桶的容量进行调整。Determine whether to adjust the capacity of the token bucket based on the determination result.

具体地,本实施例中若API网关的各个系统处于流量激增时,即在目标时间段内的流量增加量大于预设目标阈值,则需要对令牌桶的容量进行调整。其调整方式为根据预设容量阈值和动态扩容阈值增大令牌桶的容量,也就是将源桶大小(调整前桶容量大小)和动态扩容阈值相加,得到调整后桶容量大小。Specifically, in this embodiment, if the traffic of each system of the API gateway is in a surge, that is, the traffic increase in the target time period is greater than the preset target threshold, the capacity of the token bucket needs to be adjusted. The adjustment method is to increase the capacity of the token bucket according to the preset capacity threshold and the dynamic expansion threshold, that is, to add the source bucket size (bucket capacity before adjustment) and the dynamic expansion threshold to obtain the adjusted bucket capacity.

其中,动态扩容阈值的确定方法如下所示:The method for determining the dynamic expansion threshold is as follows:

首先,计算多个系统的流量均值,计算方式如下公式(1)所示:First, calculate the average flow of multiple systems. The calculation method is shown in the following formula (1):

然后,根据系统数量、流量数据以及流量均值进行聚合分析,得到分析结果δ,即目标标准差,其计算方式如以下公式(2)所示:Then, based on the number of systems, flow data, and flow mean, an aggregate analysis is performed to obtain the analysis result δ, i.e., the target standard deviation, which is calculated as shown in the following formula (2):

其中,xi为每个系统的流量数据,为流量均值,n为系统数量。Among them, xi is the flow data of each system, is the mean flow rate, and n is the number of systems.

最后,根据目标标准差δ和目标倍数组成三倍标准差即扩容基线,并结合流量均值生成动态扩容阈值,其计算方式如以下公式(3)所示:Finally, the target standard deviation δ and the target multiple are used to form the three-times standard deviation, i.e., the expansion baseline, and the dynamic expansion threshold is generated by combining the traffic mean. The calculation method is shown in the following formula (3):

其中,p为动态扩容阈值,为流量均值,3δ为扩容基线。Among them, p is the dynamic expansion threshold, is the mean flow rate, and 3δ is the expansion baseline.

本申请实施例提供的令牌回填方法,在面对流量激增情况时,通过动态扩容阈值调整令牌桶的容量大小,实现令牌容量调整的准确性、可控性以及智能化。The token backfill method provided in the embodiment of the present application adjusts the capacity of the token bucket through a dynamic expansion threshold when facing a traffic surge, thereby achieving accuracy, controllability and intelligence in token capacity adjustment.

基于以上实施例,所述基于所述判断结果确认是否对所述令牌桶的容量进行调整,包括:Based on the above embodiment, the step of confirming whether to adjust the capacity of the token bucket based on the judgment result includes:

在所述流量增加量大于所述预设阈值的情况下,获取所述令牌桶的动态扩容阈值;When the traffic increase is greater than the preset threshold, obtaining a dynamic expansion threshold of the token bucket;

基于所述令牌桶的预设容量阈值和所述动态扩容阈值对所述令牌桶的容量进行调整。The capacity of the token bucket is adjusted based on the preset capacity threshold of the token bucket and the dynamic capacity expansion threshold.

具体地,本实施例提供了在不同的流量激增情况下的实施方式之一。若API网关处于流量激增时,即上述的目标时间段内的流量增加量大于预设目标阈值,则需要对令牌桶的容量进行动态调整。Specifically, this embodiment provides one of the implementation methods under different traffic surge situations. If the API gateway is in a traffic surge, that is, the traffic increase in the above target time period is greater than the preset target threshold, the capacity of the token bucket needs to be dynamically adjusted.

需要说明的是。本实施例中的动态扩容阈值是根据各个系统的流量信息确定的,即动态扩容阈值是实时的、动态变化的,因此令牌桶的容量调整也是动态调整的。It should be noted that the dynamic expansion threshold in this embodiment is determined according to the flow information of each system, that is, the dynamic expansion threshold is real-time and dynamically changed, so the capacity adjustment of the token bucket is also dynamically adjusted.

本申请实施例提供的令牌回填方法,由于系统的流量信息是实时变化的,因此动态扩容阈值也是动态变化的,所以令牌桶的容量可根据多个系统的流量信息进行调整,因此确保了令牌桶容量调整的准确性,通过动态调整从而实现智能应对流量激增,且不压垮系统。The token backfill method provided in the embodiment of the present application has a dynamic expansion threshold that changes dynamically because the system traffic information changes in real time. Therefore, the capacity of the token bucket can be adjusted according to the traffic information of multiple systems, thereby ensuring the accuracy of the token bucket capacity adjustment. Through dynamic adjustment, intelligent response to traffic surges can be achieved without overwhelming the system.

基于以上实施例,所述基于所述判断结果确认是否对所述令牌桶的容量进行调整,包括:Based on the above embodiment, the step of confirming whether to adjust the capacity of the token bucket based on the judgment result includes:

在所述流量增加量小于或等于所述预设阈值的情况下,基于当前时间和上次令牌桶容量调整时间确认时间跨度;In the case where the traffic increase is less than or equal to the preset threshold, confirming the time span based on the current time and the last token bucket capacity adjustment time;

基于所述时间跨度和令牌桶刷新周期判断所述令牌桶是否对所述令牌桶的容量进行调整。The token bucket is judged whether to adjust the capacity of the token bucket based on the time span and the token bucket refresh period.

具体地,本实施例提供了在不同的流量激增情况下的实施方式之二。若API网关未处于流量激增时,即上述的目标时间段内的流量增加量小于或等于预设目标阈值,则需要对令牌桶的容量进行计时调整。Specifically, this embodiment provides a second implementation method under different traffic surge conditions. If the API gateway is not in a traffic surge, that is, the traffic increase in the above target time period is less than or equal to the preset target threshold, the capacity of the token bucket needs to be adjusted in time.

通过获取当前时刻和前一次向令牌桶中添加令牌的时刻确认时间跨度,根据时间跨度和令牌桶刷新周期确认是否进行令牌桶容量的调整。The time span is confirmed by obtaining the current time and the time when a token was last added to the token bucket, and whether to adjust the token bucket capacity is determined according to the time span and the token bucket refresh cycle.

本申请实施例提供的令牌回填方法,无需每次都进行令牌桶容量的调整,从而减少了令牌的多余添加造成的资源浪费。The token backfill method provided in the embodiment of the present application does not need to adjust the token bucket capacity every time, thereby reducing the waste of resources caused by unnecessary addition of tokens.

基于以上实施例,所述基于所述时间跨度和令牌桶刷新周期判断所述令牌桶是否对所述令牌桶的容量进行调整,包括:Based on the above embodiment, judging whether the token bucket adjusts the capacity of the token bucket based on the time span and the token bucket refresh period includes:

在所述时间跨度小于或等于所述令牌桶刷新周期的情况下,确认无需向所述令牌桶中添加令牌;When the time span is less than or equal to the token bucket refresh period, confirming that there is no need to add tokens to the token bucket;

在所述时间跨度大于所述令牌桶刷新周期的情况下,确认向所述令牌桶中添加新的令牌以调整所述牌桶的容量。In the case where the time span is greater than the token bucket refresh period, it is confirmed to add new tokens to the token bucket to adjust the capacity of the card bucket.

具体地,本实施例提供了对令牌桶的容量进行计时调整的具体实施过程。Specifically, this embodiment provides a specific implementation process of timing adjustment of the capacity of the token bucket.

一方面,在时间跨度小于或等于令牌桶刷新周期的情况下,确认无需向令牌桶中添加令牌。也就是说,当前时间距离上次添加令牌的时间未达到令牌添加的一个周期,不满足令牌添加条件,便不向令牌桶中添加新的令牌。On the one hand, if the time span is less than or equal to the token bucket refresh cycle, it is confirmed that there is no need to add tokens to the token bucket. In other words, the current time from the last time a token was added does not reach a cycle of token addition, and the token addition condition is not met, so no new token is added to the token bucket.

另一方面,在时间跨度大于令牌桶刷新周期的情况下,确认需要向令牌桶中添加令牌。也就是说,当前时间距离上次添加令牌的时间已达到令牌添加的一个周期,满足令牌添加条件,需要向令牌桶中添加新的令牌。On the other hand, if the time span is greater than the token bucket refresh cycle, it is confirmed that a token needs to be added to the token bucket. In other words, the current time has reached a token addition cycle from the last time a token was added, and the token addition condition is met, and a new token needs to be added to the token bucket.

需要说明的是,令牌添加时需要对令牌桶内的令牌数量进行监测,当令牌桶内的令牌数量达到目标阈值,即令牌数量达到需要的数量,或者令牌桶的容量达到最大时,停止添加令牌,生成指令确认添加完成,并将用户端的输入请求输入至其他系统中。It should be noted that when adding tokens, the number of tokens in the token bucket needs to be monitored. When the number of tokens in the token bucket reaches the target threshold, that is, the number of tokens reaches the required number, or the capacity of the token bucket reaches the maximum, stop adding tokens, generate instructions to confirm that the addition is complete, and input requests from the user end are input into other systems.

本实施例提供的令牌回填方法,通过将时间跨度和预设的令牌刷新周期进行比较从而决定令牌桶是否添加新的令牌,无需设定定时任务,也无需每次都进执行令牌添加,能够有效地减少令牌的多余添加造成的资源浪费。The token backfill method provided in this embodiment determines whether to add new tokens to the token bucket by comparing the time span with the preset token refresh period. There is no need to set a scheduled task or execute token addition every time, which can effectively reduce the waste of resources caused by unnecessary addition of tokens.

参照图3,图3是本申请实施例提供的令牌回填方法的流程示意图,包括:Referring to FIG. 3 , FIG. 3 is a flow chart of a token backfill method provided in an embodiment of the present application, including:

步骤310,输入请求。Step 310, input request.

步骤320,基于规则1、规则2和规则3获取令牌。其中,规则其中,规则1为每三分钟获取500个令牌,规则2为每五分钟获取1000个令牌,规则3为每一小时获取2000个令牌。Step 320, acquiring tokens based on rule 1, rule 2, and rule 3. Among them, 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.

步骤330,基于规则1和规则2获取令牌成功,基于规则3获取令牌失败。Step 330: Acquiring a token based on rules 1 and 2 succeeds, but acquiring a token based on rule 3 fails.

步骤340,记录每个规则下的令牌桶状态。Step 340: Record the token bucket status under each rule.

步骤350,对规则1和规则2对应的令牌桶进行令牌回填。Step 350: backfill tokens to the token buckets corresponding to rule 1 and rule 2.

步骤360,对输入请求进行限流。Step 360: Limit the flow of input requests.

下面对本申请提供的令牌回填装置进行描述,下文描述的令牌回填装置与上文描述的令牌回填方法可相互对应参照。The token backfilling device provided in the present application is described below. The token backfilling device described below and the token backfilling method described above can be referenced to each other.

参照图4,本申请实施例提供的一种令牌回填装置,包括:输出模块410、采集模块420以及回填模块430;4 , a token backfilling device provided in an embodiment of the present application includes: an output module 410 , a collection module 420 , and a backfilling module 430 ;

输出模块410,用于基于用户端输入的令牌获取请求进行令牌获取,输出不同的获取结果;The output module 410 is used to obtain a token based on a token acquisition request input by a user terminal and output different acquisition results;

采集模块420,用于采集令牌桶在每种获取结果条件下的状态信息,以及采集在获取结果为失败情况下所述令牌获取请求的限流信息;The collection module 420 is used to collect the status information of the token bucket under each acquisition result condition, and to collect the current limiting information of the token acquisition request when the acquisition result is a failure;

回填模块430,用于基于所述状态信息和限流信息对所述令牌桶进行令牌回填。The backfill module 430 is used to backfill the token bucket with tokens based on the state information and the current limiting information.

本申请实施例提供的令牌回填装置,通过基于用户端输入的令牌获取请求进行令牌获取,输出不同的获取结果,然后采集令牌桶在每种获取结果条件下的状态信息,以及采集在获取结果为失败情况下令牌获取请求的限流信息,最后基于每种获取结果对应的状态信息和对令牌获取请求的限流信息对令牌桶进行令牌回填。本申请在用户的令牌获取请求被限流的情况下,根据限流信息和状态信息能够确认令牌是否被多余扣除,以及时地对令牌桶内进行令牌回填,从而实现正确的令牌申请。The token backfilling device provided in the embodiment of the present application performs token acquisition based on the token acquisition request input by the user end, outputs different acquisition results, then collects the status information of the token bucket under each acquisition result condition, and collects the flow limiting information of the token acquisition request when the acquisition result is a failure, and finally backfills the token bucket with tokens based on the status information corresponding to each acquisition result and the flow limiting information of the token acquisition request. In the case where the user's token acquisition request is flow limited, the present application can confirm whether the token is deducted in excess according to the flow limiting information and status information, and timely backfill the token in the token bucket, thereby realizing the correct token application.

基于以上实施例,所述回填模块,具体用于:Based on the above embodiments, the backfill module is specifically used for:

基于所述限流信息确认所述令牌获取请求处于限流情况,基于所述限流信息结合所述状态信息获取所述令牌桶的令牌扣除信息;Confirming that the token acquisition request is in a current limiting state based on the current limiting information, and acquiring token deduction information of the token bucket based on the current limiting information combined with the state information;

基于令牌扣除信息判断令牌是否存在多余扣除的情况;Based on the token deduction information, determine whether there is any excess deduction of the token;

在令牌存在多余扣除的情况下,基于CAS原子操作对所述令牌桶进行令牌回填。In the case where there is excess deduction of tokens, the token bucket is backfilled with tokens based on the CAS atomic operation.

基于以上实施例,所述回填模块,进一步用于:Based on the above embodiment, the backfill module is further used for:

在令牌存在多余扣除的情况下,基于所述令牌扣除信息获取令牌扣除前后的第一目标数值和第二目标数值;In the case where there is excess deduction of the token, obtaining the first target value and the second target value before and after the token deduction based on the token deduction information;

在目标期望值等于所述第一目标值的情况下,基于所述CAS原子操作,利用所述第一目标数值替换所述第二目标数值以实现对所述令牌桶进行令牌回填。When the target expected value is equal to the first target value, based on the CAS atomic operation, the first target value is used to replace the second target value to achieve token backfilling of the token bucket.

基于以上实施例,还包括:Based on the above embodiment, it also includes:

获取模块,用于获取API网关在目标时间段内的流量增加量;The acquisition module is used to obtain the traffic increase of the API gateway within the target time period;

比较模块,用于对所述流量增加量和预设阈值进行比较,得到所述API网关是否处于流量激增情况的判断结果;A comparison module, used to compare the traffic increase with a preset threshold to obtain a judgment result of whether the API gateway is in a traffic surge situation;

确认模块,用于基于所述判断结果确认是否对所述令牌桶的容量进行调整。A confirmation module is used to confirm whether to adjust the capacity of the token bucket based on the judgment result.

基于以上实施例,所述确认模块,具体用于:Based on the above embodiments, the confirmation module is specifically used for:

在所述流量增加量大于所述预设阈值的情况下,获取所述令牌桶的动态扩容阈值;When the traffic increase is greater than the preset threshold, obtaining a dynamic expansion threshold of the token bucket;

基于所述令牌桶的预设容量阈值和所述动态扩容阈值对所述令牌桶的容量进行调整。The capacity of the token bucket is adjusted based on the preset capacity threshold of the token bucket and the dynamic capacity expansion threshold.

基于以上实施例,所述确认模块,具体用于:Based on the above embodiments, the confirmation module is specifically used for:

在所述流量增加量小于或等于所述预设阈值的情况下,基于当前时间和上次令牌桶容量调整时间确认时间跨度;In the case where the traffic increase is less than or equal to the preset threshold, confirming the time span based on the current time and the last token bucket capacity adjustment time;

基于所述时间跨度和令牌桶刷新周期判断所述令牌桶是否对所述令牌桶的容量进行调整。The token bucket is judged whether to adjust the capacity of the token bucket based on the time span and the token bucket refresh period.

基于以上实施例,所述确认模块,进一步用于:Based on the above embodiment, the confirmation module is further used for:

在所述时间跨度小于或等于所述令牌桶刷新周期的情况下,确认无需向所述令牌桶中添加令牌;When the time span is less than or equal to the token bucket refresh period, confirming that there is no need to add tokens to the token bucket;

在所述时间跨度大于所述令牌桶刷新周期的情况下,确认向所述令牌桶中添加新的令牌以调整所述牌桶的容量。In the case where the time span is greater than the token bucket refresh period, it is confirmed to add new tokens to the token bucket to adjust the capacity of the card bucket.

根据本申请实施例的一个方面,提供了一种令牌回填方法。该令牌回填方法广泛应用于智慧家庭(Smart Home)、智能家居、智能家用设备生态、智慧住宅(IntelligenceHouse)生态等全屋智能数字化控制应用场景。可选地,在本实施例中,上述令牌回填方法可以应用于如图5所示的由终端设备502和服务器504所构成的硬件环境中。如图5所示,服务器504通过网络与终端设备502进行连接,可用于为终端或终端上安装的客户端提供服务(如应用服务等),可在服务器上或独立于服务器设置数据库,用于为服务器504提供数据存储服务,可在服务器上或独立于服务器配置云计算和/或边缘计算服务,用于为服务器504提供数据运算服务。According to one aspect of an embodiment of the present application, a token backfill method is provided. The token backfill method is widely used in smart home (Smart Home), smart home, smart home device ecology, smart residential (IntelligenceHouse) ecology and other whole-house intelligent digital control application scenarios. Optionally, in this embodiment, the above-mentioned token backfill method can be applied to a hardware environment consisting of a terminal device 502 and a server 504 as shown in Figure 5. As shown in Figure 5, the server 504 is connected to the terminal device 502 via a network, and can be used to provide services (such as application services, etc.) for the terminal or the client installed on the terminal, and a database can be set on the server or independently of the server to provide data storage services for the server 504, and cloud computing and/or edge computing services can be configured on the server or independently of the server to provide data computing services for the server 504.

上述网络可以包括但不限于以下至少之一:有线网络,无线网络。上述有线网络可以包括但不限于以下至少之一:广域网,城域网,局域网,上述无线网络可以包括但不限于以下至少之一:WIFI(Wireless Fidelity,无线保真),蓝牙。终端设备502可以并不限定于为PC、手机、平板电脑、智能空调、智能烟机、智能冰箱、智能烤箱、智能炉灶、智能洗衣机、智能热水器、智能洗涤设备、智能洗碗机、智能投影设备、智能电视、智能晾衣架、智能窗帘、智能影音、智能插座、智能音响、智能音箱、智能新风设备、智能厨卫设备、智能卫浴设备、智能扫地机器人、智能擦窗机器人、智能拖地机器人、智能空气净化设备、智能蒸箱、智能微波炉、智能厨宝、智能净化器、智能饮水机、智能门锁等。The above network may include but is not limited to at least one of the following: wired network, wireless network. The above wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the above wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal device 502 may be but is not limited to a PC, a mobile phone, a tablet computer, a smart air conditioner, a smart range hood, a smart refrigerator, a smart oven, a smart stove, a smart washing machine, a smart water heater, a smart washing equipment, a smart dishwasher, a smart projection equipment, a smart TV, a smart clothes drying rack, a smart curtain, a smart audio and video, a smart socket, a smart speaker, a smart speaker, a smart fresh air equipment, a smart kitchen and bathroom equipment, a smart bathroom equipment, a smart sweeping robot, a smart window cleaning robot, a smart mopping robot, a smart air purification equipment, a smart steamer, a smart microwave oven, a smart kitchen treasure, a smart purifier, a smart water dispenser, a smart door lock, etc.

图6示例了一种电子装置的实体结构示意图,如图6所示,该电子装置可以包括:处理器(processor)610、通信接口(Communications Interface)620、存储器(memory)630和通信总线640,其中,处理器610,通信接口620,存储器630通过通信总线640完成相互间的通信。处理器610可以调用存储器630中的逻辑指令,以执行令牌回填方法,该方法包括:基于用户端输入的令牌获取请求进行令牌获取,输出不同的获取结果;采集令牌桶在每种获取结果条件下的状态信息,以及采集在获取结果为失败情况下所述令牌获取请求的限流信息;基于所述状态信息和限流信息对所述令牌桶进行令牌回填。FIG6 illustrates a schematic diagram of the physical structure of an electronic device. As shown in FIG6 , the electronic device may include: a processor 610, a communication interface 620, a memory 630 and a communication bus 640, wherein the processor 610, the communication interface 620 and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logic instructions in the memory 630 to execute the token backfill method, which includes: performing token acquisition based on the token acquisition request input by the user end, and outputting different acquisition results; collecting the status information of the token bucket under each acquisition result condition, and collecting the flow limiting information of the token acquisition request when the acquisition result is a failure; and performing token backfill on the token bucket based on the status information and the flow limiting information.

此外,上述的存储器630中的逻辑指令可以通过软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art, and the computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

另一方面,本申请还提供一种计算机程序产品,所述计算机程序产品包括计算机程序,计算机程序可存储在计算机可读的存储介质上,所述计算机程序被处理器执行时,计算机能够执行上述各方法所提供的令牌回填方法,该方法包括:基于用户端输入的令牌获取请求进行令牌获取,输出不同的获取结果;采集令牌桶在每种获取结果条件下的状态信息,以及采集在获取结果为失败情况下所述令牌获取请求的限流信息;基于所述状态信息和限流信息对所述令牌桶进行令牌回填。On the other hand, the present application also provides a computer program product, which includes a computer program. The computer program can be stored on a computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the token backfill method provided by the above methods, which includes: acquiring tokens based on a token acquisition request input by a user end, and outputting different acquisition results; collecting status information of a token bucket under each acquisition result condition, and collecting current limiting information of the token acquisition request when the acquisition result is a failure; and backfilling the token bucket with tokens based on the status information and current limiting information.

又一方面,本申请还提供一种计算机可读的存储介质,所述计算机可读的存储介质包括存储的程序,其中,所述程序运行时执行上述各方法提供的令牌回填方法,该方法包括:基于用户端输入的令牌获取请求进行令牌获取,输出不同的获取结果;采集令牌桶在每种获取结果条件下的状态信息,以及采集在获取结果为失败情况下所述令牌获取请求的限流信息;基于所述状态信息和限流信息对所述令牌桶进行令牌回填。On the other hand, the present application also provides a computer-readable storage medium, which includes a stored program, wherein the token backfill method provided by the above-mentioned methods is executed when the program is running, and the method includes: acquiring tokens based on the token acquisition request input by the user end, and outputting different acquisition results; collecting status information of the token bucket under each acquisition result condition, and collecting current limiting information of the token acquisition request when the acquisition result is a failure; and backfilling the token bucket with tokens based on the status information and current limiting information.

以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative effort.

通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分所述的方法。Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM/RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

最后应说明的是:以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some of the technical features therein with equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions 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 深圳云天励飞技术有限公司 A data traffic processing method, device, electronic device 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
CN113765820B (en) * 2020-10-30 2024-11-29 北京沃东天骏信息技术有限公司 Token bucket-based current limiting method, device, computing equipment and medium
CN114024908B (en) * 2021-11-03 2024-10-29 蚂蚁胜信(上海)信息技术有限公司 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 深圳云天励飞技术有限公司 A data traffic processing method, device, electronic device and storage medium

Also Published As

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

Similar Documents

Publication Publication Date Title
CN103763346B (en) A distributed resource scheduling method and device
JP2017126975A (en) Network traffic scheduling method and device of data center
CN115460153B (en) Dynamic adjustment method and device for token bucket capacity, storage medium and electronic device
CN110381150B (en) Data processing method and device on block chain, electronic equipment and storage medium
CN107193672B (en) Cross-block asynchronous contract calling system
CN107797859B (en) Scheduling method of timing task and scheduling server
CN108616525A (en) Website access method and device, electronic equipment and storage medium
CN111506783A (en) Transaction request processing method, device, equipment and medium in block chain
CN114064262A (en) Method, apparatus and program product for managing computing resources in a storage system
CN112463195A (en) Method, system, terminal and storage medium for cluster grouping online upgrade
CN107402851B (en) A data recovery control method and device
CN112506698A (en) Small file data reconstruction recovery method, system, terminal and storage medium
WO2019061999A1 (en) Breakpoint call method, electronic device and computer-readable storage medium
US10223189B1 (en) Root cause detection and monitoring for storage systems
CN107102889B (en) Virtual machine resource adjusting method and device
US20120297385A1 (en) Interactive service management
CN115378656B (en) Token backfill method, storage medium and electronic device
CN111512594A (en) Virtual Network Function Management
CN109976896A (en) Business re-scheduling treating method and apparatus
CN113468442A (en) Resource bit flow distribution method, computing device and computer storage medium
CN116467173A (en) Determination method and device, storage medium and electronic device of key test
Marbach et al. Gradient-based optimization of Markov reward processes: Practical variants
CN113127191B (en) Resource update method, storage medium and related device
CN112148551B (en) Method, apparatus and computer program product for determining a rate of change of usage of a storage system
CN115473852A (en) Current limiting method for user side input request, storage medium and electronic device

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