Nginx is now one of the most popular load balancers. In the face of the rapid increase in Internet traffic, interface current limiting is also very necessary, especially for high-concurrency scenarios. Nginx has two main ways of limiting the flow: limiting the access frequency and limiting the number of concurrent connections. Rate limiting is one of the most useful NGINX features, but it is also one of the most often misunderstood and misconfigured. This feature can limit the number of HTTP requests a user can make in a given period of time. The request can be as simple as a GET request for a home page or a POST request for a login form. How NGINX Rate Limiting Works NGINX throttling uses the leaky bucket algorithm, which is widely used in communications and packet-switched computer networks to handle bursts when bandwidth is limited. It's very similar to a bucket with water filling up from the top and leaking out from the bottom; if the rate at which water fills in is greater than the rate at which water leaks out, the bucket will overflow. In the request processing process, water represents requests from the client, and the bucket represents a queue where requests wait to be processed according to the first-in-first-out (FIFO) algorithm. Leaking water represents requests leaving the buffer and being processed by the server, and overflow represents requests being dropped and never served. 1. Limit access frequency (normal traffic) In Nginx, we use the ngx_http_limit_req_module module to limit the access frequency of requests, based on the principle of the leaky bucket algorithm. Next, we use the nginx limit_req_zone and limit_req instructions to limit the request processing rate of a single IP. Syntax:
2. Limit access frequency (burst traffic) According to the above configuration, when the traffic suddenly increases, the excess requests will be rejected and the burst traffic cannot be processed. So, how to deal with the burst traffic? Nginx provides the burst parameter to solve the problem of burst traffic and is used in conjunction with the nodelay parameter. Burst means the number of additional requests that can be processed after exceeding the set processing rate. burst=20 nodelay means that these 20 requests are processed immediately without delay, which is equivalent to special handling of special matters. However, even if these 20 burst requests are processed immediately, subsequent requests will not be processed immediately. burst=20 is equivalent to occupying 20 slots in the cache queue. Even if the request is processed, these 20 slots can only be released one at a time of 100ms. This achieves the effect of a stable rate, but also being able to handle sudden traffic flows normally. 3. Limit the number of concurrent connections The ngx_http_limit_conn_module module of Nginx provides the function of limiting the number of resource connections. It can be done using the limit_conn_zone and limit_conn instructions. limit_conn perip 20: The corresponding key is $binary_remote_addr, which means that a single IP is limited to holding a maximum of 20 connections at the same time. limit_conn perserver 100: The corresponding key is $server_name, which indicates the total number of concurrent connections that the virtual host (server) can handle at the same time. Note that the connection is counted only after the request header is processed by the backend server. Okay, are you clear about the above current limiting methods? The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to use JS to parse the excel content in the clipboard
>>: Installation tutorial of mysql5.7.21 decompression version under win10
Table of contents 1. What is an index? 2. Why do ...
This article mainly introduces the solution to th...
When making a website, I found that video files, s...
The mysql on a server in the computer room had be...
The drag function is mainly used to allow users t...
Table of contents 0. The kernel tree that comes w...
Through the brief introduction in the previous tw...
Table of contents 1. Overview of the page 2. Infi...
Table of contents 1.Nuxt server-side rendering ap...
Table of contents Tutorial Series 1. User Managem...
Web Application Class 1. DownForEveryoneOrJustMe ...
Update: Now you can go to the MySQL official webs...
When using apt-get to install, it will be very sl...
Problem background: There is a requirement to tak...
What is NFS? network file system A method or mech...