X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrdtool.c;h=0f02ffc2e47d5fd4147d8c93c864c3fd12dfffde;hb=055e37f556974bca6152bda8a1144742da371905;hp=2a1a569888bd2fc6b100b2dd9e392d6356533d21;hpb=c7cbb2af24de8b33186dd45b5731b87ea7152173;p=collectd.git diff --git a/src/rrdtool.c b/src/rrdtool.c index 2a1a5698..0f02ffc2 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -87,7 +87,7 @@ static rrdcreate_config_t rrdcreate_config = { * ALWAYS lock `cache_lock' first! */ static cdtime_t cache_timeout = 0; static cdtime_t cache_flush_timeout = 0; -static cdtime_t random_timeout = TIME_T_TO_CDTIME_T(1); +static cdtime_t random_timeout = 0; static cdtime_t cache_flush_last; static c_avl_tree_t *cache = NULL; static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER; @@ -605,23 +605,10 @@ static int rrd_cache_flush_identifier(cdtime_t timeout, } /* int rrd_cache_flush_identifier */ static int64_t rrd_get_random_variation(void) { - long min; - long max; - 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; - } - - max = (long)(random_timeout / 2); - min = max - ((long)random_timeout); - - return ((int64_t)cdrand_range(min, max)); + return (int64_t)cdrand_range(-random_timeout, random_timeout); } /* int64_t rrd_get_random_variation */ static int rrd_cache_insert(const char *filename, const char *value, @@ -1064,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\". " @@ -1074,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,