Graceful Apache restart and Keep-Alive connections

apache-2.2configurationhttpkeepalive

I am trying to find a way to quickly restart Apache to apply configuration changes. The goal is to:

  1. Restart without distributing currently processed requests
  2. Do this as atomically as possible, i.e. the new configuration must be applied on all new requests received from the restart time on, no new requests should by handled by the old version.

Apache has a graceful restart command that satisfies the first goal, the restart command is immediate and existing requests are not affected. However, the restart is not atomic. If there are existing connections to the server in Keep-Alive state, then all the following requests that they send are handled by old processes with the old configuration.

In my case, the Apache server is sitting behind a load balancer which may send hundreds of requests over a single connection. So after the restart, it takes many long minutes until the new configuration is applied to all new requests.

Is there any way to fix this, e.g. make Apache close any existing Keep-Alive connection to an old process after it finishes serving the current request?

Best Answer

Turn KeepAlive Off, do a graceful restart, and keep it off for some time, make the configuration change, and do another graceful restart. This is similar to the practice of reducing the TTL for a DNS entry before a change.