Re: [Hampshire] Apache expertise required

Top Page
Author: Andy Smith
Date:  
To: hampshire
Subject: Re: [Hampshire] Apache expertise required

Reply to this message
gpg: failed to create temporary file '/var/lib/lurker/.#lk0x57b63100.hantslug.org.uk.5853': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Sun Apr 28 00:18:02 2013 BST
gpg: using DSA key 2099B64CBF15490B
gpg: Can't check signature: No public key
Hi Chris,

On Sat, Apr 27, 2013 at 05:32:23PM +0100, Chris Dennis wrote:
> It may be that it doesn't have enough RAM (300MB) for Apache to run
> WordPress properly. Or perhaps I just haven't configured things
> right.


I bumped the memory up a bit to 480MiB BTW. Sorry I can't offer any
more just now. You'll need to shut it down and boot it again
(*NOT* reboot) to see the extra RAM.

If you have never touched the Apache settings then you are probably
running the whole virtual machine out of memory. Look at how big an
individual Apache child is in terms of resident memory:

$ ps -C apache2 -O rss
  PID   RSS S TTY          TIME COMMAND
 1464 25084 S ?        00:00:04 /usr/sbin/apache2 -k start
 2733 26320 S ?        00:00:04 /usr/sbin/apache2 -k start
 3752 23492 S ?        00:00:03 /usr/sbin/apache2 -k start
 4116 26448 S ?        00:00:00 /usr/sbin/apache2 -k start
14938  6544 S ?        00:00:50 /usr/sbin/apache2 -k start
32282 28560 S ?        00:00:14 /usr/sbin/apache2 -k start


So, ignoring the 6544 outlier, that's about 26MiB on average.

Next look at how you've configured Apache with regard to the MPM in
use. If you've never changed this then the default prefork MPM is
probably in use, and you'll find something like this in
/etc/apache2/apache2.conf (Debian):

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
    StartServers          2
    MinSpareServers       1
    MaxSpareServers       5
    MaxClients           10
    MaxRequestsPerChild   0
</IfModule>


It's MaxClients you're most interested in. 10 times 26MiB is 260MiB
so that's how much resident memory you'll need. If your MaxClients
were set to a common default like 256 and your RSS was 15MiB then
you're looking at 3.8GiB RAM at peak usage.

If Apache's usage of memory pushes the system into swap then
everything will get very slow very quickly. You may end up having to
reboot the VM.

So it is better to scale back the MaxClients to the point where that
is not possible.

That does not, however, make your web serving any faster. It just
stops the host from dying.

To make Apache scale further the simplest way is to allow it to run
more processes at once, so that means either more RAM or smaller
processes.

You may be able to shrink your typical Apache process by disabling
unneeded modules. "ls /etc/apache2/mods-enabled/" on Debian shows
you what's there. Some of these will be essential for what you want
to do.

Once you've gone as far with that as you can reasonably go, and once
you're sure it's not some unrelated software or an application
problem, the next scaling step is normally to put a lightweight
reverse proxy in front of Apache.

Popular reverse proxies are Nginx and Lighttpd. They accept the
client connections, generally aggressively cache and answer from
there where possible, refer back to an app server backend
(Apache+Wordpress) only when necessary. You try to make sure that
all static content is being cached so Apache never gets consulted
for images, css etc.

There are tons of guides on fronting Apache with Nginx or Lighttpd
for this purpose.

Once you go as far as you can with that, consider serving static
assets from a CDN, and having Wordpress drop the site down to a
static version of itself once load gets too high.

Cheers,
Andy

--
http://bitfolk.com/ -- No-nonsense VPS hosting
--
Please post to: Hampshire@???
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--------------------------------------------------------------