From 055e37f556974bca6152bda8a1144742da371905 Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Mon, 17 Jul 2017 11:26:04 +0700 Subject: [PATCH] rrdtool plugin: Configuration check moved to init callback The "RandomTimeout" option value check moved from rrd_get_random_variation() to rrd_init(). This will save few CPU cycles. --- src/rrdtool.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/rrdtool.c b/src/rrdtool.c index f09d6024..0f02ffc2 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -608,13 +608,6 @@ static int64_t rrd_get_random_variation(void) { if (random_timeout == 0) return (0); - /* Assure that "cache_timeout + random_variation" is never negative. */ - if (random_timeout > cache_timeout) { - INFO("rrdtool plugin: Adjusting \"RandomTimeout\" to %.3f seconds.", - CDTIME_T_TO_DOUBLE(cache_timeout)); - random_timeout = cache_timeout; - } - return (int64_t)cdrand_range(-random_timeout, random_timeout); } /* int64_t rrd_get_random_variation */ @@ -1058,6 +1051,7 @@ static int rrd_init(void) { cache_flush_last = cdtime(); if (cache_timeout == 0) { + random_timeout = 0; cache_flush_timeout = 0; } else if (cache_flush_timeout < cache_timeout) { INFO("rrdtool plugin: \"CacheFlush %u\" is less than \"CacheTimeout %u\". " @@ -1068,6 +1062,13 @@ static int rrd_init(void) { cache_flush_timeout = 10 * cache_timeout; } + /* Assure that "cache_timeout + random_variation" is never negative. */ + if (random_timeout > cache_timeout) { + INFO("rrdtool plugin: Adjusting \"RandomTimeout\" to %.3f seconds.", + CDTIME_T_TO_DOUBLE(cache_timeout)); + random_timeout = cache_timeout; + } + pthread_mutex_unlock(&cache_lock); status = plugin_thread_create(&queue_thread, /* attr = */ NULL, -- 2.30.2