diff --git a/fdbserver/Ratekeeper.actor.cpp b/fdbserver/Ratekeeper.actor.cpp index ced068bbab..0d3fc3fb4d 100644 --- a/fdbserver/Ratekeeper.actor.cpp +++ b/fdbserver/Ratekeeper.actor.cpp @@ -1403,20 +1403,31 @@ UpdateCommitCostRequest StorageQueueInfo::refreshCommitCost(double elapsed) { busiestWriteTags.clear(); TransactionTag busiestTag; TransactionCommitCostEstimation maxCost; - double maxRate = 0, maxBusyness = 0; + double maxRate = 0; + std::priority_queue, std::greater> topKWriters; for (const auto& [tag, cost] : tagCostEst) { double rate = cost.getCostSum() / elapsed; + double busyness = static_cast(maxCost.getCostSum()) / totalWriteCosts; + if (rate < SERVER_KNOBS->MIN_TAG_WRITE_PAGES_RATE * CLIENT_KNOBS->TAG_THROTTLING_PAGE_SIZE) { + continue; + } + if (topKWriters.size() < SERVER_KNOBS->SS_THROTTLE_TAGS_TRACKED) { + topKWriters.emplace(tag, rate, busyness); + } else if (topKWriters.top().rate < rate) { + topKWriters.pop(); + topKWriters.emplace(tag, rate, busyness); + } + if (rate > maxRate) { busiestTag = tag; maxRate = rate; maxCost = cost; } } - if (maxRate > SERVER_KNOBS->MIN_TAG_WRITE_PAGES_RATE * CLIENT_KNOBS->TAG_THROTTLING_PAGE_SIZE) { - // TraceEvent("RefreshSSCommitCost").detail("TotalWriteCost", totalWriteCost).detail("TotalWriteOps",totalWriteOps); - ASSERT_GT(totalWriteCosts, 0); - maxBusyness = double(maxCost.getCostSum()) / totalWriteCosts; - busiestWriteTags.emplace_back(busiestTag, maxRate, maxBusyness); + + while (!topKWriters.empty()) { + busiestWriteTags.push_back(std::move(topKWriters.top())); + topKWriters.pop(); } UpdateCommitCostRequest updateCommitCostRequest{ ratekeeperID,