Databases Reference
In-Depth Information
Web Server Issues
Apache is the most popular server software for web applications. It works well for many
purposes, but when used badly it can consume a lot of resources. The most common
issues are keeping its processes alive too long, and using it for a mixture of purposes
instead of optimizing it separately for each type of work.
Apache is usually used with mod_php , mod_perl , and mod_python in a “prefork” config-
uration. Preforking dedicates a process for each request. Because the PHP, Perl, and
Python scripts can be demanding, it's not uncommon for each process to use 50 or 100
MB of memory. When a request completes, it returns most of this memory to the
operating system, but not all of it. Apache keeps the process open and reuses it for
future requests. This means that if the next request is for a static file, such as a CSS file
or an image, you'll wind up with a big fat process serving a simple request. This is why
it's dangerous to use Apache as a general-purpose web server. It is general-purpose,
but if you specialize it, you'll get much better performance.
The other major problem is that processes can be kept busy for a long time if you have
Keep-Alive enabled. And even if you don't, some of the processes might be staying alive
too long, “spoon-feeding” content to a client that is fetching the data slowly. 1
People also often make the mistake of leaving the default set of Apache modules en-
abled. You can trim Apache's footprint by removing modules you don't need. It's sim-
ple: just review the Apache configuration file and comment out unwanted modules,
then restart Apache. You can also remove unused PHP modules from your php.ini file.
The bottom line is that if you create an all-purpose Apache configuration that faces the
Web directly, you're likely to end up with many heavyweight Apache processes. These
will waste resources on your web server. They can also keep a lot of connections open
to MySQL, wasting resources on MySQL, too. Here are some ways you can reduce the
load on your servers: 2
• Don't use Apache to serve static content, or at least use a different Apache instance.
Popular alternatives are Nginx ( http://www.nginx.com ) and lighttpd ( http://www
.lighttpd.net ) .
• Use a caching proxy server, such as Squid or Varnish, to keep requests from ever
reaching your web servers. Even if you can't cache full pages on this level, you
might be able to cache most of a page and use technologies such as edge side
1. Spoon-feeding occurs when a client makes an HTTP request but then doesn't fetch the result quickly.
Until the client fetches the entire result, the HTTP connection—and thus the Apache process—stays alive.
2. A good book on how to optimize web applications is High Performance Web Sites by Steve Souders
(O'Reilly). Though it's mostly about how to make websites faster from the client's point of view, the
practices he advocates are good for your servers, too. Steve's follow-up book, Even Faster Web Sites , is
also a good resource.
 
Search WWH ::




Custom Search