aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-07-19 11:48:57 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-07-19 11:48:57 +0100
commite49aaf4fd3b9f116ba0dc42bc108ebbf492296ca (patch)
tree973bb51d4ed8218cac4e751f83fdb4d08cd4cd13
parent244fa725db7cc475d95b4dc3e430350e9f2ff822 (diff)
downloadrspamd-e49aaf4fd3b9f116ba0dc42bc108ebbf492296ca.tar.gz
rspamd-e49aaf4fd3b9f116ba0dc42bc108ebbf492296ca.zip
[Feature] Reduce number of timers queries
-rw-r--r--src/libserver/re_cache.c18
-rw-r--r--src/libserver/symbols_cache.c49
-rw-r--r--src/libserver/worker_util.c1
3 files changed, 43 insertions, 25 deletions
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c
index 4cffe675c..59070d3da 100644
--- a/src/libserver/re_cache.c
+++ b/src/libserver/re_cache.c
@@ -463,7 +463,7 @@ rspamd_re_cache_process_pcre (struct rspamd_re_runtime *rt,
const gchar *start = NULL, *end = NULL;
guint max_hits = rspamd_regexp_get_maxhits (re);
guint64 id = rspamd_regexp_get_cache_id (re);
- gdouble t1, t2;
+ gdouble t1, t2, pr;
const gdouble slow_time = 0.1;
if (in == NULL) {
@@ -481,7 +481,11 @@ rspamd_re_cache_process_pcre (struct rspamd_re_runtime *rt,
r = rt->results[id];
if (max_hits == 0 || r < max_hits) {
- t1 = rspamd_get_ticks ();
+ pr = rspamd_random_double_fast ();
+
+ if (pr > 0.9) {
+ t1 = rspamd_get_ticks ();
+ }
while (rspamd_regexp_search (re,
in,
@@ -505,11 +509,13 @@ rspamd_re_cache_process_pcre (struct rspamd_re_runtime *rt,
rt->stat.regexp_matched += r;
}
- t2 = rspamd_get_ticks ();
+ if (pr > 0.9) {
+ t2 = rspamd_get_ticks ();
- if (t2 - t1 > slow_time) {
- msg_info_pool ("regexp '%16s' took %.2f seconds to execute",
- rspamd_regexp_get_pattern (re), t2 - t1);
+ if (t2 - t1 > slow_time) {
+ msg_info_pool ("regexp '%16s' took %.2f seconds to execute",
+ rspamd_regexp_get_pattern (re), t2 - t1);
+ }
}
}
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index 2642b607a..b4a3275d8 100644
--- a/src/libserver/symbols_cache.c
+++ b/src/libserver/symbols_cache.c
@@ -162,7 +162,8 @@ static gboolean rspamd_symbols_cache_check_symbol (struct rspamd_task *task,
struct symbols_cache *cache,
struct cache_item *item,
struct cache_savepoint *checkpoint,
- gdouble *total_diff);
+ gdouble *total_diff,
+ gdouble pr);
static gboolean rspamd_symbols_cache_check_deps (struct rspamd_task *task,
struct symbols_cache *cache,
struct cache_item *item,
@@ -1083,6 +1084,7 @@ rspamd_symbols_cache_watcher_cb (gpointer sessiond, gpointer ud)
struct cache_savepoint *checkpoint;
struct symbols_cache *cache;
gint i, remain = 0;
+ gdouble pr = rspamd_random_double_fast ();
checkpoint = task->checkpoint;
cache = task->cfg->cache;
@@ -1102,7 +1104,7 @@ rspamd_symbols_cache_watcher_cb (gpointer sessiond, gpointer ud)
}
rspamd_symbols_cache_check_symbol (task, cache, it, checkpoint,
- NULL);
+ NULL, pr);
}
}
}
@@ -1115,7 +1117,8 @@ rspamd_symbols_cache_check_symbol (struct rspamd_task *task,
struct symbols_cache *cache,
struct cache_item *item,
struct cache_savepoint *checkpoint,
- gdouble *total_diff)
+ gdouble *total_diff,
+ gdouble pr)
{
guint pending_before, pending_after;
double t1, t2;
@@ -1154,7 +1157,10 @@ rspamd_symbols_cache_check_symbol (struct rspamd_task *task,
}
if (check) {
- t1 = rspamd_get_ticks ();
+ if (pr > 0.9) {
+ t1 = rspamd_get_ticks ();
+ }
+
pending_before = rspamd_session_events_pending (task->s);
/* Watch for events appeared */
rspamd_session_watch_start (task->s, rspamd_symbols_cache_watcher_cb,
@@ -1163,19 +1169,21 @@ rspamd_symbols_cache_check_symbol (struct rspamd_task *task,
msg_debug_task ("execute %s, %d", item->symbol, item->id);
item->func (task, item->user_data);
- t2 = rspamd_get_ticks ();
- diff = (t2 - t1) * 1e6;
+ if (pr > 0.9) {
+ t2 = rspamd_get_ticks ();
+ diff = (t2 - t1) * 1e6;
- if (total_diff) {
- *total_diff += diff;
- }
+ if (total_diff) {
+ *total_diff += diff;
+ }
- if (diff > slow_diff_limit) {
- msg_info_task ("slow rule: %s: %d ms", item->symbol,
- (gint)(diff / 1000.));
- }
+ if (diff > slow_diff_limit) {
+ msg_info_task ("slow rule: %s: %d ms", item->symbol,
+ (gint)(diff / 1000.));
+ }
- rspamd_set_counter (item, diff);
+ rspamd_set_counter (item, diff);
+ }
rspamd_session_watch_stop (task->s);
pending_after = rspamd_session_events_pending (task->s);
@@ -1213,6 +1221,7 @@ rspamd_symbols_cache_check_deps (struct rspamd_task *task,
struct cache_dependency *dep;
guint i;
gboolean ret = TRUE;
+ gdouble pr = rspamd_random_double_fast ();
if (item->deps != NULL && item->deps->len > 0) {
for (i = 0; i < item->deps->len; i ++) {
@@ -1246,7 +1255,8 @@ rspamd_symbols_cache_check_deps (struct rspamd_task *task,
else if (!rspamd_symbols_cache_check_symbol (task, cache,
dep->item,
checkpoint,
- NULL)) {
+ NULL,
+ pr)) {
/* Now started, but has events pending */
ret = FALSE;
msg_debug_task ("started check of %d symbol as dep for "
@@ -1437,6 +1447,7 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task,
gboolean all_done;
const gdouble max_microseconds = 3e5;
guint start_events_pending;
+ gdouble pr = rspamd_random_double_fast ();
g_assert (cache != NULL);
@@ -1464,7 +1475,7 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task,
if (!isset (checkpoint->processed_bits, item->id * 2)) {
rspamd_symbols_cache_check_symbol (task, cache, item,
- checkpoint, &total_microseconds);
+ checkpoint, &total_microseconds, pr);
}
}
checkpoint->pass = RSPAMD_CACHE_PASS_WAIT_PREFILTERS;
@@ -1517,7 +1528,7 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task,
}
rspamd_symbols_cache_check_symbol (task, cache, item,
- checkpoint, &total_microseconds);
+ checkpoint, &total_microseconds, pr);
}
if (total_microseconds > max_microseconds) {
@@ -1567,7 +1578,7 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task,
}
rspamd_symbols_cache_check_symbol (task, cache, item,
- checkpoint, &total_microseconds);
+ checkpoint, &total_microseconds, pr);
}
if (total_microseconds > max_microseconds) {
@@ -1597,7 +1608,7 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task,
if (!isset (checkpoint->processed_bits, item->id * 2)) {
rspamd_symbols_cache_check_symbol (task, cache, item,
- checkpoint, &total_microseconds);
+ checkpoint, &total_microseconds, pr);
}
}
checkpoint->pass = RSPAMD_CACHE_PASS_WAIT_POSTFILTERS;
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 9924671cf..b7aa5035f 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -538,6 +538,7 @@ rspamd_fork_worker (struct rspamd_main *rspamd_main,
/* Lock statfile pool if possible XXX */
/* Init PRNG after fork */
rc = ottery_init (rspamd_main->cfg->libs_ctx->ottery_cfg);
+ rspamd_random_seed_fast ();
if (rc != OTTERY_ERR_NONE) {
msg_err_main ("cannot initialize PRNG: %d", rc);
g_assert (0);