Token bucket control method and device

By setting a timed and quantitative token filling method in the token bucket algorithm, the problems of token bucket volatility and calculation complexity in the prior art are solved, and more stable and efficient message traffic control is achieved.

CN119697122APending Publication Date: 2025-03-25WXILICON TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411862062.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-17
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

The existing token bucket algorithm has problems with the timing of token filling and computational complexity, which leads to large fluctuations in the number of tokens in the token bucket, affecting the stability of message traffic control and increasing system costs.

Method used

By setting the filling time interval and information rate of the token bucket, the token bucket is filled in time and quantitatively, reducing the resource waste caused by system randomness and frequent calculations.

Benefits of technology

Improve the stability of message traffic control, reduce system costs, and improve the accuracy of traffic control by accurately controlling the number of tokens.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119697122A_ABST
    Figure CN119697122A_ABST
Patent Text Reader

Abstract

The invention relates to a token bucket control method. The method comprises the following steps: setting a filling time interval of a token bucket and an information rate of the token bucket; the token bucket is filled at regular time according to the filling time interval, and the number of tokens filled each time is obtained through calculation according to the information rate and the filling time interval. The invention further provides a corresponding token bucket control device. According to the invention, an improved token bucket control scheme can be provided, the token bucket can be stably filled with tokens, the stability of message flow control is improved, and the system cost can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to a technical field related to data transmission flow control, and in particular to a token bucket control method and device. Background Art

[0002] In the context of increasingly diverse network data transmission requirements and scenarios, in order to effectively manage network resources and prevent network congestion, it is necessary to control network traffic to improve network stability and overall throughput, and to ensure network service quality and user experience. The existing technology controls and manages network data transmission by setting bandwidth speed limits, traffic shaping, etc. Among them, traffic shaping is an effective measure to actively adjust the traffic transmission rate because it allows messages to be sent out at a relatively uniform speed. The most commonly used method for traffic shaping is the token bucket algorithm. Its basic principle is to set a token bucket filled with a certain number of tokens. When a certain number of messages are sent, the corresponding number of tokens are taken out of the token bucket. In this way, the traffic of transmittable messages is controlled to achieve traffic shaping.

[0003] Among them, in the existing token bucket algorithm technology, the method of updating the number of tokens in the token bucket is: by determining the time difference between the current message and the previous message, multiplying the time difference by the information rate of the token bucket to obtain the number of tokens to be filled (i.e., added to the number of remaining tokens in the token bucket) and then writing them back into the token bucket to complete the update of the number of tokens in the token bucket. Although this method achieves smooth control of traffic to a certain extent, it has the following disadvantages:

[0004] On the one hand, the timing of token filling is triggered by the message, and the filling quantity is related to the time interval of message arrival, which is highly random and may cause large fluctuations in the number of tokens in the token bucket. For example, when a large number of messages suddenly appear or no messages arrive for a long time, the number of tokens in the token bucket may increase or decrease sharply, thereby affecting the stability of message flow control and causing unpredictability of message flow control.

[0005] On the other hand, the number of tokens to be filled is based on the multiplication of the time difference and the information rate. Frequent multiplication operations have high complexity, which increases the structural complexity of the hardware logic computing unit or the complexity of the logic operation, resulting in more resources being occupied and increased costs.

[0006] Therefore, how to provide an improved token bucket control scheme that can stably fill tokens into the token bucket to improve the stability of message flow control and reduce system costs is a technical problem to be solved. Summary of the invention

[0007] In view of the above problems in the prior art, the present application provides a token bucket control method and device, so as to stably fill tokens into the token bucket to improve the stability of message flow control and reduce system costs.

[0008] To achieve the above object, the first aspect of the present application provides a token bucket control method, comprising:

[0009] Set the token bucket filling time interval and token bucket information rate;

[0010] The token bucket is filled regularly at the filling time interval, and the number of tokens filled each time is calculated based on the information rate and the filling time interval.

[0011] As described above, by filling the token bucket with tokens at a fixed time and in a fixed quantity, the randomness of the system and the waste of system resources caused by frequent calculations are reduced.

[0012] As a possible implementation of the first aspect, the number of tokens filled each time is obtained according to the following formula:

[0013] Δ token =R×ΔT

[0014] Among them, Δ token represents the number of tokens filled each time, R represents the information rate, and ΔT represents the filling time interval.

[0015] As described above, the number of tokens filled each time is obtained through the information rate and the filling time interval, and the information rate can be directly limited to facilitate the needs in actual use.

[0016] As a possible implementation manner of the first aspect, when the ΔT is less than 1 ms, the ΔT is set according to the following formula:

