Flow rate limiting method and device

By combining global token buckets and sub-token buckets in a multi-core system, the tokens are periodically added and data processing is judged based on the number of tokens, the problem of low speed limit efficiency and accuracy is solved, and efficient and accurate flow control is achieved. Improved system performance.

CN113472681BActive Publication Date: 2024-12-03ALIBABA GROUP HOLDING LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010238135.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-03-30
Publication Date
2024-12-03
Estimated Expiration
2040-03-30

AI Technical Summary

Technical Problem

Under multi-core concurrency systems, the token bucket-based traffic limiting method has problems such as low speed limit efficiency and low accuracy, resulting in problems such as lock waiting and cache brushing, or the token is not present due to uncertain entry rate of pending data. Use or waste.

Method used

Using the combination of global token bucket and sub-token bucket, the number of tokens in the global token bucket periodically increases, and when receiving pending data, it is determined whether the number of tokens in the sub-token bucket exceeds that in the global token bucket. The number of tokens determines whether to discard or retain data, avoiding locking mechanisms and token waste.

Benefits of technology

It realizes balanced control of the entire machine, improves the accuracy and efficiency of speed limit, avoids lock waiting and cache brushing problems, and improves system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113472681B_ABST
    Figure CN113472681B_ABST
Patent Text Reader

Abstract

The present invention discloses a flow rate limiting method and device, which relates to the field of Internet technology and can solve the problems of low efficiency and inaccurate speed limiting in the prior art. The method of the present invention mainly includes: receiving sent data to be processed; judging whether the total number of first tokens in a preset number of sub-token buckets is greater than the total number of second tokens in a global token bucket; different cores correspond to different sub-token buckets, and the tokens in the global token bucket are increased periodically; if the total number of the first tokens is greater than the total number of the second tokens, the data to be processed is discarded; if the total number of the first tokens is less than or equal to the total number of the second tokens, the data to be processed is retained, and a token is added to the sub-token bucket of the current core. The present invention is mainly applicable to scenarios in which flow control is performed based on token buckets in a multi-core system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of Internet technology, and in particular to a flow rate limiting method and device. Background Art

[0002] Token bucket is a common traffic measurement technology, which is often used for traffic restriction and traffic shaping, and can measure the rate and burst of traffic. With the popularization of Internet technology, the number of Internet users has greatly increased. In order to process the data sent by users in a timely manner, the server often uses a multi-core concurrent system to limit the traffic.

[0003] Currently, in a multi-core concurrent system, the following two methods are usually used to limit traffic based on token buckets:

[0004] (I) Establish a global token bucket and lock it, so that only one core is allowed to update the global token bucket at the same time, to avoid multiple cores updating the global token bucket concurrently, which will cause high-frequency data overwriting and inaccurate speed limit. However, because of the addition of the lock mechanism, this method has problems such as lock waiting and cache flush waiting, which reduces the speed limit efficiency.

[0005] (2) Establish a token bucket for each core and add tokens to the token bucket at a specific token adding rate for the corresponding core to use. Although this method does not have the defects of the lock mechanism, since there is no fixed rule for the rate at which the data to be processed enters each core, the core with a large amount of data to be processed will have already discarded the data because it has no tokens, while the core with a small amount of data to be processed still has a large number of tokens that are not used, resulting in very inaccurate speed limits at the whole machine level.

[0006] Therefore, it can be seen that how to provide a speed limiting method with relatively high speed limiting efficiency and accuracy is an urgent problem to be solved. Summary of the invention

[0007] In view of this, the flow rate limiting method and device provided by the present invention aim to solve the problems of low speed limiting efficiency and inaccurate speed limiting in the prior art.

[0008] In a first aspect, the present invention provides a flow rate limiting method, the method comprising:

[0009] Receive the sent data to be processed;

[0010] Determine whether the total number of first tokens in a preset number of sub-token buckets is greater than the total number of second tokens in a global token bucket; different cores correspond to different sub-token buckets, and the tokens in the global token bucket are increased periodically;

[0011] If the total number of the first tokens is greater than the total number of the second tokens, discarding the data to be processed;

[0012] If the total number of the first tokens is less than or equal to the total number of the second tokens, the data to be processed is retained, and a token is added to the sub-token bucket of the current kernel.

[0013] Optionally, before determining whether the total number of first tokens in the preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket, the method further includes:

[0014] Determine whether the global continuous packet loss status is on;

[0015] The determining whether the total number of first tokens in the preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket comprises:

[0016] If the global continuous packet loss state is in the closed state, it is determined whether the total number of the first tokens is greater than the total number of the second tokens.

