In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the java leaky bucket algorithm and token bucket algorithm". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "java leaky bucket algorithm and token bucket algorithm is what" it!
Background
Every external API interface needs to do flow control, otherwise it will cause the system to crash directly. A very simple example, like the principle of the fuse, if the electricity is in line with the overload, the fuse will be blown and the power supply will be cut off for protection. The meaning of API flow limit is the same. If the traffic request on API exceeds the approved value, we have to drain or reject the request directly.
Current limiting algorithm
Since we want to limit the current, we have to mention the current limiting algorithm. generally, there are two current limiting algorithms: the leaky bucket algorithm and the token bucket algorithm.
Leaky bucket algorithm
Leaky Bucket algorithm (Leaky Bucket) is a commonly used algorithm in traffic shaping (Traffic Shaping) or rate limiting (Rate Limiting) in the network world. Its main purpose is to control the rate of data injection into the network and smooth the burst traffic on the network. The leaky bucket algorithm provides a mechanism through which burst traffic can be shaped to provide a stable traffic for the network.
A leaky bucket can be thought of as a single server queue with constant service time, and if the leaky bucket (packet cache) overflows, the packet will be discarded. In the network, the leaky bucket algorithm can control the traffic output rate of the port, smooth the burst traffic on the network, and realize traffic shaping, so as to provide a stable traffic for the network.
As shown in the picture, the request is compared to water. When the water comes, it is first put into the bucket and out of the water at a limited speed. When the water comes too hard and the water does not come out fast enough, it will lead to a direct overflow of water, that is, denial of service.
It can be seen that the leaky bucket algorithm can well control the access speed of traffic, and once it exceeds this speed, it will deny service.
Token bucket algorithm
Token bucket algorithm is the most commonly used algorithm in network traffic shaping (Traffic Shaping) and rate limiting (Rate Limiting). Typically, the token bucket algorithm is used to control the number of data sent to the network and to allow burst data to be sent.
The principle of the token bucket algorithm is that the system will put tokens into the bucket at a constant speed, and if the request needs to be processed, it needs to obtain a token from the bucket first, and when there is no token in the bucket, it denies service. In principle, token bucket algorithm and leaky bucket algorithm are opposite, one is "water intake" and the other is "leakage".
The RateLimiter class in Google's Guava package is the solution to the token bucket algorithm.
Selection of leaky bucket algorithm and token bucket algorithm
The leaky bucket algorithm and the token bucket algorithm look similar on the surface, and it is easy to confuse the two. But in fact, the two have very different characteristics and are used for different purposes.
The difference between the leaky bucket algorithm and the token bucket algorithm is that the leaky bucket algorithm can forcibly limit the data transmission rate, and the token bucket algorithm can not only limit the average data transmission rate, but also allow a certain degree of burst transmission.
It should be noted that in some cases, the leaky bucket algorithm can not use the network resources effectively, because the leakage rate of the leaky bucket is fixed, so even if there is no congestion in the network, the leaky bucket algorithm cannot make a single data flow reach the port rate. Therefore, the leaky bucket algorithm is inefficient for traffic with burst characteristics. The token bucket algorithm can satisfy these traffic with burst characteristics. In general, leaky bucket algorithm and token bucket algorithm combine to provide more efficient control of network traffic.
At this point, I believe you have a deeper understanding of "what is the java leaky bucket algorithm and token bucket algorithm". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.