Console Login
Home / Blog / Server Administration / Apache vs Lighttpd: Surviving the C10k Problem on Norwegian VPS
Server Administration 9 views

Apache vs Lighttpd: Surviving the C10k Problem on Norwegian VPS

@

Apache vs Lighttpd: The Battle for RAM and Concurrency

It starts with a trickle, then a flood. Your latest campaign just hit the front page of VG.no or got linked on a major forum. Suddenly, your load average spikes to 15.0, your SSH session lags, and your Apache error logs are screaming server reached MaxClients setting. Welcome to the C10k problem.

As a systems architect managing infrastructure across the Nordics, I've seen this scenario play out dozens of times. The default reaction? "Buy more RAM." But throwing hardware at software inefficiency is a losing battle. Today, we are looking at the architectural difference between the grandfather of the web, Apache HTTP Server, and the lightweight contender, Lighttpd (pronounced "lighty").

If you are hosting on a Virtual Private Server (VPS) where resources are ring-fenced—like the KVM-based setups we advocate for at CoolVDS—every megabyte of RAM saved is a megabyte that can be used for your MySQL buffers.

The Heavyweight: Apache 2.2

Apache has been the backbone of the internet since the mid-90s. It is stable, modular, and the .htaccess file is a developer's best friend for quick overrides. However, in 2011, Apache's default architecture (Prefork MPM) is showing its age under heavy load.

Apache handles connections by spawning a new process (or thread) for every single user. This is reliable, but memory-intensive. If a PHP process takes 20MB of RAM and you have 500 concurrent users, you need a staggering 10GB of RAM just to keep the lights on. On a standard VPS, you will hit swap immediately.

The Optimization Trap

You can tune Apache, but there is a limit. A typical httpd.conf tweak involves lowering MaxClients to prevent swapping, but this simply queues users, increasing latency.

# Typical Apache Prefork limits for a 1GB VPS
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients           40  # Set too low, and users wait. Set too high, and OOM killer strikes.
    MaxRequestsPerChild 500
</IfModule>

The Flyweight: Lighttpd 1.4

Enter Lighttpd. Designed specifically to address the C10k problem (handling 10,000 concurrent connections), Lighttpd uses an asynchronous, event-driven architecture. Instead of blocking a process for every user, it uses a single process with an event loop (using epoll on Linux) to juggle thousands of connections.

The difference is night and day. I recently migrated a high-traffic media site serving static assets and PHP via FastCGI. The memory footprint dropped from 1.2GB to 45MB. Yes, megabytes.

Why Lighttpd Wins on VPS

On a CoolVDS instance, where we provide dedicated RAM and high-speed SSD storage, Lighttpd allows you to maximize the hardware. Because the web server itself consumes negligible resources, you can allocate almost all your system memory to innodb_buffer_pool_size in MySQL.

Pro Tip: Lighttpd doesn't use .htaccess files. This is actually a feature, not a bug. Apache scans directory trees for these files on every request, adding significant disk I/O overhead. Lighttpd forces you to centralize config, which is cleaner and faster.

Configuration Face-off

Configuring Lighttpd is arguably simpler than navigating Apache's XML-like structure. Here is how we set up a performant FastCGI handler for PHP in /etc/lighttpd/lighttpd.conf:

server.modules += ( "mod_fastcgi" )

fastcgi.server = ( ".php" =>
  (( 
    "socket" => "/tmp/php-fastcgi.socket",
    "bin-path" => "/usr/bin/php-cgi",
    "max-procs" => 4,
    "bin-environment" => (
      "PHP_FCGI_CHILDREN" => "16",
      "PHP_FCGI_MAX_REQUESTS" => "10000"
    ),
    "min-procs" => 1,
    "idle-timeout" => 20
  ))
)

Local Context: Latency and Compliance

For our clients in Norway, latency to the NIX (Norwegian Internet Exchange) is critical. While a web server can't fix network routing, an overloaded Apache server adds "think time" to the Time To First Byte (TTFB). Lighttpd responds almost instantly, ensuring that your low-latency connection from Oslo or Trondheim isn't wasted by application lag.

Furthermore, regarding the Data Inspectorate (Datatilsynet) and log retention: Lighttpd makes log rotation and anonymization straightforward. You can pipe logs directly to a script to mask IP addresses before they even hit the disk, keeping you compliant with the Personal Data Act without post-processing scripts chewing up CPU cycles.

The Verdict

Feature Apache 2.2 Lighttpd 1.4
Architecture Process/Thread based (Blocking) Event-based (Asynchronous)
Memory Usage High (Scales with connections) Low (Constant)
Configuration Complex (Distributed .htaccess) Simple (Centralized)
Best For Shared hosting, heavy dynamic modules High-traffic static content, VPS environments

If you are running a legacy application that relies heavily on complex Apache modules or .htaccess rewrite rules, Apache remains the safe choice. However, if your goal is raw performance, handling traffic spikes without upgrading your plan, and getting the most out of your SSD I/O, Lighttpd is superior.

At CoolVDS, we offer optimized templates for both. However, we consistently see that clients running Lighttpd (or the emerging Nginx) on our KVM nodes achieve 30-40% higher throughput than those on default Apache setups.

Ready to ditch the bloat? Deploy a high-performance Debian squeeze instance on CoolVDS today and experience true dedicated power.

/// 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