[0017] Optionally, if the total number of the first tokens is greater than the total number of the second tokens, the method further includes:

[0018] The global continuous packet loss state is set to an open state.

[0019] Optionally, if the global continuous packet loss state is in an open state, the method further includes:

[0020] The data to be processed is discarded.

[0021] Optionally, if the global continuous packet loss state is in an open state, the method further includes:

[0022] If it is determined that the global token bucket enters the next cycle and the token increase operation has been completed for the next cycle, the global continuous packet loss state is set to a closed state;

[0023] Alternatively, when the duration of the global continuous packet loss state being in the on state is a preset duration, the global continuous packet loss state is set to be in the off state.

[0024] Optionally, before determining whether the total number of first tokens in the preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket, the method further includes:

[0025] Determine whether the number of tokens in the sub-token bucket of the current kernel is a multiple of M; M is a positive integer;

[0026] The determining whether the total number of first tokens in the preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket comprises:

[0027] If the number of tokens is a multiple of M, it is determined whether the total number of the first tokens is greater than the total number of the second tokens.

[0028] Optionally, if the number of tokens in the sub-token bucket of the current kernel is not a multiple of M, the method further includes:

[0029] The data to be processed is retained, and a token is added to the sub-token bucket of the current kernel.

[0030] Optionally, the method further includes:

[0031] For each cycle, determining whether the difference between the second total number of tokens and the first total number of tokens is greater than a committed burst size;

[0032] If it is greater than the committed burst size, updating the global token bucket so that the second total number of tokens in the global token bucket is the sum of the first total number of tokens and the committed burst size;

[0033] If it is less than or equal to the committed burst size, N tokens are added to the global token bucket, where N is the product of the committed information rate and the period.

[0034] Optionally, the bucket depth of the sub-token bucket and / or the global token bucket is infinite.

[0035] In a second aspect, the present invention provides a flow rate limiting device, the device comprising:

[0036] A receiving unit, used for receiving the sent data to be processed;

[0037] A judging unit, used to judge whether the total number of first tokens in a preset number of sub-token buckets is greater than the total number of second tokens in a global token bucket; different cores correspond to different sub-token buckets, and the tokens in the global token bucket are increased periodically;

[0038] a discarding unit, configured to discard the data to be processed if the total number of the first tokens is greater than the total number of the second tokens;

[0039] a retaining unit, configured to retain the data to be processed if the total number of the first tokens is less than or equal to the total number of the second tokens;

[0040] The adding unit is used to add a token to the sub-token bucket of the current kernel if the data to be processed is retained.

[0041] Optionally, the judgment unit is also used to judge whether the global continuous packet loss state is on before judging whether the total number of first tokens in a preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket; if the global continuous packet loss state is off, then judge whether the total number of the first tokens is greater than the total number of the second tokens.

[0042] Optionally, the device further comprises:

[0043] The first setting unit is configured to set the global continuous packet loss state to an open state if the total number of the first tokens is greater than the total number of the second tokens.

[0044] Optionally, the discarding unit is further used to discard the data to be processed if the global continuous packet loss state is in an open state.

[0045] Optionally, the device further comprises:

[0046] The second setting unit is used to set the global continuous packet loss state to a closed state if the global continuous packet loss state is in an open state, if it is determined that the global token bucket enters a next cycle and the token increase operation has been completed for the next cycle; or, when the duration of the global continuous packet loss state in the open state is a preset duration, set the global continuous packet loss state to a closed state.

[0047] Optionally, the judgment unit is also used to judge whether the number of tokens in the sub-token bucket of the current kernel is a multiple of M before judging whether the total number of first tokens in a preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket; M is a positive integer; if the number of tokens is a multiple of M, then judge whether the total number of the first tokens is greater than the total number of the second tokens.

[0048] Optionally, the retaining unit is further used to retain the data to be processed if the number of tokens in the sub-token bucket of the current kernel is not a multiple of M.

[0049] Optionally, the judging unit is further configured to judge, for each cycle, whether the difference between the second total number of tokens and the first total number of tokens is greater than a committed burst size;

[0050] The adding unit is also used to update the global token bucket if it is larger than the committed burst size, so that the total number of second tokens in the global token bucket is the sum of the first total number of tokens and the committed burst size; if it is less than or equal to the committed burst size, add N tokens to the global token bucket, where N is the product of the committed information rate and the period.

[0051] Optionally, the bucket depth of the sub-token bucket and / or the global token bucket is infinite.

[0052] In a third aspect, the present invention provides a storage medium storing a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the traffic speed limiting method as described in the first aspect.

