From f6cdd27f8babf5bdca939fe84e2bd7ab86e4f17d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 26 Feb 2022 12:43:04 +0000 Subject: [PATCH] [Minor] Add average time processing slots --- src/libserver/protocol.c | 15 +++++++++++++++ src/rspamd.c | 22 ++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index 489bba6dd0..80e73b3cab 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -1814,6 +1814,21 @@ end: __atomic_add_fetch (&task->worker->srv->stat->messages_scanned, 1, __ATOMIC_RELEASE); #endif + + /* Set average processing time */ + guint32 slot; + float processing_time = task->time_real_finish - task->task_timestamp; + +#ifndef HAVE_ATOMIC_BUILTINS + slot = task->worker->srv->stat->avg_time.cur_slot++; +#else + slot = __atomic_add_fetch (&task->worker->srv->stat->avg_time.cur_slot, + 1, __ATOMIC_RELEASE); +#endif + slot = slot % MAX_AVG_TIME_SLOTS; + /* TODO: this should be atomic but it is not supported in C */ + task->worker->srv->stat->avg_time.avg_time[slot] = processing_time; + } } diff --git a/src/rspamd.c b/src/rspamd.c index 04c574b821..61acd9abc3 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -46,6 +46,8 @@ #ifdef HAVE_OPENSSL #include #include +#include + #endif #include "sqlite3.h" @@ -1105,11 +1107,27 @@ rspamd_stat_update_handler (struct ev_loop *loop, ev_timer *w, int revents) cur_stat.actions_stat[METRIC_ACTION_REWRITE_SUBJECT]; gdouble new_ham = cur_stat.actions_stat[METRIC_ACTION_NOACTION]; + /* Kahan sum */ + float sum = 0.0f; + volatile float c = 0.0f; /* We don't want any optimisations around c */ + int cnt = 0; + + for (int i = 0; i < MAX_AVG_TIME_SLOTS; i ++) { + if (!isnan(cur_stat.avg_time.avg_time[i])) { + cnt ++; + float y = cur_stat.avg_time.avg_time[i] - c; + float t = sum + y; + c = (t - sum) - y; + sum = t; + } + } + rspamd_snprintf (proctitle, sizeof (proctitle), - "main process; %.1f msg/sec, %.1f msg/sec spam, %.1f msg/sec ham", + "main process; %.1f msg/sec, %.1f msg/sec spam, %.1f msg/sec ham; %.2fs avg processing time", rate, (new_spam - old_spam) / w->repeat, - (new_ham - old_ham) / w->repeat); + (new_ham - old_ham) / w->repeat, + cnt > 0 ? sum : 0); setproctitle (proctitle); } -- 2.47.3