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.
"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.
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!
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.