The C10k Problem: Why Your RAM is Disappearing
If you have ever watched `top` on a Friday afternoon while your traffic spikes, you know the sinking feeling. Your Load Average climbs past 5.0, your Swap usage starts ticking up, and suddenly your SSH session lags. The culprit? Usually, it's the web server architecture you blindly installed via `yum install httpd`.
It is 2010. We are moving past the era of simple static sites into rich AJAX applications and heavier CMS platforms like Drupal 6 and WordPress 2.9. The traditional LAMP stack is sturdy, but it is heavy. Today, we are pitting the undisputed heavyweight champion, Apache 2.2, against the agile contender, Lighttpd 1.4 (lighty), to see which daemon deserves the precious resources on your Virtual Private Server.
Pro Tip: Before optimizing software, ensure your underlying virtualization isn't cheating you. Many budget hosts use OpenVZ to oversell RAM. At CoolVDS, we use Xen virtualization to ensure the RAM you buy is physically reserved for your kernel. No noisy neighbors stealing your pages.
Apache 2.2: The Flexible Giant
Apache is the backbone of the internet. It powers over 50% of active websites for a reason: compatibility. If you are running a hosting business or managing varied client sites, Apache's `.htaccess` support is non-negotiable. It allows developers to modify rewrite rules and PHP settings without touching the main server config or restarting the daemon.
The Bottleneck: MPM Prefork
However, Apache's default configuration on CentOS 5 or Debian Lenny usually defaults to the Prefork MPM (Multi-Processing Module). This is process-based, not thread-based. Every single incoming connection spawns a new process (or uses an idle one). If you embed `mod_php` directly into Apache, every one of those processes bloats to 20MB-30MB.
Do the math: A CoolVDS VPS with 512MB RAM can barely handle 20 concurrent Apache clients before hitting swap if you don't tune `MaxClients` aggressively.
# /etc/httpd/conf/httpd.conf
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256 <-- DANGER ZONE. Lower this to match your RAM / Process Size.
MaxRequestsPerChild 4000
Lighttpd: The Asynchronous Speedster
Lighttpd (pronounced "lighty") takes a completely different approach. It is single-threaded, non-blocking, and asynchronous. It uses the `epoll` system call available in the Linux 2.6 kernel to handle thousands of connections in a single process loop.
High-volume sites like YouTube and Wikipedia have utilized Lighttpd for static content delivery because it doesn't care about the number of open connections—only the active ones. It consumes a tiny fraction of the CPU and RAM that Apache demands for the same load.
The Configuration Shift
Switching to Lighttpd means abandoning `.htaccess`. You must centralize your logic in `lighttpd.conf`. This scares off casual users, but for a Systems Architect, it is a blessing. It forces clean, centralized configuration.
Here is how you enable the high-performance event handler in Lighttpd to handle high concurrency on our CoolVDS infrastructure:
# /etc/lighttpd/lighttpd.conf
server.max-fds = 2048
server.event-handler = "linux-sysepoll"
server.network-backend = "writev"
stat-cache-engine = "simple"
# PHP via FastCGI (Essential, since Lighttpd doesn't embed PHP)
fastcgi.server = ( ".php" =>
(( "socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/bin/php-cgi",
"max-procs" => 2,
"idle-timeout" => 20,
))
)
Benchmark Reality: Static vs Dynamic
We ran `ab` (Apache Bench) against both servers on a standard CoolVDS slice hosted in our Oslo facility.
| Scenario | Apache 2.2 (Prefork) | Lighttpd 1.4 | Verdict |
|---|---|---|---|
| Static Images (Keep-Alive) | High RAM usage, threads blocked waiting for I/O. | Near-zero load. Handles 1000+ conn/sec easily. | Lighttpd Wins |
| Dynamic PHP (WordPress) | Easy setup, stable, high memory per user. | Requires FastCGI tuning. Slightly faster, much less RAM. | Draw (Complexity vs Speed) |
| Stability under DDoS | Crashes rapidly (MaxClients reached). | Resilient (handles "Slowloris" attacks better). | Lighttpd Wins |
The Norwegian Context: Latency and Logs
Hosting in Norway isn't just about speed; it's about compliance with the Personopplysningsloven (Personal Data Act). When you configure your web server logging, remember that IP addresses can be considered personal data by the Datatilsynet.
Lighttpd makes it easy to pipe logs to a script for anonymization before writing to disk, reducing your I/O overhead on our enterprise-grade SAS RAID arrays. Apache requires piping to a separate process like `rotatelogs`, which adds yet another process to your tree.
Verdict: Which One Should You Choose?
If you are hosting a complex shared environment where your users need `.htaccess` files to manage their rewrite rules, Apache is still the only viable choice. It is standard, documented, and predictable. However, you will need to scale your VPS plan vertically to feed it the RAM it craves.
If you are building a dedicated application server, an image host, or a high-traffic news portal targeting the Nordic market, Lighttpd is superior. It allows you to serve thousands of concurrent Norwegian users without upgrading your hardware tier.
The Infrastructure Factor: Regardless of your software choice, disk I/O is often the hidden killer. At CoolVDS, we don't rely on standard SATA drives. Our storage clusters are built on high-RPM SAS drives in RAID-10, ensuring that whether you are flushing Apache logs or reading Lighttpd static assets, the physical disk is never your bottleneck.
Ready to compile? Deploy a CentOS 5 instance on CoolVDS today and test your `ab` benchmarks against the competition. Your load average will thank you.