commit f6cdd27: [Minor] Add average time processing slots

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Feb 26 13:35:05 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-02-26 12:43:04 +0000
URL: https://github.com/rspamd/rspamd/commit/f6cdd27f8babf5bdca939fe84e2bd7ab86e4f17d

[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 489bba6dd..80e73b3ca 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 04c574b82..61acd9abc 100644
--- a/src/rspamd.c
+++ b/src/rspamd.c
@@ -46,6 +46,8 @@
 #ifdef HAVE_OPENSSL
 #include <openssl/err.h>
 #include <openssl/evp.h>
+#include <math.h>
+
 #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);
 	}
 


More information about the Commits mailing list