health: write to alarm-inventory in batches if possible
Writing into alarm-inventory one by one can be really slow if you have a
lot of units. Sysrepo is not that fast as I presumed and inserting into a
huge list one-by-one can be really expensive.
We have seen a huge CPU load during velia-health and alarms daemon
startups and shutdowns. When looking at the flame graphs for data
measured by `perf` we have seen the load mainly from these two daemons.
Both of them need some tuning, especially in the alarms processing area.
I am doing my part with velia here by trying to batch as most
alarm-inventory edits as possible.
Change-Id: I1bf07fee419f2c4e06200aaa648af6a419458858
diff --git a/src/health/SystemdUnits.h b/src/health/SystemdUnits.h
index 97f9ada..8066935 100644
--- a/src/health/SystemdUnits.h
+++ b/src/health/SystemdUnits.h
@@ -30,6 +30,11 @@
bool operator==(const UnitState&) const = default;
};
+ enum class RegisterAlarmInventory {
+ Yes,
+ No,
+ };
+
velia::Log m_log;
sysrepo::Session m_srSession;
@@ -46,7 +51,7 @@
/** Current unit state. */
std::map<std::string, UnitState> m_unitState;
- void registerSystemdUnit(sdbus::IConnection& connection, const std::string& unitName, const sdbus::ObjectPath& unitObjectPath, const std::optional<UnitState>& unitState);
+ void registerSystemdUnit(sdbus::IConnection& connection, const std::string& unitName, const sdbus::ObjectPath& unitObjectPath, const std::optional<UnitState>& unitState, const RegisterAlarmInventory registerAlarmInventory);
void onUnitStateChange(const std::string& name, const UnitState& unitState);
};