Configuration reload vs restart in Nginx - Performance Comparison
When managing nginx, we often reload or restart the server to apply changes.
We want to understand how the time cost grows when reloading versus restarting.
Analyze the time complexity of these nginx commands.
# Reload nginx configuration without stopping service
nginx -s reload
# Restart nginx service completely
systemctl restart nginx
The first reloads config gracefully; the second stops and starts nginx fully.
Look at what happens internally during reload and restart.
- Primary operation: Reload sends signal to worker processes to reload config without stopping.
- How many times: Reload affects all worker processes once each.
- Restart operation: Stops master and all workers, then starts fresh processes.
- How many times: Restart involves stopping and starting all processes fully.
Consider number of worker processes as input size (n).
| Number of Workers (n) | Reload Operations |
|---|---|
| 1 | 1 signal sent |
| 5 | 5 signals sent |
| 10 | 10 signals sent |
Reload time grows linearly with number of workers because each gets a signal.
| Number of Workers (n) | Restart Operations |
|---|---|
| 1 | Stop + start 1 master + 1 worker |
| 5 | Stop + start 1 master + 5 workers |
| 10 | Stop + start 1 master + 10 workers |
Restart time also grows linearly but includes full stop and start overhead.
Time Complexity: O(n)
This means the time to reload or restart grows roughly in direct proportion to the number of worker processes.
[X] Wrong: "Reloading nginx is instant and does not depend on number of workers."
[OK] Correct: Each worker process must receive and handle the reload signal, so more workers mean more operations and longer reload time.
Understanding how reload and restart scale helps you manage server uptime and responsiveness in real projects.
What if nginx had hundreds of worker processes? How would that affect reload and restart times?