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?"
Practice
burst option do in nginx rate limiting?Solution
Step 1: Understand the purpose of burst
Theburstoption in nginx allows extra requests that exceed the rate limit to be queued temporarily instead of being rejected immediately.Step 2: Compare with other options
Unlike rejecting or delaying all requests,burstspecifically queues extra requests to handle traffic spikes smoothly.Final Answer:
Allows extra requests to wait in a queue before being processed -> Option CQuick Check:
Burst = queue extra requests [OK]
- Thinking burst rejects extra requests immediately
- Confusing burst with fixed delay
- Assuming burst processes all requests without limit
Solution
Step 1: Identify correct order and keywords
The correct syntax placesburst=10followed bynodelaywithout extra keywords likedelay.Step 2: Validate syntax correctness
limit_req_zone $binary_remote_addr zone=mylimit:10m rate=1r/s; limit_req zone=mylimit burst=10 nodelay; correctly useslimit_req_zoneandlimit_reqdirectives with proper parameters and order.Final Answer:
limit_req_zone $binary_remote_addr zone=mylimit:10m rate=1r/s; limit_req zone=mylimit burst=10 nodelay; -> Option AQuick Check:
Syntax with burst=10 and nodelay = limit_req_zone $binary_remote_addr zone=mylimit:10m rate=1r/s; limit_req zone=mylimit burst=10 nodelay; [OK]
- Using 'delay' instead of 'nodelay'
- Placing nodelay before burst
- Omitting limit_req_zone directive
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s; limit_req zone=one burst=3 nodelay;
What happens if 5 requests arrive instantly from the same IP?
Solution
Step 1: Understand rate and burst limits
The rate is 1 request per second, burst allows 3 extra requests queued, and nodelay means queued requests run immediately.Step 2: Analyze 5 instant requests
The first request is within rate limit, next 3 fit in burst queue and run immediately due to nodelay, the 5th exceeds burst and is rejected.Final Answer:
First 4 requests processed immediately, 5th rejected -> Option BQuick Check:
Burst=3 + nodelay means 4 immediate, 5th rejected [OK]
- Assuming all 5 requests pass immediately
- Thinking requests after burst are delayed, not rejected
- Ignoring nodelay effect
burst=5 but your nginx still rejects extra requests immediately. What is the likely cause?Solution
Step 1: Check burst behavior without nodelay
Withoutnodelay, burst requests are delayed, not processed immediately, but if delay is too long, clients may see rejections.Step 2: Identify missing nodelay effect
If extra requests are rejected immediately despite burst, likelynodelayis missing, causing strict rate enforcement.Final Answer:
You forgot to add thenodelayoption -> Option AQuick Check:
Missing nodelay causes immediate rejection despite burst [OK]
- Assuming burst alone allows immediate processing
- Thinking burst must be less than 5
- Believing multiple restarts fix config issues
Solution
Step 1: Set base rate and burst for spikes
The base rate is 5 requests per second, and burst=20 allows 20 extra requests queued.Step 2: Use nodelay to process burst immediately
Addingnodelayensures the burst requests are processed right away without delay.Step 3: Confirm rejection beyond burst
Requests beyond burst=20 will be rejected, matching the requirement.Final Answer:
limit_req_zone $binary_remote_addr zone=spike:10m rate=5r/s; limit_req zone=spike burst=20 nodelay; -> Option DQuick Check:
Rate=5r/s + burst=20 + nodelay = limit_req_zone $binary_remote_addr zone=spike:10m rate=5r/s; limit_req zone=spike burst=20 nodelay; [OK]
- Setting burst too low for spikes
- Omitting nodelay causing delays
- Setting rate too high ignoring burst
Ready to prove it?
Pass the test and this pattern moves unknown
