From 1609c243964270bf033f6b79bd7946be3fec33f9 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 20 Jun 2024 15:54:57 +0100 Subject: [PATCH] [Project] Finally fix slow timer behaviour --- src/libserver/symcache/symcache_runtime.cxx | 30 ++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/libserver/symcache/symcache_runtime.cxx b/src/libserver/symcache/symcache_runtime.cxx index 8b341d6e0..c02069fb2 100644 --- a/src/libserver/symcache/symcache_runtime.cxx +++ b/src/libserver/symcache/symcache_runtime.cxx @@ -789,11 +789,33 @@ auto symcache_runtime::finalize_item(struct rspamd_task *task, cache_dynamic_ite item->internal_flags |= cache_item::bit_slow; - if (!(item->internal_flags & cache_item::bit_sync)) { + if (item->internal_flags & cache_item::bit_sync) { + + /* + * We also need to adjust start timer for all async rules that + * are started before this rule, as this rule could delay them + * on its own. Hence, we need to make some corrections for all + * rules pending + */ + + for (const auto &[i, other_item]: rspamd::enumerate(order->d)) { + auto *other_dyn_item = &dynamic_items[i]; + + if (other_dyn_item->status == cache_item_status::pending && other_dyn_item->start_msec <= dyn_item->start_msec) { + other_dyn_item->start_msec += diff; + + msg_debug_cache_task("adjust start time for %s(%d) by %.2fms to %dms", + other_item->symbol.c_str(), + other_item->id, + diff, + (int) other_dyn_item->start_msec); + } + } + if (slow_status == slow_status::none) { slow_status = slow_status::enabled; - msg_info_task("slow rule: %s(%d): %.2f ms; enable 100ms idle timer to allow other rules to be finished", + msg_info_task("slow synchronous rule: %s(%d): %.2f ms; enable 100ms idle timer to allow other rules to be finished", item->symbol.c_str(), item->id, diff); if (enable_slow_timer()) { @@ -801,13 +823,13 @@ auto symcache_runtime::finalize_item(struct rspamd_task *task, cache_dynamic_ite } } else { - msg_info_task("slow rule: %s(%d): %.2f ms; idle timer has already been activated for this scan", + msg_info_task("slow synchronous rule: %s(%d): %.2f ms; idle timer has already been activated for this scan", item->symbol.c_str(), item->id, diff); } } else { - msg_notice_task("slow synchronous rule: %s(%d): %.2f ms; no idle timer is needed", + msg_notice_task("slow asynchronous rule: %s(%d): %.2f ms; no idle timer is needed", item->symbol.c_str(), item->id, diff); } -- 2.39.5