From 905d58490282fb4cd1aff18b35a7108c53addf56 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Tue, 2 May 2023 15:43:11 +0200 Subject: [PATCH] MT#57335 Move `stats_rate_min_max()` to a separate thread To do the work more efficiently, and not be dependent on the call_timer runs by poller, we should move the `stats_rate_min_max()` to a separate thread, to make it faster and not be dependent on what happens in the `call_timer` at all. Since it has nothing to do with the call timers. Change-Id: I9a39e1b63cb8741377f5af5b2d52d4f8b428a0ad --- daemon/call.c | 3 --- daemon/main.c | 4 ++++ daemon/statistics.c | 13 +++++++++++++ include/statistics.h | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index f700cfea4..536890693 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -572,9 +572,6 @@ void call_timer(void *ptr) { stats_counters_calc_rate(&rtpe_stats, run_diff_us, &rtpe_stats_intv, &rtpe_stats_rate); - // TODO: should be moved into a separate thread/timer - stats_rate_min_max(&rtpe_rate_graphite_min_max, &rtpe_stats_rate); - // stats derived while iterating calls RTPE_GAUGE_SET(transcoded_media, hlp.transcoded_media); diff --git a/daemon/main.c b/daemon/main.c index f16d069db..3b3cfec52 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -1350,6 +1350,10 @@ int main(int argc, char **argv) { thread_create_detach_prio(sockets_releaser, NULL, rtpe_config.idle_scheduling, rtpe_config.idle_priority, "release closed sockets"); + /* separate thread for update of running min/max call counters */ + thread_create_detach_prio(call_rate_stats_updater, NULL, rtpe_config.idle_scheduling, + rtpe_config.idle_priority, "call rate stats"); + if (!is_addr_unspecified(&rtpe_config.redis_ep.address) && initial_rtpe_config.redis_delete_async) thread_create_detach(redis_delete_async_loop, NULL, "redis async"); diff --git a/daemon/statistics.c b/daemon/statistics.c index bee446b4e..c881b42b6 100644 --- a/daemon/statistics.c +++ b/daemon/statistics.c @@ -1017,3 +1017,16 @@ const char *statistics_ng(bencode_item_t *input, bencode_item_t *output) { return NULL; } + +/** + * Separate thread for update of running min/max call counters. + */ +void call_rate_stats_updater(void * dummy) { + while (!rtpe_shutdown) { + stats_rate_min_max(&rtpe_rate_graphite_min_max, &rtpe_stats_rate); + + thread_cancel_enable(); + usleep(1000000); /* sleep for 1 second in each iteration */ + thread_cancel_disable(); + } +} diff --git a/include/statistics.h b/include/statistics.h index fc5f85c92..38485b318 100644 --- a/include/statistics.h +++ b/include/statistics.h @@ -197,6 +197,7 @@ void statistics_update_foreignown_inc(struct call* c); GQueue *statistics_gather_metrics(struct interface_sampled_rate_stats *); void statistics_free_metrics(GQueue **); const char *statistics_ng(bencode_item_t *input, bencode_item_t *output); +void call_rate_stats_updater(void * dummy); INLINE void stats_counters_calc_rate(const struct global_stats_counter *stats, long long run_diff_us, struct global_stats_counter *intv, struct global_stats_counter *rate)