Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm wondering how often apache and mysql should be restarted (in particular having 150K hits/week), and what would be the actual benefit in restarting every certain time.

share|improve this question

6 Answers 6

If you're system is properly tuned and your application doesn't have any issues like memory leaks, you should only every have to restart them to apply patches.

share|improve this answer

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.

share|improve this answer
    
What does this mean: Most databases servers run better the longer they have been up? What does better mean? –  Tshepang Jul 19 '11 at 22:57

With Debian, Apache restart when the system rotate the log files.

from /etc/logrotate.d/apache2:

...
postrotate
if [ -f /var/run/apache2.pid ]; then
   /etc/init.d/apache2 restart > /dev/null
fi
...
share|improve this answer
    
That doesn't really answer the question of when it should be restarted. From a basic point of view, you should avoid doing it whenever possible. –  Rob Dec 28 '09 at 23:10

In order to understand when a system or service needs to be rebooted you first need to understand why. Memory leaks are the most common reason but there may be others, such as poorly written software (all too common!) that doesn't perform proper internal housekeeping, such as closing file handles when they are no longer required. While not being the same as a memory leak the symptoms are the same. Both Apache and MySQL are known to be very stable (unless you're running an alpha or beta version) and can run for years without issue. Normally the operating system will need rebooting to apply patches long before either application will require it.

share|improve this answer

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.

share|improve this answer

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[1] 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.

[1] e.g. every 9 months on a busy server with > 100 queries per second average

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.