]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add average time processing slots
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Feb 2022 12:43:04 +0000 (12:43 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Feb 2022 13:32:26 +0000 (13:32 +0000)
src/libserver/protocol.c
src/rspamd.c

index 489bba6dd02fc6187540ee2db586c9379db91e50..80e73b3cab0fa535d678445442a8d4336907a5bc 100644 (file)
@@ -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;
+
        }
 }
 
index 04c574b821060f5bdaa061994cf2ec8900ace1cc..61acd9abc33760c65b89293db428294fb4b79613 100644 (file)
@@ -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);
        }