From: Vsevolod Stakhov Date: Thu, 20 Jun 2024 14:54:57 +0000 (+0100) Subject: [Project] Finally fix slow timer behaviour X-Git-Tag: 3.9.0~17^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1609c243964270bf033f6b79bd7946be3fec33f9;p=thirdparty%2Frspamd.git [Project] Finally fix slow timer behaviour --- diff --git a/src/libserver/symcache/symcache_runtime.cxx b/src/libserver/symcache/symcache_runtime.cxx index 8b341d6e04..c02069fb22 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); }