aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-25 00:01:34 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-25 00:01:34 +0000
commite096fa2531250b2331c1d9d45971270c4b826b0c (patch)
tree76d5530290c93338d5bbeca96aa29c27ea538cd5 /src/libserver
parent1d74c41bb9b0a88957d950f910ecd1d2c4ddc474 (diff)
downloadrspamd-e096fa2531250b2331c1d9d45971270c4b826b0c.tar.gz
rspamd-e096fa2531250b2331c1d9d45971270c4b826b0c.zip
Use cumulative moving average for time values.
The previous version with exponential moving average cannot work well with the rspamd usage pattern.
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/symbols_cache.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index 3fa90fbd3..4f37de867 100644
--- a/src/libserver/symbols_cache.c
+++ b/src/libserver/symbols_cache.c
@@ -91,14 +91,16 @@ static double
rspamd_set_counter (struct cache_item *item, guint32 value)
{
struct counter_data *cd;
- double alpha;
cd = item->cd;
- /* Calculate new value */
+ /* Cumulative moving average */
rspamd_mempool_lock_mutex (item->mtx);
- alpha = 2. / (++cd->number + 1);
- cd->value = cd->value * (1. - alpha) + value * alpha;
+ if (cd->number == 0) {
+ cd->value = 0;
+ }
+
+ cd->value = cd->value + (value - cd->value) / (++cd->number);
rspamd_mempool_unlock_mutex (item->mtx);