Benching Lighttpd vs Nginx (static files)

February 14, 2007

As it stands, the Django development team recommends mod_python to deploy your Django applications. With that in mind, they recommend using a more efficient web server for static files. These days, most people turn to web servers like Lighttpd or Nginx for this task.

Installation

I installed both on a fresh 1GB Slice with similar configurations and benchmarked them using ApacheBench. I used the latest "stable" source releases from their websites: Lighttpd 1.4.13 and Nginx 0.5.12.

In both cases I just ran the following as root:

./configure
make
make install

Both installations went off without a hitch. To start Lighttpd I ran:

lighttpd -f /etc/lighttpd/lighttpd.conf

And for Nginx:

/usr/local/nginx/sbin/nginx

Configuration files:

Two files were used for testing purposes:

Each file was accessed 100,000 times. For index.html concurrency was set to 1000, and 10 for test.png. Keepalive was not used.

Results

index.html:

  Nginx Lighttpd
Concurrency Level: 1000 1000
Time taken for tests (seconds): 12.445774 10.951389
Complete requests: 100000 100000
Failed requests: 0 0
Write errors: 0 0
Total transferred (bytes): 56779947 62353634
HTML transferred (bytes): 35650196 35687932
Requests per second [#/sec] (mean): 8034.86 9131.26
Time per request [ms] (mean) : 124.458 109.514
Time per request [ms] (mean, across all concurrent requests): 0.124 0.110
Transfer rate [Kbytes/sec] received : 4455.25 5560.21

test.png

  Nginx Lighttpd
Concurrency Level: 10 10
Time taken for tests (seconds): 52.889986 54.976213
Complete requests: 100000 100000
Failed requests: 0 0
Write errors: 0 0
Total transferred (bytes): 32067859584 32070273152
HTML transferred (bytes): 32046457872 32045670938
Requests per second [#/sec] (mean): 1890.72 1818.97
Time per request [ms] (mean) : 5.289 5.498
Time per request [ms] (mean, across all concurrent requests): 0.529 0.550
Transfer rate [Kbytes/sec] received : 592102.06 569675.94

Conclusion

Both servers performed extremely well, though it seems that Lighttpd might perform best in a more fragmented file system (smaller files). Nginx performed better serving test.png, but the difference is smaller than the preceeding test.

Considering that each would easily saturate the pipeline I doubt a real-world performance difference would be seen.


Comments

I think the tux web server is the best!

Posted by tony

onfly gzip compression for html files was enabled on nginx?

Posted by ilya

Take a look at the bottom of the Lighty config file; Compression was enabled there too.

However, neither server actually did any compression. I would have had to tell ApacheBench to give the appropriate Accept-Encoding header.

Posted by SuperJared

Only 1 worker process for Nginx? Try bumping that up.

Posted by Wayne

Now what about CPU load and consumed memory?These are interesting things to compare under such "almost equal" load.

Posted by lamer

Yes, Tux would be faster but unfortunately it seems to crash on Linux 2.6 kernels, both SMP and non-SMP. Happens to me, and to various people on the Tux list. Actually I have not seen anybody run Tux stable on a new kernel, i.e. with Centos 4.3 upwards. I DID run Tux on Redhat 9 and it was both stable and very, very fast with close to zero Ram usage and zero server load. It's a wonderful static server but it seems the developer has to do it on the side and there is no real interest from Redhat to get it fixed in a more timely manner. Once a 2.8 etc kernel is out, it will probably run stable on 2.6 I guess.

So the remaining options are to use Tux on a 2.4 Linux kernel, or to switch to nginx/lighttpd/litespeed. I am going the nginx route I guess because some people reported memory leaks in lighttpd and litespeed's free version is limited to 150 concurrent users.

Posted by Lmm

i agree with lamer, cpu and memory usage are very important.
in my simple stress tests cpu usage showed lighttpd at 98% while nginx was never more than 52%.

Posted by grigora

I was testing same things, on my local box though (all requests made from localhost) both with static files, with a simple php file containing only phpinfo(); and with a sample wordpress installation.
Php running as fastcgi (by spawn-fcgi)

Nginx performed almost the same as lighttpd but cpu load was much better with nginx. (LA never got more than 5 while lighttpd bumped it up to ~10, and apache to 20+ while testing with the wordpress setup)

Btw, can't even compare it to apache, which almost crashed my box when testing the sample wordpress install.( 10000 requests, 1000 concurrent)

http://nixfloyd.blogspot.com/

Posted by floyd

Would the benchmarks be different if the image file was a JPG or GIF and be between 60-400kb in filesize?

Posted by James Warren

The difference of filetype would not change anything. And test.png is 313k.

Posted by SuperJared

You know what's strange, every time you run the benchmark it returns a different result. So how can you really get an accurate result?

Posted by Carlos

Perform the benchmark several times to get an average. If the ranges vary wildly then something's wrong. Plus this isn't an exact science anyway.

Posted by SuperJared

Hey, I stumbled across this page from google and and wanted to add something to these results. I recently wrote a simple C application to act as a HTTP server and to have some continuity, I re-run my tests with your index.html.

Take a look:
http://www.zenebo.com/word/asynchrono...

Posted by Arek

How many kbit of "test.png"?

Posted by 01478.com

Add your comment

No HTML; Only URLs and line breaks are converted.