Why httpd graceful restart takes such a long time?

I am checking /usr/local/apache/logs/error_log

This has happened several times. Sometimes server restart is fast sometimes it's slow. What factor could possibly contribute to this mess.

[Mon Dec 31 21:40:49 2012] [notice] Graceful restart requested, doing restart
[Mon Dec 31 21:40:53 2012] [error] [client 66.249.74.237] File does not exist: /home2/wallpape/public_html/tag
[Mon Dec 31 21:40:53 2012] [error] [client 66.249.74.237] File does not exist: /home2/wallpape/public_html/404.shtml
[Mon Dec 31 21:50:02 2012] [notice] SSL FIPS mode disabled
[Mon Dec 31 21:50:03 2012] [notice] Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 configured -- resuming normal operations

On the other hand ungraceful restart seems to be faster:

[Mon Dec 31 21:52:58 2012] [notice] SIGHUP received.  Attempting to restart
[Mon Dec 31 21:52:58 2012] [notice] SSL FIPS mode disabled
[Mon Dec 31 21:52:58 2012] [notice] Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 configured -- resuming normal operations

From the manual: http://httpd.apache.org/docs/2.2/stopping.html

The parent re-reads its configuration files and re-opens its log files. As each child dies off the parent replaces it with a child from the new generation of the configuration, which begins serving new requests immediately.

It seems that graceful restart is designed so that service can run with no interruption at all. It doesn't work that way though. All domains in my server is death while restarting :(


Solution 1:

A graceful restart waits for all current connections to close before restarting, whereas a standard restart just aborts current connections.

Solution 2:

Note that if you have an invalid hostname in your etc/hosts file -- for example, if you did not modify the default installation settings -- then you may wait up to 90 seconds for various tasks to be performed, including starting/restarting httpd.

vi /etc/hosts

Change

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

To

127.0.0.1   localhost
::1         localhost
111.222.333.444  www.mysite.com mysite.com

References:

/etc/hosts entry for single IP server serving multiple domains

https://unix.stackexchange.com/questions/57439/slow-start-of-midnight-commander#answer-397879