]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix ticks processing
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 27 Oct 2017 10:34:23 +0000 (11:34 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 27 Oct 2017 10:34:23 +0000 (11:34 +0100)
src/libserver/re_cache.c
src/libserver/symbols_cache.c
src/libutil/util.c

index 5bb153872df9f8ad6b84ce1a629d9be9886698e9..760b2a4401b4d550c5a35d385d5d5f1cbb7b222f 100644 (file)
@@ -488,7 +488,7 @@ rspamd_re_cache_process_pcre (struct rspamd_re_runtime *rt,
        guint max_hits = rspamd_regexp_get_maxhits (re);
        guint64 id = rspamd_regexp_get_cache_id (re);
        gdouble t1, t2, pr;
-       const gdouble slow_time = 0.1;
+       const gdouble slow_time = 1e8;
 
        if (in == NULL) {
                return rt->results[id];
@@ -540,7 +540,7 @@ rspamd_re_cache_process_pcre (struct rspamd_re_runtime *rt,
                        t2 = rspamd_get_ticks (TRUE);
 
                        if (t2 - t1 > slow_time) {
-                               msg_info_task ("regexp '%16s' took %.2f seconds to execute",
+                               msg_info_task ("regexp '%16s' took %.0f ticks to execute",
                                                rspamd_regexp_get_pattern (re), t2 - t1);
                        }
                }
index ece7895dab0e35036b1708a1c53713be6d93f437..7a9e05d27609fe0ad34fd5c23e13e4050b2f0dd0 100644 (file)
@@ -1613,10 +1613,10 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task,
        struct cache_item *item = NULL;
        struct cache_savepoint *checkpoint;
        gint i;
-       gdouble total_microseconds = 0;
+       gdouble total_ticks = 0;
        gboolean all_done;
        gint saved_priority;
-       const gdouble max_microseconds = 3e5;
+       const gdouble max_ticks = 3e8;
        guint start_events_pending;
 
        g_assert (cache != NULL);
@@ -1669,7 +1669,7 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task,
                                }
 
                                rspamd_symbols_cache_check_symbol (task, cache, item,
-                                               checkpoint, &total_microseconds);
+                                               checkpoint, &total_ticks);
                        }
                }
 
@@ -1746,10 +1746,10 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task,
                                }
 
                                rspamd_symbols_cache_check_symbol (task, cache, item,
-                                               checkpoint, &total_microseconds);
+                                               checkpoint, &total_ticks);
                        }
 
-                       if (total_microseconds > max_microseconds) {
+                       if (total_ticks > max_ticks) {
                                /* Maybe we should stop and check pending events? */
                                if (rspamd_session_events_pending (task->s) > start_events_pending) {
                                        /* Add some timeout event to avoid too long waiting */
@@ -1769,8 +1769,8 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task,
                                                        (rspamd_mempool_destruct_t)event_del, ev);
 #endif
                                        msg_info_task ("trying to check async events after spending "
-                                                       "%d microseconds processing symbols",
-                                                       (gint)total_microseconds);
+                                                       "%.0f ticks processing symbols",
+                                                       total_ticks);
 
                                        return TRUE;
                                }
@@ -1792,16 +1792,16 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task,
                                }
 
                                rspamd_symbols_cache_check_symbol (task, cache, item,
-                                               checkpoint, &total_microseconds);
+                                               checkpoint, &total_ticks);
                        }
 
-                       if (total_microseconds > max_microseconds) {
+                       if (total_ticks > max_ticks) {
                                /* Maybe we should stop and check pending events? */
                                if (rspamd_session_events_pending (task->s) >
                                                start_events_pending) {
                                        msg_debug_task ("trying to check async events after spending "
-                                                       "%d microseconds processing symbols",
-                                                       (gint)total_microseconds);
+                                                       "%.0f microseconds processing symbols",
+                                                       total_ticks);
                                        return TRUE;
                                }
                        }
@@ -1842,8 +1842,9 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task,
                                                return TRUE;
                                        }
                                }
+
                                rspamd_symbols_cache_check_symbol (task, cache, item,
-                                               checkpoint, &total_microseconds);
+                                               checkpoint, &total_ticks);
                        }
                }
                checkpoint->pass = RSPAMD_CACHE_PASS_WAIT_POSTFILTERS;
@@ -1901,7 +1902,7 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task,
                                        }
                                }
                                rspamd_symbols_cache_check_symbol (task, cache, item,
-                                               checkpoint, &total_microseconds);
+                                               checkpoint, &total_ticks);
                        }
                }
                checkpoint->pass = RSPAMD_CACHE_PASS_WAIT_IDEMPOTENT;
index f022b4689cb99176fe6ee9329ef3370aa7511ce3..7cb2ff81a4c470ada806d70c543cb414de6650e6 100644 (file)
@@ -1792,14 +1792,29 @@ rspamd_get_ticks (gboolean rdtsc_ok)
 # endif
        clock_gettime (clk_id, &ts);
 
-       res = (double)ts.tv_sec + ts.tv_nsec / 1000000000.;
+       if (rdtsc_ok) {
+               res = (double) ts.tv_sec + ts.tv_nsec / 1000000000.;
+       }
+       else {
+               res = (double) ts.tv_sec * 1e9 + ts.tv_nsec;
+       }
 # elif defined(__APPLE__)
-       res = mach_absolute_time () / 1000000000.;
+       if (rdtsc_ok) {
+               res = mach_absolute_time ();
+       }
+       else {
+               res = mach_absolute_time () / 1000000000.;
+       }
 #else
        struct timeval tv;
 
        (void)gettimeofday (&tv, NULL);
-       res = (double)tv.tv_sec + tv.tv_usec / 1000000.;
+       if (rdtsc_ok) {
+               res = (double) ts.tv_sec * 1e9 + tv.tv_usec * 1e3;
+       }
+       else {
+               res = (double)tv.tv_sec + tv.tv_usec / 1000000.;
+       }
 #endif
 
        return res;