Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement socket activation for couchdb #5411

Open
hadmut opened this issue Jan 22, 2025 · 7 comments
Open

Implement socket activation for couchdb #5411

hadmut opened this issue Jan 22, 2025 · 7 comments

Comments

@hadmut
Copy link

hadmut commented Jan 22, 2025

Hi,

systemd offers a particular way to start daemons called "socket activation", where systemd does not start a daemon at boot time as a service unit, but itself occupies an inet or unix domain socket, and once that socket is connected for the first time, starts a daemon and passes the socket to the daemon. Very similar to what inetd did on older linux systems, but there is two ways to pass the socket now. See man systemd.socket or google for "socket activation".

Advantage is, that a daemon (here: couchdb server) is not always running, but started only, if it is actually used for the first time.

A daemon/server needs to be able to take a socket handed over instead of a regular bind. Furthermore, it should have some timeout parameter to shut itself down after a given time without connections.

I did not find any documentation about for couchdb, so my guess is that it hasn't been implemented yet.

regards

@nickva
Copy link
Contributor

nickva commented Jan 23, 2025

Thanks for reaching out @hadmut, and thanks for the neat idea! I think it might be interesting to have it, but yeah, agree, I think it would depend first of all on a solid support from Erlang OTP + mochiweb (our web library) to be able to take a file descriptor from systemd. I think it would be quite a bit for work implement that from scratch ourselves.

@rnewson
Copy link
Member

rnewson commented Feb 3, 2025

Caching is vital to couchdb as is the processing we do when opening databases and indexes, it doesn't make sense to me for couchdb to start on demand.

@hadmut
Copy link
Author

hadmut commented Feb 3, 2025

Oh, it doesn't mean to restart it for every single request. And it doesn't mean terminating after a connection. Once started, it should run for a given time period after last use.

But if you do use CouchDB only occasionally, as I do, why should it consume memory, boot time, battery power, if it isn't used most of the time? After all, I am just asking for supporting it, not for enforcing it, thus leaving the decision to the admin.

Especially for a non-centralized structure as couchdb has, it makes sense to start couchdb (e.g. on desktop machines, notebooks, ...) only if actually needed, and not on every boot.

And, btw., that's what good 'ole inetd or modern systemd socket activation is made for.

@rnewson
Copy link
Member

rnewson commented Feb 3, 2025

Ok, I get it. It might be a nice (if niche) feature though I wouldn't want to tie it to systemd.

@hadmut
Copy link
Author

hadmut commented Feb 3, 2025

Couchdb is already tied to systemd, because that's the way it is started on modern systems. We're not in the System V or BSD days anymore.

It's just a modification of the way systemd starts couchdb, to make it even more modern. As an option.

@pgj
Copy link
Contributor

pgj commented Feb 5, 2025

Couchdb is already tied to systemd, because that's the way it is started on modern systems. We're not in the System V or BSD days anymore.

For what it is worth, the FreeBSD port of CouchDB still uses an rc.d script to start and stop the application. I believe that is a different conversation to decide if FreeBSD constitutes a modern system, but it proves that CouchDB could be managed without systemd.

@rnewson
Copy link
Member

rnewson commented Feb 5, 2025

systemd certainly not a requirement for couchdb, and I agree that's a separate discussion.

A pull request adding this as an option (off by default) against https://github.com/apache/couchdb-pkg seems the next step. we can review the details there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants