Apache's graceful restart (reprise)

In my last week's blog entry Urban legends: Apache reload(ed) I tried to prove that an Apache reload is quite exactly the same as the restart of an Apache web server.

One of my dear readers - yes, at least someone seems to read this blog - pointed out that this is not always true, and a reload sometimes work and sometimes not. In contrast to a restart, which always work like a charm.

I strongly assume that's a classic observer effect:

In physics, the term observer effect refers to changes that the act of observation will make on the phenomenon being observed.

Let's imagine: You have a web site, you have an Apache web server. With your browser you're on your web site, you change your Apache's configuration, you reload your Apache, you reload your browser, and - surprise - you don't see the new configuration active. You reload your browser again and again. Still, the old configuration. What's wrong?

Okay, let's do this step by step.

  1. My Apache is running:

    # apache2ctl status
                           Apache Server Status for localhost
    
       Current Time: Friday, 02-Oct-2009 11:46:29 CEST
       Restart Time: Friday, 18-Sep-2009 09:55:56 CEST
       Parent Server Generation: 12
       Server uptime: 14 days 1 hour 50 minutes 32 seconds
       87 requests currently being processed, 89 idle workers
    
    ..KK_._K_K.KK_._KK.KKK.K_K.K_K_._KKKK._KKK__._KK_C_KK_.KK.C_K__K
    K_K.K_K_KKK_KK_C_KKK__K_KKKK.KWK__KKKK.K_.__..K.._..___K___W__KK
    W_K_K_K_._K_K____K_K__K__K..K_KK__K______K_KK_K_K____K___K___.__
    .____K_K__._.K..................................................
    

    Three childs are closing the connection (C), 3 are sending a reply to any browser (W), 89 are waiting for a new connection (_) and 81 childs are kept alive by KeepAlive (K). The one red K represents my own bowser's connection.

  2. Now I'm reloading my Apache:

    # /etc/init.d/apache2 reload

    Wait a second, and ask again for the status:

    # apache2ctl status
                           Apache Server Status for localhost
    
       Current Time: Friday, 02-Oct-2009 11:47:04 CEST
       Restart Time: Friday, 18-Sep-2009 09:55:56 CEST
       Parent Server Generation: 13
       Server uptime: 14 days 1 hour 51 minutes 8 seconds
       71 requests currently being processed, 80 idle workers
    
    G.GG_.__GG.GG_._GG.___.___.____._GG__.__GGG_.K_GGK__K_.G_.___K_G
    ___.G___GGG_____KG__GG__.GG_.__GG__KG_.__._W.._.._..___GG__K_GG_
    _K__G_G_.GK_K____GKG__G___..K..G.KK..G...K.KGGWGC....KG..G......
    .GG...._G.._.G..................................................
    

    Now, after one or two seconds, 51 Apache childs are waiting for their graceful end. Including the G representing my own bowser's connection.

  3. In parallel I'm reloading my browser (which accesses the web site my Apache's hosting) in a 3 seconds interval.

  4. After 2 minutes I look again at my Apache's status:

    # apache2ctl status
                           Apache Server Status for localhost
    
       Current Time: Friday, 02-Oct-2009 11:48:40 CEST
       Restart Time: Friday, 18-Sep-2009 09:55:56 CEST
       Parent Server Generation: 13
       Server uptime: 14 days 1 hour 52 minutes 44 seconds
       77 requests currently being processed, 51 idle workers
    
    KKK__KKKWKK__K_K..W_K_KKK___K_K____K_K_K__.K_K.._K_K.K..KWK._KKK
    .K_._KKK_KK___..KG_K_KK___.K.KK__KK_K.KK_K_W..K.....__K..W__K..W
    _KK_._....K.KKK__.K.KK.K_K..K...._W......K.K.._.K....K..........
    .......K...K....................................................

    There is still one child process waiting for it's graceful end. That's the one I kept alive with of my own browser. And this child still has it's old configuration active and that's why I'll never notice the new config within my own bowser, but everyone else already got the new configuration.

  5. To catch up, I just have to wait at least KeepAlive seconds, and than doing a final reload in my browser.

    # apache2ctl status
                           Apache Server Status for localhost
    
       Current Time: Friday, 02-Oct-2009 11:49:00 CEST
       Restart Time: Friday, 18-Sep-2009 09:55:56 CEST
       Parent Server Generation: 13
       Server uptime: 14 days 1 hour 53 minutes 4 seconds
       63 requests currently being processed, 76 idle workers
    
    .K__KKKK_K_K______..KKK______W_K_C_K___KK.___KKK.___K_K__K__KKK.
    W_KC_KK_CK._K_KK___K_KK____._KK___K_____C__K__CK.___KK_K___K_KK_
    C_K..K__K.C..K..__......K......_..K....._....K......C.K.K._.....
    ................................................................

    No more gracefully dying childs anywhere. And finally I noticed the new configuration in my own browser.

That's the reason why people think an Apache reload sometimes work and sometimes not.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Kai 'Oswald' Seidler writes about his life as co-founder of Apache Friends, creator of XAMPP, and technology evangelist for web tier products at Sun Microsystems.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today