[0053] In a fourth aspect, the present invention provides an electronic device, the electronic device comprising a storage medium and a processor;

[0054] The processor is adapted to implement each instruction;

[0055] The storage medium is suitable for storing a plurality of instructions;

[0056] The instructions are suitable for being loaded by the processor and executing the method for recognizing named entities as described in the first aspect.

[0057] By means of the above technical scheme, the traffic speed limiting method and device provided by the present invention can first create a global token bucket and respectively create a sub-token bucket for each core, and then periodically add tokens to the global token bucket. For each sub-token bucket, when the current core receives data to be processed, the total number of tokens of a preset number of sub-token buckets (the total number of first tokens) cannot exceed the total number of tokens of the global token bucket (the total number of second tokens) as a restriction condition to determine whether to add tokens to the sub-token bucket of the current core (that is, if the total number of first tokens is greater than the total number of second tokens, the data to be processed is discarded, and no tokens are added to the sub-token bucket of the current core; if the total number of first tokens is less than or equal to the total number of second tokens, the data to be processed is retained, and a token is added to the sub-token bucket of the current core). Therefore, the phenomenon that the number of unused tokens in a sub-token bucket is far more than that in other sub-token buckets will not occur, thereby achieving balanced control of the entire machine and improving the accuracy of the speed limit of the entire machine. Furthermore, since no lock mechanism is used, there will be no lock waiting and cache flushing waiting problems caused by the lock mechanism, thereby greatly improving the efficiency of speed limiting and improving system performance compared to the prior art using the lock mechanism.

[0058] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0060] Figure 1 A flow chart of a flow rate limiting method provided by an embodiment of the present invention is shown;

[0061] Figure 2 A flow chart of another flow rate limiting method provided by an embodiment of the present invention is shown;

[0062] Figure 3 A flow chart of another flow rate limiting method provided by an embodiment of the present invention is shown;

[0063] Figure 4 A flow chart of another flow rate limiting method provided by an embodiment of the present invention is shown;

[0064] Figure 5 A block diagram showing a flow rate limiting device provided by an embodiment of the present invention is shown;

[0065] Figure 6 A block diagram showing the composition of another flow rate limiting device provided by an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0066] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0067] In order to improve the speed limit efficiency and speed limit accuracy, the embodiment of the present invention provides a traffic speed limit method that combines a global token bucket with each core sub-token bucket and uses the global token bucket to control the number of tokens in the sub-token bucket. The method is mainly applied to a single core side, such as Figure 1 As shown, the method mainly includes:

[0068] 101. Receive the data to be processed.

[0069] The embodiments of the present invention can be applied to any network project, in which a multi-core network device with a safe speed limit function can be set, and the network device can perform speed limit operations on the data to be processed sent from the outside. The data to be processed can be a message or a data packet in data format, and can be a request or a non-request in content. The embodiments of the present invention do not limit the format and data content of the specific data of the interaction. For example, in the field of message processing, the embodiments of the present invention can limit the message sending frequency, and can also limit the message forwarding frequency.

[0070] 102. Determine whether the total number of first tokens in a preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket; if the total number of the first tokens is greater than the total number of the second tokens, execute step 103; if the total number of the first tokens is less than or equal to the total number of the second tokens, execute step 104.

[0071] Each core corresponds to a sub-token bucket, and different cores correspond to different sub-token buckets. The tokens in the global token bucket are periodically increased (one of the cores can be designated to perform a token increase operation on the global token bucket), and the tokens in the sub-token bucket are increased by executing steps 101-104. The bucket depth of the global token bucket and / or the sub-token bucket can be infinite, that is, the number of tokens can only increase but not decrease, and can be increased infinitely.

[0072] In order to use the global token bucket to control the flow of the sub-token bucket, thereby improving the speed limit efficiency and accuracy, the total number of first tokens accumulated in a preset number of sub-token buckets and the total number of second tokens in the global token bucket can be compared, and the discarding and retention of the pending data can be determined by different comparison results. In practical applications, the preset number can be determined according to the requirements of speed limit efficiency and speed limit accuracy. The higher the speed limit accuracy requirement, the more preset numbers there are. For example, when the preset number is the sum of all sub-token buckets, the speed limit accuracy is higher than the speed limit accuracy of other numbers, but the speed limit efficiency may be lower than that of other numbers. In specific implementation, the sub-token buckets that need to be accumulated to obtain the total number of first tokens can be determined according to preset conditions. Among them, the preset conditions include but are not limited to sub-token buckets whose token numbers are greater than a preset threshold, and sub-token buckets whose token numbers are in the first N (N is a positive integer) names.

