Apache vs Lighttpd in 2009: Surviving the C10k Problem on Your VPS
Let’s be honest: Apache 2.2 is bloated. If you are running a standard LAMP stack with the Prefork MPM, you are essentially asking your server to spawn a heavy, memory-hungry process for every single visitor. It works fine for your personal blog, but the moment you get Slashdotted or featured on Digg, your server load spikes, swap fills up, and the OOM killer starts shooting processes in the head.
I recently audited a high-traffic media site hosted here in Oslo. They were throwing hardware at the problem—adding more RAM sticks to their 1U Dell servers—when the real bottleneck was architectural. They were trying to serve 5,000 concurrent static file requests using Apache mod_php processes. That is insanity.
Today, we look at the challenger: Lighttpd (Lighty).
The Architecture: Process vs. Event
The fundamental difference lies in how connections are handled. Apache (in its most common Prefork configuration) creates a new process for each connection. If you have 100 simultaneous users, you have 100 Apache processes. If each process consumes 25MB of RAM (common with PHP libraries loaded), you need 2.5GB of RAM just for the web server.
Lighttpd, released in 2003 and now maturing in version 1.4, uses an asynchronous, event-driven architecture. It uses a single process (or very few) and handles I/O events using epoll() on Linux 2.6 kernels. This means it can juggle thousands of connections with a tiny memory footprint.
Configuration Showdown
Apache's configuration is legendary for its complexity and the ability to use .htaccess files (which kill performance due to constant disk seeks). Lighttpd keeps it simple.
Apache (httpd.conf) - The Memory Hog:
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
Lighttpd (lighttpd.conf) - The Lightweight Champion:
server.max-fds = 2048
server.event-handler = "linux-sysepoll"
server.network-backend = "linux-sendfile"
Pro Tip: If you must use Apache, disableAllowOverrideto stop the server from checking for.htaccessfiles in every directory. It reduces I/O wait significantly on busy servers.
PHP Performance: mod_php vs FastCGI
The biggest trade-off is PHP. Apache embeds the PHP interpreter directly into the web server process via mod_php. This is convenient but inefficient for static content. Why does an image request need a process with a PHP interpreter loaded?
Lighttpd talks to PHP via FastCGI. This separates the web server from the PHP processing. You spawn a pool of php-cgi processes specifically for dynamic content, while Lighttpd serves images, CSS, and JS using almost zero CPU.
The Verdict: When to Switch?
| Feature | Apache 2.2 | Lighttpd 1.4 |
|---|---|---|
| Architecture | Process/Thread based | Event-driven (Asynchronous) |
| Memory Usage | High (scales with clients) | Low (constant) |
| Static Content | Good, but heavy | Blazing fast (sendfile) |
| Stability | Rock solid | Good, occasional leaks |
If you are running a complex application relying on .htaccess rewrite rules or specific Apache modules, migration can be painful. However, for serving high-volume static assets or strictly controlled PHP applications, Lighttpd is superior.
Infrastructure Matters: The CoolVDS Approach
Software optimization can only take you so far. If your underlying disk subsystem is slow, iowait will bottleneck your application regardless of whether you use Lighttpd or Apache. This is especially true here in Norway, where data sovereignty and the Personopplysningsloven (Personal Data Act) require local hosting, but local options are often running on aging hardware.
This is why CoolVDS uses Enterprise 15k RPM SAS RAID-10 arrays rather than standard SATA drives found in budget hosting. We utilize Xen virtualization technology to ensure hard resource isolation. Unlike OpenVZ, where a "noisy neighbor" can steal your CPU cycles, our Xen implementation guarantees the RAM and CPU cores you pay for are actually yours.
Whether you choose the maturity of Apache or the raw speed of Lighttpd, you need a chassis that doesn't rattle. Don't let disk latency kill your SEO rankings.
Ready to handle the slashdot effect? Deploy a high-performance CentOS 5 instance on CoolVDS today and experience true hardware isolation.