I am trying to find a way to quickly restart Apache to apply configuration changes. The goal is to:
- Restart without distributing currently processed requests
- 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?
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.What about setting your MaxKeepAliveReqests and your KeepAliveTimeout low enough so that clients can still use keepalive, but not keep those connections around as long?