How often should Apache and MySQL be restarted? – Problems with loading a website are often blamed on the Internet connection, but even the most perfectly set up network cannot help if there is no service to reply at your destination. One of the most popular HTTP servers used for this task is Apache2. Much of Apache’s popularity can be attributed to its easy installation and use, but never the less it is possible to run into problems with even the easiest of the software. If you’ve encountered an issue loading your web page, follow these simple troubleshooting methods outlined in this guide to attempt to get your web server back up and working again. Below are some tips in manage your apache2 server when you find problem about apache-2.2, mysql, , , .
How often should Apache and MySQL be restarted (in particular having 150K hits/week), and what would be the actual benefit in restarting every certain time?
If your system is properly tuned and your application doesn’t have any issues like memory leaks, you should only ever have to restart them to apply patches.
Apache and MySQL by themselves should be free of memory leaks. Most databases servers run better the longer they have been up. However, modules which are compiled into Apache like PHP often have memory leaks.
The Apache mpm module automatically recycles processes after 10,000 requests. You can change the
MaxRequestsPerChild to something different, but 10,000 is a reasonable default.
Apache does not need regular restarting; nor should MySQL.
Apache running in prefork mode can recycle its child processes using MaxRequestsPerChild; this is a good thing as it defends against slow memory leaks, etc.
MySQL should not be restarted regularly, as restarting it will cause a service outage. Restarting MySQL needs to wait for the engines to start up and will also clear out the cache causing performance to suck until it warms up. We seem to find that it needs restarting from time to time because of address space fragmentation, but this should not happen so much on a 64-bit system, which new installations should always go on to.
 e.g. every 9 months on a busy server with > 100 queries per second average
You should avoid restarting MySQL whenever possible for performance reasons. MySQL uses lots of memory to cache data pages and indexes. When you restart MySQL, all cached pages are freed and you need some time to warm up caches. On highly loaded sites database restart could cause performance problems.
Your site is not heavily loaded (150k hits/week gives only 1req/4s), so MySQL restart should not cause big problems.