[0073] For counting the total number of first tokens accumulated by a preset number of sub-token buckets, a total number of first tokens can be stored in a preset storage space. If a sub-token bucket adds a token, the total number of first tokens stored in the preset storage space is updated. When it is necessary to compare with the total number of second tokens, the total number of first tokens can be directly read from the preset storage space. A temporary token bucket can also be created. When a sub-token bucket adds a token, a token is added to the temporary token bucket. When it is necessary to compare with the total number of second tokens, the number of tokens in the temporary token bucket is counted as the total number of first tokens.

[0074] The tokens of the sub-token bucket are increased according to the data to be processed. If there is no data to be processed sent for a long time, or the data to be processed received for a long time is relatively small, the tokens of the global token bucket will continue to increase periodically, which will cause the total number of second tokens in the global token bucket to be much larger than the total number of first tokens accumulated by the preset number of sub-token buckets. At this time, if a large amount of data to be processed suddenly arrives, according to the judgment mechanism of the embodiment of the present invention, these data to be processed are allowed to be retained, which will cause a sudden increase in the kernel load and cause failures such as downtime. In order to avoid this technical problem, the following method can be used to periodically increase tokens in the global token bucket:

[0075] For each cycle, determine whether the difference between the second total number of tokens and the first total number of tokens is greater than the committed burst size (Committed Burst Size, CBS); if it is greater than the committed burst size, update the global token bucket so that the second total number of tokens in the global token bucket is the sum of the first total number of tokens and the committed burst size; if it is less than or equal to the committed burst size, add N tokens to the global token bucket, where N is the product of the committed information rate (Committed Information Rate, CIR) and the cycle.

[0076] The committed burst size is also called the committed burst volume, which refers to the total amount of data that the network allows to be transmitted on the virtual circuit under normal conditions and within a certain time interval. The embodiment of the present invention controls the total amount of the second tokens of the global token bucket not to exceed the sum of the first total amount of tokens and the committed burst size, so that the total amount of to-be-processed data allowed to be retained within a time interval does not exceed the amount of data represented by the committed burst size, so that the burst volume is limited, and the kernel is prevented from being unable to withstand the sudden increase and causing failure.

[0077] The committed information rate is the virtual circuit information transmission rate under normal conditions agreed upon by the user and the network. If the difference between the second total number of tokens and the first total number of tokens is less than or equal to the committed burst size, tokens can be added to the global token bucket according to the committed information rate, that is, the number of tokens N allowed to be added per cycle can be the product of the committed information rate and the cycle. When the committed information rate is represented by CIR and the cycle is represented by T, N = CIR*T.

[0078] It should be added that when allocating memory for the sub-token buckets of each core, they can be separated and decoupled as much as possible to minimize cache occupancy conflicts.

[0079] 103. Discard the data to be processed.

[0080] If the total number of the first tokens is greater than the total number of the second tokens, the function of the global token bucket controlling the sub-token bucket can be achieved by discarding the data to be processed, thereby achieving speed limit for the entire machine.

[0081] 104. Keep the data to be processed, and add a token to the sub-token bucket of the current kernel.

[0082] If the total number of the first tokens is less than or equal to the total number of the second tokens, the accumulated tokens of the preset number of sub-token buckets have not reached the upper limit allowed by the whole machine, so the data to be processed received this time can be retained, and a token is added to the sub-token bucket of the current kernel, and the added token is allocated to the data to be processed. The specific implementation method of retaining the data to be processed can be to add the data to be processed to the cache queue corresponding to the current kernel so that it can be processed later.

[0083] The flow rate limiting method provided by the embodiment of the present invention can first create a global token bucket and respectively create a sub-token bucket for each core, and then periodically add tokens to the global token bucket. For each sub-token bucket, when the current core receives data to be processed, the total number of tokens of the sub-token buckets (the total number of first tokens) of the preset number of tokens cannot exceed the total number of tokens of the global token bucket (the total number of second tokens) as a restriction condition to determine whether the sub-token bucket of the current core adds tokens (i.e., if the total number of first tokens is greater than the total number of second tokens, the data to be processed is discarded, and no tokens are added to the sub-token bucket of the current core, and if the total number of first tokens is less than or equal to the total number of second tokens, the data to be processed is retained, and a token is added to the sub-token bucket of the current core), so that the phenomenon that the unused tokens in a sub-token bucket are far more than those in other sub-token buckets will not occur, thereby realizing balanced control of the entire machine and improving the accuracy of the speed limit of the entire machine. In addition, since no lock mechanism is used, there will be no lock waiting and cache back flush waiting problems caused by the lock mechanism, thereby greatly improving the efficiency of speed limit and improving system performance compared to the prior art using the lock mechanism.

