HTTP/2 configuration in Nginx - Time & Space Complexity
We want to understand how the time it takes for nginx to handle requests changes when HTTP/2 is enabled.
Specifically, how does the server's work grow as more requests come in using HTTP/2?
Analyze the time complexity of the following nginx HTTP/2 configuration snippet.
server {
listen 443 ssl http2;
ssl_certificate /etc/ssl/certs/example.crt;
ssl_certificate_key /etc/ssl/private/example.key;
location / {
root /var/www/html;
index index.html;
}
}
This config enables HTTP/2 on port 443 with SSL and serves static files from a directory.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Handling each incoming HTTP/2 request stream.
- How many times: Once per request, but HTTP/2 allows multiple streams concurrently.
As the number of HTTP/2 requests increases, nginx handles each stream individually but can multiplex many streams over one connection.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 request handling operations |
| 100 | 100 request handling operations |
| 1000 | 1000 request handling operations |
Pattern observation: The work grows linearly with the number of requests, even though HTTP/2 can handle them more efficiently.
Time Complexity: O(n)
This means the time to handle requests grows directly in proportion to how many requests come in.
[X] Wrong: "HTTP/2 makes nginx handle all requests instantly, so time does not grow with more requests."
[OK] Correct: HTTP/2 improves efficiency by multiplexing, but nginx still processes each request, so total work grows with request count.
Understanding how HTTP/2 affects request handling helps you explain server performance clearly and shows you grasp real-world web server behavior.
"What if we disabled HTTP/2 and used HTTP/1.1 instead? How would the time complexity change?"