diff --git a/fdbclient/DatabaseContext.h b/fdbclient/DatabaseContext.h index b197e9edff..62413cea7a 100644 --- a/fdbclient/DatabaseContext.h +++ b/fdbclient/DatabaseContext.h @@ -167,7 +167,7 @@ public: UID dbId; bool internal; // Only contexts created through the C client and fdbcli are non-internal - std::map, TagThrottleInfo>> throttledTags; + PrioritizedTagThrottleMap throttledTags; CounterCollection cc; diff --git a/fdbclient/MasterProxyInterface.h b/fdbclient/MasterProxyInterface.h index b0d9289806..c1e6f29686 100644 --- a/fdbclient/MasterProxyInterface.h +++ b/fdbclient/MasterProxyInterface.h @@ -165,7 +165,7 @@ struct GetReadVersionReply { bool locked; Optional metadataVersion; - std::map, TagThrottleInfo> tagThrottleInfo; + TagThrottleMap tagThrottleInfo; GetReadVersionReply() : version(invalidVersion), locked(false) {} diff --git a/fdbclient/TagThrottle.h b/fdbclient/TagThrottle.h index d1d8f40a55..eb2d1c66c3 100644 --- a/fdbclient/TagThrottle.h +++ b/fdbclient/TagThrottle.h @@ -86,6 +86,8 @@ struct TagThrottleInfo { } }; +BINARY_SERIALIZABLE(TagThrottleInfo::Priority); + class TagSet { public: typedef std::set::const_iterator const_iterator; @@ -148,7 +150,8 @@ struct dynamic_size_traits : std::true_type { } }; -BINARY_SERIALIZABLE(TagThrottleInfo::Priority); +typedef std::unordered_map, TagThrottleInfo, std::hash> TagThrottleMap; +typedef std::map PrioritizedTagThrottleMap; namespace ThrottleApi { // Currently, only 1 tag in a key is supported diff --git a/fdbserver/MasterProxyServer.actor.cpp b/fdbserver/MasterProxyServer.actor.cpp index fb44891d83..f8e9ee0eed 100644 --- a/fdbserver/MasterProxyServer.actor.cpp +++ b/fdbserver/MasterProxyServer.actor.cpp @@ -99,7 +99,7 @@ struct ProxyStats { ACTOR Future getRate(UID myID, Reference> db, int64_t* inTransactionCount, int64_t* inBatchTransactionCount, double* outTransactionRate, double* outBatchTransactionRate, GetHealthMetricsReply* healthMetricsReply, GetHealthMetricsReply* detailedHealthMetricsReply, - std::map, TagThrottleInfo>> *throttledTags) { + PrioritizedTagThrottleMap *throttledTags) { state Future nextRequestTimer = Never(); state Future leaseTimeout = Never(); state Future reply = Never(); @@ -1292,7 +1292,7 @@ ACTOR Future getLiveCommittedVersion(ProxyCommitData* commi } ACTOR Future sendGrvReplies(Future replyFuture, std::vector requests, - ProxyStats* stats, Version minKnownCommittedVersion, std::map, TagThrottleInfo>> throttledTags) { + ProxyStats* stats, Version minKnownCommittedVersion, PrioritizedTagThrottleMap throttledTags) { GetReadVersionReply _baseReply = wait(replyFuture); GetReadVersionReply baseReply = _baseReply; double end = g_network->timer(); @@ -1353,7 +1353,7 @@ ACTOR static Future transactionStarter( state Deque batchQueue; state vector otherProxies; - state std::map, TagThrottleInfo>> throttledTags; + state PrioritizedTagThrottleMap throttledTags; state PromiseStream replyTimes; addActor.send(getRate(proxy.id(), db, &transactionCount, &batchTransactionCount, &normalRateInfo.rate, &batchRateInfo.rate, healthMetricsReply, detailedHealthMetricsReply, &throttledTags)); diff --git a/fdbserver/Ratekeeper.actor.cpp b/fdbserver/Ratekeeper.actor.cpp index 5e5534858d..0245a4eea3 100644 --- a/fdbserver/Ratekeeper.actor.cpp +++ b/fdbserver/Ratekeeper.actor.cpp @@ -187,8 +187,7 @@ struct RatekeeperData { double lastWarning; double lastSSListFetchedTimestamp; - typedef std::map, TagThrottleInfo> ThrottleMap; - std::map tagThrottles; + PrioritizedTagThrottleMap tagThrottles; RatekeeperLimits normalLimits; RatekeeperLimits batchLimits; @@ -417,8 +416,8 @@ ACTOR Future monitorThrottlingChanges(RatekeeperData *self) { } TraceEvent("RatekeeperReadThrottles").detail("NumThrottledTags", throttledTags.get().size()); - std::map newThrottles; - std::map> oldThrottleIterators; + PrioritizedTagThrottleMap newThrottles; + std::map> oldThrottleIterators; for(auto t : self->tagThrottles) { oldThrottleIterators[t.first] = std::make_pair(t.second.begin(), t.second.end()); } @@ -473,7 +472,7 @@ ACTOR Future monitorThrottlingChanges(RatekeeperData *self) { } } -void updateRate(RatekeeperData* self, RatekeeperLimits* limits, RatekeeperData::ThrottleMap& throttledTags) { +void updateRate(RatekeeperData* self, RatekeeperLimits* limits, TagThrottleMap& throttledTags) { //double controlFactor = ; // dt / eFoldingTime double actualTps = self->smoothReleasedTransactions.smoothRate(); diff --git a/fdbserver/RatekeeperInterface.h b/fdbserver/RatekeeperInterface.h index 554b5a5608..80eeeb7b9b 100644 --- a/fdbserver/RatekeeperInterface.h +++ b/fdbserver/RatekeeperInterface.h @@ -59,7 +59,7 @@ struct GetRateInfoReply { double leaseDuration; HealthMetrics healthMetrics; - std::map, TagThrottleInfo>> throttledTags; + PrioritizedTagThrottleMap throttledTags; template void serialize(Ar& ar) { diff --git a/fdbserver/storageserver.actor.cpp b/fdbserver/storageserver.actor.cpp index b2099ee47c..bcceac20db 100644 --- a/fdbserver/storageserver.actor.cpp +++ b/fdbserver/storageserver.actor.cpp @@ -460,7 +460,7 @@ public: : tag(tag), count(count), fractionalBusyness((double)count/totalCount), elapsed(elapsed) {} }; - std::map, int64_t> intervalCounts; // TODO: use a hash for performance + std::unordered_map, int64_t, std::hash> intervalCounts; int64_t intervalTotalCount = 0; Standalone busiestTag; int64_t busiestTagCount = 0; diff --git a/flow/Arena.h b/flow/Arena.h index 74a29c8b82..4dcf8a9418 100644 --- a/flow/Arena.h +++ b/flow/Arena.h @@ -585,7 +585,17 @@ private: }; #pragma pack( pop ) -template<> +namespace std { + template <> + struct hash { + static constexpr std::hash hashFunc{}; + std::size_t operator()(StringRef const& tag) const { + return hashFunc(std::string_view((const char*)tag.begin(), tag.size())); + } + }; +} + +template <> struct TraceableString { static const char* begin(StringRef value) { return reinterpret_cast(value.begin()); diff --git a/flow/flat_buffers.h b/flow/flat_buffers.h index 5847c40bf2..fbea9b72d5 100644 --- a/flow/flat_buffers.h +++ b/flow/flat_buffers.h @@ -174,6 +174,29 @@ struct vector_like_traits> : std::true_type return v.begin(); } }; +template +struct vector_like_traits> : std::true_type { + using Vec = std::unordered_map; + using value_type = std::pair; + using iterator = typename Vec::const_iterator; + using insert_iterator = std::insert_iterator; + + template + static size_t num_entries(const Vec& v, Context&) { + return v.size(); + } + template + static void reserve(Vec& v, size_t size, Context&) {} + + template + static insert_iterator insert(Vec& v, Context&) { + return std::inserter(v, v.end()); + } + template + static iterator begin(const Vec& v, Context&) { + return v.begin(); + } +}; template struct vector_like_traits> : std::true_type {