[0017]

[0018] Accordingly, the bit width of the bit position of the portion below 1 bit used for the binary count value of the number of tokens is set to n.

[0019] From the above, the rate accuracy of the token is adjusted by the bit width of the fractional part of the number of tokens, so that the number of tokens less than 1 bit can be filled into the token bucket.

[0020] As a possible implementation of the first aspect, the following also includes:

[0021] The token bucket operation cycle includes the bucket read request phase, the bucket output token quantity phase, the token quantity calculation phase, and the calculation result write-back bucket phase, and the clock cycle occupied by each phase is the first duration;

[0022] With respect to the triggered operations on each token bucket, the operations on each token bucket are processed in sequence in a pipeline manner, wherein the minimum time interval for processing two adjacent operations is the first time length.

[0023] From the above, the operations of multiple token buckets can be processed in parallel through the pipeline operation execution mode, which effectively utilizes the bandwidth and avoids waste.

[0024] As a possible implementation method of the first aspect, when the triggered operation on the token bucket is to fill the token bucket periodically, in this operation, in the token quantity calculation phase, the number of tokens output in the bucket output token quantity phase is added to the number of tokens filled each time to obtain the number of tokens to be written back in the calculation result write back bucket phase.

[0025] From the above, the number of tokens in the token bucket is modified by calculation and write-back, and tokens are filled into the token bucket at a regular and quantitative manner.

[0026] As a possible implementation method of the first aspect, when the operation on the token bucket triggered is a query token bucket triggered when a message is sent, in this operation, in the token quantity calculation stage, the number of tokens output in the bucket output token quantity stage is subtracted from the number of tokens corresponding to the message to obtain the number of tokens to be written back in the calculation result write back bucket stage.

[0027] From the above, by means of calculation and write-back, the number of tokens in the token bucket is modified according to the message length, so as to achieve the effect of controlling the message transmission speed through the token bucket.

[0028] As a possible implementation of the first aspect, the following also includes:

[0029] In the pipeline method, when at least two operations on the same token bucket are triggered within a period of one cycle of the operation token bucket, the subsequent operation selects the number of tokens calculated in the token number calculation stage in the most recent previous operation as the input of the token number calculation stage of the subsequent operation.

[0030] From the above, by defining the token bucket data source selection, confusion in data source selection caused by data correlation, thereby avoiding the problem of data errors.

[0031] As a possible implementation method of the first aspect, the cycle of operating the token bucket also includes at least one waiting stage, and the waiting stage is located after the bucket read request stage, the bucket output token quantity stage, the token quantity calculation stage or the calculation result write back bucket stage, and the clock cycle occupied by one of the waiting stages is the first duration.

[0032] From the above, by inserting a short delay, it is ensured that the output or calculation result has been correctly updated and synchronized, making the system state more stable.

[0033] A second aspect of the present application provides a token bucket control device, which is used to implement the token bucket control method according to any one of claims 1 to 8, including:

[0034] A token bucket unit, used to fill tokens into a bucket at a fixed rate, take out the tokens according to the length of the arriving message, and release the message if the number of tokens in the token bucket is sufficient, and not release the message if the number of tokens in the bucket is insufficient;

[0035] The processing unit is used to read, calculate, and write back the number of tokens in the token bucket.

[0036] A third aspect of the present application provides a computing device, comprising: a processor, and a memory, on which program instructions are stored, and when the program instructions are executed by the processor, the processor executes the token bucket control method described in any one of the first aspects. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] Figure 1 is a flow chart of a first embodiment of a token bucket control method of the present application;

[0038] Figure 2a is a flow chart of a second embodiment of the token bucket control method of the present application;

[0039] Figure 2b is a schematic diagram of information rate provided by the second embodiment of the present application;

[0040] Figure 2c This is a schematic diagram of pipeline control provided in the second embodiment of the present application;

[0041] Figure 2d It is a flow chart of pipeline control provided in the second embodiment of the present application;

[0042] Figure 3 is a schematic diagram of a token bucket control device provided in an embodiment of the present application;

[0043] Figure 4 It is a structural schematic diagram of a computing device provided in an embodiment of the present application.

[0044] It should be understood that the size and shape of each block diagram in the above structural diagram are for reference only and should not constitute an exclusive interpretation of the embodiment of the present invention. The relative position and inclusion relationship between the blocks presented in the structural diagram are only schematic representations of the structural association between the blocks, and do not limit the physical connection method of the embodiment of the present invention. DETAILED DESCRIPTION