[0084] Optionally, in order to further improve the speed limiting efficiency, the embodiment of the present invention provides the following three methods:

[0085] Method 1: If Figure 2 As shown, the method mainly includes:

[0086] 201. Receive the data to be processed.

[0087] The specific implementation method of this step is the same as that of the above step 101 and will not be repeated here.

[0088] 202. Determine whether the global continuous packet loss state is in an open state.

[0089] Among them, the global continuous packet loss state is a parameter used to control global packet loss. That is, when it is turned on, it is used to indicate that each core must discard new data to be processed after receiving it, and there is no need to add tokens to the sub-token bucket.

[0090] Since the global continuous packet loss status is a global parameter, and when it is in the open state, regardless of whether the total number of first tokens in the preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket, the kernel needs to discard the newly received data to be processed. Therefore, after receiving the sent data to be processed, the kernel first determines whether the global continuous packet loss status is in the open state to avoid wasting time and resources on judging the total number of tokens.

[0091] 203. If the global continuous packet loss state is in an open state, discard the data to be processed.

[0092] After the global continuous packet loss state is turned on, all newly received data to be processed will be discarded, so the sub-token bucket will stop adding tokens, but the global token bucket will still periodically add tokens, so if the global continuous packet loss state is always in the turned-on state, the total number of second tokens in the global token bucket will be much larger than the total number of first tokens accumulated by the preset number of sub-token buckets, which will cause the phenomenon of being unable to respond to the sudden increase of new data in time. In order to solve the problem, the global continuous packet loss state can be set to the closed state under specific conditions. Among them, the relatively good time is: if it is determined that the global token bucket enters the next cycle, and the token increase operation has been completed for the next cycle, the global continuous packet loss state is set to the closed state. In the case of little impact on the accuracy of the speed limit of the whole machine, other times can also be selected to set the global continuous packet loss state to the closed state. For example, when the duration of the global continuous packet loss state in the open state reaches the preset duration, the global continuous packet loss state can be set to the closed state.

[0093] 204. If the global continuous packet loss state is in the closed state, determine whether the total number of first tokens in a preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket.

[0094] If the global continuous packet loss state is in the closed state, there is no mandatory control on packet loss globally, so it is necessary to determine whether to discard or retain the data to be processed by judging the size of the total number of first tokens and the total number of second tokens.

[0095] 205. If the total number of the first tokens is greater than the total number of the second tokens, discard the data to be processed and set the global continuous packet loss state to an open state.

[0096] Since when the global token bucket periodically adds tokens, within a cycle, it may take the first part of the cycle to complete the token addition operation, and the total number of the second tokens in the global token bucket will not change during the remaining time of the cycle, so during this remaining time, once the total number of the first tokens accumulated by the preset number of sub-token buckets is greater than the total number of the second tokens, from the moment of occurrence (which can be called the first moment of occurrence) until the next time the global token bucket is added with tokens, regardless of whether a judgment is made, the conclusion obtained is that the total number of the first tokens is greater than the total number of the second tokens, and the data to be processed needs to be discarded. In order to save judgment resources and judgment time, the global continuous packet loss state can be set to the open state, so that when new data to be processed is received later, it can be directly discarded according to the global continuous packet loss state.

[0097] Among them, when the first judgment result is that the total number of the first tokens is greater than the total number of the second tokens, the global continuous packet loss state can be set to the open state, and the global continuous packet loss state can be set to the open state only when the Xth (X is greater than 1)th judgment result is that the total number of the first tokens is greater than the total number of the second tokens. As long as the timing of setting the global continuous packet loss state to the open state can be guaranteed from the first occurrence time until the next time tokens are added to the global token bucket, judgment resources and judgment time can be saved to a certain extent, thereby improving the limit efficiency to a certain extent.

[0098] 206. If the total number of the first tokens is less than or equal to the total number of the second tokens, retain the data to be processed and add a token to the sub-token bucket of the current kernel.

[0099] The specific implementation method of this step is the same as that of the above step 104 and will not be repeated here.

[0100] The flow rate limiting method provided by the embodiment of the present invention is Figure 1 On the basis of the illustrated embodiment, by enabling the global continuous packet loss state, and only when the global continuous packet loss state is in the off state, a drop / keep decision is made, and when the global continuous packet loss state is in the on state, the data to be processed is directly discarded, thereby reducing the number of judgments for the drop / keep decision, and further improving the speed limit efficiency on the basis of improving the accuracy of the speed limit of the entire machine.

