Tuning Apache

Hi all. Ran into a troubling problem yesterday with a website I host on a Linode 120. Traffic was a bit higher than usual, but the server began to crawl so bad that I could not even log-in via SSL.

Can anyone who has experience on tuning Apache for Linode give me some advice?

I would like to tune Apache to be as responsive as is possible, but not kill the machine if it gets pounded on.

Specs:

Linode 120 - 120Mbytes of RAM

Lots of disk space available

Debian 3.0r1 Small

Apache 1.3

  • modules running:

  • modlogconfig

  • modmimemagic

  • mod_mime

  • mod_autoindex

  • mod_dir

  • mod_alias

  • mod_rewrite

  • mod_access

  • mod_auth

  • mod_expires

  • moduniqueid

  • mod_setenvif

  • mod_ssl

  • mod_lib4php

PHP 4.3.10-16

MySQL 4.0.24

I average ~1000-5000 users per day, maybe 4x that in page views, each page runs on average ~4 MySQL queries.

Can someone suggest a few of the more common httpd.conf settings that would be most appropriate in this setup (ie. MinSpareServers, MaxSpareServers, KeepAliveTimeout, MaxClients, MaxRequestsPerChild) Anything special I can do to lighten the Apache footprint so to speak? Are any of the modules un-needed? I use mod rewrite, mod ssl, mod php for sure, not sure about some of the others.

I realize that my performance issues are much more likely to be MySQL related, but I just want to be sure my Apache is humming along like a fine-tuned machine before touching my.cnf. And yes, I am performing a code audit to try and tighten up the more intensive code and reduce database trips. (EXPLAIN SELECT is great)

Thanks for the advice!

17 Replies

MaxKeepAliveRequests 32 KeepAliveTimeout 20 MinSpareServers 5 MaxSpareServers 10 StartServers 5 MaxClients 10 MaxRequestsPerChild 32

Adjust to suite, but those will get you close. Just for a reference…

For mysql, have a look at these, specifically the buffer values. You could go even lower…

http://www.theshore.net/~caker/uml/my.cnf

http://www.theshore.net/~caker/uml/my.c … stable.txt">http://www.theshore.net/~caker/uml/my.cnf-debian-unstable.txt

-Chris

This is exactly what I needed. Have tuned Apache, MySQL accordingly.

I don't suppose you have any way of speeding up SSL processing on Apache… ;-) My server is pretty slow when members are in their secure account areas.

Thanks again!

Linode.com is run under a UML Linode (granted, with lots of RAM), but SSL doesn't seem to be an issue there. More info?

-Chris

In general, it is just a little slow, which I know is a given with SSL. Just looking to make sure I have everything possible tuned up.

Well, found this article, some of it doesn't apply to linux, but disabling 3DES seems like a good idea for the speed bonus you may get. Am I nuts or would following some of this work?

http://www.kom.com/apache_tune.html

I did add the SSLCipherSuite line, and it seems more responsive on my SSL pages. Will have to figure out how to test that.

@caker:

MaxKeepAliveRequests 32
KeepAliveTimeout 20
MinSpareServers 5
MaxSpareServers 10
StartServers 5
MaxClients 10
MaxRequestsPerChild 32

Adjust to suite, but those will get you close. Just for a reference…

For mysql, have a look at these, specifically the buffer values. You could go even lower…

http://www.theshore.net/~caker/uml/my.cnf

http://www.theshore.net/~caker/uml/my.c … stable.txt">http://www.theshore.net/~caker/uml/my.cnf-debian-unstable.txt

-Chris

Hi Chris,

Do you know if these can also be applied Apache2?

Steve

Apache2 is a little different. You first need to determine which MPM you're running under. To do that, I believe you can run "httpd -V | grep MPM". Once you have that, you can modify the appropriate section of your httpd.conf file.

-Chris

on the note of MPM which one are linoders generally running?

I was running prefork, but am thinking about changing over to worker, as it is supposed to be better.