[0045] The technical solution provided by the present application is further described below with reference to the accompanying drawings and examples. It should be understood that the system structure and business scenarios provided in the examples of the present application are mainly to illustrate the possible implementation methods of the technical solution of the present application and should not be interpreted as the only limitation on the technical solution of the present application. It is known to those of ordinary skill in the art that with the evolution of the system structure and the emergence of new business scenarios, the technical solution provided by the present application is also applicable to similar technical problems.

[0046] It should be understood that the token bucket control scheme provided in the embodiments of the present application includes a token bucket control method, device, computing device and computer-readable storage medium. Since the principles of solving the problems in these technical solutions are the same or similar, some repetitions may not be repeated in the following specific embodiments, but it should be regarded as that these specific embodiments have been referenced to each other and can be combined with each other.

[0047] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of this application. In the event of any inconsistency, the meaning described in this specification or the meaning derived from the contents recorded in this specification shall prevail. In addition, the terms used herein are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application. In order to accurately describe the technical content in this application and to accurately understand the present invention, the following explanations or definitions are given to the terms used in this specification before describing the specific embodiments:

[0048] 1) Pipeline technology: A quasi-parallel processing implementation technology that decomposes a sequential process into several sub-processes, each of which can be effectively executed simultaneously with other sub-processes. Pipeline technology aims to improve the processing efficiency of the processor. It achieves performance improvement by decomposing a complex task into a series of continuous, simpler sub-tasks or stages, and then letting these stages execute different data items in parallel. The core idea of ​​pipeline technology is overlapping execution, that is, starting the next operation before one operation is fully completed, thereby reducing the overall processing time.

[0049] The token bucket control scheme provided in the embodiment of the present application is achieved by setting the filling time interval of the token bucket and the information rate of the token bucket; the token bucket is filled regularly at the filling time interval, and the number of tokens filled each time is calculated based on the information rate and the filling time interval. This method can provide an improved token bucket control scheme, which can stably fill tokens into the token bucket to improve the stability of message flow control and reduce system costs. The embodiment of the present application can be applied to scenarios such as network traffic shaping and rate limiting in the fields of cloud computing, network security, Web services, and database management. The embodiments of the present application are described in detail below with reference to the accompanying drawings.

[0050] The first embodiment of the present application provides a token bucket control method. Figure 1 , specifically describing the implementation of each step of the modification operation described in the method, including steps S10-S20.

[0051] S10: Set the token bucket filling time interval and token bucket information rate.

[0052] In some embodiments, the information rate of the token bucket is a globally fixed value, such as a dual-bucket single-rate algorithm, including a credit token bucket (hereinafter referred to as the C bucket), which is used to control the average transmission rate of the data flow, and the information rate is the committed information rate (CIR); and an excess token bucket (hereinafter referred to as the E bucket), and the dual buckets share the same CIR rate.

[0053] In some embodiments, the token bucket can have multiple information rates. For example, the token bucket uses a dual-bucket dual-rate algorithm, including a C bucket and a peak token bucket (hereinafter referred to as a P bucket), which is used to limit the instantaneous maximum transmission rate of the data flow. In addition to the CIR rate, the information rate also includes the peak information rate (PIR).

[0054] In some embodiments, the filling time interval of the token bucket is set to a fixed time interval, or a fixed time interval within a period of time.

[0055] S20: regularly filling the token bucket at the filling time interval, and the number of tokens filled each time is calculated based on the information rate and the filling time interval.

[0056] In some embodiments, the number of tokens filled each time (denoted as Δ token ) is calculated based on the product of the information rate value (here denoted as R) and the filling time interval (here denoted as ΔT), which is Δ token =R×ΔT. For example, if the information rate is 100 kbps and the time interval is 1 ms, the fixed number of padding tokens is 100 bits.

[0057] In some embodiments, the ΔT may be set to be less than 1 ms to adjust the rate accuracy of the fill token. In the present application, when the ΔT is less than 1 ms, its value is set by the following formula:

[0058]

[0059] Accordingly, the bit width of the part of the binary count value of the number of tokens that is less than 1 bit is set to n. That is, by adjusting the filling interval time, and correspondingly adjusting the bit width of the decimal part of the binary count of the number of tokens to n, the rate accuracy of filling tokens can be adjusted. For example, when ΔT<1ms, and n=3 (such as Figure 2aAs shown, n = 3, that is, the lowest 3 bits are used to represent the fractional part less than 1 bit), then the ΔT determined according to the above ΔT calculation formula is 125μs, and according to the above Δ token The calculation formula can be obtained as Δ token =1 / 8bit (corresponding to Figure 2a The lowest decimal place in ).

