Apache vs Lighttpd: The 2012 Performance Showdown for Norwegian Systems
It is 3:00 AM in Oslo. Your monitoring system just sent a critical alert: Load Average is spiking above 15.00 on your dual-core VPS. Your marketing team just launched a campaign, and traffic is hitting the server like a freight train. You SSH in, run top, and see the culprit immediately. It’s not the database. It’s a wall of Apache processes, each consuming 40MB of RAM, fighting for resources until the system collapses into swap death.
If you have been in the trenches of server administration long enough, you know this scenario. The "C10k problem" (handling 10,000 concurrent connections) isn't just theory anymore; it's a Tuesday requirement for high-traffic sites.
Today, we are dissecting the architecture of the two main contenders fighting for your port 80: the ubiquitous Apache HTTP Server and the lightweight challenger, Lighttpd (pronounced "Lighty"). We will analyze memory footprint, concurrency, and why the underlying virtualization of your host—specifically CoolVDS's KVM implementation—matters just as much as your software stack.
The Heavyweight: Apache 2.2 (The Forking Model)
Apache has been the backbone of the internet since the mid-90s. In 2012, it is still the default on almost every CentOS or Debian install. Its power lies in its modularity and the ubiquitous .htaccess file, which allows developers to modify server configuration without touching the root config.
However, Apache's strength is its weakness. The standard MPM Prefork model handles requests by spawning a separate process for each connection. This is stable, but expensive.
Pro Tip: If you must run Apache on a VPS with less than 2GB RAM, you absolutely must calculate your MaxClients limit based on your average process size. Do not use the defaults.
Configuring Apache for Survival
To prevent Apache from eating all your RAM, you need to tune the httpd.conf file carefully. Here is a configuration tuned for a standard 1GB VPS running CentOS 6:
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
# The real killer: KeepAlive
KeepAlive On
KeepAliveTimeout 2 # Drastically reduce this from default 15
Why reduce KeepAliveTimeout? Because with the Prefork model, a worker process sits idle waiting for that timeout to expire. If you have 200 users, that is 200 processes doing nothing but consuming RAM. On a CoolVDS instance, we provide dedicated RAM allocation, but even the best hardware cannot save a bad configuration.
The Challenger: Lighttpd (The Event Model)
Lighttpd takes a radically different approach. Instead of blocking processes, it uses an asynchronous event loop (leveraging epoll on Linux). It handles thousands of connections with a single process or a very small number of workers. It is the architecture of choice for sites like YouTube (in their early days) and Wikipedia for static assets.
The difference in memory usage is staggering. Under load, Apache might consume 800MB for 500 connections. Lighttpd? Often less than 50MB.
Setting Up Lighttpd with FastCGI
Lighttpd does not embed PHP like mod_php. It talks to PHP via FastCGI. This separation further stabilizes the web server; if PHP crashes, the web server stays up.
Here is a robust lighttpd.conf snippet for high-performance serving:
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
"mod_rewrite",
"mod_fastcgi"
)
server.max-fds = 2048
server.event-handler = "linux-sysepoll"
server.network-backend = "linux-sendfile"
# FastCGI Configuration for PHP
fastcgi.server = ( ".php" =>
((
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/bin/php-cgi",
"max-procs" => 2,
"idle-timeout" => 20,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "4",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"min-procs" => 1,
"broken-scriptfilename" => "enable"
))
)
Benchmark: The Load Test
We deployed two identical instances on CoolVDS (1GB RAM, 1 vCPU, CentOS 6.3). We used ab (Apache Bench) to simulate 1000 concurrent requests against a static 50KB image file.
The Command:
ab -n 10000 -c 1000 http://localhost/test.jpg
The Results
| Metric | Apache 2.2 (Prefork) | Lighttpd 1.4 |
|---|---|---|
| Requests per Second | 845 req/sec | 3,240 req/sec |
| Memory Usage (Peak) | 680 MB | 35 MB |
| Load Average | 4.50 | 0.85 |
The numbers do not lie. For static content and high concurrency, Lighttpd destroys Apache in 2012. It leaves your CPU cycles free to process actual data rather than managing process overhead.
Why Infrastructure Still Matters: The CoolVDS Factor
Software optimization is critical, but it relies on the hardware beneath it. Even Lighttpd will choke if the disk I/O is saturated. This is where the distinction between "cheap VPS" and "professional hosting" becomes clear.
Many providers oversell their nodes using OpenVZ, meaning if your neighbor compiles a kernel, your Lighttpd instance stalls. At CoolVDS, we strictly use KVM (Kernel-based Virtual Machine). This guarantees that your RAM is yours, and your CPU cycles are reserved. Furthermore, we are rolling out SSD-cached storage arrays, which significantly reduces the `iowait` time that often kills web server performance during log rotation or heavy database writes.
Compliance and Latency in Norway
For our Norwegian clients, physical location is paramount. Hosting your server in Frankfurt or London adds 20-40ms of latency. Hosting with CoolVDS in Oslo ensures single-digit millisecond ping times for local users.
Additionally, keeping data within the borders satisfies the strict requirements of the Personopplysningsloven (Personal Data Act). While Safe Harbor exists for US transfers, local storage removes the legal ambiguity entirely.
Conclusion: Which One Should You Choose?
The choice between Apache and Lighttpd comes down to your specific use case:
- Choose Apache if: You rely heavily on
.htaccessfiles, complex rewrite rules, or third-party modules that require Apache compatibility. It is the safe, compatible choice. - Choose Lighttpd if: You are serving static media (images, CSS, JS), you have limited RAM (under 512MB), or you expect massive concurrency spikes.
Whatever server you choose, ensure it runs on hardware that respects your uptime. Don't let IO bottlenecks negate your software tuning.
Ready to test the difference? Deploy a KVM instance on CoolVDS today and see how your web server performs with true dedicated resources.