How to optimize Apache and MySQL?
All errors were almost the same:
WordPress database error MySQL server has gone away for query...
I submitted a ticket. They told me to "tune the Apache MaxClients directive to limit the number of connections". Honestly I do not know how to set that numbers.
In my apache2.conf, it's:
<ifmodule mpm_prefork_module="">StartServers 16
MinSpareServers 8
MaxSpareServers 24
ServerLimit 400
MaxClients 200
MaxRequestsPerChild 500</ifmodule>
I think it's using prefork mpm (dont know how to check that out).
My control panel is ISPConfig.
I have been too afraid to put that site on my linode. Several months ago I've tried several times then finally I gave up. Now I have to face it. The shared hosting wont allow the site on it any more.
If any body can help me out, it would be so nice and I'm so happy.
Thank you so much!
19 Replies
@nfn:
Try to raise mysql wait_timeout in /etc/mysql/my.cnf
Mine is set to 300.
Hi, my MySQL database is not in localhost, it's in another shared hosting. I connected to that database from my Linode.
Moving MySQL to localhost will probably solve this. Or, you may want to use this workaround:
@saman007uk:
What is happening is that the MySQL server closes the connection - and when PHP tries to access it again, it fails.
Moving MySQL to localhost will probably solve this.
But at the same time, my other site which uses localhost MySQL was also down. I think there must be something wrong with apache.
@whatness:
I think it's using prefork mpm (dont know how to check that out).
You can do this with the -l option to the Apache server (depending on your system and version, probably either apache2 or httpd).
# apache2 -l
Compiled in modules:
core.c
mod_log_config.c
mod_logio.c
prefork.c
http_core.c
mod_so.c
On Linux, you'll probably see either prefork.c (the default) or worker.c. I think any others
@Vance:
You can do this with the -l option to the Apache server (depending on your system and version, probably either apache2 or httpd).
Hi, thanks! It's prefork.c.
It basically checks that the persistent connection is working before using it.
Also, this does not have anything to do with Apache directly - it is PHP which connects to the MySQl server through the php5-mysql library, not the Apache server itself.
http://wordpress.org/extend/plugins/wp-super-cache/
I hope this helps somewhat; the plugin is intended to make sites "Digg-proof." I've withstood a Slashdotting, if that's any indication of its worth.
> Site down again hours ago when the CPU usage jump to about 400%
If you haven't already, install munin (as is posted ad nausium elsewhere
Or for a quick (?) check, run a cron job every few minutes to append useful stats to a file.
Read this first
@refactorial:
Try reducing MaxClients to 35. You should see your performance improve dramatically.
Yay! that works! The site is up for one whole day now.
http://rathercurious.net/pdo-for-wordpress
did you look "ps aux" of what's going on on your box and what programs exactly are using the memory ?
also, if you don't want to completely replace apache you can consider using nginx as a reverse proxy and have it serve the static pages while you'd keep apache for just the PHP pages.