[0060] Among them, the benefits of setting ΔT in the above manner include: on the one hand, under the prior art, the basic unit of the token is bit, that is, the minimum amount of tokens filled is 1 bit, while the present application can realize that the count of tokens filled each time can be less than 1 bit, thereby improving the accuracy of the token information rate (that is, more fine-grained); on the other hand, the above formula setting of ΔT can be directly mapped to the corresponding binary bit, which is convenient for the calculation of the hardware logic calculation unit (calculated in binary), and avoids the complexity of the circuit or operation logic of the logic calculation unit caused by the inability to directly map to binary. That is, by setting the decimal part bit width and using integer operations to achieve the fine granularity of the accuracy of the token bucket, complex floating-point operations can be avoided, so that the circuit of the hardware logic calculation unit is relatively streamlined, such as using addition and subtraction logic circuits and shift logic circuits in the circuit to achieve high-precision token bucket operations.

[0061] The embodiment of the present application also provides a method for processing token bucket operations in a pipeline manner based on the above steps, including:

[0062] The token bucket operation cycle includes the bucket read request phase, the bucket output token quantity phase, the token quantity calculation phase, and the calculation result write-back bucket phase, and the clock cycle occupied by each phase is the first duration;

[0063] With respect to the triggered operations on each token bucket, the operations on each token bucket are processed in sequence in a pipeline manner, wherein the minimum time interval for processing two adjacent operations is the first time length.

[0064] In some embodiments, the first duration may be one clock cycle, so that the bucket read request phase, the bucket output token quantity phase, the token quantity calculation phase, and the calculation result write back bucket phase each occupy one clock cycle. When the first operation on a token bucket is started in the first clock cycle, the second operation on another token bucket is started at the same time in the second clock cycle (the bucket output token quantity phase in the first operation), without having to wait until the fifth clock cycle (i.e. after the first operation ends) to start the second operation. In this way, by staggering the start of different operations, each operation can be executed in parallel in a pipelined manner. In this way, each electronic component such as a RAM controller and other processing units, computing elements, etc. can be in working condition in each clock cycle to achieve full load and full bandwidth operation.

[0065] In some embodiments, after obtaining a read request in the read bucket request phase, the token bucket number and the read request type to be changed are first determined; the token bucket number corresponds to an address in RAM, in which the table entries of the token bucket, such as the rate value, cumulative upper limit value, current number of tokens, etc. of the corresponding token bucket are stored in the form of a table.

[0066] In some embodiments, when the triggered operation on the token bucket is to fill the token bucket periodically, in this operation, in the token quantity calculation phase, the number of tokens output in the bucket output token quantity phase is added to the number of tokens filled each time to obtain the number of tokens to be written back in the calculation result write back bucket phase.

[0067] In some embodiments, if the current read request type is to fill the token bucket regularly, the current number of tokens is calculated to increase the fixed number of tokens Δ token After that, it will check whether the accumulated upper limit is exceeded. If so, no operation will be performed.

[0068] In some embodiments, when a dual-rate algorithm is used, the fixed number of fill tokens at the two rates needs to be calculated respectively, and then the corresponding token bucket is modified according to the calculation results. The fixed number of fill tokens can be calculated before the modification operation begins, or during the token number calculation phase of each modification operation.

[0069] In some embodiments, when the triggered operation on the token bucket is a query token bucket triggered when a message is sent, in this operation, in the token quantity calculation phase, the number of tokens output in the bucket output token quantity phase is subtracted from the number of tokens corresponding to the message to obtain the number of tokens to be written back in the calculation result write back bucket phase.

[0070] In some embodiments, if the read request type is a query token bucket triggered when sending a message, the message length is also required. The message length is used for subsequent token quantity calculation to determine whether there are enough tokens to process the message. If the current read request type is a query token bucket triggered when sending a message, the message length is calculated to see if it exceeds the current token quantity. If so, no operation is performed.

[0071] In some embodiments, when at least two operations on the same token bucket are triggered within a period of one cycle of the operation token bucket, the subsequent operation selects the number of tokens calculated in the token number calculation phase in the most recent previous operation as the input of the token number calculation phase of the subsequent operation.

[0072] For example, the first operation on a token bucket is in the second stage after the bucket read request stage, and the second operation on the token bucket is generated. There is a possibility that the first operation modifies the token number between the bucket read request stage and the bucket output token number stage of the second operation. At this time, in order to make the data read out by the bucket read request stage of the second operation the latest data, the token number output in the token number calculation stage or the calculation result write back to the bucket stage in the first operation should be used as the data source read by the second operation.

