From: Michael Tremer Date: Mon, 27 Jan 2025 10:28:05 +0000 (+0000) Subject: daemon: Submit stats a little bit less often X-Git-Tag: 0.9.30~361 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d539d86a1cdd932db2c4f64f71de1b2fe26539a;p=pakfire.git daemon: Submit stats a little bit less often 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 --- diff --git a/src/pakfire/daemon.c b/src/pakfire/daemon.c index 78ec35c1..2ba904d4 100644 --- a/src/pakfire/daemon.c +++ b/src/pakfire/daemon.c @@ -37,6 +37,10 @@ #include #include +// 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); diff --git a/src/pakfire/util.h b/src/pakfire/util.h index fc7ea821..c3c9f00e 100644 --- a/src/pakfire/util.h +++ b/src/pakfire/util.h @@ -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 (