Web Hosting Infrastructure – Part 2

Tuning your Web Hosting Infrastructure

Let 4word Systems help you with some basics for tuning your Web Hosting Infrastructure.

In our last installment, we made a big deal about splitting off a database server from a web server for performance reasons. This time we'll talk about how to properly tune the Apache web server.

The Biggest Mistake in Web Hosting

Simply put, the biggest mistake in web hosting today is leaving Apache in the standard configuration to run a PHP app. Unless you have servers with way too much RAM (32gb or more), it's a crash waiting to happen. 80-90% of all the web server crashes we have seen have been the result of allowing Apache to overrun physical RAM on the machine and swap out to disk. If you are running in 16gb or less of RAM with the stock Apache configuration, it is almost inevitable that you will encounter this problem at some point in the future.

Tuning Apache for PHP

By default, the Apache web server ships with a configuration that is terribly wrong for running a PHP application like WordPress or Magento. It seems that the Apache folks think that most users won't install any of the memory-hogging modules that are not shipped as part of the core product. As a result, the default configuration assumes a very small "per-thread" memory footprint.

It's All About the RAM

The fact is that most web servers that use Apache these days are configured to run PHP, and PHP is a memory hog. So much in fact, that a whole list of add-ons like APC and eAccellerator have been created to help it perform better. Even so, the reality is that a single Apache process running PHP can be many tens of megabytes of RAM. When compared to a "vanilla" Apache footprint on the order of 1MB or less (per-thread), this is a major difference that can not be overlooked.

The Solution is Simple

Believe it or not, the solution is extremely simple. There are only 2 things you need to know, and one thing you need to do to make this nightmare disappear for good.

What You Need to Know

  1. Total amount of RAM available to run Apache processes before swapping to disk
  2. Average size of a running Apache process

Once you have that information, simply take the total amount of RAM available to Apache, divide by the average process size, and you have a good benchmark for setting a hard "limit" to the number of processes allowed to run simultaneously. Once you have that number, you should subtract around 15% to account for variations from the average size.

If you need help figuring these things out, drop us a line and we'll give you a hand.

What You Need to Do

In the primary Apache configuration file (httpd.conf), set the value of MaxClients to the number you determined by the previous calculation. Reload the configuration (apachctl reload, service httpd reload, /etc/init.d/httpd reload, or whatever your Linux flavor happens to be), and you're protected from the dreaded memory overrun.

Do it NOW

If you've not done this already, we highly recommend that you make it a priority. This simple fix will most likely save you a lot of head-scratching and downtime.

About Steve Szettella

Love to Jeep, Ski, Golf, and Travel. Living near Boulder Colorado. Founder and president of 4word Systems - among other things.

Speak Your Mind

Mobile Version