From 5ec026b659effcc9fb17aefca9adea2ef358c1ac Mon Sep 17 00:00:00 2001 From: Dan Larkin Date: Wed, 24 May 2017 13:45:53 -0400 Subject: [PATCH] Added sizeHint method for caches to improve warmup procedures. --- arangod/Cache/Cache.cpp | 9 +++++++++ arangod/Cache/Cache.h | 8 ++++++++ arangod/Cache/Table.h | 5 ++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/arangod/Cache/Cache.cpp b/arangod/Cache/Cache.cpp index d659e1bc54..d649187b2c 100644 --- a/arangod/Cache/Cache.cpp +++ b/arangod/Cache/Cache.cpp @@ -115,6 +115,15 @@ uint64_t Cache::usage() { return usage; } +void Cache::sizeHint(uint64_t numElements) { + uint64_t numBuckets = static_cast(static_cast(numElements) + / (static_cast(_slotsPerBucket) * Table::idealUpperRatio)); + uint32_t requestedLogSize = 0; + for (; (static_cast(1) << requestedLogSize) < numBuckets; + requestedLogSize++) {} + requestMigrate(requestedLogSize); +} + std::pair Cache::hitRates() { double lifetimeRate = std::nan(""); double windowedRate = std::nan(""); diff --git a/arangod/Cache/Cache.h b/arangod/Cache/Cache.h index 075273eca6..bb75527f63 100644 --- a/arangod/Cache/Cache.h +++ b/arangod/Cache/Cache.h @@ -97,6 +97,14 @@ class Cache : public std::enable_shared_from_this { ////////////////////////////////////////////////////////////////////////////// uint64_t usage(); + ////////////////////////////////////////////////////////////////////////////// + /// @brief Gives hint to attempt to preallocate space for an incoming load. + /// + /// The parameter specifies an expected number of elements to be inserted. + /// This allows for migration to an appropriately-sized table. + ////////////////////////////////////////////////////////////////////////////// + void sizeHint(uint64_t numElements); + ////////////////////////////////////////////////////////////////////////////// /// @brief Returns the cache hit-rates. /// diff --git a/arangod/Cache/Table.h b/arangod/Cache/Table.h index c4779689a3..83d747ca09 100644 --- a/arangod/Cache/Table.h +++ b/arangod/Cache/Table.h @@ -39,6 +39,8 @@ namespace cache { //////////////////////////////////////////////////////////////////////////////// class Table : public std::enable_shared_from_this { public: + static constexpr double idealLowerRatio = 0.05; + static constexpr double idealUpperRatio = 0.33; static const uint32_t minLogSize; static const uint32_t maxLogSize; static constexpr uint32_t standardLogSizeAdjustment = 6; @@ -186,9 +188,6 @@ class Table : public std::enable_shared_from_this
{ uint32_t idealSize(); private: - static constexpr double idealLowerRatio = 0.05; - static constexpr double idealUpperRatio = 0.33; - State _state; uint32_t _logSize;