Flow control method, device, equipment and storage medium
By consuming tokens in the total token bucket and adjusting the number of tokens in the sub-token bucket, the problems of low resource utilization and traffic competition in subscription traffic control are solved, and more efficient traffic resource utilization and stability improvement are achieved .
Patent Information
- Application Number
- CN202310226499.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-09
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2043-03-09
AI Technical Summary
When the existing subscription traffic control method is used to control traffic for each consumer, some consumers whose subscription traffic does not reach the threshold have idle resources, and the resource utilization rate is not high; when the overall traffic control is used to control traffic for consumers, due to different Consumers' traffic consumption speeds are different, resulting in traffic competition among consumers and affecting the consumption experience.
By consuming tokens in the total token bucket, transfer data is requested separately for each user, and adjusting the number of tokens in each user's subtoken bucket according to the user's data transmission traffic, so that the data in the subtoken bucket is made The difference between the transmission traffic and the user's data transmission traffic is less than a certain threshold, ensuring full utilization of resources and reducing traffic competition.
It effectively reduces traffic competition among users, improves the utilization rate of traffic resources, reduces network blockage, and improves the stability and availability of message queues.
Smart Images

Figure CN116233010B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of communication technology, specifically to technical fields such as data transmission, data monitoring, and flow control, and can be applied to scenarios such as file transmission and consumer flow control, and in particular to a flow control method, device, equipment, and storage medium. Background Art
[0002] Data producers can publish data in message queues, and consumers can consume data published by producers from message queues. The traffic resources consumed by producers to publish data can be called publishing traffic, and the traffic resources consumed by consumers to consume data can be called subscription traffic. When there is too much subscription traffic, the server where the message queue is located will be overloaded due to excessive throughput, affecting the stability and availability of the message queue. By controlling the subscription traffic, the throughput of the server where the message queue is located can be limited to improve the stability and availability of the message queue.
[0003] At present, the schemes for controlling subscription traffic may include: a scheme for controlling traffic for each consumer, or a scheme for controlling traffic for consumers as a whole. Among them, the scheme for controlling traffic for each consumer means: controlling the subscription traffic of each consumer separately according to whether the subscription traffic of each consumer reaches the traffic control threshold. The scheme for controlling traffic for consumers as a whole means: controlling the overall subscription traffic of all consumers according to whether the subscription traffic of all consumers as a whole reaches the overall traffic control threshold.
[0004] However, in the above solution for flow control for each consumer, there are idle resources on the connections of some consumers whose subscription flow does not reach the flow control threshold, and the resource utilization rate is not high. In the above solution for flow control for consumers as a whole, due to the different flow consumption speeds of different consumers, there is flow competition among consumers, which seriously affects the consumption experience of some consumers. Summary of the invention
[0005] The present disclosure provides a flow control method, device, equipment and storage medium, which can effectively reduce flow competition among consumers, make full use of overall flow resources, and improve the utilization rate of flow resources.
[0006] According to a first aspect of the present disclosure, a flow control method is provided, the method comprising:
[0007] By consuming the tokens in the total token bucket, the first target data requested to be transmitted by at least one user is transmitted, and the number of tokens in the total token bucket does not exceed the first number of tokens; in response to detecting that the number of users and the data transmission flow required by at least one user reach a preset condition, by consuming the tokens in the sub-token bucket corresponding to each user, the first target data requested to be transmitted by each user is transmitted, and the tokens in the sub-token bucket come from the total token bucket; according to the first data transmission flow required by the user, the number of tokens in the sub-token bucket corresponding to the user is adjusted so that the difference between the second data transmission flow corresponding to the tokens in the sub-token bucket and the first data transmission flow is less than the first flow threshold.
[0008] According to a second aspect of the present disclosure, a flow control device is provided, the device comprising: a transmission unit and an adjustment unit.
[0009] A transmission unit is used to transmit first target data requested by at least one user respectively by consuming tokens in a total token bucket, wherein the number of tokens in the total token bucket does not exceed the first number of tokens; the transmission unit is also used to transmit first target data requested by each user respectively by consuming tokens in a sub-token bucket corresponding to each user in response to detecting that the number of users and the data transmission flow required by at least one user reach a preset condition, wherein the tokens in the sub-token bucket come from the total token bucket; an adjustment unit is used to adjust the number of tokens in the sub-token bucket during the transmission of the first target data by the transmission unit, so that the difference between the second data transmission flow corresponding to the tokens in the sub-token bucket and the first data transmission flow is less than a first flow threshold.
[0010] According to a third aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method described in the first aspect.
[0011] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause a computer to execute the method according to the first aspect.
[0012] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method according to the first aspect.
[0013] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0015] Figure 1 A flow chart of a flow control method provided by an embodiment of the present disclosure;
[0016] Figure 2 A flowchart of a token quantity adjustment method provided in an embodiment of the present disclosure;
[0017] Figure 3 A schematic diagram of an implementation flow of recovering tokens from a second target sub-token bucket provided in an embodiment of the present disclosure;
[0018] Figure 4 Another flow chart of the flow control method provided by the embodiment of the present disclosure;
[0019] Figure 5 Another flow chart of the flow control method provided by the embodiment of the present disclosure;
[0020] Figure 6 A schematic diagram of the composition of a flow control device provided in an embodiment of the present disclosure;
[0021] Figure 7 The present disclosure is provided as a schematic block diagram of an example electronic device 700 that can be used to implement the present disclosure. DETAILED DESCRIPTION
[0022] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0023] It should be understood that in the embodiments of the present disclosure, the character " / " generally indicates that the objects associated with each other are in an "or" relationship. The terms "first", "second", etc. are used only for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features.
[0024] Data producers can publish data in message queues, and consumers can consume data published by producers from message queues. The traffic resources consumed by producers to publish data can be called publishing traffic, and the traffic resources consumed by consumers to consume data can be called subscription traffic. When there is too much subscription traffic, the server where the message queue is located will be overloaded due to excessive throughput, affecting the stability and availability of the message queue. By controlling the subscription traffic, the throughput of the server where the message queue is located can be limited to improve the stability and availability of the message queue.
[0025] For example, the producer is the publisher of a video file, and the consumer is the viewer of this video file. In this scenario, the data refers to this video file; the publishing traffic is the traffic resources consumed by the producer to publish this video file, and the subscription traffic is the traffic resources consumed by the consumer to load this video file. When a large number of consumers load this video file at the same time, it may cause network congestion, freezes and other problems. At this time, it is necessary to control the traffic consumed by consumers to load this video file to improve the stability and availability of the message queue.
[0026] At present, the schemes for controlling subscription traffic may include: a scheme for controlling traffic for each consumer, or a scheme for controlling traffic for consumers as a whole. Among them, the scheme for controlling traffic for each consumer means: controlling the subscription traffic of each consumer separately according to whether the subscription traffic of each consumer reaches the traffic control threshold. The scheme for controlling traffic for consumers as a whole means: controlling the overall subscription traffic of all consumers according to whether the subscription traffic of all consumers as a whole reaches the overall traffic control threshold.
[0027] For example, if there are 10 consumers, the solution for traffic control for each consumer is to control the subscription traffic of each of the 10 people according to whether the subscription traffic of each of the 10 people reaches the traffic control threshold. If the subscription traffic of a certain person reaches the traffic control threshold, the subscription traffic of this person will be restricted. The solution for traffic control for consumers as a whole means that when the total value of the subscription traffic of all the 10 people reaches the overall traffic control threshold, the overall subscription traffic will be restricted.
[0028] However, in the above solution for flow control for each consumer, there are idle resources on the connections of some consumers whose subscription flow does not reach the flow control threshold, and the resource utilization rate is not high. In the above solution for flow control for consumers as a whole, due to the different flow consumption speeds of different consumers, there is flow competition among consumers, which seriously affects the consumption experience of some consumers.
[0029] For example, in a solution for flow control for each consumer, suppose that both consumer 1 and consumer 2 have 100 units of flow resources, but consumer 1 only needs 80 units, while consumer 2 needs 110 units. At this time, the remaining 20 units of consumer 1 become idle resources, and consumer 2 cannot use the idle resources of consumer 1, resulting in low resource utilization.
[0030] For another example, in a solution for overall traffic control for consumers, assuming that there are 100 units of traffic resources for consumers 3 and 4 to use, and both consumers 3 and 4 require 60 units, but consumer 3 consumes faster than consumer 4, consumer 3 will consume 60 units first, leaving insufficient resources for consumer 4. There is traffic competition between consumers 3 and 4, which seriously affects the consumption experience of consumer 4.
[0031] Against this background technology, the present disclosure provides a traffic control method that can control the traffic resources allocated to each user according to the changes in the number of users and the traffic resources used by the users, and limit the overall traffic resources of all users. It can make full use of the overall traffic resources and improve the utilization rate of traffic resources, while effectively reducing traffic competition between users and reducing network congestion.
[0032] The user may be a consumer of data or a producer of data. The embodiment of the present disclosure will be described by taking the user as a consumer as an example, but the specific category of the user is not limited.
[0033] Exemplarily, the execution subject of the flow control method may be a computer or a server, or may be other devices with data processing capabilities. The execution subject of the method is not limited here.
[0034] For example, the server may be a server that maintains a message queue, and the message queue may be a channel or platform for data producers to transmit data to consumers.
[0035] In some embodiments, the server may be a single server, or a server cluster composed of multiple servers. In some implementations, the server cluster may also be a distributed cluster. The present disclosure does not limit the specific implementation of the server.
[0036] Figure 1 Schematic diagram of the flow control method provided by the embodiment of the present disclosure. Figure 1 As shown, the method may include:
[0037] S101. Transmit first target data requested to be transmitted by at least one user by consuming tokens in a total token bucket, wherein the number of tokens in the total token bucket does not exceed a first number of tokens.
[0038] Exemplarily, a token bucket is a mechanism for controlling data transmission. The token bucket may include tokens. When transmitting data, the data can be transmitted by consuming the tokens in the token bucket, so that the speed of data transmission, the data transmission flow, etc. can be controlled according to the tokens in the token bucket. Among them, the total token bucket can generate new tokens at a preset rate while consuming tokens. The preset rate can be 100 tokens per second, 50 tokens per second, etc., and there is no limit on the size of the preset rate. Moreover, the number of tokens in the total token bucket does not exceed the first token number, and the first token number refers to the maximum capacity of the total token bucket.
[0039] For example, taking a user watching a video file as an example, the producer of the video file can transfer the video file to the message queue. When a consumer user wants to watch the video file, he can send a request to download or watch the video file to the server of the message queue through a terminal device such as a mobile phone or a computer. This request is the first data transmission request. The server of the message queue can receive the first data transmission request. At this time, the video file is equivalent to the first target data, and the first data transmission request is used to request the transmission of the first target data.
[0040] S102. In response to detecting that the number of users and the data transmission flow required by at least one user reach a preset condition, the first target data requested to be transmitted by each user is transmitted respectively by consuming the tokens in the sub-token bucket corresponding to each user, and the tokens in the sub-token bucket come from the total token bucket.
[0041] Exemplarily, for example, when data arrives at a device (such as a server), the server can first take out a number of tokens corresponding to the size of the data from the sub-token bucket corresponding to the user according to the size of the data to transmit the data. The tokens in the sub-token bucket are allocated by the total token bucket. Each token in the token bucket can represent one or more bytes. If there is a token in the token bucket, data is allowed to be sent; if there is no token in the token bucket, data is not allowed to be sent. The larger the data, the larger the data transmission flow required, and the more tokens are consumed; the smaller the data, the smaller the data transmission flow required, and the fewer tokens are consumed.
[0042] Exemplarily, during the execution of S102, S103 may be executed in the process of transmitting the first target data requested by the user corresponding to the sub-token bucket by consuming the tokens in the sub-token bucket.
[0043] S103. According to the first data transmission flow required by the user, adjust the number of tokens in the sub-token bucket corresponding to the user so that the difference between the second data transmission flow corresponding to the tokens in the sub-token bucket and the first data transmission flow is less than the first flow threshold.
[0044] Exemplarily, in some implementations, the first traffic threshold may be the data transmission traffic corresponding to the minimum adjustment granularity, wherein the data transmission traffic corresponding to the minimum adjustment granularity may be a preset value, such as the data transmission traffic corresponding to the minimum adjustment granularity may be 1 megabyte (MB), 2MB, etc., and there is no restriction on the data transmission traffic corresponding to the minimum adjustment granularity.
[0045] For example, taking the second token quantity as 0 as an example, for a certain consumer X, in the above S102, when the number of consumers and the data transmission flow required by at least one consumer reach the preset condition, the number of tokens in the sub-token bucket generated for the consumer X is 0. At this time, when the first target data requested by consumer X to be transmitted is transmitted, there are no tokens to be consumed in the sub-token bucket corresponding to consumer X. The tokens in the original total token bucket can be temporarily used to transmit the first target data requested by consumer X to be transmitted. In the process of transmitting the first target data, the number of tokens in the sub-token bucket corresponding to consumer X can be adjusted so that the difference between the data transmission flow corresponding to the tokens in the sub-token bucket corresponding to consumer X and the data transmission flow of consumer X is less than the data transmission flow corresponding to the minimum adjustment granularity.
[0046] Similarly, for each user, the number of tokens in the sub-token bucket corresponding to each user X can be adjusted in the manner of adjusting the number of tokens in the sub-token bucket corresponding to consumer X.
[0047] In the embodiment of the present disclosure, a total token bucket may be provided. The present disclosure may perform transmission by consuming tokens in the total token bucket according to the data transmission control principle of the above-mentioned token bucket. For example, in S102, in response to detecting that the number of users and the data transmission flow required by at least one user reach a preset condition, the first target data may be transmitted by consuming tokens in the sub-token bucket corresponding to each user. The greater the data transmission flow required by the first target data, the more tokens the first target data consumes; the smaller the data transmission flow required by the first target data, the fewer tokens the first target data consumes.
[0048] In the process of transmitting the first target data requested by the user by consuming the tokens in the total token bucket, when the number of users and the data transmission flow required by at least one user reach the preset conditions, the present disclosure generates a corresponding sub-token bucket for each user, allocates the tokens in the total token bucket to each sub-token bucket until the number of tokens in the sub-token bucket reaches the second token number, and transmits the first target data requested by the user corresponding to the sub-token bucket by consuming the tokens in the sub-token bucket, which can effectively reduce the traffic competition between users. In the process of transmitting the first target data, by adjusting the number of tokens in the sub-token bucket so that the difference between the data transmission flow corresponding to the tokens in the sub-token bucket and the data transmission flow of the user corresponding to the sub-token bucket is less than the first traffic threshold, the redundant traffic resources occupied by the user corresponding to the sub-token bucket can be reduced, thereby reducing the waste of traffic resources and improving the utilization of traffic resources. That is, the present disclosure can effectively reduce the traffic competition between users, and can also reduce the redundant traffic resources occupied by the user corresponding to the sub-token bucket, thereby reducing the waste of traffic resources and improving the utilization of traffic resources.
[0049] For example, taking the total token bucket as bucket A and the sub-token bucket as bucket B as an example, in the embodiment of the present disclosure, the data requested by the user can be transmitted by consuming the tokens in bucket A. In the process of consuming the tokens in bucket A to transmit the data requested by the user, when the number of users and the data transmission traffic required by at least one user reach the preset conditions, a corresponding bucket B can be generated for each user, and the tokens in bucket A are allocated to each bucket B until the number of tokens in bucket B reaches the second token number. Then, the data requested by the user corresponding to B can be transmitted by consuming the tokens in bucket B. Since the data corresponding to different users are transmitted by consuming the tokens in the corresponding buckets B, the traffic competition between different users can be effectively reduced.
[0050] In the process of consuming the tokens in bucket B and transmitting the data requested by the user corresponding to B, the number of tokens in bucket B can be adjusted so that the difference between the data transmission flow corresponding to the tokens in bucket B and the data transmission flow of the user corresponding to B is less than the first flow threshold. When the number of tokens in bucket B is further adjusted to meet the above conditions, the redundant flow resources occupied by the user corresponding to bucket B can be reduced, thereby reducing the waste of flow resources and improving the utilization rate of flow resources.
[0051] Optionally, the difference between the second data transmission flow corresponding to the token in the sub-token bucket and the first data transmission flow is less than the first flow threshold, which means that the absolute value of the difference between the second data transmission flow corresponding to the token in the sub-token bucket and the first data transmission flow is less than the first flow threshold.
[0052] Optionally, in an embodiment of the present disclosure, the above-mentioned preset condition refers to that the number of users is greater than the preset number of users, and the data transmission flow corresponding to the tokens consumed in the total token bucket is greater than the second flow threshold.
[0053] Exemplarily, the preset number of users refers to any value greater than 1, and the specific value of the preset number of users is not limited herein. For example, the preset number of users can be 1, or 2, 3, 4, 5, etc. The second flow threshold refers to the flow threshold of the total token bucket, and the second flow threshold can be a preset value, and the size of the second flow threshold is not limited herein. For example, the second flow threshold can be a value corresponding to 80% of the data transmission flow corresponding to all tokens in the total token bucket (such as tokens of the first token number).
[0054] Optionally, in the embodiment of the present disclosure, before executing step S102, it is necessary to generate a corresponding sub-token bucket for each user, and allocate tokens in the total token bucket to each sub-token bucket until the number of tokens in the sub-token bucket reaches the second token number.
[0055] Exemplarily, when the number of users and the data transmission flow required by at least one user reach a preset condition, a corresponding sub-token bucket may be generated for each user. After a corresponding sub-token bucket is generated for each user, tokens in the total token bucket may be allocated to each sub-token bucket until the number of tokens in the sub-token bucket reaches the second token number, and the first target data requested to be transmitted by the user corresponding to the sub-token bucket is transmitted by consuming the tokens in the sub-token bucket.
[0056] This embodiment generates a corresponding sub-token bucket for each user, allocates tokens in the total token bucket to each sub-token bucket until the number of tokens in the sub-token bucket reaches the second token number, and consumes the tokens in the sub-token bucket to transmit the first target data requested by the user corresponding to the sub-token bucket, thereby effectively reducing traffic competition between users.
[0057] Optionally, in the embodiment of the present disclosure, the number of tokens in the sub-token bucket corresponding to the user is adjusted according to the first data transmission flow required by the user, so that the second data transmission flow corresponding to the tokens in the sub-token bucket is greater than the first data transmission flow, and the difference between the second data transmission flow and the first data transmission flow is less than the first flow threshold.
[0058] Exemplarily, during the transmission of the first target data, the number of tokens in the sub-token bucket corresponding to consumer X can be adjusted so that the data transmission flow corresponding to the tokens in the sub-token bucket corresponding to consumer X is greater than the data transmission flow of consumer X, and the difference between the data transmission flow corresponding to the tokens in the sub-token bucket corresponding to consumer X and the data transmission flow of consumer X is less than the data transmission flow corresponding to the minimum adjustment granularity.
[0059] This embodiment adjusts the number of tokens in the sub-token bucket corresponding to consumer X to a point where the second data transmission flow corresponding to the tokens in the sub-token bucket is greater than the first data transmission flow, and the difference between the second data transmission flow and the first data transmission flow is less than the first flow threshold, so that the number of tokens in the sub-token bucket corresponding to each user can meet the number of tokens required for transmitting the first data transmission flow as much as possible, thereby reducing competition between users.
[0060] Optionally, the above introduces the situation where the number of users and the data transmission traffic required by at least one user meet the preset conditions. When the number of users and the data transmission traffic required by at least one user do not meet the preset conditions, there are two situations. The first is when the number of users is equal to 1, and the data transmission traffic corresponding to the tokens consumed in the total token bucket is greater than the first traffic threshold, the user's traffic resources can be controlled only based on the total token bucket, such as: limiting the user's data transmission traffic to not exceed the above-mentioned first traffic threshold. The second is when the number of users is equal to 1, and the data transmission traffic corresponding to the tokens consumed in the total token bucket is not greater than (less than or equal to) the first traffic threshold, the traffic control is not triggered and no other operations are performed.
[0061] Optionally, in some other implementations, the first traffic threshold may also be a data transmission traffic greater than the minimum adjustment granularity, and the present disclosure does not limit the size of the first traffic threshold. When the first traffic threshold is a data transmission traffic greater than the minimum adjustment granularity, a portion of idle tokens may be reserved for each sub-token bucket to cope with a sudden increase in the data transmission traffic of the user corresponding to the sub-token bucket, thereby improving the user's consumption experience.
[0062] Figure 2 A flowchart of a token quantity adjustment method provided by an embodiment of the present disclosure. Figure 2 As shown, in some embodiments, the step of adjusting the number of tokens in the sub-token bucket corresponding to the user according to the first data transmission flow required by the user may include:
[0063] S201. For each first target sub-token bucket, detect the second data transmission flow corresponding to the tokens in the first target sub-token bucket and the third data transmission flow of the target user corresponding to the first target sub-token bucket according to a preset period. The first target sub-token bucket is any sub-token bucket.
[0064] The first target sub-token bucket may be any of the above sub-token buckets. For each first target sub-token bucket, the second data transmission flow corresponding to the token in the first target sub-token bucket and the third data transmission flow of the target user corresponding to the first target sub-token bucket may be detected according to a preset period. For example, if the first target sub-token bucket is sub-token bucket 1, then S201 may detect the second data transmission flow corresponding to the token in sub-token bucket 1 and the third data transmission flow of the target user corresponding to sub-token bucket 1 according to a preset period.
[0065] Exemplarily, the preset period may be 1 minute, 3 minutes, 5 minutes, etc., and the preset period may be a preset value, and there is no limitation on the size of the preset period.
[0066] For example, taking the preset period of 3 minutes as an example, the number of tokens in each sub-token bucket (ie, the first target sub-token bucket) and the third data transmission flow of the target user corresponding to each sub-token bucket can be detected every three minutes in S201.
[0067] After detecting the second data transmission flow corresponding to the tokens in the first target sub-token bucket and the third data transmission flow of the target user corresponding to the first target sub-token bucket, S202 or S203 may be executed according to the sizes of the two.
[0068] S202. Within each preset period, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is less than the third data transmission flow of the target user, continue to select a preset number of tokens from the total token bucket and allocate them to the first target sub-token bucket.
[0069] Exemplarily, taking the first target sub-token bucket as B1 and the target user corresponding to B1 as user 1, within any preset period, when the second data transmission flow corresponding to the token in B1 is less than the third data transmission flow of user 1 (that is, the data transmission flow actually required by user 1), a preset number of tokens can continue to be selected from the total token bucket and allocated to B1.
[0070] The preset number may be the number of tokens corresponding to the data transmission flow corresponding to the minimum adjustment granularity, that is, the preset number of tokens can provide the data transmission flow corresponding to the minimum adjustment granularity.
[0071] For example, assuming the preset number is 5, within a preset period, if it is detected that a user needs 20 tokens to transmit data, and there are only 10 tokens in his sub-token bucket, then 5 tokens are first allocated from the total token bucket to the sub-token bucket of this user.
[0072] S203. Within each preset period, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is greater than the third data transmission flow of the target user, and the difference between the second data transmission flow corresponding to the tokens in the first target sub-token bucket and the third data transmission flow of the target user is greater than or equal to the first flow threshold, a preset number of tokens are selected from the first target sub-token bucket and recycled into the total token bucket; wherein the fourth data transmission flow corresponding to the preset number of tokens is less than or equal to the first flow threshold.
[0073] Exemplarily, taking the first target sub-token bucket as B1 and the target user corresponding to B1 as user 1, within any preset period, when the second data transmission flow corresponding to the token in B1 is greater than the third data transmission flow of user 1, and the difference between the second data transmission flow corresponding to the token in B1 and the third data transmission flow of user 1 is greater than or equal to the first flow threshold, a preset number of tokens can be selected from B1 and recycled into the total token bucket.
[0074] For example, assuming that the first traffic threshold is equal to the fourth data transmission traffic corresponding to a preset number of tokens, and the preset number is 5, within a preset period, if it is detected that a user needs 10 tokens to transmit data, and at this time there are 30 tokens in his sub-token bucket, there are 20 tokens extra, and the number of the extra 20 tokens is greater than the preset number (that is, the difference between the second data transmission traffic corresponding to the tokens in the sub-token bucket corresponding to the user and the third data transmission traffic of the user is greater than the first traffic threshold), then 5 of the excess 20 tokens can be selected and recycled into the total token bucket within the current period.
[0075] Through the above S201-S203, it is possible to adjust the number of tokens in the sub-token bucket during the transmission of the first target data, so that the second data transmission flow corresponding to the tokens in the sub-token bucket is greater than the third data transmission flow of the user corresponding to the sub-token bucket, and the difference between the second data transmission flow corresponding to the tokens in the sub-token bucket and the third data transmission flow of the user corresponding to the sub-token bucket is less than the first flow threshold.
[0076] This embodiment periodically detects the second data transmission flow corresponding to the tokens in the first target sub-token bucket and the third data transmission flow of the target user corresponding to the first target sub-token bucket, and when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is greater than the third data transmission flow of the target user, and the difference between the second data transmission flow corresponding to the tokens in the first target sub-token bucket and the third data transmission flow of the target user is greater than or equal to the first flow threshold, selects a preset number of tokens from the first target sub-token bucket and recycles them into the total token bucket, and when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is less than the third data transmission flow of the target user, continues to select a preset number of tokens from the total token bucket and allocate them to the first target sub-token bucket, so as to reduce the redundant traffic resources occupied by the users corresponding to the sub-token buckets, improve resource utilization, reduce the adjustment range of the tokens in the sub-token buckets, and make the adjustment of the tokens in the sub-token buckets more in line with the user's traffic requirements, thereby improving the stability of the users' use of traffic resources.
[0077] In some embodiments, the above S202 may include: within each preset period, when the second data transmission flow corresponding to the token in the first target sub-token bucket is less than the third data transmission flow of the target user, and the number of surplus tokens in the total token bucket is greater than or equal to the preset number, continue to select a preset number of tokens from the total token bucket and allocate them to the first target sub-token bucket.
[0078] The flow control method may also include: within each preset period, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is less than the third data transmission flow of the target user, and the number of surplus tokens in the total token bucket is less than the preset number, recovering the preset number of tokens from the second target sub-token bucket and allocating them to the first target sub-token bucket, the second target sub-token bucket being a sub-token bucket in which the number of tokens is greater than the third number of tokens, and the third number of tokens is the average number of tokens obtained based on the first number of tokens and the number of users.
[0079] Exemplarily, in an embodiment of the present disclosure, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is less than the third data transmission flow of the target user, the number of surplus tokens in the total token bucket may be greater than or equal to the preset number, or may be less than the preset number. When the number of surplus tokens in the total token bucket is greater than or equal to the preset number, a preset number of tokens can continue to be selected from the total token bucket and allocated to the first target sub-token bucket. When the number of surplus tokens in the total token bucket is less than the preset number, it is necessary to recover the preset number of tokens from the second target sub-token bucket and allocate them to the first target sub-token bucket.
[0080] The method for determining the second target sub-token bucket may include: calculating the average token number according to the first token number and the number of users to obtain a third token number; and taking the sub-token bucket with a token number greater than the third token number as the second target sub-token bucket.
[0081] Exemplarily, assuming that there are user 1, user 2, and user 3, the total token bucket is A, user 1 corresponds to a sub-token bucket B1, user 2 corresponds to a sub-token bucket B2, and user 3 corresponds to a sub-token bucket B3. When the second data transmission flow corresponding to the token in B1 is less than the third data transmission flow of user 1, the number of surplus tokens in A may be greater than or equal to the preset number, or may be less than the preset number. When the number of surplus tokens in A is greater than or equal to the preset number, a preset number of tokens can continue to be selected from A and allocated to B1. When the number of surplus tokens in A is less than the preset number, the first token number of A can be divided by the number of users (the number of users is 3) to obtain an average token number, which is the third token number; then, the sub-token bucket with a token number greater than the third token number is used as the second target sub-token bucket. If it is assumed that the token number of B2 is greater than the third token number, then B2 can be the second target sub-token bucket, and a preset number of tokens can be recovered from B2 and allocated to B1.
[0082] In this embodiment, the second data transmission flow corresponding to the token in the first target sub-token bucket is smaller than the third data transmission flow of the target user, and it is possible to distinguish two scenarios: the number of surplus tokens in the total token bucket is smaller than a preset number, or the number of surplus tokens in the total token bucket is greater than or equal to a preset number. According to the number of surplus tokens in the total token bucket, it is determined to continue allocating tokens from the total token bucket to the first target sub-token bucket, or to allocate tokens from other sub-token buckets to the first target sub-token bucket. This can achieve more flexible adjustment of the number of tokens in the sub-token buckets, and can further reduce traffic competition between users.
[0083] Optionally, in the scenario where, when the number of surplus tokens in the total token bucket is less than the preset number, a preset number of tokens are recovered from the second target sub-token bucket and allocated to the first target sub-token bucket, the number of tokens already in the first target sub-token bucket is less than the third number of tokens. When the number of tokens already in the first target sub-token bucket is greater than or equal to the third number of tokens, the number of tokens may no longer be increased.
[0084] In some embodiments, the second target sub-token bucket may include multiple ones. Figure 3 A schematic diagram of an implementation flow of recovering tokens from the second target sub-token bucket provided in an embodiment of the present disclosure. Figure 3 As shown, the above step of recovering a preset number of tokens from the second target sub-token bucket and allocating them to the first target sub-token bucket may include:
[0085] S301. Determine a third target sub-token bucket having the largest number of tokens from multiple second target sub-token buckets.
[0086] Illustratively, after obtaining multiple second target sub-token buckets, a sub-token bucket having the largest number of tokens higher than the average number of tokens may be selected from the multiple second target sub-token buckets, and this sub-token bucket is the third target sub-token bucket.
[0087] For example, there are three users, user 1 has 50 tokens in the sub-token bucket, user 2 has 60 tokens in the sub-token bucket, and user 3 has 10 tokens in the sub-token bucket. If the third token quantity calculated at this time is 40, and the token quantities of the sub-token buckets corresponding to user 1 and user 2 are both greater than the third token quantity, then the second target sub-token bucket may include the sub-token bucket corresponding to user 1 and the sub-token bucket corresponding to user 2. The sub-token bucket corresponding to user 2 has the largest number of tokens, so the sub-token bucket corresponding to user 2 can be determined as the third target sub-token bucket.
[0088] S302: Recover a preset number of tokens from the third target sub-token bucket, and distribute them to the first target sub-token bucket.
[0089] For example, if the sub-token bucket corresponding to user 2 has been determined to be the third target sub-token bucket, assuming the preset number is 10, 10 tokens are recovered from the sub-token bucket corresponding to user 2 and allocated to the first target sub-token bucket.
[0090] This embodiment selects the sub-token bucket with the largest number of tokens from all second target sub-token buckets whose number of tokens is greater than the third target sub-token bucket as the third target sub-token bucket, recovers a preset number of tokens therefrom, and distributes them to the first target sub-token bucket, thereby preferentially recovering traffic resources from the sub-token buckets corresponding to users who occupy the most traffic resources and giving them to other users with less traffic resources, thereby ensuring the traffic experience of more users.
[0091] Figure 4 Another flow chart of the flow control method provided by the embodiment of the present disclosure. Figure 4 As shown, the flow control method may also include:
[0092] S401. In response to a second data transmission request from a new user, generate a corresponding sub-token bucket for the new user, where the second data transmission request is used to request transmission of second target data.
[0093] The new user refers to a user who newly joins the message queue. The second data transmission request can refer to the first data transmission request. For the convenience of distinguishing descriptions, the data requested to be transmitted by the new user can be referred to as the second target data.
[0094] For example, when a new user is connected, the server can generate a corresponding sub-token bucket for the new user. For the new user, the initial token quantity of the sub-token bucket can be 0.
[0095] S402. When the number of surplus tokens in the total token bucket is greater than or equal to a preset number, a preset number of tokens are selected from the total token bucket and allocated to the sub-token bucket corresponding to the new user, and the second target data is transmitted by consuming the tokens in the sub-token bucket corresponding to the new user.
[0096] For example, when a new user is connected, the number of surplus tokens in the total token bucket is 20, and the preset number is set to 10. If the number of surplus tokens in the total token bucket is greater than the preset number, 10 tokens can be selected from the total token bucket and allocated to the sub-token bucket corresponding to the new user, and the second target data can be transmitted by consuming the tokens in the sub-token bucket corresponding to the new user.
[0097] S403. During the transmission of the second target data, when the number of surplus tokens in the total token bucket is greater than or equal to the fifth data transmission flow of the new user, the number of tokens in the sub-token bucket corresponding to the new user is adjusted so that the sixth data transmission flow corresponding to the tokens in the sub-token bucket corresponding to the new user is greater than the fifth data transmission flow of the new user, and the difference between the sixth data transmission flow corresponding to the tokens in the sub-token bucket corresponding to the new user and the fifth data transmission flow of the new user is less than the first flow threshold.
[0098] Exemplarily, when the number of surplus tokens in the total token bucket is greater than or equal to the fifth data transmission flow of the new user, the specific method of adjusting the number of tokens in the sub-token bucket corresponding to the new user can refer to the method of adjusting the number of tokens in the sub-token bucket corresponding to each user in the aforementioned embodiment, and will not be repeated here.
[0099] For example, when a new user is connected, the number of surplus tokens in the total token bucket is 30, the preset number is 8, the number of tokens in the sub-token bucket of the new user is 0, and the number of tokens required for the new user to transmit data is 15. At this time, the total token bucket first divides 8 tokens into the sub-token bucket of the new user, and then the total token bucket adjusts the number of tokens in the sub-token bucket of the new user so that the number of tokens in the sub-token bucket of the new user is greater than 15 but less than 23.
[0100] This embodiment can allocate a sub-token bucket for a user newly connected to the message queue, and when the number of surplus tokens in the total token bucket is greater than or equal to the data transmission traffic of the new user, adjust the number of tokens in the sub-token bucket corresponding to the new user, so that the number of tokens in the sub-token bucket corresponding to the new user can meet the data transmission demand of the new user, while reducing the redundant traffic resources occupied by the new user.
[0101] Figure 5 Another flow chart of the flow control method provided by the embodiment of the present disclosure. Figure 5 As shown, the flow control method may also include:
[0102] S501. During the transmission of the second target data, when the number of surplus tokens in the total token bucket is less than the fifth data transmission flow of the new user, all the surplus tokens in the first token bucket are allocated to the sub-token bucket corresponding to the new user.
[0103] For example, during the transmission of the second target data, the number of surplus tokens in the total token bucket is 10, the initial number of tokens in the new user's sub-token bucket is 0, and the number of tokens required for the new user to transmit data is 15. First, all the 10 surplus tokens in the total token bucket are allocated to the new user's sub-token bucket.
[0104] S502. When the fifth data transmission flow of the new user is less than the fourth token number, the first target number of tokens is recovered from the fourth target sub-token bucket in which the token number is greater than the fourth token number, and the first target number of tokens is allocated to the sub-token bucket corresponding to the new user, the first target number being the difference between the number of tokens corresponding to the fifth data transmission flow of the new user and the number of tokens already in the sub-token bucket corresponding to the new user, and the fourth token number being the average token number obtained based on the first token number and the number of users after the new user is added.
[0105] Exemplarily, when the number of surplus tokens in the total token bucket is less than the fifth data transmission flow of the new user, when the fifth data transmission flow of the new user is less than the fourth token number, the first target number of tokens is recovered from the fourth target sub-token bucket in which the number of tokens is greater than the fourth number of tokens, and the recovered first target number of tokens is allocated to the sub-token bucket corresponding to the new user.
[0106] The method for determining the fourth target sub-token bucket may include: calculating the average token number according to the first token number and the number of all users to obtain the fourth token number; and taking the sub-token bucket with a token number greater than the fourth token number as the fourth target sub-token bucket.
[0107] Exemplarily, assume that there are user 1, user 2, and user 3, user 1 corresponds to sub-token bucket B1, user 2 corresponds to sub-token bucket B2, user 3 corresponds to sub-token bucket B3, the total token bucket is A, the new user is user 4, and the sub-token bucket corresponding to the new user is B4. When the fifth data transmission flow of the new user is less than the fourth token number, the first token number of A can be divided by the number of users (the number of users is 4) to obtain an average token number, which is the fourth token number; then, the sub-token bucket with a token number greater than the fourth token number is used as the fourth target sub-token bucket. If it is assumed that the token number of B2 is greater than the fourth token number, then B2 can be the fourth target sub-token bucket, and a preset number of tokens can be recovered from B2 and allocated to B4.
[0108] For example, when a new user is connected, the initial number of tokens in the new user's sub-token bucket is 0, the number of tokens in the total token bucket is 10, and the number of tokens required for the new user to transmit data is 15. First, all the 10 tokens in the total token bucket are allocated to the sub-token bucket of the new user. At this time, the number of tokens already in the sub-token bucket corresponding to the new user is 10. The number of tokens corresponding to the fifth data transmission flow of the new user minus the number of tokens already in the sub-token bucket corresponding to the new user can be used to subtract the number of tokens in the sub-token bucket corresponding to the new user to obtain the first target number 5. At this time, there are still three old users. The number of tokens in the sub-token bucket corresponding to old user 1 is 20, the number of tokens in the sub-token bucket corresponding to old user 2 is 60, and the number of tokens in the sub-token bucket corresponding to old user 3 is 30. The first number of tokens in the total token bucket can be divided by the number of users (the number of users is 4) to obtain an average number of tokens, which is the fourth number of tokens; the fourth number of tokens is 30, and it can be seen that the number of tokens in the sub-token bucket corresponding to old user 2 is higher than the fourth number of tokens, so 5 tokens are recovered from the sub-token bucket corresponding to old user 2 and allocated to the sub-token bucket corresponding to the new user.
[0109] S503. When the fifth data transmission flow of the new user is greater than or equal to the fourth token number, the second target number of tokens is recovered from the fourth target sub-token bucket whose token number is greater than the fourth token number, and the second target number of tokens is allocated to the sub-token bucket corresponding to the new user, where the second target number is the difference between the fourth token number and the number of tokens already in the sub-token bucket corresponding to the new user.
[0110] For example, assuming that there are user 1, user 2, and user 3, user 1 corresponds to a sub-token bucket B1, user 2 corresponds to a sub-token bucket B2, user 3 corresponds to a sub-token bucket B3, the total token bucket is A, the new user is user 4, and the sub-token bucket corresponding to the new user is B4. When the fifth data transmission flow of the new user is less than the fourth token number, the first token number of A can be divided by the number of users (the number of users is 4) to obtain an average token number, which is the fourth token number, and the sub-token bucket with a token number greater than the fourth token number can be used as the fourth target sub-token bucket; then, the token number corresponding to the fifth data transmission flow of the new user can be subtracted from the fourth token number to obtain a value, which is the second target number, and the second target number of tokens can be recovered from the fourth target sub-token bucket, and the recovered second target number of tokens can be allocated to the sub-token bucket corresponding to the new user. If it is assumed that the token number of B2 is greater than the fourth token number, then B2 can be the fourth target sub-token bucket, and a preset number of tokens can be recovered from B2 and allocated to B4.
[0111] In this embodiment, when the number of surplus tokens in the total token bucket is less than the fifth data transmission traffic of the new user, a preset number of tokens are recovered from the fourth target sub-token bucket in which the number of tokens is greater than the fourth number of tokens, and allocated to the sub-token bucket of the new user. This achieves the goal of preferentially recovering traffic resources from the sub-token bucket corresponding to the user who occupies the most traffic resources and giving it to the new user, thereby ensuring the traffic experience of the new user.
[0112] Optionally, in some other embodiments, the second token quantity may be an average token quantity obtained according to the first token quantity and the number of users, or a preset fixed token quantity. The second token quantity may be 0.
[0113] For example, assuming user 1 and user 2, there are 100 tokens in the total token bucket, the preset value is 10, the preset period is 20 seconds, the number of tokens required for user 1 and user 2 to transmit data is 40, there are 0 tokens in user 1's sub-token bucket (that is, the second token number of the sub-token bucket corresponding to user 1 is 0), and there are 30 tokens in user 2's sub-token bucket (that is, the second token number of the sub-token bucket corresponding to user 2 is 60). When adjusting the number of tokens in the sub-token buckets corresponding to user 1 and user 2, user 1 needs 4 periods to achieve the expected adjustment effect, and user 2 needs 1 period to achieve the expected adjustment effect.
[0114] In this embodiment, when the second token number is an average token number obtained according to the first token number and the number of users, or a preset fixed token number, the sub-token bucket of the user can achieve the expected adjustment effect more efficiently.
[0115] Optionally, one message queue corresponds to one storage partition, one storage partition corresponds to one total token bucket, and the flow control method in the embodiment of the present disclosure is performed within one storage partition.
[0116] Optionally, in the aforementioned embodiment, the tokens in the sub-token bucket corresponding to the user's data transmission traffic consumption means that the user preferentially consumes the tokens in the corresponding sub-token bucket. When the tokens in the sub-token bucket are insufficient, the tokens in the total token bucket can be consumed.
[0117] In an exemplary embodiment, the present disclosure also provides a flow control device, which can be used to implement the flow control method as described in the aforementioned embodiment. Figure 6 Schematic diagram of the composition of the flow control device provided in the embodiment of the present disclosure. Figure 6 As shown, the device may include: a transmission unit 601 and an adjustment unit 602.
[0118] The transmission unit 601 is used to transmit the first target data requested to be transmitted by at least one user by consuming the tokens in the total token bucket, and the number of tokens in the total token bucket does not exceed the first number of tokens; the transmission unit 601 is also used to transmit the first target data requested to be transmitted by each user by consuming the tokens in the sub-token bucket corresponding to each user in response to detecting that the number of users and the data transmission traffic required by at least one user meet the preset conditions, and the tokens in the sub-token bucket come from the total token bucket.
[0119] The adjustment unit 602 is used to adjust the number of tokens in the sub-token bucket corresponding to the user according to the first data transmission flow required by the user, so that the difference between the second data transmission flow corresponding to the tokens in the sub-token bucket and the first data transmission flow is less than the first flow threshold.
[0120] Optionally, the number of users is greater than a preset number of users, and the data transmission flow corresponding to the tokens consumed in the total token bucket is greater than a second flow threshold.
[0121] Optionally, the adjusting unit 602 is specifically configured to: generate a corresponding sub-token bucket for each user, and allocate tokens in the total token bucket to each sub-token bucket until the number of tokens in the sub-token bucket reaches a second token number.
[0122] Optionally, the adjustment unit 602 is specifically used to adjust the number of tokens in the sub-token bucket corresponding to the user according to the first data transmission flow required by the user, so that the second data transmission flow corresponding to the tokens in the sub-token bucket is greater than the first data transmission flow, and the difference between the second data transmission flow and the first data transmission flow is less than the first flow threshold.
[0123] Optionally, the adjustment unit 602 is specifically used to: for each first target sub-token bucket, detect the second data transmission flow corresponding to the tokens in the first target sub-token bucket and the third data transmission flow of the target user corresponding to the first target sub-token bucket according to a preset period, the first target sub-token bucket being any sub-token bucket; within each preset period, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is less than the third data transmission flow of the target user, continue to select a preset number of tokens from the total token bucket and allocate them to the first target sub-token bucket; within each preset period, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is greater than the third data transmission flow of the target user, and the difference between the second data transmission flow corresponding to the tokens in the first target sub-token bucket and the third data transmission flow of the target user is greater than or equal to the first flow threshold, select a preset number of tokens from the first target sub-token bucket and recycle them into the total token bucket; wherein the fourth data transmission flow corresponding to the preset number of tokens is less than or equal to the first flow threshold.
[0124] Optionally, the adjustment unit 602 is also used to: within each preset period, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is less than the third data transmission flow of the target user, and the number of surplus tokens in the total token bucket is greater than or equal to the preset number, continue to select a preset number of tokens from the total token bucket and allocate them to the first target sub-token bucket; the adjustment unit 602 is also used to: within each preset period, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is less than the third data transmission flow of the target user, and the number of surplus tokens in the total token bucket is less than the preset number, reclaim a preset number of tokens from the second target sub-token bucket and allocate them to the first target sub-token bucket, the second target sub-token bucket being a sub-token bucket in which the number of tokens is greater than the third number of tokens, and the third number of tokens is the average number of tokens obtained based on the first number of tokens and the number of users.
[0125] Optionally, the adjustment unit 602 is further configured to: determine a third target sub-token bucket having the largest number of tokens from the multiple second target sub-token buckets; and recycle a preset number of tokens from the third target sub-token bucket and distribute them to the first target sub-token bucket.
[0126] Optionally, the transmission unit 601 is also used to: generate a corresponding sub-token bucket for the new user in response to a second data transmission request from the new user, the second data transmission request being used to request the transmission of second target data; the transmission unit 601 is also used to: when the number of surplus tokens in the total token bucket is greater than or equal to a preset number, select a preset number of tokens from the total token bucket and distribute them to the sub-token bucket corresponding to the new user, and transmit the second target data by consuming the tokens in the sub-token bucket corresponding to the new user; the adjustment unit 602 is also used to: in the process of transmitting the second target data, when the number of surplus tokens in the total token bucket is greater than or equal to the fifth data transmission flow of the new user, adjust the number of tokens in the sub-token bucket corresponding to the new user, so that the sixth data transmission flow corresponding to the tokens in the sub-token bucket corresponding to the new user is greater than the fifth data transmission flow of the new user, and the difference between the sixth data transmission flow corresponding to the tokens in the sub-token bucket corresponding to the new user and the fifth data transmission flow of the new user is less than the first flow threshold.
[0127] Optionally, the adjustment unit 602 is also used to: during the transmission of the second target data, when the number of surplus tokens in the total token bucket is less than the fifth data transmission flow of the new user, all the surplus tokens in the first token bucket are allocated to the sub-token bucket corresponding to the new user; when the fifth data transmission flow of the new user is less than the fourth token number, the first target number of tokens is recovered from the fourth target sub-token bucket whose token number is greater than the fourth token number, and the first target number of tokens is allocated to the sub-token bucket corresponding to the new user, the first target number is the difference between the number of tokens corresponding to the fifth data transmission flow of the new user and the number of tokens already in the sub-token bucket corresponding to the new user, and the fourth token number is the average token number obtained based on the first token number and the number of users after the new user is added; when the fifth data transmission flow of the new user is greater than or equal to the fourth token number, the second target number of tokens is recovered from the fourth target sub-token bucket whose token number is greater than the fourth token number, and the second target number of tokens is allocated to the sub-token bucket corresponding to the new user, and the second target number is the difference between the fourth token number and the number of tokens already in the sub-token bucket corresponding to the new user.
[0128] Optionally, the second token quantity is an average token quantity obtained according to the first token quantity and the number of users, or a preset fixed token quantity.
[0129] In the technical solution disclosed herein, the acquisition, storage and application of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0130] According to an embodiment of the present disclosure, the present disclosure further provides an electronic device, a readable storage medium, and a computer program product. The electronic device may be the server described in the above embodiment.
[0131] In an exemplary embodiment, an electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method described in the above embodiments.
[0132] In an exemplary embodiment, the readable storage medium may be a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to execute the method according to the above embodiments.
[0133] In an exemplary embodiment, a computer program product includes a computer program, and when the computer program is executed by a processor, the method according to the above embodiments is implemented.
[0134] Figure 7 A schematic block diagram of an example electronic device 700 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0135] like Figure 7 As shown, the electronic device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 702 or a computer program loaded from a storage unit 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the electronic device 700 can also be stored. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0136] Multiple components in the electronic device 700 are connected to the I / O interface 705, including: an input unit 706, such as a keyboard, a mouse, etc.; an output unit 707, such as various types of displays, speakers, etc.; a storage unit 708, such as a disk, an optical disk, etc.; and a communication unit 709, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 709 allows the electronic device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0137] The computing unit 701 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 701 performs the various methods and processes described above, such as the flow control method. For example, in some embodiments, the flow control method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 700 via the ROM 702 and / or the communication unit 709. When the computer program is loaded into the RAM 703 and executed by the computing unit 701, one or more steps of the flow control method described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to perform the flow control method in any other appropriate manner (e.g., by means of firmware).
[0138] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0139] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0140] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0141] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0142] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0143] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0144] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0145] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A flow control method, the method comprising: Transmitting first target data requested to be transmitted by at least one user respectively by consuming tokens in a total token bucket, wherein the number of tokens in the total token bucket does not exceed the first number of tokens; In response to detecting that the number of the users and the first data transmission flow required by at least one user reach a preset condition, the first target data requested to be transmitted by each of the users is transmitted respectively by consuming tokens in a sub-token bucket corresponding to each of the users, where the tokens in the sub-token bucket come from the total token bucket; According to the first data transmission flow required by the user, the number of tokens in the sub-token bucket corresponding to the user is adjusted so that the difference between the second data transmission flow corresponding to the tokens in the sub-token bucket and the first data transmission flow is less than the first flow threshold, including: for each first target sub-token bucket, the second data transmission flow corresponding to the tokens in the first target sub-token bucket and the third data transmission flow of the target user corresponding to the first target sub-token bucket are detected according to a preset period, and the first target sub-token bucket is any one of the sub-token buckets; within each of the preset periods, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is less than the third data transmission flow of the target user, continue to select a preset number of tokens from the total token bucket and allocate them to the first target sub-token bucket; wherein the fourth data transmission flow corresponding to the preset number of tokens is less than or equal to the first flow threshold.
2. According to the method of claim 1, the preset condition comprises: The number of users is greater than a preset number of users, and the data transmission flow corresponding to the tokens consumed in the total token bucket is greater than a second flow threshold.
3. The method according to claim 1 or 2, before consuming the tokens in the sub-token bucket corresponding to each of the users and transmitting the first target data requested to be transmitted by each of the users, the method further comprises: A corresponding sub-token bucket is generated for each of the users, and tokens in the total token bucket are allocated to each of the sub-token buckets until the number of tokens in the sub-token bucket reaches the second token number.
4. The method according to claim 1 or 2, wherein the step of adjusting the number of tokens in the sub-token bucket corresponding to the user according to the first data transmission flow required by the user, so that the difference between the second data transmission flow corresponding to the tokens in the sub-token bucket and the first data transmission flow is less than a first flow threshold, comprises: According to the first data transmission flow required by the user, the number of tokens in the sub-token bucket corresponding to the user is adjusted, so that the second data transmission flow corresponding to the tokens in the sub-token bucket is greater than the first data transmission flow, and the difference between the second data transmission flow and the first data transmission flow is less than the first flow threshold.
5. The method according to claim 4, wherein the step of adjusting the number of tokens in the sub-token bucket corresponding to the user according to the first data transmission flow required by the user, so that the second data transmission flow corresponding to the tokens in the sub-token bucket is greater than the first data transmission flow, and the difference between the second data transmission flow and the first data transmission flow is less than the first flow threshold, comprises: Within each of the preset cycles, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is greater than the third data transmission flow of the target user, and the difference between the second data transmission flow corresponding to the tokens in the first target sub-token bucket and the third data transmission flow of the target user is greater than or equal to the first flow threshold, the preset number of tokens are selected from the first target sub-token bucket and recycled into the total token bucket.
6. The method according to claim 5, wherein within each of the preset periods, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is less than the third data transmission flow of the target user, continuing to select a preset number of tokens from the total token bucket and allocating them to the first target sub-token bucket comprises: In each of the preset cycles, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is less than the third data transmission flow of the target user, and the number of surplus tokens in the total token bucket is greater than or equal to the preset number, continue to select the preset number of tokens from the total token bucket and allocate them to the first target sub-token bucket; The method further comprises: In each of the preset cycles, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is less than the third data transmission flow of the target user, and the number of surplus tokens in the total token bucket is less than the preset number, the preset number of tokens is recovered from the second target sub-token bucket and allocated to the first target sub-token bucket, where the second target sub-token bucket is the sub-token bucket in which the number of tokens is greater than the third number of tokens, and the third number of tokens is the average number of tokens obtained based on the first number of tokens and the number of users.
7. The method according to claim 6, wherein the second target sub-token bucket comprises a plurality of; The step of recovering the preset number of tokens from the second target sub-token bucket and allocating them to the first target sub-token bucket includes: Determine a third target sub-token bucket having the largest number of tokens from the plurality of second target sub-token buckets; The preset number of tokens are recovered from the third target sub-token bucket and allocated to the first target sub-token bucket.
8. The method according to any one of claims 1-2, 5-7, further comprising: In response to a second data transmission request of a new user, generating a corresponding sub-token bucket for the new user, wherein the second data transmission request is used to request transmission of second target data; When the number of surplus tokens in the total token bucket is greater than or equal to a preset number, selecting the preset number of tokens from the total token bucket and allocating them to the sub-token bucket corresponding to the new user, and transmitting the second target data by consuming the tokens in the sub-token bucket corresponding to the new user; During the transmission of the second target data, when the number of surplus tokens in the total token bucket is greater than or equal to the fifth data transmission flow of the new user, the number of tokens in the sub-token bucket corresponding to the new user is adjusted so that the sixth data transmission flow corresponding to the tokens in the sub-token bucket corresponding to the new user is greater than the fifth data transmission flow of the new user, and the difference between the sixth data transmission flow corresponding to the tokens in the sub-token bucket corresponding to the new user and the fifth data transmission flow of the new user is less than the first flow threshold.
9. The method according to claim 8, further comprising: In the process of transmitting the second target data, when the number of surplus tokens in the total token bucket is less than the fifth data transmission flow of the new user, all the surplus tokens in the first token bucket are allocated to the sub-token bucket corresponding to the new user; When the fifth data transmission flow of the new user is less than the fourth token number, a first target number of tokens is recovered from a fourth target sub-token bucket whose token number is greater than the fourth token number, and the first target number of tokens is allocated to the sub-token bucket corresponding to the new user, wherein the first target number is the difference between the number of tokens corresponding to the fifth data transmission flow of the new user and the number of tokens already in the sub-token bucket corresponding to the new user, and the fourth token number is the average token number obtained based on the first token number and the number of users after the new user is added; When the fifth data transmission flow of the new user is greater than or equal to the fourth token number, a second target number of tokens is recovered from the fourth target sub-token bucket in which the token number is greater than the fourth token number, and the second target number of tokens is allocated to the sub-token bucket corresponding to the new user, where the second target number is the difference between the fourth token number and the number of tokens already in the sub-token bucket corresponding to the new user.
10. The method according to claim 3, wherein the second token number is an average token number obtained according to the first token number and the number of users, or a preset fixed token number.
11. A flow control device, comprising: A transmission unit, configured to transmit first target data requested to be transmitted by at least one user respectively by consuming tokens in a total token bucket, wherein the number of tokens in the total token bucket does not exceed the first number of tokens; The transmission unit is further configured to transmit the first target data requested to be transmitted by each user respectively by consuming tokens in a sub-token bucket corresponding to each user in response to detecting that the number of users and the data transmission flow required by at least one user reach a preset condition, wherein the tokens in the sub-token bucket are from the total token bucket; an adjusting unit, configured to adjust the number of tokens in the sub-token bucket corresponding to the user according to the first data transmission flow required by the user, so that the difference between the second data transmission flow corresponding to the tokens in the sub-token bucket and the first data transmission flow is less than a first flow threshold; The adjustment unit is also used to: for each first target sub-token bucket, detect the second data transmission flow corresponding to the tokens in the first target sub-token bucket and the third data transmission flow of the target user corresponding to the first target sub-token bucket according to a preset period, and the first target sub-token bucket is any one of the sub-token buckets; within each of the preset periods, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is less than the third data transmission flow of the target user, continue to select a preset number of tokens from the total token bucket and allocate them to the first target sub-token bucket; wherein the fourth data transmission flow corresponding to the preset number of tokens is less than or equal to the first flow threshold.
12. The device according to claim 11, wherein the preset condition comprises: The number of users is greater than a preset number of users, and the data transmission flow corresponding to the tokens consumed in the total token bucket is greater than a second flow threshold.
13. The device according to claim 11 or 12, wherein the adjustment unit is specifically configured to: A corresponding sub-token bucket is generated for each of the users, and tokens in the total token bucket are allocated to each of the sub-token buckets until the number of tokens in the sub-token bucket reaches the second token number.
14. The device according to claim 11 or 12, wherein the adjustment unit is further used for: According to the first data transmission flow required by the user, the number of tokens in the sub-token bucket corresponding to the user is adjusted, so that the second data transmission flow corresponding to the tokens in the sub-token bucket is greater than the first data transmission flow, and the difference between the second data transmission flow and the first data transmission flow is less than the first flow threshold.
15. The device according to claim 14, wherein the adjusting unit is further configured to: Within each of the preset cycles, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is greater than the third data transmission flow of the target user, and the difference between the second data transmission flow corresponding to the tokens in the first target sub-token bucket and the third data transmission flow of the target user is greater than or equal to the first flow threshold, the preset number of tokens are selected from the first target sub-token bucket and recycled into the total token bucket.
16. The device according to claim 15, wherein the adjusting unit is further configured to: In each of the preset cycles, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is less than the third data transmission flow of the target user, and the number of surplus tokens in the total token bucket is greater than or equal to the preset number, continue to select the preset number of tokens from the total token bucket and allocate them to the first target sub-token bucket; The adjustment unit is also used to: within each preset period, when the second data transmission flow corresponding to the tokens in the first target sub-token bucket is less than the third data transmission flow of the target user, and the number of surplus tokens in the total token bucket is less than the preset number, recover the preset number of tokens from the second target sub-token bucket and allocate them to the first target sub-token bucket, the second target sub-token bucket being the sub-token bucket in which the number of tokens is greater than the third number of tokens, and the third number of tokens is the average number of tokens obtained based on the first number of tokens and the number of users.
17. The device according to claim 16, wherein the second target sub-token bucket comprises a plurality of tokens; and the adjustment unit is further configured to: Determine a third target sub-token bucket having the largest number of tokens from the plurality of second target sub-token buckets; The preset number of tokens are recovered from the third target sub-token bucket and allocated to the first target sub-token bucket.
18. An electronic device, comprising: at least one processor; and a memory communicatively coupled to the at least one processor; The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method according to any one of claims 1 to 10.
19. A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to execute the method according to any one of claims 1 to 10.
20. A computer program product, comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 10.
