core: don't process dbus unit and job queue when there are already too many messages...
authorLennart Poettering <lennart@poettering.net>
Tue, 13 Feb 2018 17:30:34 +0000 (18:30 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Feb 2018 18:54:29 +0000 (19:54 +0100)
commite0a085811de1d1976c019afcfc2e4e74f590cc9f
tree9ed530ddcc376cb5c41cd339dc218f9a1b918a63
parent9fc677e3c997548e701f418e0b413441e1c5e891
core: don't process dbus unit and job queue when there are already too many messages pending

We maintain a queue of units and jobs that we are supposed to generate
change/new notifications for because they were either just created or
some of their property has changed. Let's throttle processing of this
queue a bit: as soon as > 1K of bus messages are queued for writing
let's skip processing the queue, and then recheck on the next
iteration again.

Moreover, never process more than 100 units in one go, return to the
event loop after that. Both limits together should put effective limits
on both space and time usage of the function, delaying further
operations until a later moment, when the queue is empty or the the
event loop is sufficiently idle again.

This should keep the number of generated messages much lower than
before on busy systems or where some client is hanging.

Note that this also means a bad client can slow down message dispatching
substantially for up to 90s if it likes to, for all clients. But that
should be acceptable as we only allow trusted bus clients, anyway.

Fixes: #8166
src/core/dbus.c
src/core/dbus.h
src/core/manager.c
src/systemd/sd-bus.h