]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Try better to expiry bayes in a clustered setup
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 12 Mar 2018 13:24:36 +0000 (13:24 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 12 Mar 2018 13:24:36 +0000 (13:24 +0000)
src/plugins/lua/bayes_expiry.lua

index 0088298e24be6cb2d315a623cb3b57e14ec3577d..de848611a64b98e07e969d1ef7af5a0062c6b6e7 100644 (file)
@@ -32,6 +32,7 @@ local settings = {
   common_ttl_divisor = 10, -- how should we discriminate common elements
   significant_factor = 3.0 / 4.0, -- which tokens should we update
   classifiers = {},
+  cluster_nodes = 0,
 }
 
 local template = {
@@ -130,7 +131,16 @@ if opts then
   end
 end
 
--- Fill template
+-- In clustered setup, we need to increase interval of expiration
+-- according to number of nodes in a cluster
+if settings.cluster_nodes == 0 then
+  local neighbours = obj.neighbours or {}
+  local n_neighbours = 0
+  for _,_ in pairs(neighbours) do n_neighbours = n_neighbours + 1 end
+  settings.cluster_nodes = n_neighbours
+end
+
+  -- Fill template
 template.count = settings.count
 template.threshold = settings.threshold
 template.common_ttl_divisor = settings.common_ttl_divisor
@@ -260,9 +270,11 @@ rspamd_config:add_on_load(function (_, ev_base, worker)
 
   -- Expire tokens at regular intervals
   for _,cls in ipairs(settings.classifiers) do
-    rspamd_config:add_periodic(ev_base, settings['interval'], function ()
-      expire_step(cls, ev_base, worker)
-      return true
-    end, true)
+    rspamd_config:add_periodic(ev_base,
+        settings['interval'] * (tonumber(settings.cluster_nodes) + 1),
+        function ()
+          expire_step(cls, ev_base, worker)
+          return true
+        end, true)
   end
 end)