[0101] Method 2: If Figure 3 As shown, the method mainly includes:

[0102] 301. Receive the sent data to be processed.

[0103] The specific implementation method of this step is the same as that of the above step 101 and will not be repeated here.

[0104] 302. Determine whether the number of tokens in the sub-token bucket of the current kernel is a multiple of M; if the number of tokens is not a multiple of M, execute step 303; if the number of tokens is a multiple of M, execute step 304.

[0105] Wherein, M is a positive integer, and the specific value of M can be determined based on historical experience.

[0106] Since the number of tokens in the sub-token bucket of each kernel and the global token bucket are accumulated, the total number of tokens is judged once every M data to be processed (i.e., the decision of discarding / retaining), and when the data to be processed in the middle is directly retained, even if Y data are received more in a certain cycle (M data is one cycle), the new data will be discarded in the subsequent cycles due to the restriction of the total number of second tokens on the total number of first tokens, that is, Y data will be reduced in the subsequent cycles, so for the whole machine, its speed limit accuracy is almost unchanged. Therefore, when receiving the data to be processed, it can be judged first whether the number of tokens in the sub-token bucket of the current kernel is a multiple of M. If not, it can be directly retained and a token can be added to the sub-token bucket of the current kernel (i.e., step 303). If so, the total number of tokens is judged again, and the decision of discarding / retaining the data to be processed is made based on the result of the judgment of the total number of tokens (i.e., steps 304->305->303).

[0107] 303. Keep the data to be processed, and add a token to the sub-token bucket of the current kernel.

[0108] The specific implementation method of this step is the same as that of the above step 104 and will not be repeated here.

[0109] 304. Determine whether the total number of first tokens in a preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket; if the total number of the first tokens is greater than the total number of the second tokens, execute step 305; if the total number of the first tokens is less than or equal to the total number of the second tokens, execute step 303.

[0110] 305. Discard the data to be processed.

[0111] The flow rate limiting method provided by the embodiment of the present invention is Figure 1 On the basis of the illustrated embodiment, a discard / keep decision is made for every M data to be processed, and the intermediate data to be processed is directly retained, which can reduce the number of discard / keep decisions, thereby further improving the speed limit efficiency on the basis of improving the accuracy of the speed limit of the entire machine.

[0112] Method 3: Since Method 1 improves the speed limit efficiency from a global level, and Method 2 improves the speed limit efficiency from a single core level, and the two have no dependencies or conflicts, they can be combined to form Method 3 to further improve the speed limit efficiency. Figure 4 As shown, the method includes:

[0113] 401. Receive the data to be processed.

[0114] 402. Determine whether the global continuous packet loss state is in an on state; if the global continuous packet loss state is in an on state, execute step 403; if the global continuous packet loss state is in a off state, execute step 404.

[0115] 403. Discard the data to be processed.

[0116] 404. Determine whether the number of tokens in the sub-token bucket of the current kernel is a multiple of M; if the number of tokens is not a multiple of M, execute step 405; if the number of tokens is a multiple of M, execute step 406.

[0117] 405. Keep the data to be processed, and add a token to the sub-token bucket of the current kernel.

[0118] 406. Determine whether the total number of first tokens in a preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket; if the total number of the first tokens is greater than the total number of the second tokens, execute step 407; if the total number of the first tokens is less than or equal to the total number of the second tokens, execute step 405.

[0119] 407. Discard the data to be processed and set the global continuous packet loss state to an open state.

[0120] Further, according to the above method embodiment, another embodiment of the present invention also provides a flow rate limiting device, such as Figure 5 As shown, the device comprises:

[0121] A receiving unit 51, configured to receive the sent data to be processed;

[0122] A judging unit 52, used to judge whether the total number of first tokens in a preset number of sub-token buckets is greater than the total number of second tokens in a global token bucket; different cores correspond to different sub-token buckets, and the tokens in the global token bucket are increased periodically;

[0123] a discarding unit 53, configured to discard the data to be processed if the total number of the first tokens is greater than the total number of the second tokens;

[0124] A retaining unit 54, configured to retain the data to be processed if the total number of the first tokens is less than or equal to the total number of the second tokens;

[0125] The adding unit 55 is used to add a token to the sub-token bucket of the current kernel if the data to be processed is retained.

[0126] Optionally, the judgment unit 52 is also used to judge whether the global continuous packet loss state is on before judging whether the total number of first tokens in a preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket; if the global continuous packet loss state is off, then judge whether the total number of the first tokens is greater than the total number of the second tokens.

