nginx limit_req burst behavior: queued requests with nodelay vs without nodelay
0 reputation · 22 Apr 2024, 19:11 UTC
Configuration goal
I am configuring the limit_req module in nginx to throttle clients per IP using limit_req_zone with a rate of 10 r/s and burst=20. I want excess requests to be absorbed rather than rejected, and I am deciding whether to add nodelay.
Uncertainty
My understanding is that with burst=20 and no nodelay, requests above the rate are queued and processed at the defined rate, while nodelay lets burst requests through immediately up to the burst capacity. What I cannot reconcile is how the queue interacts with the burst counter: does a queued request still consume a burst slot, and how does this change when nodelay is set?
Questions
With burst=20 and nodelay, are requests above the burst size immediately rejected with 503, or does the burst counter refill at the defined rate regardless of nodelay? Also, if nginx is behind a load balancer, does binary_remote_addr still reflect the real client IP, or must I switch to a different key such as http_x_forwarded_for to avoid rate limiting the proxy address? Finally, how should I size the shared memory zone to avoid overflow when tracking thousands of unique client IPs?