From bfc9799c7ed62c43acf149ed676c704a3dc8561c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 28 Aug 2019 09:03:50 -0400 Subject: [PATCH] TT#65100 don't start a redis notification context/thread when not in use There's no point in starting the notification thread and another Redis connection if there are no keyspaces to subscribe to Change-Id: I2a9ef3b7764219b6ca08ebbe81461efd45b3e9de --- daemon/main.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/daemon/main.c b/daemon/main.c index fd8831fc3..c4e735799 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -739,11 +739,19 @@ no_kernel: if (!is_addr_unspecified(&rtpe_config.redis_ep.address)) { rtpe_redis = redis_new(&rtpe_config.redis_ep, rtpe_config.redis_db, rtpe_config.redis_auth, rtpe_redis_write ? ANY_REDIS_ROLE : MASTER_REDIS_ROLE, rtpe_config.no_redis_required); - rtpe_redis_notify = redis_new(&rtpe_config.redis_ep, rtpe_config.redis_db, rtpe_config.redis_auth, rtpe_redis_write ? ANY_REDIS_ROLE : MASTER_REDIS_ROLE, rtpe_config.no_redis_required); - if (!rtpe_redis || !rtpe_redis_notify) - die("Cannot start up without running Redis %s database! See also NO_REDIS_REQUIRED parameter.", + if (!rtpe_redis) + die("Cannot start up without running Redis %s database! " + "See also NO_REDIS_REQUIRED parameter.", endpoint_print_buf(&rtpe_config.redis_ep)); + if (rtpe_config.redis_subscribed_keyspaces.length) { + rtpe_redis_notify = redis_new(&rtpe_config.redis_ep, rtpe_config.redis_db, rtpe_config.redis_auth, rtpe_redis_write ? ANY_REDIS_ROLE : MASTER_REDIS_ROLE, rtpe_config.no_redis_required); + if (!rtpe_redis_notify) + die("Cannot start up without running notification Redis %s database! " + "See also NO_REDIS_REQUIRED parameter.", + endpoint_print_buf(&rtpe_config.redis_ep)); + } + if (!rtpe_redis_write) rtpe_redis_write = rtpe_redis; } @@ -793,7 +801,7 @@ int main(int argc, char **argv) { thread_create_detach_prio(poller_timer_loop, rtpe_poller, rtpe_config.idle_scheduling, rtpe_config.idle_priority); thread_create_detach_prio(load_thread, NULL, rtpe_config.idle_scheduling, rtpe_config.idle_priority); - if (!is_addr_unspecified(&rtpe_config.redis_ep.address)) + if (!is_addr_unspecified(&rtpe_config.redis_ep.address) && rtpe_redis_notify) thread_create_detach(redis_notify_loop, NULL); if (!is_addr_unspecified(&rtpe_config.graphite_ep.address)) @@ -831,12 +839,12 @@ int main(int argc, char **argv) { service_notify("STOPPING=1\n"); - if (!is_addr_unspecified(&rtpe_config.redis_ep.address)) + if (!is_addr_unspecified(&rtpe_config.redis_ep.address) && rtpe_redis_notify) redis_notify_event_base_action(EVENT_BASE_LOOPBREAK); threads_join_all(1); - if (!is_addr_unspecified(&rtpe_config.redis_ep.address)) + if (!is_addr_unspecified(&rtpe_config.redis_ep.address) && rtpe_redis_notify) redis_notify_event_base_action(EVENT_BASE_FREE); ilog(LOG_INFO, "Version %s shutting down", RTPENGINE_VERSION);