puma/puma

Support for shutdown on idle

schuetzm opened this issue · 2 comments

Is your feature request related to a problem? Please describe.
In order to reduce resource consumption, infrequently utilised Rails/Rack apps should not occupy memory when they are not actively used. Socket activation, which Puma already supports, solves part of this; applications can be started on demand as soon as a request comes in. However, there doesn't seem to be a way to shut down the server again when the app is no longer active.

Describe the solution you'd like
There should be an (opt-in) setting that allows to specify a timeout. If no new request is received inside that timeout, the server should shut down and exit cleanly. Care must be taken not to close the sockets received from systemd.

Describe alternatives you've considered
This feature cannot be implemented in the service manager (systemd), as it doesn't keep track of activity on the sockets it created after the service has been started. This information is only available to Puma itself.

(I'd be willing to implement this if someone can point me at the right place to start.)

This sounds interesting but it's not clear to me yet in what configuration/platform where this would make sense. I'd love to learn about examples of where/when to use this.

@dfuentes77 Take a look at fly.io's docs on "stopping a machine by terminating its main process"