From 687850a612465cee9b484670b1f4b6c15fb5a6fe Mon Sep 17 00:00:00 2001 From: John Sully Date: Mon, 24 Oct 2022 15:27:10 +0000 Subject: [PATCH] Make semi-ordered-set rehashing configurable to aid in latency tuning --- src/config.cpp | 2 ++ src/semiorderedset.h | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 253f0726a..bb2a1f413 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -40,6 +40,7 @@ #endif const char *KEYDB_SET_VERSION = KEYDB_REAL_VERSION; +size_t g_semiOrderedSetTargetBucketSize = 0; // Its a header only class so nowhere else for this to go /*----------------------------------------------------------------------------- * Config file name-value maps. @@ -2910,6 +2911,7 @@ standardConfig configs[] = { createBoolConfig("allow-write-during-load", NULL, MODIFIABLE_CONFIG, g_pserver->fWriteDuringActiveLoad, 0, NULL, NULL), createBoolConfig("force-backlog-disk-reserve", NULL, MODIFIABLE_CONFIG, cserver.force_backlog_disk, 0, NULL, NULL), createBoolConfig("soft-shutdown", NULL, MODIFIABLE_CONFIG, g_pserver->config_soft_shutdown, 0, NULL, NULL), + createSizeTConfig("semi-ordered-set-bucket-size", NULL, MODIFIABLE_CONFIG, 0, 1024, g_semiOrderedSetTargetBucketSize, 0, INTEGER_CONFIG, NULL, NULL), #ifdef USE_OPENSSL createIntConfig("tls-port", NULL, MODIFIABLE_CONFIG, 0, 65535, g_pserver->tls_port, 0, INTEGER_CONFIG, NULL, updateTLSPort), /* TCP port. */ diff --git a/src/semiorderedset.h b/src/semiorderedset.h index c9ff10bac..2cd28b507 100644 --- a/src/semiorderedset.h +++ b/src/semiorderedset.h @@ -27,6 +27,7 @@ namespace keydbutils template<> size_t hash(const sdsview &); } +extern size_t g_semiOrderedSetTargetBucketSize; template class semiorderedset @@ -41,11 +42,14 @@ class semiorderedset size_t idxRehash = (1ULL << bits_min); int cfPauseRehash = 0; - constexpr size_t targetElementsPerBucket() + inline size_t targetElementsPerBucket() { // Aim for roughly 4 cache lines per bucket (determined by imperical testing) // lower values are faster but use more memory - return std::max((64/sizeof(T))*8, (size_t)2); + if (g_semiOrderedSetTargetBucketSize == 0) + return std::max((64/sizeof(T))*8, (size_t)2); + else + return g_semiOrderedSetTargetBucketSize; } public: