Kartik Anand
Kartik Anand

Reputation: 4609

Resource usage of a static web server

I came across this question in a blog post. It was asked by Mozilla in their internship interview. (Blog Post)

You are running a HTTP server (nginx, Apache, etc) that is configured to serve static files off the local filesystem of your modern, multi-core server connected to a gigabit network. A handful of clients start requesting the same 4kb static file as fast as they can. What system resource do you think will be exhausted first?

a. CPU
b. Disk / I/O
c. Memory
d. Network
e. Other

According to me, none of this would be exhausted on a modern machine, with Nginx/Apache. Won't the web server cache such a small file and just keep serving that. Also, for repeated request it can easily send a Not-Modified header.

In case of Apache, I guess due to it handling multiple clients by spawning threads, CPU will be exhausted first, but for a "handful" of clients, that won't matter.

I wanted to know what others have to say about this question.

Upvotes: 1

Views: 634

Answers (1)

DaSourcerer
DaSourcerer

Reputation: 6606

It reeeeeeeeally depends. 4k is that magical size that will fit into as good as all caches and buffers at their default settings, so it is easy (and fast) to pass around. memory is not a limiting factor here as webservers will operate on filehandles, not entire files. In this case I would assume they keep it right in memory, but that would be one file per worker instance which would usually come down to 4kb * (num_cores + 1) at most, which is not really an issue.

One could argue that either memory- or diskspeed were an issue. But former one were neglectable when methods like are properly configured, enabling for a zero-copy approach. Latter one would amortize over time once a copy of the file got loaded into memory.

Lastly, there's the interface and the CPU(s). Overall, CPU time tends to be a lot cheaper than network time, so I would expect the NIC to be the bottleneck long before the CPU - if at all.

The question is a bit unspecific on the location of the clients. If they are connected to the same GbE network, they could indeed have the power to saturate your NIC with their requests. If not, some intermediary could become the limiting factor.

Now let us assume those clients were in our network and we had a single-homed 10GbE NIC here, connected via 8 lanes (which is fairly standard IMHO): PCIe 3.0 x8 is specified with 7,877 MB/s. A Core i7 3770 has a bus speed of 5GT/s, which is translating to roughly 8 GB/s at 8 lanes. Assuming no other I/O-intensive workload, this CPU could easily saturate the NIC.

So in summary: Network/NIC saturation before CPU saturation before anything else.

Upvotes: 2

Related Questions