[systemd-devel] Socket activation in parallel?

Mantas Mikulėnas grawity at gmail.com
Thu Mar 5 23:51:43 UTC 2020


The default mode (Accept=no) expects your daemon to remain running forever
and handle *all* requests in the same instance. Basically once the daemon
is started and receives the listening socket, it continues working like a
traditional daemon would: start an event loop, perhaps use threads or
workers, and so on. Parallelization is up to you.

If you actually want to have one instance per client, then use Accept=yes
and make sure your .service unit is templated – i.e. named "foobar at .service".
(In this case systemd will call accept() for you, so you'll directly
receive the client socket, not the listener socket.)

On Fri, Mar 6, 2020, 00:16 Daniel Tihelka <dtihelka at gmail.com> wrote:

> Hello,
> I am adding socket activation to a daemon. It basically works well, but
> for multiple simultaneous connections, the systemd seems to serialize the
> incoming requests, spawning the daemon for each request only after the
> previous request is served (i.e. the daemon terminates).
>
> Is it really the case? Or I am doing something wrong?
>
> I use "classic" approach as:
>
> n = sd_listen_fds(0);
> if (n >= 1) {
>   for (int fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++)
>  ...
>
>
> So, the question is: how to convince systemd to spawn instances in
> parallel every time a new connection is established on the socket, instead
> of serializing them? Although the server is contacted rather rarely (and
> thus I deal with socket activation), it takes a longer time to finish with
> the client. And when would multiple clients contact the server
> simultaneously, they will wait for a long time ...
>
> Thank you for your advice.
>
> Best regards,
> Dan T.
>
>
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20200306/f80982ab/attachment.htm>


More information about the systemd-devel mailing list