Live data from Hacker News

Systemd: Enable indefinite service restarts

michael.stapelberg.ch

71–80 of 83 posts

Re: Systemd: Enable indefinite service restarts

#71
post #64

Earlier quoted context omitted.

So, you two know how systemd gets heat for doing too much, right? This is one of those things. The 'After=' and 'Requires=' directives address this. Depends on a mount? Point those directives at a '.mount' unit. Depends on networking, perhaps a specific NIC? Point those directives at 'systemd-networkd-wait-online@$REQUIRED_NIC.service' Point being: declare these things, don't wait for entropy to eventually become sta…

I get your point, but these features are the bare minimum any boot system should have. If someone calls that “bloat”, they should go back and hit rocks together.

Agreed. Relationships in 'init' are principle

Back on point though: don't expect the 11th restart to work when the last 10 didn't.

Contrived examples are contrived, it's solved. Declaring dependencies.

Re: Systemd: Enable indefinite service restarts

#72
post #33

> Why does systemd give up by default? > I’m not sure. If I had to speculate, I would guess the developers wanted to prevent laptops running out of battery too quickly because one CPU core is permanently busy just restarting some service that’s crashing in a tight loop. sigh … bounded randomized exponential backoff retry. (exponential: double the maximum time you might wait each iteration. Randomized: the time you wa…

Q: Why is the optimal lower bound zero and not "at least as long as you waited last time"?

edit: I did some more investigation, and I missed something crucial: The distribution of requests over time becomes very wonky if the lower bound isn't 0. It stabilizes given enough time, but that time seems very long. Whereas lower-bound 0 quickly becomes uniform.

See the following figure, where I plot the # of requests over type: https://i.imgur.com/PNUFhjc.png

And that is why you should use 0.

---

I am not an expert, but I got nerd-sniped.

I have made some simulations[1] and done some napkin math[2], and I would summarize as follows:

I don't think there is any globally optimal, I think it depends on your exact circumstances, and which of {excess waiting time, excess load} you want to optimize. Defaulting to 0 is a lot easier to implement, and is at most a factor 2 worse than the optimal lower bound w.r.t. waiting time vs. load. You may also consider [0.5 * maximum, maximum], which trades some excess waiting time for less load. Your suggestion is a similar heuristic one might use depending on their exact circumstances.

[1] https://gist.github.com/Dryvnt/1984d9389ae7386127f5e8998bf52...

[2] Consider a family of random bounded exponential back-off strategies with ultimate upper bound U as follows:

  Strategy X(z): Random of [z * U, U], where z is constant, 0 
There are other families of back-off algorithms with other characteristics, and I am not considering or comparing those, just this family. Note that strategy OP suggests is X(0). Consider that X(1) is non-random, which is undesirable.

Simple probability tells us

  avg(X(z)) = (1 + z) * U / 2
Server load ~= frequency, frequency is inverse duration, so

  load(X(z)) ~= 1 / avg(X(z)) = 2 / (1 + z) * U
The difference in load between any two X strategies is

  load(X(z1)) / load(X(z2)) = (1 + z1) / (1 + z2)
Since z1 and z2 are constant, this relative load is constant. Due to the bounds on z, the largest possible relative load is

  load(X(1)) / load(X(0)) = 2 / 1 = 2
Now consider your suggested strategy

  Strategy Y: Random of [L, U], where L is the last choice
Note that

  Y = X(y), where y = L / U.
In fact, Y approaches X(1) exponentially fast, since the difference between L and T is halved each step, on average. So your suggestion still falls within this at-most-factor-2 difference. Exactly where just depends on the outage length.

Re: Systemd: Enable indefinite service restarts

#73
post #66

Earlier quoted context omitted.

It's funny how some people call systemd overcomplicated and here we have someone complaining because it only has two levels (default/specific) for config instead of three (default/specific/forced default).

You've got the argument wrong. I'm suggesting you don't need two, you only need one. Unconfigurable forced default.

That would be a bit hard to swallow for a general purpose supervisor.

Re: Systemd: Enable indefinite service restarts

#74
post #52

Earlier quoted context omitted.

... and how many of us knew this before the article?

Anyone who read its documentation, which is comprehensive and clear.

Indeed, if I hadn't written my own .service file then I probably wouldn't know, but when you write a service file I don't think it's unreasonable to expect that the writer looks up the possible settings to make sure they're configuring it optimally. It's fairly easy to find a list and (IMHO) the parameter names are very self-descriptive

Re: Systemd: Enable indefinite service restarts

#75
post #31

Earlier quoted context omitted.

Correct, because the startup limit had been reached: `service start request repeated too quickly, refusing to start`.

Thats terrifying, systemd shouldn't pretend to be smarter than manual intervention. That violates everything I ever enjoyed linux for, I left Windows because it thought it knew better than me.

SystemD's philosophy is incompatible with UNIX principles. This statement shouldn't be controversial, yet we live in a world where SystemD criticisms are treated like heresy, and Wayland is unnecessary and unusable according to some X11 users directly contradicting most X.org maintainers and contributors.

Re: Systemd: Enable indefinite service restarts

#76
> And then you need to remember to restart the dependent services later, which is easy to forget.

You missed the other direction of the relationship.

I posted elsewhere in the thread on this, don't rely on entropy. Define your dependencies (well)

After=/Requires= are obvious. People forget PartOf=.

Re: Systemd: Enable indefinite service restarts

#77
post #59

Earlier quoted context omitted.

Or a disk not attached yet. Or another service it depends on being slow to finish starting up.

So, you two know how systemd gets heat for doing too much, right? This is one of those things. The 'After=' and 'Requires=' directives address this. Depends on a mount? Point those directives at a '.mount' unit. Depends on networking, perhaps a specific NIC? Point those directives at 'systemd-networkd-wait-online@$REQUIRED_NIC.service' Point being: declare these things, don't wait for entropy to eventually become sta…

[deleted]

Re: Systemd: Enable indefinite service restarts

#78
post #17

> I would guess the developers wanted to prevent laptops running out of battery too quickly And I would guess sysadmins also don't like their logging facilities filling the disks just because a service is stuck in a start loop. There are many reasons to think a service failing to start multiple times in a row won't start. Misconfiguration is probably the most frequent reason for that.

Exactly. If a service crashes within a second ten times in a row, it's not going to come up cleanly an eleventh time. The right thing to do is stay down, and let monitoring get the attention of a human operator who can figure out what the problem is. Continually rebooting is just going to fill up logs, spam other services, and generally make trouble. I'm sure there are exceptions to this. For those, set Restart=alway…

Interestingly, the kubernetes approach is the opposite one. Dependencies between pods / software components are encouraged to be a little softer, so that the scheduler is simpler.

Starting up, noticing that the environment doesn't have what you need yet and dying quickly appears to be The Kubernetes Way. A scheduler will eventually restart you and you'll have another go. Repeat until everything is up.

The kubelet operates the same way afair. On a node that hasn't joined a cluster yet, it sits in a fail/restart loop until it's provisioned.

Re: Systemd: Enable indefinite service restarts

#79

I can understand avoiding infinite restarts when there is something clearly wrong with configuration, but I can't figure out why they made the "systemctl restart" command also limited by this. For services which don't support dynamic reloading, restarting them is a substitute for that. This makes "systemctl restart" extremely brittle when used from scripts. Nobody accidentally runs "systemctl restart" too fast, when…

systemctl just uses dbus, as far as I understand, and someone can easily send dbus commands too fast

Re: Systemd: Enable indefinite service restarts

#80
post #72
post #33

Earlier quoted context omitted.

Q: Why is the optimal lower bound zero and not "at least as long as you waited last time"?

edit: I did some more investigation, and I missed something crucial: The distribution of requests over time becomes very wonky if the lower bound isn't 0. It stabilizes given enough time, but that time seems very long. Whereas lower-bound 0 quickly becomes uniform. See the following figure, where I plot the # of requests over type: https://i.imgur.com/PNUFhjc.png And that is why you should use 0. --- I am not an expe…

Yeah, all fair. What piqued my curiosity is that you could wait _less_ time than you did before (potentially not at all!) which feels like the opposite of what you want to do in such situations.
Post reply on HN