Help with server slowing way down and going into swap

I'm relatively inexperienced with the specific settings for servers and I'm reading all I can, so please be patient.

We have a Linode512 with Debian 6.0 and using Apache2 to run a Wordpress front side of a site and a phpBB3 forums area. The site is www.feelslike98.com and about 88% of pageviews are in the forums.

The server is slowing down a lot at times. Using the Linode graphs I figured out it's IO spikes, mostly caused by memory going into swap.

I started watching the server with htop and did some research and realized it might be the MaxClients setting for MPM prefork that's letting memory run out. I backed the default number down from 150 to 30, but that seemed to make things worse. I currently have it at 80 and things are ok, but it still goes into swap.

It seems each process for apache is using about 16.8MB and the listed available memory is 497.

/usr/sbin/mysqld also consistently is using 10 processes each with 2.7% of available memory.

Just from reading, some things I'm considering looking at are lightpd and FastCGI.

Any opinions on what settings to change or things to install to help? Any input appreciated.

10 Replies

Do you have apc installed? that will help a lot with phpbb

APC might only use more memory since it's an opcode cache….

I have had good success running phpbb on lighttpd so that is definitely an option. Apache is generally a resource hog when it comes to RAM and switching webservers might help you out.

Try "MaxClients" of about 20 or so, and be sure to disable Keepalives (or set the timeout to ~1 second)… that should get it to stop killing itself. Running PHP within Apache requires mpm-prefork, and Apache's default settings aren't great for mpm-prefork on systems with a finite amount of RAM.

@Ghan_04:

APC might only use more memory since it's an opcode cache….

I have had good success running phpbb on lighttpd so that is definitely an option. Apache is generally a resource hog when it comes to RAM and switching webservers might help you out.

Yes, APC takes up some memory, but because it's a cache, it means you can keep a number of requests from hitting the database. In turn, you lower the maxclients because most users will be served quickly.

@glg:

Yes, APC takes up some memory, but because it's a cache, it means you can keep a number of requests from hitting the database.
APC doesn't help reduce database queries. It's not that kind of cache. Unless you use the variable cache functions, which very few people seem to do.

APC prevents the PHP runtime from compiling the same scripts over and over again. Half of PHP script execution time is spent compiling, so skipping this step can easily make your scripts twice as fast.

@hybinet:

@glg:

Yes, APC takes up some memory, but because it's a cache, it means you can keep a number of requests from hitting the database.
APC doesn't help reduce database queries. It's not that kind of cache. Unless you use the variable cache functions, which very few people seem to do.

APC prevents the PHP runtime from compiling the same scripts over and over again. Half of PHP script execution time is spent compiling, so skipping this step can easily make your scripts twice as fast.

FWIW, phpBB3 actually can use APC as a SQL result cache (as opposed to using its native filecache). Take a look:

https://github.com/phpbb/phpbb3/blob/ma … cm_apc.php">https://github.com/phpbb/phpbb3/blob/master/phpBB/includes/acm/acm_apc.php

Also worth noting is that if you're on a prosilver style with phpBB, you're calling style.php every pageload, which is pretty taxing with performance. Use a subsilver-based style, or hack phpBB itself to use a static version of the stylesheet - it WILL net you some performance, it drops the amount of processing per user pageload drastically.

SMF forum also uses APC (or xcache, memcached, …) for the same purpose.

But yes, on its own, APC only does opcode caching.

Thanks a lot. I lowered MaxClients a lot, Set KeepAlive to 2 seconds, and installed php-cgi. It's staying out of swap much better now.

I want to let it run a bit to get a baseline, but will likely install APC.

I wonder if I need to optimize MySQL, though. There's 10 processes running (/usr/sbin/mysqld) and they seem to have grown a bit in size, now taking 5.1% of memory each. That's half my memory, although I know that's not a real number, as free memory is often greater than half. Any recommendations there?

@Obsidian:

FWIW, phpBB3 actually can use APC as a SQL result cache (as opposed to using its native filecache).
Thanks for correcting me there. Is this automatically activated when APC is installed, or does the admin need to change a setting?

@volantis:

I wonder if I need to optimize MySQL, though.
For basic tuning, nothing beats this script: http://mysqltuner.pl

@hybinet:

@Obsidian:

FWIW, phpBB3 actually can use APC as a SQL result cache (as opposed to using its native filecache).
Thanks for correcting me there. Is this automatically activated when APC is installed, or does the admin need to change a setting?

@volantis:

I wonder if I need to optimize MySQL, though.
For basic tuning, nothing beats this script: http://mysqltuner.pl
Apologies for the late reply - you need to change the acm setting (should be something that mentions ACM anyways) in the config.php file to get it to use APC for the cache module.

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