[0127] Optional, such as Figure 6 As shown, the device also includes:

[0128] The first setting unit 56 is configured to set the global continuous packet loss state to an open state if the total number of the first tokens is greater than the total number of the second tokens.

[0129] Optionally, the discarding unit 53 is further configured to discard the data to be processed if the global continuous packet loss state is in an open state.

[0130] Optional, such as Figure 6 As shown, the device also includes:

[0131] The second setting unit 57 is used to set the global continuous packet loss state to a closed state if the global continuous packet loss state is in an open state, if it is determined that the global token bucket enters a next cycle and the token increase operation for the next cycle has been completed; or, when the duration of the global continuous packet loss state in the open state is a preset duration, set the global continuous packet loss state to a closed state.

[0132] Optionally, the judgment unit 52 is also used to judge whether the number of tokens in the sub-token bucket of the current kernel is a multiple of M before judging whether the total number of first tokens in a preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket; M is a positive integer; if the number of tokens is a multiple of M, then judge whether the total number of the first tokens is greater than the total number of the second tokens.

[0133] Optionally, the retaining unit 54 is further configured to retain the data to be processed if the number of tokens in the sub-token bucket of the current kernel is not a multiple of M.

[0134] Optionally, the judging unit 52 is further configured to judge, for each cycle, whether the difference between the second total number of tokens and the first total number of tokens is greater than a committed burst size;

[0135] The adding unit 55 is also used to update the global token bucket if it is larger than the committed burst size, so that the total number of second tokens in the global token bucket is the sum of the first total number of tokens and the committed burst size; if it is less than or equal to the committed burst size, add N tokens to the global token bucket, where N is the product of the committed information rate and the period.

[0136] Optionally, the bucket depth of the sub-token bucket and / or the global token bucket is infinite.

[0137] The flow rate limiting device provided by the embodiment of the present invention can first create a global token bucket and a sub-token bucket for each core respectively, and then periodically add tokens to the global token bucket. For each sub-token bucket, when the current core receives data to be processed, the total number of tokens of the sub-token buckets (the total number of first tokens) of the preset number of token buckets cannot exceed the total number of tokens of the global token bucket (the total number of second tokens) as a restriction condition to determine whether the sub-token bucket of the current core adds tokens (i.e., if the total number of first tokens is greater than the total number of second tokens, the data to be processed is discarded, and tokens will not be added to the sub-token bucket of the current core, and if the total number of first tokens is less than or equal to the total number of second tokens, the data to be processed is retained, and a token is added to the sub-token bucket of the current core), so that the phenomenon that the unused tokens in a sub-token bucket are far more than those in other sub-token buckets will not occur, thereby realizing balanced control of the entire machine and improving the accuracy of the speed limit of the entire machine. In addition, since no lock mechanism is used, there will be no lock waiting and cache back flush waiting problems caused by the lock mechanism, thereby greatly improving the efficiency of speed limit and improving system performance compared to the prior art using the lock mechanism. On this basis, by enabling the global continuous packet loss state, and only when the global continuous packet loss state is turned off, the discard / keep decision is made. When the global continuous packet loss state is turned on, the pending data is directly discarded, thereby reducing the number of discard / keep decisions. If a discard / keep decision is made every M pending data, and the intermediate pending data is directly retained, the number of discard / keep decisions can also be reduced, thereby further improving the speed limit efficiency on the basis of improving the accuracy of the speed limit of the entire machine.

[0138] Furthermore, another embodiment of the present invention provides a storage medium, wherein the storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the traffic speed limiting method as described above.

[0139] Furthermore, another embodiment of the present invention provides an electronic device, the electronic device comprising a storage medium and a processor;

[0140] The processor is adapted to implement each instruction;

[0141] The storage medium is suitable for storing a plurality of instructions;

[0142] The instructions are suitable for being loaded by the processor and executing the traffic rate limiting method as described above.

[0143] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0144] It is understandable that the related features in the above methods and devices can be referenced to each other. In addition, the "first", "second" and the like in the above embodiments are used to distinguish the embodiments, but do not represent the advantages and disadvantages of the embodiments.

[0145] 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.

[0146] The algorithm and display provided herein are not inherently related to any particular computer, virtual system or other device. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious to construct the structure required for this type of system. In addition, the present invention is not directed to any specific programming language either. It should be understood that various programming languages ​​can be utilized to realize the content of the present invention described herein, and the description of the above specific language is for disclosing an embodiment of the present invention.

[0147] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.

[0148] Similarly, it should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the intention that the claimed invention requires more features than those explicitly recited in each claim. More specifically, as reflected in the claims below, inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present invention.

