From f778e30d48ce6bfef7f5434c2e30b617189bbdf0 Mon Sep 17 00:00:00 2001 From: Unbit Date: Mon, 13 Oct 2014 13:00:07 +0200 Subject: [PATCH] run the sweeper only if required --- core/cache.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/cache.c b/core/cache.c index a3df2cfa..8cf9b1b2 100644 --- a/core/cache.c +++ b/core/cache.c @@ -1163,20 +1163,24 @@ void uwsgi_cache_start_sweepers() { if (uwsgi.cache_no_expire) return; + int need_to_run = 0; while(uc) { - pthread_t cache_sweeper; - if (!uc->no_expire && !uc->purge_lru) { - if (pthread_create(&cache_sweeper, NULL, cache_sweeper_loop, uwsgi.caches)) { - uwsgi_error("pthread_create()"); - uwsgi_log("unable to run the sweeper!!!\n"); - } - else { - uwsgi_log("sweeper thread enabled\n"); - } + if (!uc->no_expire && !uc->purge_lru && !uc->lazy_expire) { + need_to_run = 1; break; } uc = uc->next; } + + if (!need_to_run) return; + + pthread_t cache_sweeper; + if (pthread_create(&cache_sweeper, NULL, cache_sweeper_loop, uwsgi.caches)) { + uwsgi_error("uwsgi_cache_start_sweepers()/pthread_create()"); + uwsgi_log("unable to run the cache sweeper!!!\n"); + return; + } + uwsgi_log("cache sweeper thread enabled\n"); } void uwsgi_cache_start_sync_servers() {