3

A bsic web server such as python SimpleHTTPServer or THTTPD reads static files with least process; thus is quite fast. Normally, adding more features to create an advanced web server (but still lightweight such as nginx) will slow down this process.

Can an advanced web server play a trick to make the process faster? or simpler than simplest is impossible, and the simplest is fastest way to read static files? I mean can nginx (or other lightweight web servers which claim to be fast) be faster than THTTPD (or other basic web servers with minimal process)?

And what about CGI scripts, as HTTPD and python CGIHTTPServer can simply execute cgi scripts.

1
  • 1
    Yes and No. I've seen Apache do as well as Nginx/Lighttpd in certain work loads and not in others. You really have to benchmark your app to know for sure. In general, I find Nginx to excel at high concurrency for static content whereas Apache begins to suffer. Dec 5, 2011 at 20:42

3 Answers 3

2

Web servers with less features have a smaller memory and CPU footprint, which makes them faster at doing specific tasks. Some of them are also specifically designed to one task well.

This is why software like PHP-FPM has emerged. Instead of having a bloated apache2 process which loads a PHP module for every single process, you rather use a front-end for static files (like nginx), and a back-end (like PHP-FPM via FastCGI) for dynamic applications.

It does however depend on your usage and enviroment. If you're doing 99% dynamic processing then it might not be worth the hassle. One good example could be a Java application.. it doesnt make much sense to do all the work of setting up a front-end and a back-end, when you could just use tomcat and nothing else.

6

"Simple" and "Fast" aren't always related, especially in computing -- in this case, SimpleHTTPServer uses the simple file reading methods, the simple networking methods, clean and obvious processing that's easy for a new programmer to read, etc; nginx has a ton of complicated code to make use of the advanced high-speed file & network APIs in the most efficient way possible, weird tricks with memory allocation to avoid copying data around, etc.

Plus, language overheads - python is plenty fast when your bottleneck is the database or the filesystem, but I've actually found that for serving thousands of thumbnails per second, nginx with all its complicated stuff in C is 10x faster than a simple python program that just returns data from memory.

As to THTTPD vs nginx, they're both C, and both designed for speed over simplicity, so I'd guess they'd be closer in performance - but thttpd seems to have been last updated in 2003, which means it pre-dates most of the high-speed APIs that nginx makes use of.

1
  • +1 for very useful, informative and descriptive answer :)
    – Googlebot
    Dec 5, 2011 at 12:57
4

In general, simpler means faster. However, you will not be sure that server x is faster than server y unless you try it yourself. You can also look at the already done benchmarks (if any) to have an idea about it.

The advanced web server can be slower than a simple/basic server because of the added complexity. However, the advanced server can be better in other scenarios. The advanced server usually allows you to turn on/off some features and optimize it to get better performance. So, there is no general answer!

2
  • Actually, I looked for benchmarks, but there is no for basic web servers; probably because they are not for production.
    – Googlebot
    Dec 5, 2011 at 10:35
  • @Ali - You need to implement each solution and benchmark how your app/site behaves.
    – gWaldo
    Dec 5, 2011 at 13:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .