CN113992594A - Flow control method and device, electronic equipment and computer readable storage medium - Google Patents

Flow control method and device, electronic equipment and computer readable storage medium Download PDF

Info

Publication number
CN113992594A
CN113992594A CN202111270940.9A CN202111270940A CN113992594A CN 113992594 A CN113992594 A CN 113992594A CN 202111270940 A CN202111270940 A CN 202111270940A CN 113992594 A CN113992594 A CN 113992594A
Authority
CN
China
Prior art keywords
token bucket
tokens
total length
message
determining
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202111270940.9A
Other languages
Chinese (zh)
Other versions
CN113992594B (en
Inventor
张赟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Topsec Technology Co Ltd
Beijing Topsec Network Security Technology Co Ltd
Beijing Topsec Software Co Ltd
Original Assignee
Beijing Topsec Technology Co Ltd
Beijing Topsec Network Security Technology Co Ltd
Beijing Topsec Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Topsec Technology Co Ltd, Beijing Topsec Network Security Technology Co Ltd, Beijing Topsec Software Co Ltd filed Critical Beijing Topsec Technology Co Ltd
Priority to CN202111270940.9A priority Critical patent/CN113992594B/en
Publication of CN113992594A publication Critical patent/CN113992594A/en
Application granted granted Critical
Publication of CN113992594B publication Critical patent/CN113992594B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • H04L47/215Flow control; Congestion control using token-bucket
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/70Reducing energy consumption in communication networks in wireless communication networks

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The application provides a flow control method, a flow control device, an electronic device and a computer-readable storage medium, wherein a specific implementation manner of the method comprises the following steps: determining the total length of an initial message corresponding to the current period; determining total received current message data at the current moment, and determining the total length of a current message corresponding to the current message data; determining the number of target tokens to be consumed according to the total length of the current message and the total length of the initial message; controlling the flow corresponding to the target message data according to the target token number and the total number of tokens in a preset token bucket; and the period for storing the token in the preset token bucket is the same as the period for determining the total length of the initial message. The method can control the flow without designing locking operation or atomic operation, and can be deployed in a multi-core processor.

Description

Flow control method and device, electronic equipment and computer readable storage medium
Technical Field
The present application relates to the field of flow control, and in particular, to a flow control method, apparatus, electronic device, and computer-readable storage medium.
Background
When data is transmitted in a network, in order to prevent network congestion, it is necessary to limit the traffic flowing out of the network so that the traffic is sent out at a relatively uniform speed. The token bucket algorithm accomplishes this function by controlling the amount of data sent onto the network and allowing the transmission of bursts of data.
In the related art, in order to better provide network forwarding services for users under limited bandwidth resources, a hardware solution and a software solution are generally adopted. Among them, the hardware solution is too costly to process using a dedicated FPGA (Field Programmable Gate Array) or a QOS (Quality of Service) processor (e.g., ezchip network processor) integrated inside the network processor. One way to implement the software solution is to optimize the QoS module provided by DPDK (Data Plane Development Kit) by code, and after optimization, the performance equivalent to that of the hardware solution can be achieved. Although the QOS module in this implementation can save cost, it needs strict deployment requirements (for example, a kernel must be configured for the QOS module to use), and cannot be deployed in a flexible scenario with low requirement on quality of service without limitation. Another way to implement the software solution is to provide related services by using QOS-related algorithms (e.g., HTB, Hierarchical Token Bucket algorithm) provided in the Linux kernel, but these algorithms are mostly compromise products and are difficult to meet the requirements of the network device in terms of function or performance.
Disclosure of Invention
An object of the embodiments of the present application is to provide a flow control method, a flow control apparatus, an electronic device, and a computer-readable storage medium, which can control a flow without designing a lock operation or an atomic operation, and thus can be deployed in a multi-core processor.
In a first aspect, an embodiment of the present application provides a flow control method, where the method is applied to a terminal device, a central processing unit of the terminal device includes at least two cores, and the method includes: determining the total length of an initial message corresponding to the current period; determining total received current message data at the current moment, and determining the total length of a current message corresponding to the current message data; determining the number of target tokens to be consumed according to the total length of the current message and the total length of the initial message; controlling the flow corresponding to the target message data according to the target token number and the total number of tokens in a preset token bucket; and the period for storing the token in the preset token bucket is the same as the period for determining the total length of the initial message. Therefore, the flow can be controlled without designing a lock operation or an atomic operation, and the method can be deployed in a multi-core processor.
Optionally, the determining the number of target tokens to be consumed according to the total length of the current packet and the total length of the initial packet includes: obtaining the total length of a target message to be sent at the current moment according to the total length of the current message and the total length of the initial message; and determining the number of the target tokens according to the total length of the target message. Here, an embodiment is provided that can determine the target number of tokens to be consumed according to the total length of the initial packet and the total length of the current packet, so as to conveniently calculate the number of tokens that may be consumed in the current period, so as to conveniently determine whether current limiting is required.
Optionally, the determining current packet data received at the current time in total and determining a total length of a current packet corresponding to the current packet data include: in the period, accumulating the length of a single message corresponding to the single message data received at the current moment by taking the total length of the initial message as a calculation starting point; and determining the length sum of the messages obtained at the end time of the period as the total length of the current message. Therefore, the total length of the message to be sent in the period can be directly counted, so that the number of the target tokens can be periodically calculated, and the purpose of periodically controlling the flow can be realized.
Optionally, the flow control method further includes: determining that the period is finished when a preset fixed time length is reached by taking the time for determining the total length of the initial message as a period starting point; and determining the total length of the current message received at the end time of the previous period as the total length of the initial message of the period. Therefore, when the total length of the next current message is counted, the total length of the previous current message can be used as an accumulation basis, and even if the accumulation basis has errors, the influence on the performance is limited.
Optionally, the preset token bucket has a constant preset capacity, and the flow control method further includes: storing a fixed number of tokens in the preset token bucket in the period; and if the total number of tokens in the preset token bucket is larger than the preset capacity after the tokens are stored, overflowing redundant tokens. Therefore, redundant tokens can be collected, the token waste is avoided, and the actual utilization rate of the tokens is improved.
Optionally, the preset token bucket comprises a guaranteed token bucket for providing tokens of guaranteed bandwidth and a restricted token bucket for providing tokens of restricted bandwidth; and if the total number of tokens in the preset token bucket is larger than the preset capacity after the tokens are stored, overflowing redundant tokens, comprising: and preferentially storing tokens in the guarantee token bucket, and overflowing redundant tokens into the limit token bucket if the total number of tokens in the guarantee token bucket is greater than the preset capacity corresponding to the guarantee token bucket. Therefore, on one hand, the token required by bandwidth guarantee can be provided to meet the requirement, and on the other hand, the waste of the token can be avoided.
Optionally, the preset token bucket includes a token bucket parent node and at least one token bucket child node, a sum of guaranteed bandwidths corresponding to the at least one token bucket child node is not greater than a guaranteed bandwidth corresponding to the token bucket parent node, and a restricted bandwidth corresponding to each of the at least one token bucket child node is not greater than a restricted bandwidth corresponding to the token bucket parent node; and the guaranteed token bucket and the restricted token bucket are the token bucket parent nodes; and controlling the flow corresponding to the target message data according to the target token number and the total number of tokens in a preset token bucket, including: determining a token bucket child node of a token to be consumed; indicating the token bucket child node to apply for a token in the guaranteed token bucket when detecting a message of which the receiving rate does not exceed the committed information rate; and applying for tokens in the restricted token bucket when detecting that the receiving rate exceeds the committed information rate. In this way, the preset token bucket is subjected to hierarchical processing to realize hierarchical control on the flow.
In a second aspect, an embodiment of the present application provides a flow control apparatus, where the apparatus is applied to a terminal device, a central processing unit of the terminal device includes at least two cores, and the apparatus includes: an initial determining module, configured to determine a total length of an initial packet corresponding to a current period; the middle determining module is used for determining the total received current message data at the current moment and determining the total length of the current message corresponding to the current message data; the token number determining module is used for determining the number of target tokens to be consumed according to the total length of the current message and the total length of the initial message; the control module is used for controlling the flow corresponding to the target message data according to the target token number and the total number of tokens in a preset token bucket; and the period for storing the token in the preset token bucket is the same as the period for determining the total length of the initial message. Therefore, the flow can be controlled without designing a lock operation or an atomic operation, and the method can be deployed in a multi-core processor.
In a third aspect, an embodiment of the present application provides an electronic device, including a processor and a memory, where the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps in the method as provided in the first aspect are executed.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium, on which a computer program is stored, which, when executed by a processor, performs the steps in the method as provided in the first aspect above.
Additional features and advantages of the present application will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the embodiments of the present application. The objectives and other advantages of the application may be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments of the present application will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and that those skilled in the art can also obtain other related drawings based on the drawings without inventive efforts.
Fig. 1 is a flowchart of a flow control method according to an embodiment of the present application;
fig. 2 is a schematic view of an application scenario of a multi-layer preset token bucket according to an embodiment of the present disclosure;
fig. 3 is a block diagram of a flow control device according to an embodiment of the present disclosure;
fig. 4 is a schematic structural diagram of an electronic device for executing a flow control method according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. The components of the embodiments of the present application, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present application, presented in the accompanying drawings, is not intended to limit the scope of the claimed application, but is merely representative of selected embodiments of the application. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present application without making any creative effort, shall fall within the protection scope of the present application.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. Meanwhile, in the description of the present application, the terms "first", "second", and the like are used only for distinguishing the description, and are not to be construed as indicating or implying relative importance.
It should be noted that the embodiments or technical features of the embodiments in the present application may be combined without conflict.
In the related art, a hardware solution has a problem of high cost, and a software solution can solve the problem of high cost, but cannot be flexibly deployed in a multi-core scene. In order to solve the problem that a software solution provided in the related art cannot be flexibly deployed in a multi-core scenario, the present application provides a flow control method, apparatus, electronic device, and computer-readable storage medium; further, the message can be periodically sent to the token bucket, and after the token bucket receives the message, the number of tokens to be consumed can be determined according to the total length of the current message obtained by accumulating at the current moment, so that whether the message can be directly sent out or not can be determined according to the number of tokens to be consumed and the total number of tokens in the preset token bucket, and the flow control is realized. Thus, if a plurality of cores exist in a Central Processing Unit (CPU), the number of tokens to be consumed can be determined by the total length of the initial packet corresponding to the current period and the total length of the current packet, and then the flow can be controlled according to the number of tokens to be consumed. In the process, the flow control can be flexibly realized without designing locking operation or atomic operation, thereby solving the problems.
The above solutions in the related art are all the results of practical and careful study of the inventor, and therefore, the discovery process of the above problems and the solutions proposed by the following embodiments of the present invention to the above problems should be the contribution of the inventor to the present invention in the course of the present invention.
Referring to fig. 1, a flowchart of a flow control method according to an embodiment of the present application is shown. The flow control method can be applied to terminal equipment, and a central processing unit of the terminal equipment at least comprises two cores. As shown in fig. 1, the flow control method includes the following steps 101 to 103.
Step 101, determining the total length of the initial message corresponding to the current period.
In some application scenarios, the total length of the initial packet corresponding to the current period may be determined first. In these application scenarios, for example, the sent message data may be determined first, and the message length of each sent message data may be accumulated to obtain the total message length, and at this time, the total message length may be determined as the initial total message length. In these application scenarios, the initial packet total length may also be 0. That is, at this time, in the first period, the message data has not yet been sent.
Step 102, determining the total received current message data at the current moment, and determining the total length of the current message corresponding to the current message data.
After the terminal device determines the total length of the initial packet corresponding to the current period, it may determine the total current packet data received at the current time. That is, in the current period, the terminal device may further determine the total amount of the message data received at the current time, and may determine the total length of the corresponding current message according to the current message data. For example, if the total current packet data received at the current time includes packet data a with a length of 4 bytes and packet data B with a length of 6 bytes, the total length of the current packet may be 10 bytes.
And 103, determining the number of the target tokens to be consumed according to the total length of the current message and the total length of the initial message.
After the total length of the initial message and the total length of the current message are determined, the number of target tokens to be consumed can be determined. In some application scenarios, in order to ensure that the total length of the current packet can have the corresponding target token number as much as possible, one or several errors of the packet length may be allowed to exist. For example, the message length of an error value such as 4 bytes or 6 bytes is subtracted from the total length of the current message, and the number of target tokens to be consumed is determined according to the total length of the current message from which the error value is subtracted and the total length of the initial message. In these application scenarios, the message length corresponding to the message data to be sent at the current moment in the current period can be determined according to the initial message length, the current message length and the error value, and then the target token number can be determined according to the message length.
104, controlling the flow corresponding to the target message data according to the target token number and the total number of tokens in a preset token bucket; and the period for storing the token in the preset token bucket is the same as the period for determining the total length of the initial message.
After the target token number is determined, the traffic may be controlled according to the target token number and the total number of tokens in the preset token bucket. In some application scenarios, for example, the target token number may be compared with the total number of tokens in the preset token bucket, and if it is detected that the target token number is not greater than the total number of tokens in the preset token bucket, the packet may be sent out all the time. And if the number of the target tokens is detected to be larger than the total number of the tokens in the preset token bucket, the message is temporarily stopped from being sent outwards so as to control the flow.
In the related art, if the token bucket algorithm is to be executed in a processor, the return value needs to be locked to ensure correctness of the counted traffic. However, this method can only be applied to a single-core processor, and cannot be flexibly applied to a multi-core processor.
In this embodiment, through the above steps 101 to 104, the traffic can be controlled without designing a lock operation or an atomic operation, and thus the method can be deployed in a multicore processor.
In some application scenarios, there are reasons such as a delay in reading data from the cache and reading data from the memory, which results in an error in the total length of the current packet. However, since no lock operation or atomic operation is configured, the determined total length of the current packet is at least the total length of the packet closest to the standard total length of the current packet. Therefore, even if the determined total length of the current message has an error, the error is within an allowable range, and the influence on the performance is limited. Then, after being applied to a multi-core processor, the performance impact problem may not need to be concerned.
In some optional implementations, the step 103 may include the following sub-steps:
and a substep 1031, obtaining the total length of the target message to be sent at the current moment according to the total length of the current message and the total length of the initial message.
In some application scenarios, after determining the total length of the initial packet and the total length of the current packet corresponding to the current period, the two may be subtracted to obtain the total length of the target packet to be sent at the current time. For example, after determining that the total length of the initial packet is 38 bytes and the total length of the current packet is 88 bytes, it may be determined that the total length of the target packet to be sent at the current time is 50 bytes.
And a substep 1032 of determining the number of the target tokens according to the total length of the target message.
In some application scenarios, after the total length of the target packet is determined, the number of target tokens may be further determined. Here, the technology of determining the number of tokens to be consumed according to the length of the message to be sent is the prior art, and details are not described here.
Through the sub-steps 1031 to 1032, an embodiment is provided in which the number of target tokens to be consumed can be determined according to the total length of the initial packet and the total length of the current packet, so as to conveniently calculate the number of tokens that may be consumed in the current period, and to conveniently determine whether current limiting is required.
In some optional implementations, the step 102 may include: in the period, accumulating the length of a single message corresponding to the single message data received at the current moment by taking the total length of the initial message as a calculation starting point; and determining the length sum of the messages obtained at the end time of the period as the total length of the current message.
In some application scenarios, the lengths of the received single packets may be accumulated to obtain the total length of the current packet. Specifically, in the same period, the total length of the initial packet determined in the period may be used as a calculation starting point, and all packet data received by the terminal device in a time period from the start time of the period to the current time may be counted. Further, the message length corresponding to each message data may be accumulated to obtain the current message length accumulated sum corresponding to the current time.
In some application scenarios, the sum of the lengths of the messages obtained at the end of the period may be determined as the total length of the current message. That is, in the process of periodically measuring the traffic, the sum of the lengths of the messages corresponding to the end time of each period may be determined as the total length of the current message. Therefore, the total length of the message to be sent in the period can be directly counted, so that the number of the target tokens can be periodically calculated, and the purpose of periodically controlling the flow can be realized.
In some optional implementations, the flow control method further includes: determining that the period is finished when a preset fixed time length is reached by taking the time for determining the total length of the initial message as a period starting point; and determining the total length of the current message received at the end time of the previous period as the total length of the initial message of the period.
In some application scenarios, the fixed duration may be a cycle time. For example, 1 second is one period. Thus, the time for determining the total length of the initial packet can be determined as the starting time of the period, and when the preset fixed time length is reached, the period is determined to be ended.
In these application scenarios, the total length of the current packet received at the end of the previous period may be determined as the total length of the initial packet of the present period. Therefore, when the total length of the next current message is counted, the total length of the previous current message can be used as an accumulation basis, and even if the accumulation basis has errors, the influence on the performance is limited.
In some optional implementations, the preset token bucket has a constant preset capacity, and the flow control method further includes: storing a fixed number of tokens in the preset token bucket in the period; and if the total number of tokens in the preset token bucket is larger than the preset capacity after the tokens are stored, overflowing redundant tokens.
In some application scenarios, a fixed capacity may be configured for a preset token bucket. For example, the preset capacity of the preset token bucket a may be 100 tokens. In these application scenarios, a fixed number of tokens may be deposited into a preset token bucket per cycle. For example, for the above-mentioned preset token bucket a, 100 tokens may be stored therein at the beginning of each cycle.
In these application scenarios, if the total number of tokens in the preset token bucket is greater than the preset capacity of the preset token bucket after the fixed number of tokens are stored in the preset token bucket, redundant tokens may overflow.
In some application scenarios, for example, a plurality of preset token buckets may be set, and then the overflowed tokens may be stored in other preset token buckets that are not full of tokens, so as to avoid wasting tokens.
In some optional implementations, the preset token bucket includes a guaranteed token bucket for providing tokens of a guaranteed bandwidth and a restricted token bucket for providing tokens of a restricted bandwidth; and if the total number of tokens in the preset token bucket is greater than the preset capacity after the tokens are stored, overflowing redundant tokens, comprising: and preferentially storing tokens in the guarantee token bucket, and overflowing redundant tokens into the limit token bucket if the total number of tokens in the guarantee token bucket is greater than the preset capacity corresponding to the guarantee token bucket.
In some application scenarios, a guaranteed token bucket for carrying guaranteed bandwidth and a restricted token bucket for carrying restricted bandwidth may be set. Thus, each preset token bucket can perform its own role and provide tokens for corresponding message data.
In these application scenarios, when storing tokens in the preset token bucket, it may be preferable to store tokens in the guaranteed token bucket. In this way, the token required to guarantee the bandwidth can be provided even if the network is very busy.
Further, if the total number of tokens in the guarantee token bucket is greater than the preset capacity of the guarantee token bucket after the tokens are stored in the guarantee token bucket, the redundant tokens can be overflowed into the limit token bucket. In this way, the overflow tokens are not wasted.
For example, during the period T1, 100 tokens are preferentially stored in the guaranteed token bucket with the preset capacity of 100 token buckets. If the number of target tokens determined in the period T1 is 70, 30 tokens remain in the guaranteed token bucket in the period T1. At this time, the next period T2 is entered. Similarly, 100 token buckets are preferentially stored in the guarantee token bucket, but since the preset capacity of the guarantee token bucket is 100 tokens, 30 more token buckets are stored after 100 token buckets are stored in the period T2. At this point, the 30 tokens may be overflowed into the constraint token bucket. Therefore, on one hand, the token required by bandwidth guarantee can be provided to meet the requirement, and on the other hand, the waste of the token can be avoided.
In some optional implementations, the preset token bucket includes a token bucket parent node and at least one token bucket child node, a sum of guaranteed bandwidths corresponding to the at least one token bucket child node is not greater than a guaranteed bandwidth corresponding to the token bucket parent node, and a restricted bandwidth corresponding to each of the at least one token bucket child node is not greater than a restricted bandwidth corresponding to the token bucket parent node; and the guaranteed token bucket and the restricted token bucket are the token bucket parent nodes.
In some application scenarios, the preset token bucket may be configured as a multi-tiered token bucket, following the HTB algorithm. Specifically, the preset token bucket may include a token bucket parent node and a plurality of token bucket child nodes. At this time, the token bucket parent node may be regarded as a first layer of the preset token bucket, and the token bucket child node may be regarded as a second layer of the preset token bucket, forming a multi-layer structure (as shown in fig. 2).
In some application scenarios, when a multilayer preset token bucket is set, the sum of guaranteed bandwidths corresponding to all token bucket child nodes may be not greater than the guaranteed bandwidth corresponding to a token bucket parent node, so that the token bucket child nodes can always apply for a required token from the token bucket parent node. Furthermore, the limited bandwidth corresponding to each token bucket child node may not be greater than the limited bandwidth corresponding to the token bucket parent node, so as to limit the traffic corresponding to each token bucket child node.
Thus, the above step 104 may comprise the following sub-steps:
substep 1041, determining a token bucket child node of the token to be consumed;
in some application scenarios, the terminal device may first determine a token bucket child node of the token to be consumed. For example, if there is another network device applying for a token from the token bucket child node a, the token bucket child node a may be determined as the token bucket child node of the token to be consumed.
Substep 1042, indicating the token bucket child node to apply for a token in the guaranteed token bucket when detecting a message whose receiving rate does not exceed the promised information rate; and applying for tokens in the restricted token bucket when detecting that the receiving rate exceeds the committed information rate.
The committed information rate may be considered as the information transfer rate in a normal state on a specific virtual circuit predetermined by the network. In some application scenarios, when detecting that the receiving rate of the packet is less than the committed information rate, the token bucket child node may be instructed to apply for a token from the guaranteed token bucket to meet the requirement in a normal state. And can instruct the sub-node of token bucket to apply for the token from the restriction token bucket when detecting that the receiving rate of the message is greater than the promised information rate, so as to restrict the sending rate of the message and achieve the purpose of controlling the flow.
Referring to fig. 2, an application scenario of a multi-level default token bucket is shown. The token bucket parent node a is a first layer of a preset token bucket, and the token bucket child node b and the token bucket child node c are a second layer of the preset token bucket. And token bucket parent node a includes guaranteed token bucket a1 and restricted token bucket a 2. If guaranteed token bucket a1 holds tokens providing 10M of guaranteed bandwidth; the restricted token bucket a2 holds tokens that provide a restricted bandwidth of 20M. The token bucket child node b and the token bucket child node c hold tokens for providing a bandwidth of (5-20) M.
When both token bucket child b and token bucket child c need to apply for tokens providing bandwidth of (5-20) M, both token bucket children may apply for tokens providing bandwidth within 5M from guaranteed token bucket a1 and may apply for tokens needed to provide remaining bandwidth from restricted token bucket a 2. The bandwidth-limited token bucket a2 may determine the object to which tokens are issued preferentially according to the time order in which tokens are applied by the two token bucket child nodes.
When one of the token bucket children (e.g., token bucket child b) can provide (5-20) M of bandwidth and another token bucket child (e.g., token bucket child c) cannot provide bandwidth, the token in token bucket child b for sending packet data within 5M can be applied from guaranteed token bucket a1, and token bucket child b can only apply for 15M of bandwidth-limited tokens from restricted token bucket a2 because guaranteed token bucket a1 can only provide tokens for sending 10M of guaranteed bandwidth. However, since token bucket a1 is guaranteed to overflow 5M of bandwidth required tokens into restricted token bucket a2, token bucket child node b can apply for 20M of bandwidth required tokens, without wasting tokens.
Referring to fig. 3, a block diagram of a flow control device provided in an embodiment of the present application is shown, where the flow control device may be a module, a program segment, or code on an electronic device. Further, the flow control device can be applied to a terminal device, and a central processing unit of the terminal device at least comprises two cores. It should be understood that the apparatus corresponds to the above-mentioned embodiment of the method of fig. 1, and can perform various steps related to the embodiment of the method of fig. 1, and the specific functions of the apparatus can be referred to the description above, and the detailed description is appropriately omitted here to avoid redundancy.
Optionally, the flow control apparatus includes an initial determination module 301, an intermediate determination module 302, a token number determination module 303, and a control module 304. The initial determining module 301 is configured to determine a total length of an initial packet corresponding to a current period; a middle determining module 302, configured to determine total current packet data received at a current time, and determine a total current packet length corresponding to the current packet data; a token number determining module 303, configured to determine the number of target tokens to be consumed according to the total length of the current packet and the total length of the initial packet; a control module 304, configured to control a flow corresponding to the target packet data according to the number of the target tokens and a total number of tokens in a preset token bucket; and the period for storing the token in the preset token bucket is the same as the period for determining the total length of the initial message.
Optionally, the token number determining module 303 is further configured to: obtaining the total length of a target message to be sent at the current moment according to the total length of the current message and the total length of the initial message; and determining the number of the target tokens according to the total length of the target message.
Optionally, the intermediate determination module 302 is further configured to: in the period, accumulating the length of a single message corresponding to the single message data received at the current moment by taking the total length of the initial message as a calculation starting point; and determining the length sum of the messages obtained at the end time of the period as the total length of the current message.
Optionally, the flow control apparatus further includes a reset module, and the reset module is further configured to: determining that the period is finished when a preset fixed time length is reached by taking the time for determining the total length of the initial message as a period starting point; and determining the total length of the current message received at the end time of the previous period as the total length of the initial message of the period.
Optionally, the preset token bucket has a constant preset capacity, and the flow control apparatus further includes an overflow module, where the overflow module is configured to: storing a fixed number of tokens in the preset token bucket in the period; and if the total number of tokens in the preset token bucket is larger than the preset capacity after the tokens are stored, overflowing redundant tokens.
Optionally, the preset token bucket comprises a guaranteed token bucket for providing tokens of guaranteed bandwidth and a restricted token bucket for providing tokens of restricted bandwidth; and the overflow module is further to: and preferentially storing tokens in the guarantee token bucket, and overflowing redundant tokens into the limit token bucket if the total number of tokens in the guarantee token bucket is greater than the preset capacity corresponding to the guarantee token bucket.
Optionally, the preset token bucket includes a token bucket parent node and at least one token bucket child node, a sum of guaranteed bandwidths corresponding to the at least one token bucket child node is not greater than a guaranteed bandwidth corresponding to the token bucket parent node, and a restricted bandwidth corresponding to each of the at least one token bucket child node is not greater than a restricted bandwidth corresponding to the token bucket parent node; and the guaranteed token bucket and the restricted token bucket are the token bucket parent nodes; and the control module 304 is further configured to: determining a token bucket child node of a token to be consumed; indicating the token bucket child node to apply for a token in the guaranteed token bucket when detecting a message of which the receiving rate does not exceed the committed information rate; and applying for tokens in the restricted token bucket when detecting that the receiving rate exceeds the committed information rate.
It should be noted that, for the convenience and brevity of description, the specific working procedure of the above-described apparatus may refer to the corresponding procedure in the foregoing method embodiment, and the description is not repeated herein.
Referring to fig. 4, fig. 4 is a schematic structural diagram of an electronic device for executing a flow control method according to an embodiment of the present application, where the electronic device may include: at least one processor 401, e.g., a CPU, at least one communication interface 402, at least one memory 403 and at least one communication bus 404. Wherein the communication bus 404 is used for realizing direct connection communication of these components. The communication interface 402 of the device in the embodiment of the present application is used for performing signaling or data communication with other node devices. The memory 403 may be a high-speed RAM memory, or may be a non-volatile memory (e.g., at least one disk memory). The memory 403 may optionally be at least one memory device located remotely from the aforementioned processor. The memory 403 stores computer readable instructions, and when the computer readable instructions are executed by the processor 401, the electronic device can execute the method process shown in fig. 1.
It will be appreciated that the configuration shown in fig. 4 is merely illustrative and that the electronic device may include more or fewer components than shown in fig. 4 or may have a different configuration than shown in fig. 4. The components shown in fig. 4 may be implemented in hardware, software, or a combination thereof.
Embodiments of the present application provide a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, may perform the method processes performed by an electronic device in the method embodiment shown in fig. 1.
Embodiments of the present application provide a computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions, which when executed by a computer, enable the computer to perform the method provided by the above-mentioned method embodiments, for example, the method may include: determining the total length of an initial message corresponding to the current period; determining total received current message data at the current moment, and determining the total length of a current message corresponding to the current message data; determining the number of target tokens to be consumed according to the total length of the current message and the total length of the initial message; controlling the flow corresponding to the target message data according to the target token number and the total number of tokens in a preset token bucket; and the period for storing the token in the preset token bucket is the same as the period for determining the total length of the initial message.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
In addition, units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
Furthermore, the functional modules in the embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
In this document, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions.
The above description is only an example of the present application and is not intended to limit the scope of the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims (10)

1. A flow control method is applied to a terminal device, a central processing unit of the terminal device at least comprises two cores, and the method comprises the following steps:
determining the total length of an initial message corresponding to the current period;
determining total received current message data at the current moment, and determining the total length of a current message corresponding to the current message data;
determining the number of target tokens to be consumed according to the total length of the current message and the total length of the initial message; and
controlling the flow corresponding to the target message data according to the target token number and the total number of tokens in a preset token bucket;
and the period for storing the token in the preset token bucket is the same as the period for determining the total length of the initial message.
2. The method of claim 1, wherein determining the number of target tokens to be consumed according to the total length of the current packet and the total length of the initial packet comprises:
obtaining the total length of a target message to be sent at the current moment according to the total length of the current message and the total length of the initial message;
and determining the number of the target tokens according to the total length of the target message.
3. The method of claim 1, wherein the determining the total current packet data received at the current time and determining the total current packet length corresponding to the current packet data comprises:
in the period, accumulating the length of a single message corresponding to the single message data received at the current moment by taking the total length of the initial message as a calculation starting point;
and determining the length sum of the messages obtained at the end time of the period as the total length of the current message.
4. The method according to any one of claims 1-3, further comprising:
determining that the period is finished when a preset fixed time length is reached by taking the time for determining the total length of the initial message as a period starting point; and
and determining the total length of the current message received at the end moment of the previous period as the total length of the initial message of the period.
5. The method of claim 1, wherein the preset token bucket has a constant preset capacity, the method further comprising:
storing a fixed number of tokens in the preset token bucket in the period;
and if the total number of tokens in the preset token bucket is larger than the preset capacity after the tokens are stored, overflowing redundant tokens.
6. The method of claim 5, wherein the preset token bucket comprises a guaranteed token bucket for providing tokens of guaranteed bandwidth and a restricted token bucket for providing tokens of restricted bandwidth; and
if the total number of tokens in the preset token bucket is greater than the preset capacity after the tokens are stored, overflowing redundant tokens, comprising:
and preferentially storing tokens in the guarantee token bucket, and overflowing redundant tokens into the limit token bucket if the total number of tokens in the guarantee token bucket is greater than the preset capacity corresponding to the guarantee token bucket.
7. The method of claim 6, wherein the predetermined token bucket comprises a token bucket parent node and at least one token bucket child node, a sum of guaranteed bandwidths corresponding to the at least one token bucket child node is not greater than a guaranteed bandwidth corresponding to the token bucket parent node, and a constrained bandwidth corresponding to each of the at least one token bucket child node is not greater than a constrained bandwidth corresponding to the token bucket parent node; and the guaranteed token bucket and the restricted token bucket are the token bucket parent nodes; and
the controlling the flow corresponding to the target message data according to the target token number and the total number of tokens in a preset token bucket includes:
determining a token bucket child node of a token to be consumed;
indicating the token bucket child node to apply for a token in the guaranteed token bucket when detecting a message of which the receiving rate does not exceed the committed information rate; and applying for tokens in the restricted token bucket when detecting that the receiving rate exceeds the committed information rate.
8. A flow control device is characterized in that the flow control device is applied to a terminal device, a central processing unit of the terminal device at least comprises two cores, and the flow control device comprises:
an initial determining module, configured to determine a total length of an initial packet corresponding to a current period;
the middle determining module is used for determining the total received current message data at the current moment and determining the total length of the current message corresponding to the current message data;
the token number determining module is used for determining the number of target tokens to be consumed according to the total length of the current message and the total length of the initial message;
the control module is used for controlling the flow corresponding to the target message data according to the target token number and the total number of tokens in a preset token bucket; and the period for storing the token in the preset token bucket is the same as the period for determining the total length of the initial message.
9. An electronic device comprising a processor and a memory, the memory storing computer readable instructions that, when executed by the processor, perform the method of any of claims 1-7.
10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1 to 7.
CN202111270940.9A 2021-10-29 2021-10-29 Flow control method, flow control device, electronic equipment and computer readable storage medium Active CN113992594B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111270940.9A CN113992594B (en) 2021-10-29 2021-10-29 Flow control method, flow control device, electronic equipment and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111270940.9A CN113992594B (en) 2021-10-29 2021-10-29 Flow control method, flow control device, electronic equipment and computer readable storage medium

Publications (2)

Publication Number Publication Date
CN113992594A true CN113992594A (en) 2022-01-28
CN113992594B CN113992594B (en) 2023-11-10

Family

ID=79744287

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111270940.9A Active CN113992594B (en) 2021-10-29 2021-10-29 Flow control method, flow control device, electronic equipment and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN113992594B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114785735A (en) * 2022-04-26 2022-07-22 杭州迪普信息技术有限公司 FPGA-based network message current limiting method and device
CN115208833A (en) * 2022-07-12 2022-10-18 北京天融信网络安全技术有限公司 Flow control method and device, electronic equipment and storage medium
CN115225580A (en) * 2022-06-10 2022-10-21 新浪网技术(中国)有限公司 Service isolation speed limiting method and device for multiple processor cores

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106413002A (en) * 2016-11-22 2017-02-15 京信通信技术(广州)有限公司 Terminal velocity control method, terminal velocity control device and terminal velocity control base station
CN106453127A (en) * 2016-11-18 2017-02-22 杭州华三通信技术有限公司 Token processing method and device
CN112187661A (en) * 2020-09-14 2021-01-05 武汉思普崚技术有限公司 QOS flow control method, system, equipment and storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106453127A (en) * 2016-11-18 2017-02-22 杭州华三通信技术有限公司 Token processing method and device
CN106413002A (en) * 2016-11-22 2017-02-15 京信通信技术(广州)有限公司 Terminal velocity control method, terminal velocity control device and terminal velocity control base station
CN112187661A (en) * 2020-09-14 2021-01-05 武汉思普崚技术有限公司 QOS flow control method, system, equipment and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
付桂涛: ""面向多核处理器的令牌一致性协议优化技术研究"", 《中国博士学位论文全文数据库信息科技辑》, no. 2 *

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114785735A (en) * 2022-04-26 2022-07-22 杭州迪普信息技术有限公司 FPGA-based network message current limiting method and device
CN114785735B (en) * 2022-04-26 2023-09-12 杭州迪普信息技术有限公司 FPGA-based network message current limiting method and device
CN115225580A (en) * 2022-06-10 2022-10-21 新浪网技术(中国)有限公司 Service isolation speed limiting method and device for multiple processor cores
CN115225580B (en) * 2022-06-10 2024-02-02 新浪技术(中国)有限公司 Service isolation speed limiting method and device for multiprocessor cores
CN115208833A (en) * 2022-07-12 2022-10-18 北京天融信网络安全技术有限公司 Flow control method and device, electronic equipment and storage medium
CN115208833B (en) * 2022-07-12 2023-11-28 北京天融信网络安全技术有限公司 Flow control method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN113992594B (en) 2023-11-10

Similar Documents

Publication Publication Date Title
CN113992594B (en) Flow control method, flow control device, electronic equipment and computer readable storage medium
US9363184B2 (en) Token bucket-based traffic limiting method and apparatus
US11785113B2 (en) Client service transmission method and apparatus
CN108768873B (en) Flow control method and related equipment
US20080084824A1 (en) Dual Leaky Bucket Flow Control Method and System
US10419965B1 (en) Distributed meters and statistical meters
CN113691461B (en) Token bucket management method and device for multi-core equipment
WO2020142867A1 (en) Traffic shaping method and related device
CN113032410B (en) Data processing method, device, electronic equipment and computer storage medium
CN114579296A (en) Server idle calculation scheduling method and device and electronic equipment
CN114124830A (en) RDMA service quality assurance method and system for multiple application scenes of data center
EP3485618B1 (en) Device and method for managing end-to-end connections
CN111131061B (en) Data transmission method and network equipment
CN113906720B (en) Traffic scheduling method, traffic scheduling device and storage medium
CN113453285B (en) Resource adjusting method, device and storage medium
CN111131083B (en) Method, device and equipment for data transmission between nodes and computer readable storage medium
CN109547360B (en) Data transmission scheduling method and device
CN114070776B (en) Improved time-sensitive network data transmission method, device and equipment
CN111865808B (en) Data flow control method and device
CN109491948B (en) Data processing method and device for double ports of solid state disk
WO2015120699A1 (en) Packet forwarding method and device, and network forwarding device
CN117544688A (en) Network service method, device, server and storage medium
CN113778672A (en) Data processing method and device, electronic equipment and storage medium
CN116016357A (en) Data transmission method, device, storage medium and electronic equipment
CN116192244A (en) OSU-oriented protected service protection switching method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant