]> source.dussan.org Git - rspamd.git/commitdiff
Use cumulative moving average for time values.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 25 Mar 2015 00:01:34 +0000 (00:01 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 25 Mar 2015 00:01:34 +0000 (00:01 +0000)
The previous version with exponential moving average cannot work well
with the rspamd usage pattern.

src/libserver/symbols_cache.c

index 3fa90fbd30b09adbb86ead775c0801b5ce9697a0..4f37de86795e089c4adae8e64c0501875c85775a 100644 (file)
@@ -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);