My only issues are that i use both PHP and TOMCAT, from which java is run via mod-jk and im not sure if worker is compatabile with mod-jk. and PHP will run via suexec.

I'm using prefork, since I use mod_php and it needs that worker.

(btw, the best bet would be "apache2ctl -V | grep MPM" instead of "httpd -V | grep MPM".)

The Apache tuning technique I found works best is 'apt-get remove apache && apt-get install lighttpd'. If you need something unique to apache (e.g. Tomcat, I suppose) this is no good, of course, but I've found running PHP under fastcgi with lighttpd to be a lot less memory intensive than Apache/mod_php. Less memory for the webserver means more memory available for the DB, which is always good.

@Internat:

on the note of MPM which one are linoders generally running?

From http://packages.debian.org/unstable/net … mpm-worker">http://packages.debian.org/unstable/net/apache2-mpm-worker

High speed threaded model for Apache HTTPD

The worker MPM provides a threaded implementation for Apache HTTPD. It is considerably faster than the traditional model, and is the recommended MPM.

Worker generally is a good choice for high-traffic servers because it has a smaller memory footprint than the prefork MPM.

On my linode, ubuntu hence debian, 'apache2ctl -V | grep MPM' yields

-D APACHEMPMDIR="server/mpm/worker"

I started out with prefork and found that with skunkweb ( http://skunkweb.sourceforge.net/about.html ) I didn't need it, as the skunkweb processes are independent so I just kill 'em when needed or out of programmatic laziness - the simplest total process cleanup is to kill the process and let skunkweb's process pool manager generate another process in the background.

James

@Internat:

on the note of MPM which one are linoders generally running?

I just dropped lighttpd after running it for the last ~2 years!? Nothing wrong with lighttpd, just tired of knowing how to do things (config settings) in apache and have to figure out how to pull off the same thing with lighttpd.

I did also need php5 support, but rather than use the pre-fork, I stayed with the threaded model by utilizing mod_fcgid.

If anyone cares how to set up this config rather than write it again… blog posting.

I'll monitor and see how it runs over the next couple weeks.

Hi, i'm using this topic instead start a new one because i need help on the same issues (i apologize if i'm wrong).

I've a (debian etch) linode 1440 that runs "only" apache2+mysql5+php5, to host a phpbb board with about 300/400 users connected at the same time, and i noted that it use a huge amount of cpu (max 203% avg 69%, about 100~160 in daylight) almost totally used by apache (which use Server MPM: Prefork).

So i wonder if there is a way to decrease the cpu usage.

Thanks in advance.

P.S.

Sorry for my bad english.

@Floppy:

I've a (debian etch) linode 1440 that runs "only" apache2+mysql5+php5, to host a phpbb board with about 300/400 users connected at the same time…

If you are running Apache2 + PHP5 I presume you are using mod_php? So the CPU time used by Apache could have been used by PHP instead.

Tried op-code accelerators like xcache?

@scotty:

Tried op-code accelerators like xcache?

Not yet, how do they work and how can i install (and configure) one of them?

HowtoForge has a few nice tutorials on intergrating op-code accelerators.

These two are for debian & apache with php5

http://howtoforge.com/apc-php5-apache2-debian-etch

http://howtoforge.com/xcache-php5-apache2-debian-etch

And if you decide to switch to lighthttpd

http://howtoforge.com/xcache-php5-lighttpd-debian-etch

@Floppy:

Not yet, how do they work and how can i install (and configure) one of them?

As you are on Etch.

$ sudo apt-get install php5-xcache

And just restart Apache after that. You might also look at /etc/php/conf.d/xcache.ini to fine tune your settings (like increasing the cache size since you are running a linode 1440).

Those op-code cache/optimisers basically caches the parsed and compiled PHP byte code in memory so there is no need to re-parse/compile again for subsequent requests. They do a bit more like runtime optimisation and share memory API but they are usually a bit more experimental.

It seems that i can find xcache only in sid's repositories, but i'm running a stable version, install it from them may cause me any problem?

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct