In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Welcome to scan the code to join Java Gaozhi × × × stream.
1. Leaky bucket principle
What is the principle of leaky bucket? We can literally understand that there is a bucket, its volume is fixed, there is a small hole under the bucket will keep leaking out, and at the top of the bucket there is a faucet, also keep pouring water into the bucket.
Assuming that the volume of our bucket is 1L and the maximum rate of water leakage in the mouth of the hole is 100ml/s, experiments are carried out under the following conditions:
(1) the rate of water intake is 50ml/s, at this time there is no pressure for the small hole, then the water in the bucket will not overflow and all the water will leak out of the small hole.
(2) then we increase the water discharge rate of the faucet to 100ml/s, which is the same as the leakage rate of the small hole, the water in the bucket will not overflow, the water in the bucket will not change, and all the water will leak out of the hole.
(3) We turn up the faucet and turn it to 150m/m. At this time, the rate of water inflow is higher than that of water outlet by 50ml per second. After 20 seconds, the bucket is full and will overflow, and then 50ml water will overflow every second.
In either case, the same thing is that the maximum rate of leakage is the same. When the rate of water intake is greater than the rate of leakage, when the bucket is full, some of the water will be overflowed.
It is the same for us to access a server, limit the storage capacity and rate of its traffic, and directly discard some requests when it cannot be handled, to ensure the normal traffic processing of the server.
This is the leaky bucket principle.
2. Nginx leaky bucket principle configuration
Nginx uses leaky Bucket principle (leaky bucket) to restrict the requested ip too frequently. For more information, please see https://en.wikipedia.org/wiki/Leaky_bucket
The specific configuration is as follows:
# define three leaky buckets based on the user's binary IP address. The dripping rate is 1-3req/sec. The bucket space 1m IP 1m can maintain about 16000 (IP) states limit_req_zone $binary_remote_addr zone=qps1:1m rate=1r/s;limit_req_zone $binary_remote_addr zone=qps2:1m rate=2r/s;limit_req_zone $binary_remote_addr zone=qps3:1m rate=3r/s. Server {# rate qps=1, peak burst=5, delay request # processes requests per second in strict accordance with leaky bucket rate qps=1 # concurrent requests within the peak burst=5 will be suspended. If the delay processing exceeds the limit, it will directly return to the 50 requests client as long as the concurrency is controlled within the peak [burst], the limit_req_error_log# will not be triggered example 1: initiate a concurrent request = 6, reject 1, process 1 There are 4 delay queues: # time request refuse sucess delay#00:01 6 1 1 4 00 delay 02 00 1 3 00 00 3 00 00 1 2 00 00 04 00 1 1 1 00 00 05 00 1 0location / delay {delay } # rate qps=1, peak burst=5, no delay request # after adding nodelay, the leaky bucket controls the average qps= leaky bucket rate over a period of time, allowing instantaneous peak qps > leaky bucket qps#, so the maximum qps= (brust+qps-1) at the peak value is not delay, either processed or directly returned to the 50th client needs to control the number of qps requests per second. It will not trigger limit_req_error_log# example 2: initiate concurrent requests that peak every 5 seconds. Because of the average qps=1 during the time period, it still conforms to the leaky bucket rate: # time request refuse sucess#00:01 5 05 # 00:05 5 05 # 00:10 5 05 # case 3: consecutive concurrent requests per second = 5, because the average qps in the time period > > 1 The request for excess was denied: # time request refuse sucess#00:01 5 0 5 00 00 nodelay 02 5 4 1 3 5 4 1 location / nodelay {limit_req zone=qps1 burst=5 nodelay }}
Welcome to scan the code to join Java Gaozhi × × × stream.
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.