Httpd: how to dynamically delay request forwarding to proxy

apache-2.2httpdmod-proxyPROXYsystemd

I have Apache httpd (2.2.22) configured as reverse proxy.

There is a situation in which I need to take my web server (the receiver of the proxied requests) offline for a few milliseconds. During this time the web server should not receive any requests but I also don't want to reject any requests.

What I'd like to do is to somehow get httpd to delay all requests for that period of time. In steps:

  1. tell httpd to delay all requests until further notice
  2. stop web server
  3. start web server
  4. continue request forwarding from httpd

A fixed delay would also do the trick but since I cannot foresee the actual amount of time the web server will be offline (other than that it will be less than one second), a dynamical approach would be better suited.

I've looked at how mod_proxy or mod_balancer could help me but I didn't find an obvious solution.

I'll be happy about any pointers you can give me.

Edit:

It looks like a static approach is sufficient.
Some helpful resources:

Alternative solution:

We will be deploying systemd to our servers. systemd will solve my problem because it can retain requests on sockets that are closed on one end. This means that when I stop the backend server for a short period of time, all the requests will be queued until I start it again and connect to the socket. That's what I call elegant 🙂

Best Answer

The ProxyPass directive accepts many parameters to configure how the connection is handled with the backend server.

Among those parameters, you may be interested by:

  • connectiontimeout <n>: The number of seconds Apache waits for the creation of a connection to the backend to complete.
  • timeout <n>: The number of seconds Apache waits for data sent by/to the backend.
  • ttl <n>: Time to live for inactive connections and associated connection pool entries, in seconds.

A better solution would be to have multiple backend servers and balance the load over the members and detect offline servers using the pingparameter. So, when you reboot a backend server, another one could take the relay.