Passenger-style idle shutdown and on-demand wake-up for hosting many low-traffic applications #222
Replies: 3 comments 2 replies
-
|
A brief update: I have continued validating the existing approach locally, without opening a new PR or pushing changes upstream. I adapted the draft implementation from #197 and tested it with real Docker containers and a Rails application deployed through Kamal. The prototype successfully:
I also addressed several race conditions and failure cases found during testing. Before preparing any PR, I would still appreciate guidance on the main architectural question: is direct Docker socket access an acceptable responsibility for kamal-proxy, or should container lifecycle operations be delegated externally? I am happy to share the prototype branch or collaborate with @martijnenco if maintainers would like to explore this direction. |
Beta Was this translation helpful? Give feedback.
-
|
I published a detailed write-up of the experiment, including the motivation, real-VPS validation results, problems found with real Docker, and instructions for trying the exact forks: https://docs.komagata.org/6456 The main results were:
The article links the exact experimental kamal-proxy and Kamal revisions. They are not official releases or upstream PRs, but they are available for anyone who wants to reproduce the experiment. @martijnenco, the work is based on #197 and includes the review-app use case you described. @mhenrixon, I also referenced the related direction from your issue. Test results from review-app or internal-tool environments would be especially useful. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @komagata and @martijnenco for working on this. I do think it's a great idea, and definitely worth pursuing if we can get an implementation we're happy with. It would be nice to get this capability into Kamal.
This is the biggest tradeoff I think. Mounting the Docker socket is the simplest approach, but effectively it's giving root to the proxy process. I don't think it's a showstopper given it would be opt-in, but worth thinking about alternatives too. The only more restricted alternative that springs to mind would be to have a simple start/stop service on the host and mount access to that instead. But maybe there's a better way -- do you have any other ideas in mind? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to discuss whether kamal-proxy could provide an opt-in feature that stops an application container after a period without requests and automatically starts it again when the next request arrives.
I found the following existing draft PRs for essentially this feature:
I do not want to duplicate or supersede that work. Before doing further implementation, I would first like to confirm whether this use case fits the direction of Kamal and kamal-proxy, and how the existing draft PRs should be handled.
Background
Kamal 2 makes it practical to host multiple independent web applications on a single server.
However, a Rails application continues to consume a meaningful amount of memory through its Puma and Rails processes even when it receives no traffic. In my experience, even a small Rails application can use roughly 150–300 MB per container.
When many low-traffic applications share one server, the limiting resource is therefore often the memory consumed by idle applications, rather than CPU or request throughput.
A concrete use case
I am involved with a programming school where students create Rails applications as their graduation projects.
There is value in keeping these applications publicly available after graduation, both as portfolios and as records of the students' work. However, most receive very little traffic and may go days or weeks without a request.
Many students cannot afford ongoing hosting fees. I would like to provide a minimal hosting environment for them at no cost. If an application becomes genuinely popular, we would ask its owner to move it to a dedicated server or a regular PaaS.
I believe the same mechanism would also be useful for:
For these applications, a cold-start delay of 10–30 seconds can be acceptable.
Similarity to Passenger
Phusion Passenger has supported a similar execution model for Ruby applications for many years.
Passenger can spawn an application process when a request arrives and shut it down after an idle timeout. It can also limit the total number of application processes running on a server.
What I am considering is applying this proven Passenger-style model at the container level for applications deployed with Kamal.
Expected behavior
Conceptually, I imagine an opt-in flow like this:
A possible configuration might look like this:
I am not proposing this exact configuration or implementation as a requirement. I would prefer whichever design best fits the project.
Non-goals
This is not intended to turn Kamal into a general-purpose orchestrator or PaaS.
At least initially, I think the following can remain out of scope:
The intended scope is an opt-in transition between zero and one web container.
Issues that would need consideration
I understand that this requires more than a simple timer and
docker stop/docker start. At minimum, the design should consider:Existing draft implementation
As I understand it, kamal-proxy#197 connects directly to the Docker socket and starts or stops the target container itself.
This provides a very simple user experience and does not require an additional service. On the other hand, direct Docker access changes the responsibilities and security profile of kamal-proxy.
One alternative might be for kamal-proxy to expose generic activation and deactivation hooks while delegating Docker operations to a small external lifecycle service.
I do not want to decide between these approaches in advance. I would appreciate guidance from the maintainers about which direction, if either, is appropriate for the project.
Questions
Before proceeding with implementation, I would appreciate feedback on the following:
If this use case fits the project, I would be happy to collaborate with the existing PR author and help with design, tests, and validation in a real environment.
I would first like to reach agreement on the responsibility and smallest useful scope before doing more implementation work.
Beta Was this translation helpful? Give feedback.
All reactions