[0073] In some embodiments, the cycle of operating the token bucket also includes at least one waiting stage, and the waiting stage is located after the bucket read request stage, the bucket output token quantity stage, the token quantity calculation stage, or the calculation result write back bucket stage, and the clock cycle occupied by one of the waiting stages is the first duration. This is because the execution subjects (such as read-write control units, storage units, and computing units) of different stages are different, or the execution complexity of different stages is different, which may lead to different clock cycles required for different stages, and thus the waiting stage needs to be filled. For example, there may be one or two waiting stages after the bucket read request stage, so that there are enough clock cycles to complete processes such as responding to bucket read requests, RAM address calculation, and accessing addresses, and then entering the bucket output token quantity stage to output the token quantity.

[0074] In some embodiments, the bucket output token quantity phase responds to the read request of the bucket read request phase and obtains the rate value, the accumulated upper limit value and the current token quantity from the RAM.

[0075] In some embodiments, the new token quantity (i.e., the calculation result) obtained in the token quantity calculation phase is used as the current token quantity to be written back. The calculation result writes the new token quantity back to the corresponding address in the RAM in the write-back bucket phase to ensure that the status of the token bucket is updated.

[0076] The second embodiment of the present application provides a control method for a dual-bucket dual-speed multi-token bucket. In this embodiment, the entry data of the token bucket is stored in a random access memory RAM. The address of the RAM is the number of the token bucket entry, which can be shown in the following table:

[0077] serial number CIR(bps) CBS(bits) Current token number (bits) 1 1000 10000 10000 2 500 5000 5000 3 2000 20000 20000

[0078] For example, the first row in the table shows the CIR, CBS and current number of tokens for bucket 1. The operation on the token bucket is the operation on the corresponding address data in the RAM. Figure 2a The method provided by the second embodiment includes the following steps S200-S220.

[0079] S200: pre-configure the filling time interval of each token bucket, the number of tokens filled each time, the cumulative upper limit value, etc. The configured number of tokens filled each time and the cumulative upper limit value can be stored as table data of the token bucket.

[0080] For each token bucket (C bucket), a committed information rate (CIR) and a cumulative upper limit value, namely, a committed burst size CBS, are configured; for each peak token bucket (P bucket), a peak information rate (PIR) and a cumulative upper limit value, namely, a peak burst size PBS, are configured.

[0081] Configure bucket C and bucket P to add a fixed number of tokens to the buckets at regular intervals. Take bucket C as an example. The number of tokens added each time is:

[0082] Δ token =CIR×ΔT

[0083] Where ΔT is the configured fill time interval. When ΔT<1ms, the specific value of ΔT can be configured according to the decimal width n of the number of tokens (here refers to the number of binary counts), as follows:

[0084]

[0085] For example, if the decimal point width of the token number is 3 and ΔT is 125 μs, then for a CIR of 1 kbps, Δ token The decimal place width of the number of tokens is 3, that is, the lowest 3 digits of the information rate accumulation value are used to represent values ​​less than 1 bit, such as Figure 2b shown.

[0086] S210: The operations of each token bucket are triggered successively, wherein some operations are triggered based on the timed filling of the token bucket, and some operations are triggered based on querying the token bucket during the message sending process.

[0087] For example, when a port is to send a message, a processing unit (eg, a RAM controller) generates a read request to query a token bucket, and the request triggers an operation on the token bucket corresponding to the port.

[0088] For another example, when the filling time interval configured in step S200 arrives, the processing unit (eg, RAM controller) generates a read request for filling the token bucket in a timely manner, and the request triggers an operation on the token bucket.

[0089] S220: Scheduling and controlling the operations of the token buckets that are triggered successively, so as to process the operations of the token buckets in sequence in a pipeline manner, and full bandwidth processing can be achieved through the pipeline manner.

[0090] The scheduling control here includes arranging the processing order of the corresponding bucket operations in the pipeline according to the time sequence in which each token bucket operation is triggered, or arranging the processing order of the corresponding bucket operations in the pipeline according to the pre-configured priority order of each token bucket or each operation.

[0091] In this example, if Figure 2c As shown, an operation cycle in the pipeline includes a bucket read request phase (READ_n), a bucket output token quantity phase (DOUT_n), a token quantity calculation phase (CALCU_n) and a calculation result write-back bucket phase (WRITE_n) which are arranged in sequence, wherein the bucket read request phase occupies 2 first durations (i.e., includes a waiting phase), and the bucket output token quantity phase, the token quantity calculation phase and the calculation result write-back bucket phase occupy a first duration. For the processing process of an operation cycle in the pipeline, the following steps S221-S229 may be specifically included:

