From b49c36f0b0ee45aa7145ac788eb1870897699843 Mon Sep 17 00:00:00 2001 From: sfc-gh-tclinkenbeard Date: Sat, 2 Jul 2022 14:50:09 -0700 Subject: [PATCH] Add StorageQueueInfo::getWriteQueueSizeLimitRatio method --- fdbserver/Ratekeeper.actor.cpp | 19 +++++++++++++++++++ fdbserver/include/fdbserver/Ratekeeper.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/fdbserver/Ratekeeper.actor.cpp b/fdbserver/Ratekeeper.actor.cpp index 573feb6666..bde7ef6410 100644 --- a/fdbserver/Ratekeeper.actor.cpp +++ b/fdbserver/Ratekeeper.actor.cpp @@ -1018,6 +1018,25 @@ void StorageQueueInfo::refreshCommitCost(double elapsed) { totalWriteCosts = 0; } +Optional StorageQueueInfo::getWriteQueueSizeLimitRatio(int64_t storageSpringBytes, + int64_t storageTargetBytes) const { + auto const minFreeSpace = + std::max(SERVER_KNOBS->MIN_AVAILABLE_SPACE, + (int64_t)(SERVER_KNOBS->MIN_AVAILABLE_SPACE_RATIO * smoothTotalSpace.smoothTotal())); + auto const storageQueue = getStorageQueueBytes(); + auto const springBytes = std::max( + 1, std::min(storageSpringBytes, (smoothFreeSpace.smoothTotal() - minFreeSpace) * 0.2)); + auto const targetBytes = + std::max(1, std::min(storageTargetBytes, smoothFreeSpace.smoothTotal() - minFreeSpace)); + auto const targetRateRatio = std::min((storageQueue - targetBytes + springBytes) / (double)springBytes, 2.0); + auto const inputRate = smoothInputBytes.smoothRate(); + if (targetRateRatio > 0 && inputRate > 0) { + return verySmoothDurableBytes.smoothRate() / (inputRate * targetRateRatio); + } else { + return {}; + } +} + TLogQueueInfo::TLogQueueInfo(UID id) : valid(false), id(id), smoothDurableBytes(SERVER_KNOBS->SMOOTHING_AMOUNT), smoothInputBytes(SERVER_KNOBS->SMOOTHING_AMOUNT), verySmoothDurableBytes(SERVER_KNOBS->SLOW_SMOOTHING_AMOUNT), diff --git a/fdbserver/include/fdbserver/Ratekeeper.h b/fdbserver/include/fdbserver/Ratekeeper.h index 948cca851b..a2c79cede9 100644 --- a/fdbserver/include/fdbserver/Ratekeeper.h +++ b/fdbserver/include/fdbserver/Ratekeeper.h @@ -73,6 +73,9 @@ public: int64_t getDurabilityLag() const { return smoothLatestVersion.smoothTotal() - smoothDurableVersion.smoothTotal(); } void update(StorageQueuingMetricsReply const&, Smoother& smoothTotalDurableBytes); void addCommitCost(TransactionTagRef tagName, TransactionCommitCostEstimation const& cost); + + // Determine the ratio (limit / current throughput) for throttling based on write queue size + Optional getWriteQueueSizeLimitRatio(int64_t storageSpringBytes, int64_t storageTargetBytes) const; }; struct TLogQueueInfo {