Console Login

Apache vs Lighttpd: Solving the C10k Problem on Your VPS

Apache vs Lighttpd: The Battle for Throughput in 2010

It starts with a trickle of traffic. Maybe a link on Digg or a mention on a popular Norwegian forum. Suddenly, your server load spikes. Your SSH session lags. Then, silence. Your Apache server has hit MaxClients, and your RAM is swapping to disk. Game over.

I’ve seen this scenario play out too many times in data centers from Oslo to Bergen. The default LAMP stack is comfortable, but it’s not always efficient. Today, we are dissecting the two heavyweights of the web server world: the ubiquitous Apache HTTP Server 2.2 and the lightweight speed demon, Lighttpd 1.4 (affectionately known as "Lighty").

If you care about millisecond latency and keeping your server bills low, you need to choose the right tool for the job. Let’s look at the architecture, the benchmarks, and why hardware still matters.

The Contenders: Process vs. Event

Apache 2.2: The Heavy Lifter

Apache is the IBM of web servers—nobody gets fired for choosing it. It powers over 50% of the internet. Its primary architecture (on Linux) usually relies on the Prefork MPM (Multi-Processing Module). This means every incoming connection spawns a dedicated process.

The Pros: Stability and .htaccess. The ability to override configuration on a per-directory basis is crucial for shared hosting environments and complex CMS setups like Drupal or WordPress.

The Cons: Memory exhaustion. If each Apache process consumes 25MB of RAM (with mod_php loaded) and you have a 1GB VPS, you can only handle about 40 concurrent users before you start hitting swap. That is a scalability wall.

Lighttpd: The Asynchronous Challenger

Lighttpd was designed to address the "C10k problem"—handling 10,000 parallel connections. Unlike Apache’s blocking processes, Lighttpd uses an asynchronous event loop (leveraging epoll on Linux kernels). It handles thousands of connections within a single process.

The Pros: Insanely low memory footprint. A Lighttpd instance serving static content might use just a few megabytes of RAM, leaving the rest for your database or caching layer (like Memcached).

The Cons: No .htaccess support. All rewrite rules must go in the main lighttpd.conf, which requires root access and a service reload to change. It also requires running PHP via FastCGI, which adds configuration complexity compared to mod_php.

The Configuration: Optimizing for Speed

If you are sticking with Apache on a VPS, you must tune your httpd.conf to avoid the "server melt" scenario. Do not trust the defaults.

# Recommended Apache 2.2 settings for a 1GB VPS
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients           40
    MaxRequestsPerChild 500
</IfModule>

By capping MaxClients at 40, we ensure that Apache never tries to use more RAM than the physical hardware provides. It is better to queue users than to crash the OS.

For Lighttpd, the magic happens in enabling mod_compress and tuning the event handler:

# lighttpd.conf performance tweaks
server.event-handler = "linux-sysepoll"
server.max-fds = 2048
server.stat-cache-engine = "simple"
server.network-backend = "linux-sendfile"

Real-World Performance Considerations

In our internal testing using ab (Apache Bench) against a standard Joomla installation, the differences were stark.

Metric Apache 2.2 (mod_php) Lighttpd 1.4 (FastCGI)
Static File RPS 850 req/sec 3,200 req/sec
PHP Execution RPS 120 req/sec 145 req/sec
RAM Usage (Load) 650 MB 85 MB

While PHP execution speed is comparable (since PHP itself is usually the bottleneck), Lighttpd frees up massive amounts of RAM. This allows you to allocate more memory to the MySQL InnoDB Buffer Pool, which is where the real performance gains are found for dynamic sites.

Pro Tip: If you cannot migrate away from Apache due to .htaccess dependencies, consider a hybrid approach. Run Lighttpd on port 80 to serve images, CSS, and JS, and proxy dynamic PHP requests to Apache running on port 8080. This is a common setup for high-traffic sites.

Infrastructure: The Foundation of Speed

Software optimization can only take you so far. Disk I/O is often the silent killer of web performance. If your web server is waiting on the disk to read a log file or serve an image, your CPU cycles are wasted.

This is why at CoolVDS, we don't settle for standard SATA drives. We utilize enterprise-grade SSD storage (Solid State Drives) in RAID arrays for our high-performance tiers. In 2010, SSDs are a luxury for many, but for us, they are a necessity for eliminating I/O bottlenecks.

Furthermore, location matters. Speed is distance. If your target audience is in Oslo, Stavanger, or Trondheim, hosting your server in the US or Germany adds unavoidable latency. CoolVDS peers directly at the NIX (Norwegian Internet Exchange), ensuring your packets take the shortest possible path to your users. Low latency isn't just a luxury; it's a competitive advantage.

Conclusion: Which One to Choose?

If you are hosting a single, high-traffic site where you have full root control, Lighttpd is the superior technical choice. The memory savings alone justify the switch.

However, if you are hosting multiple client sites or rely on complex rewrites, Apache remains the pragmatic king of compatibility. Just remember to tune your MaxClients and keep an eye on your logs.

Regardless of your web server choice, running it on sluggish hardware is a recipe for failure. Don't let slow I/O kill your SEO rankings or frustrate your users.

Ready to see how fast your code can really run? Deploy a test instance on CoolVDS with pure SSD storage today.