[0092] S221: In the read bucket request phase (READ_n), a read request is sent to the corresponding token bucket, and a response from the token bucket is waited for.

[0093] Specifically, the RAM controller may send a read request to the RAM to read the corresponding address.

[0094] S222: In the bucket output token quantity phase (DOUT_n), read out the token bucket related information, such as the information rate value, cumulative upper limit value and current token quantity of the token bucket.

[0095] Specifically, the table entry data of the corresponding address in the RAM may be read out to the register, wherein the table entry data includes the information rate value, the accumulated upper limit value and the current number of tokens in the token bucket.

[0096] S223: In the token quantity calculation stage (CALCU_n), determine whether there is data correlation, select the corresponding data source accordingly, and calculate the new token quantity.

[0097] Data correlation refers to the situation where at least two operations on the same token bucket are triggered within a period of one cycle of the token bucket operation. Specifically, for example, within an operation cycle of an address in the RAM (i.e., the write-back bucket stage has not been completed), this operation is also an operation on the address, which indicates data correlation.

[0098] When there is data correlation, the data source selection method is: the subsequent operation selects the number of tokens calculated in the token number calculation stage in the most recent previous operation as the input of the token number calculation stage of the subsequent operation.

[0099] Further example: Check several operations that have started and not yet ended (in this example, one operation cycle takes 5 time cycles, so the operations that have not been completed are at most the first 5 operations). If there is an unfinished operation k, and the token bucket to be modified is the same as the token bucket to be modified by the current operation, then select the output result of CALCU_k of operation k as the input data source of the current token quantity calculation stage (CALCU_n). If there are multiple operations k1, k2, ... as above, select the result of the operation with the closest operation start time to the current operation as the data source of the current operation token quantity calculation stage (CALCU_n). If there is no operation k as above, select the output of the bucket output token quantity stage (DOUT_n) in the current operation as the data source.

[0100] Further integration Figure 2b To explain: Figure 2b The token bucket pipeline processing shown in the figure, each row of the figure represents a clock cycle, and each row represents the operation process of a bucket read request phase-bucket output token quantity phase-token quantity calculation phase-calculation result write back bucket phase. ID_n represents the table entry ID number of the nth operation, that is, the token bucket number. Assuming that the clock cycle from initiating a read request to reading out valid data is m, then m=2 in the figure, and the clock cycle difference from READ_n to DOUT_n in the figure is 2, or it can be expressed as a waiting phase of 1 first duration.

[0101] like Figure 2b As shown, the maximum clock cycle difference of data-related operations is 4, and the method of selecting conflicting data sources is fed back to the input of the circuit that performs calculations according to the read request type. For example, when ID_1 is equal to ID_5, when ID_5 issues a bucket read operation corresponding to the token bucket number, the calculation result of ID_1 is ready to be written back to the RAM. At this time, if the data directly read from the RAM is still the data before the update, the data required by ID_5 during calculation should be selected as the calculation result of the token quantity calculation stage of ID_1 instead of the RAM output data obtained in the bucket output token quantity stage of ID_5.

[0102] The new number of tokens is calculated, specifically, the sum of the number of tokens in the current bucket and the number of tokens filled each time and the subtraction of the number of tokens in the current bucket and the number of tokens corresponding to the message are calculated as one of the possible write-back data.

[0103] S224: In the calculation result writing back to the bucket stage (WRITE_n), the number of tokens calculated in step S223 is written back to the corresponding token bucket.

[0104] Specifically, it is written back to the corresponding address in RAM.

[0105] Steps S221-S224 can be performed as follows: Figure 2d The description language shown is described, including:

[0106] In the bucket read request phase (READ_n), a read request READ request is issued to the corresponding token bucket; and in the bucket output token quantity phase (DOUT_n), the token bucket related information RAM_out is read out;

[0107] In the token quantity calculation phase (CALCU_n), the following logic is included:

[0108] First, make the input data calc_in of the token quantity calculation phase equal to the result RAM_out of the bucket output token quantity phase;

[0109] Determine whether the token bucket number cur_id of the current operation is equal to the token bucket number id_pre_1 of the previous operation;

[0110] If they are equal, calc_in selects the previous operation calculation result cal_out_pre1 as the data source;

[0111] If they are not equal, determine whether the token bucket number cur_id of the current operation is equal to the token bucket number id_pre_2 of the previous two operations;

[0112] If they are equal, calc_in selects the calculation result of the first two operations, cal_out_pre2, as the data source;

[0113] If they are not equal, determine whether the token bucket number cur_id of the current operation is equal to the token bucket number id_pre_3 of the third previous operation;

