Get rid of mysql sleep process/connections
Some times there are many many sleep processes in your SQL connection. These sleep connections consume a lot of resources (RAM, cache and processor). This can cause you mysql server slow down. If your mysql server is not responding then the query to the database will take a lot of time. In such situations, your website will open very slowly.
This is really frustrating for webmasters. Here, I will show you how can you get rid of these sleep processes.
What is sleep process and Why are there too many sleep process in mysql?
Sleep process are the connections waiting for new Mysql query. This can happen if the database connection is not closed properly. Or you are using mysql_pconnect() command in your php script.
How To Get Rite of Sleep Process?
It is very important to close the DB connection after the query is done.
To do this, add mysql_close() function at end of the every script that has an open mysql connection. It will close the connection and it will not go into sleep.
There is another way to do so . If you have the root access to your server then you can edit my.cnf using following command
First Find my.cnf
$Locate my.cnf
It will show the location of mysql configuration file then use following command to edit my.cnf
$vi /etc/my.cnf
And add this line in my.cnf
wait_timeout = 60
where time is in second
Thus, the connections will automatically be closed after waiting for 60 seconds.
These are little webmaster tips that can help you improve the performance of your website.
Thanks for a great tip, will try this out ASAP!!
I searched for tags and ”Web Site Optimization” Tag was attacted me,this is why I am here now. I thought that this article was realted to Seo (in Turkish it means :”Arama Motoru Optimizasyonu” or Optimizasyon). But I read your article at the end of this and I learnt a new Optimization(Optimizasyon) part.My SQL of course so important. Thank you very much for new and detailed my SQL sleep process article here for sharing with us.
I can advice a web site related to Web Optimization Process in Turkish Language but using Google Translate everybody can understand the SEO and Google Seo or other search engines (means arama motorları) process from this:
http://www.aramamotoruoptimizasyonu.gen.tr
I wanted to share this valuable Optimization Site for Search engines.