commit e49a938: [Minor] Properly print top symbols by timeout
Vsevolod Stakhov
vsevolod at rspamd.com
Sat Sep 10 13:14:08 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-09-10 14:13:30 +0100
URL: https://github.com/rspamd/rspamd/commit/e49a9382bee59c794293e036171be67f7016962e (HEAD -> master)
[Minor] Properly print top symbols by timeout
---
src/libserver/symcache/symcache_c.cxx | 2 +-
src/libserver/symcache/symcache_impl.cxx | 4 ++--
src/libserver/worker_util.c | 30 +++++++++++++++++++++++-------
3 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/src/libserver/symcache/symcache_c.cxx b/src/libserver/symcache/symcache_c.cxx
index f957aa9b6..f8de95281 100644
--- a/src/libserver/symcache/symcache_c.cxx
+++ b/src/libserver/symcache/symcache_c.cxx
@@ -265,7 +265,7 @@ rspamd_symcache_item_name(struct rspamd_symcache_item *item)
auto *real_item = C_API_SYMCACHE_ITEM(item);
if (real_item == nullptr) {
- return 0;
+ return nullptr;
}
return real_item->get_name().c_str();
diff --git a/src/libserver/symcache/symcache_impl.cxx b/src/libserver/symcache/symcache_impl.cxx
index b2f6004aa..e7e0a56b0 100644
--- a/src/libserver/symcache/symcache_impl.cxx
+++ b/src/libserver/symcache/symcache_impl.cxx
@@ -1215,7 +1215,7 @@ auto symcache::get_max_timeout(std::vector<std::pair<double, const cache_item *>
auto max_timeout = 0.0, added_timeout = 0.0;
const cache_item *max_elt = nullptr;
for (const auto &it : vec) {
- if (it->priority != saved_priority) {
+ if (it->priority != saved_priority && max_elt != nullptr && max_timeout > 0) {
accumulated_timeout += max_timeout;
added_timeout += max_timeout;
msg_debug_cache_lambda("added %.2f to the timeout (%.2f) as the priority has changed (%d -> %d);"
@@ -1276,7 +1276,7 @@ auto symcache::get_max_timeout(std::vector<std::pair<double, const cache_item *>
/* Sort in decreasing order by timeout */
std::stable_sort(std::begin(elts), std::end(elts),
[](const auto &p1, const auto &p2) {
- return p2.first > p1.first;
+ return p1.first > p2.first;
});
msg_debug_cache("overall cache timeout: %.2f, %.2f from prefilters,"
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 8c716fb94..5e296b1d9 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -960,8 +960,6 @@ rspamd_main_heartbeat_start (struct rspamd_worker *wrk, struct ev_loop *event_lo
static bool
rspamd_maybe_reuseport_socket (struct rspamd_worker_listen_socket *ls)
{
- gint nfd = -1;
-
if (ls->is_systemd) {
/* No need to reuseport */
return true;
@@ -978,6 +976,7 @@ rspamd_maybe_reuseport_socket (struct rspamd_worker_listen_socket *ls)
}
#if defined(SO_REUSEPORT) && defined(SO_REUSEADDR) && defined(LINUX)
+ gint nfd = -1;
if (ls->type == RSPAMD_WORKER_SOCKET_UDP) {
nfd = rspamd_inet_address_listen (ls->addr,
@@ -1005,8 +1004,6 @@ rspamd_maybe_reuseport_socket (struct rspamd_worker_listen_socket *ls)
*/
nfd = ls->fd;
}
-#else
- nfd = ls->fd;
#endif
#if 0
@@ -2240,9 +2237,28 @@ rspamd_worker_check_and_adjust_timeout (struct rspamd_config *cfg, gdouble timeo
g_assert (tres != 0);
if (tres->max_timeout > timeout) {
- msg_info_config("configured task_timeout %.2f is less than maximum symbols cache timeout %.2f, so"
- "some symbols could be terminated early", timeout, tres->max_timeout);
- /* TODO: list timeouts for top symbols */
+ msg_info_config("configured task_timeout %.2f is less than maximum symbols cache timeout %.2f; "
+ "some symbols can be terminated before checks", timeout, tres->max_timeout);
+ GString *buf = g_string_sized_new(512);
+ static const int max_displayed_items = 12;
+
+ for (int i = 0; i < MIN(tres->nitems, max_displayed_items); i++) {
+ if (i == 0) {
+ rspamd_printf_gstring(buf, "%s(%.2f)",
+ rspamd_symcache_item_name((struct rspamd_symcache_item *)tres->items[i].item),
+ tres->items[i].timeout);
+ }
+ else {
+ rspamd_printf_gstring(buf, "; %s(%.2f)",
+ rspamd_symcache_item_name((struct rspamd_symcache_item *)tres->items[i].item),
+ tres->items[i].timeout);
+ }
+ }
+ msg_info_config("list of top %d symbols by execution time: %v",
+ MIN(tres->nitems, max_displayed_items),
+ buf);
+
+ g_string_free(buf, TRUE);
}
rspamd_symcache_timeout_result_free (tres);
More information about the Commits
mailing list