[0114] If they are equal, calc_in selects the calculation result of the first three operations, cal_out_pre3, as the data source;

[0115] If they are not equal, determine whether the token bucket number cur_id of the current operation is equal to the token bucket number id_pre_4 of the fourth previous operation;

[0116] If they are equal, calc_in selects the calculation result of the first four operations, cal_out_pre4, as the data source;

[0117] If they are not equal, calc_in will not be modified;

[0118] Determine whether the read request type cur_typ of the current operation is a token bucket query command triggered when sending a message;

[0119] If the result is yes, the calculation result of one of the write-back data is selected as the difference between the input data in the token quantity calculation phase and the message length, that is, calc_out = calc_in - pkt_len;

[0120] If the result is no, the calculation result of one of the write-back data is the sum of the input data in the token quantity calculation phase and the corresponding token bucket information rate, that is, calc_out = calc_in + CIR;

[0121] Then, the calculation result write-back bucket phase (WRITE_n) is entered to write the calculation result back to the token bucket.

[0122] The third embodiment of the present application provides a token bucket control device, which can be used to implement the token bucket control method in the above embodiment, such as Figure 3 As shown, the control device of the token bucket includes:

[0123] A token bucket unit is used to fill tokens into a bucket at a fixed rate, take out the tokens according to the length of the arriving message, and release the message if the number of tokens in the token bucket is sufficient; if the number of tokens in the bucket is insufficient, the message is not released; specifically, the token bucket unit can be used to implement steps S10 and S20 in the first embodiment and its optional embodiments.

[0124] The processing unit is used to read, calculate, and write back the number of tokens in the token bucket. Specifically, the processing unit can be used to implement steps S10 and S20 in the first embodiment and its optional embodiments.

[0125] Figure 4 900 is a schematic structural diagram of a computing device 900 provided in an embodiment of the present application. The computing device can execute each optional embodiment of the above method, and the computing device can be a terminal, or a chip or chip system inside the terminal. Figure 4 As shown, the computing device 900 includes: a processor 910 , a memory 920 , and a communication interface 930 .

[0126] It should be understood that Figure 4 The communication interface 930 in the computing device 900 shown may be used to communicate with other devices, and may specifically include one or more transceiver circuits or interface circuits.

[0127] The processor 910 may be connected to a memory 920. The memory 920 may be used to store the program code and data. Therefore, the memory 920 may be a storage unit inside the processor 910, or an external storage unit independent of the processor 910, or a component including a storage unit inside the processor 910 and an external storage unit independent of the processor 910.

[0128] Optionally, the computing device 900 may further include a bus. The memory 920 and the communication interface 930 may be connected to the processor 910 via the bus. The bus may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 A line without an arrow is used to represent the bus, but this does not mean that there is only one bus or one type of bus.

[0129] It should be understood that in the embodiment of the present application, the processor 910 may adopt a central processing unit (CPU). The processor may also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. Alternatively, the processor 910 may adopt one or more integrated circuits to execute relevant programs to implement the technical solutions provided in the embodiment of the present application.

[0130] The memory 920 may include a read-only memory and a random access memory, and provides instructions and data to the processor 910. A portion of the processor 910 may also include a nonvolatile random access memory. For example, the processor 910 may also store information on the device type.

[0131] When the computing device 900 is running, the processor 910 executes the computer-executable instructions in the memory 920 to perform any operation step of the above method and any optional embodiment thereof.

[0132] It should be understood that the computing device 900 according to the embodiment of the present application can correspond to the corresponding subjects in the methods according to the embodiments of the present application, and the above-mentioned and other operations and / or functions of each module in the computing device 900 are respectively for implementing the corresponding processes of each method of the present embodiment. For the sake of brevity, they will not be repeated here.

[0133] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0134] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0135] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0136] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0137] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0138] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. 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. The computer software product is stored in a storage medium and includes several instructions for 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 methods 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.

[0139] An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, it is used to execute the above method, which includes at least one of the solutions described in the above embodiments.

[0140] The computer storage medium of the embodiment of the present application can adopt any combination of one or more computer-readable media. Computer-readable media can be computer-readable signal media or computer-readable storage media. Computer-readable storage media can be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or devices, or any combination of the above. More specific examples (non-exhaustive lists) of computer-readable storage media include: electrical connections with one or more wires, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In this document, computer-readable storage media can be any tangible medium containing or storing programs, which can be used by instruction execution systems, devices or devices or used in combination with them.

[0141] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0142] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0143] Computer program code for performing the operation of the present application can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., using an Internet service provider to connect through the Internet).

