From ef125b8b1c6f2b84567acd284d1050ee7ace6845 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 26 Feb 2018 16:23:52 +0000 Subject: [PATCH] [Minor] Change logic of frequency computation for cache --- src/libserver/symbols_cache.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c index 4c15184d4..5f710d459 100644 --- a/src/libserver/symbols_cache.c +++ b/src/libserver/symbols_cache.c @@ -79,7 +79,6 @@ struct symbols_cache { guint stats_symbols_count; guint64 total_hits; struct rspamd_config *cfg; - rspamd_mempool_mutex_t *mtx; gdouble reload_time; gint peak_cb; }; @@ -977,7 +976,6 @@ rspamd_symbols_cache_new (struct rspamd_config *cfg) cache->postfilters = g_ptr_array_new (); cache->idempotent = g_ptr_array_new (); cache->composites = g_ptr_array_new (); - cache->mtx = rspamd_mempool_get_mutex (cache->static_pool); cache->reload_time = cfg->cache_reload_time; cache->total_hits = 1; cache->total_weight = 1.0; @@ -2026,9 +2024,7 @@ rspamd_symbols_cache_resort_cb (gint fd, short what, gpointer ud) double_to_tv (tm, &tv); event_add (&cbdata->resort_ev, &tv); - if (rspamd_worker_is_scanner (cbdata->w)) { - rspamd_mempool_lock_mutex (cache->mtx); - + if (rspamd_worker_is_primary_controller (cbdata->w)) /* Gather stats from shared execution times */ for (i = 0; i < cache->items_by_id->len; i ++) { item = g_ptr_array_index (cache->items_by_id, i); @@ -2089,20 +2085,17 @@ rspamd_symbols_cache_resort_cb (gint fd, short what, gpointer ud) } } - /* Sync virtual symbols */ - for (i = 0; i < cache->items_by_id->len; i ++) { - item = g_ptr_array_index (cache->items_by_id, i); + /* Sync virtual symbols */ + for (i = 0; i < cache->items_by_id->len; i ++) { + item = g_ptr_array_index (cache->items_by_id, i); - if (item->parent != -1) { - parent = g_ptr_array_index (cache->items_by_id, item->parent); + if (item->parent != -1) { + parent = g_ptr_array_index (cache->items_by_id, item->parent); - if (parent) { - item->st->avg_time = parent->st->avg_time; - } + if (parent) { + item->st->avg_time = parent->st->avg_time; } } - - rspamd_mempool_unlock_mutex (cache->mtx); } cbdata->last_resort = cur_ticks; @@ -2125,12 +2118,13 @@ rspamd_symbols_cache_start_refresh (struct symbols_cache * cache, tm = rspamd_time_jitter (cache->reload_time, 0); msg_debug_cache ("next reload in %.2f seconds", tm); g_assert (cache != NULL); - evtimer_set (&cbdata->resort_ev, rspamd_symbols_cache_resort_cb, cbdata); + evtimer_set (&cbdata->resort_ev, rspamd_symbols_cache_resort_cb, + cbdata); event_base_set (ev_base, &cbdata->resort_ev); double_to_tv (tm, &tv); event_add (&cbdata->resort_ev, &tv); rspamd_mempool_add_destructor (cache->static_pool, - (rspamd_mempool_destruct_t)event_del, + (rspamd_mempool_destruct_t) event_del, &cbdata->resort_ev); } -- 2.39.5