[0149] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.

[0150] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.

[0151] The various component embodiments of the present invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) may be used in practice to implement some or all functions of some or all components in the flow rate limiting method and device according to an embodiment of the present invention. The present invention may also be implemented as a device or device program (e.g., a computer program and a computer program product) for executing part or all of the methods described herein. Such a program implementing the present invention may be stored on a computer-readable medium, or may have the form of one or more signals. Such a signal may be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.

[0152] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be construed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising a number of different elements and by means of a suitably programmed computer. In a unit claim enumerating a number of devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc., does not indicate any order. These words may be interpreted as names.

Claims

1. A flow rate limiting method, characterized in that: The method comprises: Receive the sent data to be processed; Determine whether the total number of first tokens in a preset number of sub-token buckets is greater than the total number of second tokens in a global token bucket; different cores correspond to different sub-token buckets, the tokens in the global token bucket are increased periodically, and the preset number of sub-token buckets is determined according to preset conditions; If the total number of the first tokens is greater than the total number of the second tokens, discarding the data to be processed; If the total number of the first tokens is less than or equal to the total number of the second tokens, the data to be processed is retained, and a token is added to the sub-token bucket of the current kernel.

2. The method according to claim 1, characterized in that Before determining whether the total number of first tokens in the preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket, the method further includes: Determine whether the global continuous packet loss status is on; The determining whether the total number of first tokens in the preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket comprises: If the global continuous packet loss state is in the closed state, it is determined whether the total number of the first tokens is greater than the total number of the second tokens.

3. The method according to claim 2, characterized in that If the total number of the first tokens is greater than the total number of the second tokens, the method further includes: The global continuous packet loss state is set to an open state.

4. The method according to claim 2, characterized in that: If the global continuous packet loss state is in an open state, the method further includes: The data to be processed is discarded.

5. The method according to claim 2, characterized in that: If the global continuous packet loss state is in an open state, the method further includes: If it is determined that the global token bucket enters the next cycle and the token increase operation has been completed for the next cycle, the global continuous packet loss state is set to a closed state; Alternatively, when the duration of the global continuous packet loss state being in the on state is a preset duration, the global continuous packet loss state is set to be in the off state.

6. The method according to claim 1, characterized in that Before determining whether the total number of first tokens in the preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket, the method further includes: Determine whether the number of tokens in the sub-token bucket of the current kernel is a multiple of M; M is a positive integer; The determining whether the total number of first tokens in the preset number of sub-token buckets is greater than the total number of second tokens in the global token bucket comprises: If the number of tokens is a multiple of M, it is determined whether the total number of the first tokens is greater than the total number of the second tokens.

7. The method according to claim 6, characterized in that If the number of tokens in the sub-token bucket of the current kernel is not a multiple of M, the method further includes: The data to be processed is retained, and a token is added to the sub-token bucket of the current kernel.

8. The method according to claim 1, characterized in that The method further comprises: For each cycle, determining whether the difference between the second total number of tokens and the first total number of tokens is greater than a committed burst size; If it is greater than the committed burst size, updating the global token bucket so that the second total number of tokens in the global token bucket is the sum of the first total number of tokens and the committed burst size; If it is less than or equal to the committed burst size, N tokens are added to the global token bucket, where N is the product of the committed information rate and the period.

9. The method according to any one of claims 1 to 8, characterized in that The bucket depth of the sub-token bucket and / or the global token bucket is infinite.

10. A flow rate limiting device, characterized in that: The device comprises: A receiving unit, used for receiving the sent data to be processed; A judging unit, used to judge whether the total number of first tokens in a preset number of sub-token buckets is greater than the total number of second tokens in a global token bucket; different cores correspond to different sub-token buckets, the tokens in the global token bucket are increased periodically, and the preset number of sub-token buckets is determined according to a preset condition; a discarding unit, configured to discard the data to be processed if the total number of the first tokens is greater than the total number of the second tokens; a retaining unit, configured to retain the data to be processed if the total number of the first tokens is less than or equal to the total number of the second tokens; The adding unit is used to add a token to the sub-token bucket of the current kernel if the data to be processed is retained.

11. A storage medium, characterized in that: The storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the traffic speed limiting method according to any one of claims 1 to 9.

12. An electronic device, characterized in that: The electronic device includes a storage medium and a processor; The processor is adapted to implement each instruction; The storage medium is suitable for storing a plurality of instructions; The instructions are suitable for being loaded by the processor and executing the traffic rate limiting method according to any one of claims 1 to 9.