]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Properly print top symbols by timeout
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 10 Sep 2022 13:13:30 +0000 (14:13 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 10 Sep 2022 13:13:30 +0000 (14:13 +0100)
src/libserver/symcache/symcache_c.cxx
src/libserver/symcache/symcache_impl.cxx
src/libserver/worker_util.c

index f957aa9b67a78958356276c2fb21d3413357b9c6..f8de952810068a9aabc8b26731dbb4bba23f8eff 100644 (file)
@@ -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();
index b2f6004aab70b88692f1cead5def2adc65eb7d92..e7e0a56b079bd75cb9c3643d8b79f2f237e5277e 100644 (file)
@@ -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,"
index 8c716fb94b6b21d75ead4a98dd72db20b5a0bee7..5e296b1d9dd0541f822e1d49526bbb5a2cfdb79c 100644 (file)
@@ -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);