Burst and nodelay options in Nginx - Time & Space Complexity
We want to understand how the burst and nodelay options affect request handling speed in nginx.
How does the number of requests waiting or sent quickly change the work nginx does?
Analyze the time complexity of the following nginx rate limiting snippet.
limit_req_zone $binary_remote_addr zone=mylimit:10m rate=5r/s;
server {
location /api/ {
limit_req zone=mylimit burst=10 nodelay;
}
}
This code limits requests per second per user IP, allowing bursts and sending requests immediately without delay.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Checking and updating the request count for each incoming request.
- How many times: Once per request, repeated for every request arriving at the server.
As more requests come in, nginx checks each request against the limit and burst settings.
| Input Size (requests per second) | Approx. Operations per second |
|---|---|
| 10 | 10 checks and updates |
| 100 | 100 checks and updates |
| 1000 | 1000 checks and updates |
Pattern observation: The work grows linearly with the number of requests.
Time Complexity: O(n)
This means nginx does a constant amount of work for each request, so total work grows directly with request count.
[X] Wrong: "Using burst and nodelay makes nginx do extra loops or checks that slow it down a lot."
[OK] Correct: The burst and nodelay options only affect how requests are counted and released, but each request is still checked once. There are no extra loops per request.
Understanding how nginx handles bursts and immediate request processing helps you explain real-world server behavior clearly and confidently.
"What if we removed the nodelay option? How would the time complexity or request handling change?"