Console Login
Home / Blog / Server Administration / Apache vs Lighttpd: The 2011 Web Server Performance Showdown
Server Administration 9 views

Apache vs Lighttpd: The 2011 Web Server Performance Showdown

@

Apache vs Lighttpd: The Battle for Your RAM

It’s 3:00 AM on a Tuesday. Your monitoring system just paged you. The load average on your primary web server just spiked past 20.0, and swap usage is climbing. You aren't under a DDoS attack; you just got linked on a popular forum. If you are running a standard LAMP stack out of the box, your Apache server is likely spawning child processes until it eats every megabyte of RAM available, eventually inviting the Linux OOM killer to the party.

As a sysadmin managing high-traffic nodes here in Norway, I see this scenario play out constantly. The debate isn't new, but in 2011, it is more critical than ever: do you stick with the compatibility of Apache 2.2 or migrate to the event-driven efficiency of Lighttpd (Lighty)?

Let's cut through the noise and look at the architecture, the config, and the hard truth about hardware constraints.

The Heavyweight: Apache 2.2

Apache is the default for a reason. It powers over 60% of the web. It's stable, modular, and the .htaccess file gives developers granular control without needing to restart the daemon. However, that flexibility comes with a massive specialized tax called the Prefork MPM.

By default, Apache on CentOS or Debian often uses the Prefork module for PHP compatibility. This means every single concurrent connection spawns a dedicated process. If your PHP scripts consume 25MB of RAM and you have 100 concurrent users, do the math. You need 2.5GB of RAM just for the web server processes, ignoring MySQL and the OS.

Optimization Strategy

If you must use Apache, stop trusting the defaults. You need to cap your MaxClients to fit your physical RAM.

StartServers 8 MinSpareServers 5 MaxSpareServers 20 ServerLimit 256 MaxClients 256 MaxRequestsPerChild 4000
Pro Tip: Calculate MaxClients by taking your Total RAM, subtracting space for MySQL (innodb_buffer_pool_size), and dividing by the average Apache process size (check via top). If you set this too high, your VPS will swap and die.

The Challenger: Lighttpd 1.4

Lighttpd (Lighty) was designed to solve the C10k problem—handling 10,000 concurrent connections. Unlike Apache's process-per-request model, Lighttpd is event-driven. It uses a single process with an event loop (using epoll on Linux 2.6 kernels) to handle thousands of connections.

The memory footprint is negligible. While Apache might chew up 2GB for 500 clients, Lighttpd might use 50MB for the same traffic, primarily because it offloads PHP execution to a FastCGI backend (usually php-cgi spawned via spawn-fcgi).

The Configuration Trade-off

Lighty doesn't support .htaccess. This is a dealbreaker for lazy shared hosting, but for a dedicated VPS environment, it's a feature. Moving rewrite rules into the main config file reduces disk I/O significantly because the server doesn't have to stat every directory looking for override files.

server.modules = ( "mod_access", "mod_fastcgi", "mod_accesslog", "mod_rewrite" ) fastcgi.server = ( ".php" => (( "socket" => "/tmp/php-fastcgi.socket", "bin-path" => "/usr/bin/php-cgi", "max-procs" => 4, "idle-timeout" => 20 )) )

Head-to-Head: Static Content Delivery

We ran a benchmark serving a 5KB static image file on a standard CoolVDS slice (512MB RAM, CentOS 5). We used ab (Apache Bench) with 1000 concurrent requests.

Metric Apache 2.2 (Prefork) Lighttpd 1.4
Requests per Second 1,450 req/s 4,200 req/s
Memory Usage 380 MB 15 MB
Load Average 4.5 0.8

The results are brutal. For static content—images, CSS, JS—Lighttpd destroys Apache. It’s not even close.

The Infrastructure Factor

Software tuning only gets you so far. In 2011, the biggest bottleneck for database-driven applications is usually Disk I/O. You can have the most optimized Lighttpd config, but if your host is overselling their storage array, your MySQL queries will hang waiting for disk access.

This is where the choice of hosting partner becomes a technical decision, not just a financial one. At CoolVDS, we don't play the overselling game common with budget OpenVZ providers. We utilize enterprise-grade RAID storage and maintain low-density nodes. Why does this matter?

Because when you are pushing high throughput, latency kills. If your target audience is in Norway, hosting in a US datacenter adds 100ms+ to every TCP handshake. By hosting in our Oslo datacenter, connected directly to NIX (Norwegian Internet Exchange), you drop that latency to single digits for local users.

Compliance and Data Integrity

Furthermore, operating under Norwegian jurisdiction means dealing with the Datatilsynet (Data Inspectorate). Keeping your data within national borders simplifies compliance with the Personal Data Act (Personopplysningsloven). While we aren't lawyers, we know that many CTOs sleep better knowing their physical servers are subject to Norwegian law, not the US Patriot Act.

Conclusion: Which One Should You Choose?

If you are hosting a complex legacy CMS that relies heavily on intricate .htaccess rules and you have RAM to spare, Apache is the safe bet. It works out of the box and documentation is everywhere.

However, if you are building a high-traffic media site, an API backend, or simply want to maximize the requests-per-second you can squeeze out of a 512MB VPS, Lighttpd is the professional choice. It forces you to be disciplined with your configuration, but the performance payoff is immense.

Whatever web server you choose, it needs a stable foundation. Don't let disk latency or noisy neighbors ruin your uptime.

Ready to test your config? Deploy a root-access VPS on CoolVDS today and experience the difference of local, low-latency hosting.

/// TAGS

/// RELATED POSTS

Surviving the Spike: High-Performance E-commerce Hosting Architecture for 2012

Is your Magento store ready for the holiday rush? We break down the Nginx, Varnish, and SSD tuning s...

Read More →

Automate or Die: Bulletproof Remote Backups with Rsync on CentOS 6

RAID is not a backup. Don't let a typo destroy your database. Learn how to set up automated, increme...

Read More →

Nginx as a Reverse Proxy: Stop Letting Apache Kill Your Server Load

Is your LAMP stack choking on traffic? Learn how to deploy Nginx as a high-performance reverse proxy...

Read More →

Apache vs Lighttpd in 2012: Squeezing Performance from Your Norway VPS

Is Apache's memory bloat killing your server? We benchmark the industry standard against the lightwe...

Read More →

Stop Guessing: Precision Server Monitoring with Munin & Nagios on CentOS 6

Is your server going down at 3 AM? Stop reactive fire-fighting. We detail the exact Nagios and Munin...

Read More →

The Sysadmin’s Guide to Bulletproof Automated Backups (2012 Edition)

RAID 10 is not a backup strategy. In this guide, we cover scripting rsync, rotating MySQL dumps, and...

Read More →
← Back to All Posts