[0144] In addition, the words "first, second, third, etc." or module A, module B, module C and other similar terms in the specification and claims are only used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that the specific order or sequence can be interchanged where permitted so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.

[0145] In the above description, the numbers representing the steps, such as S110, S120, etc., do not necessarily mean that the steps will be executed in this manner. If permitted, the order of the steps can be interchanged or they can be executed simultaneously.

[0146] The term "comprising" as used in the description and claims should not be interpreted as being limited to what is listed thereafter; it does not exclude other elements or steps. Therefore, it should be interpreted as specifying the presence of the features, integers, steps or components mentioned, but does not exclude the presence or addition of one or more other features, integers, steps or components and groups thereof. Therefore, the expression "a device comprising means A and B" should not be limited to a device consisting of components A and B only.

[0147] References to "one embodiment" or "an embodiment" in this specification mean that a particular feature, structure, or characteristic described in conjunction with the embodiment is included in at least one embodiment of the present application. Therefore, the phrases "in one embodiment" or "in an embodiment" appearing in various places in this specification do not necessarily refer to the same embodiment, but may refer to the same embodiment. In addition, in one or more embodiments, the particular features, structures, or characteristics can be combined in any appropriate manner, as would be apparent to one of ordinary skill in the art from this disclosure.

[0148] Note that the above are only preferred embodiments of the present application and the technical principles used. Those skilled in the art will understand that the present application is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present application. Therefore, although the present application is described in more detail through the above embodiments, the present application is not limited to the above embodiments, and may also include more other equivalent embodiments without departing from the concept of the present application, all of which belong to the scope of protection of the present application.

Claims

1. A token bucket control method, characterized in that: include: Set the token bucket filling time interval and token bucket information rate; The token bucket is filled regularly at the filling time interval, and the number of tokens filled each time is calculated based on the information rate and the filling time interval.

2. The method according to claim 1, characterized in that: The number of tokens filled each time is obtained according to the following formula: D token =R×ΔT Among them, Δ token represents the number of tokens filled each time, R represents the information rate, and ΔT represents the filling time interval.

3. The method according to claim 2, characterized in that When the ΔT is less than 1 ms, the ΔT is set according to the following formula: Accordingly, the bit width of the bit position of the portion below 1 bit used for the binary count value of the number of tokens is set to n.

4. The method according to claim 1, characterized in that Also includes: The token bucket operation cycle includes the bucket read request phase, the bucket output token quantity phase, the token quantity calculation phase, and the calculation result write-back bucket phase, and the clock cycle occupied by each phase is the first duration; With respect to the triggered operations on each token bucket, the operations on each token bucket are processed in sequence in a pipeline manner, wherein the minimum time interval for processing two adjacent operations is the first time length.

5. The method according to claim 4, characterized in that When the triggered operation on the token bucket is to fill the token bucket periodically, in this operation, in the token quantity calculation phase, the number of tokens output in the bucket output token quantity phase is added to the number of tokens filled each time to obtain the number of tokens to be written back in the calculation result write back bucket phase.

6. The method according to claim 4, characterized in that When the operation triggered on the token bucket is a query token bucket triggered by sending a message, in this operation, in the token quantity calculation phase, the number of tokens output in the bucket output token quantity phase is subtracted from the number of tokens corresponding to the message to obtain the number of tokens to be written back in the calculation result write back bucket phase.

7. The method according to claim 5 or 6, characterized in that: Also includes: In the pipeline method, when at least two operations on the same token bucket are triggered within a period of one cycle of the operation token bucket, the subsequent operation selects the number of tokens calculated in the token number calculation stage in the most recent previous operation as the input of the token number calculation stage of the subsequent operation.

8. The method according to claim 4, characterized in that The token bucket operation cycle also includes at least one waiting stage, which is located after the bucket read request stage, the bucket output token quantity stage, the token quantity calculation stage or the calculation result write back bucket stage, and the clock cycle occupied by one of the waiting stages is the first duration.

9. A token bucket control device, characterized in that: A method for controlling a token bucket according to any one of claims 1 to 8, comprising: A token bucket unit, used to fill tokens into a bucket at a fixed rate, take out the tokens according to the length of the arriving message, and release the message if the number of tokens in the token bucket is sufficient, and not release the message if the number of tokens in the bucket is insufficient; The processing unit is used to read, calculate, and write back the number of tokens in the token bucket.

10. A computing device, characterized in that include: processor, and A memory having program instructions stored thereon, wherein when the program instructions are executed by the processor, the processor executes the token bucket control method according to any one of claims 1 to 8.

Citation Information

Cited By

  • Token bucket verification method and system, electronic equipment and medium

    CN120389986A