]> git.ipfire.org Git - pakfire.git/commitdiff
daemon: Submit stats a little bit less often
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 27 Jan 2025 10:28:05 +0000 (10:28 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 27 Jan 2025 10:28:05 +0000 (10:28 +0000)
I don't think we need stats that often when the host is idle, and even
when it is busy, once every 15 seconds sounds fine to me.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/daemon.c
src/pakfire/util.h

index 78ec35c1e95f0c9ac5415baa6c43de56baa50e61..2ba904d4866c4ebd4babf14ae5fc376ab65986af 100644 (file)
 #include <pakfire/string.h>
 #include <pakfire/util.h>
 
+// How often to submit stats?
+#define PAKFIRE_STATS_WHEN_BUSY S_TO_US(15)
+#define PAKFIRE_STATS_WHEN_IDLE S_TO_US(60)
+
 // It would be nice store the credentials cache in memory, but on Debian,
 // cURL is compiled with Heimdal which is incompatible with the KRB5 in-memory cache.
 // The on-disk format is however is compatible between two implementations.
@@ -140,7 +144,7 @@ static int pakfire_daemon_submit_stats(sd_event_source* s, uint64_t usec, void*
 
        // If we have any jobs running, we will submit our stats
        // every five seconds, otherwise 30 seconds is enough.
-       uint64_t next = (daemon->running_jobs > 0) ? 5000000 : 30000000;
+       uint64_t next = (daemon->running_jobs > 0) ? PAKFIRE_STATS_WHEN_BUSY : PAKFIRE_STATS_WHEN_IDLE;
 
        // Reset the timer
        r = sd_event_source_set_time_relative(daemon->stats_timer, next);
index fc7ea821eb372a43cb2693fd00283c1cc667750e..c3c9f00e1228ab04a07103f07126160d904538fb 100644 (file)
@@ -101,6 +101,15 @@ int pakfire_copy(struct pakfire_ctx* ctx, FILE* src, FILE* dst);
 
 // Time
 
+// seconds to microseconds
+#define S_TO_MS(s) (s * 1000)
+#define S_TO_US(s) (s * 1000000)
+#define S_TO_NS(s) (s * 1000000000)
+
+#define MS_TO_S(s) (s / 1000)
+#define US_TO_S(s) (s / 1000000)
+#define NS_TO_S(s) (s / 1000000000)
+
 static inline double pakfire_timespec_delta(struct timespec* t1, struct timespec* t2) {
        // Compute delta in seconds
        return (