Console Login
Home / Blog / Performance Optimization / Apache vs Lighttpd: Surviving the C10k Problem in 2011
Performance Optimization 7 views

Apache vs Lighttpd: Surviving the C10k Problem in 2011

@

The RAM limit is not a suggestion; it's a wall.

If you have ever stared at top while your load average climbs past 10.0 and your swap usage ticks upward, you know the feeling. It's the "Apache Spike." One moment your site is responsive; the next, a Reddit thread links to you, and your httpd processes consume every megabyte of available memory until the OOM killer steps in.

It is 2011. We are seeing a fundamental shift in how the web is consumed. It is no longer just static HTML; it is AJAX polling, long-held connections, and heavy dynamic content. The traditional LAMP stack is under siege by the C10k problem (handling 10,000 concurrent connections). While Apache remains the market leader with over 60% share, Lighttpd (pronounced "lighty") has emerged as the weapon of choice for high-traffic sites like YouTube and Wikipedia.

At CoolVDS, we see this battle play out daily across our Oslo data center. Clients migrate from shared hosting to our VPS platform expecting miracles, but if your software architecture is flawed, even our enterprise hardware can't save you from a configured bottleneck. Let's dissect the differences.

The Incumbent: Apache 2.2

Apache is the tank of the web. It is armored, versatile, and heavy. Its primary architecture (on Linux) usually relies on the Prefork MPM (Multi-Processing Module). This means every incoming connection spawns a dedicated process or uses an idle one. This is excellent for stability—if one PHP script segfaults, it doesn't take down the whole server—but it is terrible for memory efficiency.

Consider a standard configuration in /etc/httpd/conf/httpd.conf:

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

If each Apache process with mod_php consumes 25MB of RAM, and you allow 150 clients, you need nearly 4GB of dedicated RAM just for the web server. In a world where a typical robust VPS has 512MB or 1GB of RAM, Apache becomes a resource hog immediately.

Pro Tip: If you are stuck with Apache, disable .htaccess checks. Setting AllowOverride All forces Apache to check every directory in the path for a config file, generating massive disk I/O. Set it to None and put your rules in the main config.

The Challenger: Lighttpd 1.4

Lighttpd takes a completely different approach. It is event-driven and asynchronous. Instead of spawning a heavy process for every user, it uses a single process with an event loop (using epoll on Linux) to handle thousands of connections simultaneously. It only wakes up when there is data to process.

The memory footprint is negligible. You can handle thousands of keep-alive connections with a few megabytes of RAM. This makes Lighttpd ideal for serving static content (images, CSS, JS) or acting as a load balancer.

However, it handles PHP differently. Since it doesn't embed PHP, it talks to PHP via FastCGI. This separates the web server from the application logic, which is actually a cleaner architecture, though slightly more complex to configure initially.

Configuration Comparison

FeatureApache 2.2Lighttpd 1.4
ArchitectureProcess-based (Blocking)Event-based (Asynchronous)
Memory UsageHigh (scales with connections)Low (constant)
ConfigurationComplex, distributed (.htaccess)Centralized (lighttpd.conf)
PHP Supportmod_php (native) or FastCGIFastCGI only

Real World Scenario: The "Slashdot Effect"

We recently assisted a Norwegian media outlet hosting on a CoolVDS plan. They were running a standard CentOS 5 stack with Apache. When a major news story broke, their traffic spiked from 50 concurrent users to 800.

The result: Apache hit its MaxClients limit. New visitors just saw a loading spinner until the request timed out. The server wasn't down, but it was useless. The load average was low, but RAM was exhausted by idle Keep-Alive connections waiting for data.

The Fix: We swapped Apache for Lighttpd. Because Lighttpd handles Keep-Alive connections without holding a dedicated process hostage, the memory usage dropped from 90% to 15%. The site stayed up, handling the 800 concurrents without breaking a sweat. The latency to the NIX (Norwegian Internet Exchange) remained under 2ms because the server wasn't swapping to disk.

Infrastructure: The Foundation of Speed

Software optimization is critical, but it cannot overcome slow hardware. In 2011, disk I/O is arguably the biggest bottleneck for database-driven sites. Whether you choose Apache or Lighttpd, if your MySQL database is waiting on a slow 7.2k RPM SATA drive, your Time-To-First-Byte (TTFB) will suffer.

This is why CoolVDS utilizes high-performance RAID10 SAS arrays and enterprise-grade SSD caching on our host nodes. Virtualization overhead (especially with older OpenVZ kernels) can introduce latency, which is why we meticulously tune our KVM host parameters to ensure your CPU cycles aren't stolen by "noisy neighbors."

Legal and Latency Considerations

For our Norwegian clients, hosting abroad is becoming a liability. Under the Personopplysningsloven (Personal Data Act) and the watchful eye of Datatilsynet, ensuring your user data stays within Norwegian jurisdiction is safer than relying on Safe Harbor agreements with US providers. Furthermore, the speed of light is immutable. Hosting in Oslo ensures your local users get the snappy response times they expect.

Verdict: Which One to Choose?

  • Choose Apache if: You rely heavily on .htaccess files (common in WordPress or Drupal shared environments), or you need specific modules not available elsewhere. It is the safe, compatible choice.
  • Choose Lighttpd if: You need to squeeze every ounce of performance out of a VPS, you are serving high-volume static files, or you are comfortable configuring FastCGI.

Ultimately, the best web server is the one you can configure securely. But do not let slow I/O kill your SEO efforts or user experience. Whether you deploy the "heavy lifter" or the "speed demon," ensure your foundation is solid.

Ready to test your configuration? Spin up a CoolVDS instance in Oslo. Our high-performance storage guarantees that your web server—be it Apache or Lighttpd—never waits on the disk.

/// TAGS

/// RELATED POSTS

Taming Latency: Tuning NGINX as an API Gateway on Linux (2015 Edition)

Is your REST API choking under load? We dive deep into Linux kernel tuning, NGINX upstream keepalive...

Read More →

Stop Letting Apache mod_php Eat Your RAM: The PHP-FPM Performance Guide

Is your server swapping during peak hours? We ditch the bloated Apache mod_php model for the lean, m...

Read More →

Stop Wasting RAM: Migrating from Apache mod_php to Nginx & PHP-FPM on CentOS 6

Is your server swapping out under load? The old LAMP stack architecture is dead. Learn how to implem...

Read More →

PHP-FPM vs mod_php: Tuning High-Performance LAMP Stacks in 2011

Is your Apache server thrashing under load? Stop relying on the bloated mod_php handler. We dive dee...

Read More →

Stop Using mod_php: Optimizing PHP Performance with FPM and Nginx

Is your web server struggling under load? Learn why moving from Apache's mod_php to PHP-FPM and Ngin...

Read More →

Stop Watching 'wa' in Top: Why Spinning Disks Are the Bottleneck in 2011

Is your server load spiking despite low CPU usage? The culprit is likely I/O wait. We break down why...

Read More →
← Back to All Posts