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

Apache vs Lighttpd: Surviving the C10k Problem on Your VPS

@

Apache vs. Lighttpd: Surviving the C10k Problem on Your VPS

Let’s be honest. If you are running a standard LAMP stack on a VPS with 512MB or even 1GB of RAM, you have likely woken up to a server that has panic-swapped itself to death. The culprit is almost always Apache. It is the reliable workhorse of the internet, powering over 50% of websites, but it is heavy. It is old.

I have seen perfectly good marketing campaigns in Oslo crash and burn not because the code was bad, but because httpd processes multiplied until the server choked. Today, we are looking at the heavyweight champion, Apache 2.2, and the agile challenger, Lighttpd 1.4 (Lighty). Which one belongs on your node?

The Apache Architecture: Process Heavy

Apache usually runs the MPM prefork module. This is great for stability and compatibility, specifically with non-thread-safe libraries in PHP. However, it handles concurrency by spawning a new process for every single connection.

Do the math. If one Apache process consumes 15MB of RAM (a conservative estimate with PHP loaded) and you get 100 concurrent users, you need 1.5GB of RAM just for the web server. That doesn't account for MySQL or the OS overhead.

Pro Tip: If you are stuck with Apache, stop letting it spawn infinitely. Edit your httpd.conf and cap the MaxClients based on your actual available RAM, not the default 256.
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients           50
    MaxRequestsPerChild 500
</IfModule>

The Lighttpd Alternative: Asynchronous Speed

Lighttpd (Lighty) takes a different approach. It uses an asynchronous, event-driven architecture. In Linux environments like our CoolVDS nodes, it utilizes epoll(). This allows a single process to handle thousands of connections effectively.

Instead of embedding PHP directly into the web server process (like mod_php), Lighttpd talks to PHP via FastCGI. This separates the serving of static content (images, CSS, JS) from the dynamic code execution.

Why Lighttpd Wins on Static Content

When a user requests a JPEG from Apache, an entire heavyweight process (with the PHP engine loaded) is tied up just to hand over a file. That is wasteful. Lighttpd uses a tiny amount of memory to serve that same file using sendfile() system calls.

Feature Apache 2.2 Lighttpd 1.4
Architecture Process/Thread based (Blocking) Event-driven (Asynchronous)
Memory Usage High (scales with traffic) Low (constant)
Configuration .htaccess (Dynamic) lighttpd.conf (Centralized)
Best For Shared hosting, complex rewrite rules High-load static files, FastCGI

The Trade-off: Convenience vs. Raw Power

Apache is still the king of convenience. The .htaccess file allows developers to change rewrite rules and configuration options without restarting the server. This is essential for shared hosting environments. If you move to Lighttpd, .htaccess does not work. You must translate those rules into lighttpd.conf syntax and reload the service.

However, for a dedicated project, that trade-off is worth it. We recently migrated a high-traffic media site targeting the Ukrainian market from Apache to Lighttpd. The load average dropped from 5.0 to 0.4. The memory usage dropped by 70%.

Hardware Matters: The CoolVDS Factor

Software tuning only gets you so far. You need I/O performance. Many VPS providers in Norway oversell their storage, putting fifty customers on a single SATA drive. When everyone hits the disk at once, your fancy web server config won't save you.

At CoolVDS, we don't play those games. We use Enterprise 15k RPM SAS RAID-10 arrays. We utilize Xen virtualization to ensure strict resource isolation. Unlike OpenVZ, where a noisy neighbor can steal your CPU cycles, Xen guarantees that the RAM and CPU cores you pay for are actually yours.

Furthermore, latency is critical. If your target audience is in Oslo or Bergen, hosting in Germany or the US adds unnecessary milliseconds. Our datacenter is directly peered at NIX (Norwegian Internet Exchange). Combining Lighttpd's efficiency with our low-latency network means your content hits the user's browser instantly.

Privacy and Compliance

For our Norwegian clients, data location is becoming a serious topic under the Personopplysningsloven (Personal Data Act). Keeping your data on Norwegian soil satisfies Datatilsynet requirements and ensures you aren't subject to foreign jurisdiction surprises.

Verdict: Which one should you choose?

Choose Apache if:

  • You rely heavily on .htaccess files.
  • You are using a CMS that assumes Apache (like standard WordPress installs without caching plugins).
  • You have plenty of RAM and low concurrency.

Choose Lighttpd if:

  • You are facing the C10k problem (10,000 concurrent connections).
  • You want to maximize the resources of your VPS.
  • You serve a lot of static media (video, images).

Don't let disk I/O bottlenecks or bloated processes kill your uptime. Deploy a Xen VPS with us today and see the difference real hardware makes.

Ready to optimize? Launch a CoolVDS instance in Oslo now.

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

Xen vs. KVM: Why Kernel Integration Wars Define Your VPS Performance

Red Hat Enterprise Linux 6 has shifted the battlefield from Xen to KVM. We analyze the kernel-level ...

Read More →

Escaping the Shared Hosting Trap: A SysAdmin’s Guide to VDS Migration

Is your application choking on 'unlimited' shared hosting? We break down the technical migration to ...

Read More →

IPTables Survival Guide: Locking Down Your Linux VPS in a Hostile Network

Stop script kiddies and botnets cold. We dive deep into stateful packet inspection, fail2ban configu...

Read More →

Sleep Soundly: The Paranoid SysAdmin's Guide to Bulletproof Server Backups

RAID is not a backup. If you accidentally drop a database table at 3 AM, mirroring just replicates t...

Read More →
← Back to All Posts