mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-25 06:05:53 +00:00
added cache hit rate to server info (#220)
This commit is contained in:
@@ -53,11 +53,13 @@ SimpleCache::getSuccessor(ripple::uint256 const& key, uint32_t seq) const
|
||||
if (!full_)
|
||||
return {};
|
||||
std::shared_lock{mtx_};
|
||||
successorReqCounter_++;
|
||||
if (seq != latestSeq_)
|
||||
return {};
|
||||
auto e = map_.upper_bound(key);
|
||||
if (e == map_.end())
|
||||
return {};
|
||||
successorHitCounter_++;
|
||||
return {{e->first, e->second.blob}};
|
||||
}
|
||||
|
||||
@@ -81,11 +83,13 @@ SimpleCache::get(ripple::uint256 const& key, uint32_t seq) const
|
||||
if (seq > latestSeq_)
|
||||
return {};
|
||||
std::shared_lock lck{mtx_};
|
||||
objectReqCounter_++;
|
||||
auto e = map_.find(key);
|
||||
if (e == map_.end())
|
||||
return {};
|
||||
if (seq < e->second.seq)
|
||||
return {};
|
||||
objectHitCounter_++;
|
||||
return {e->second.blob};
|
||||
}
|
||||
|
||||
@@ -117,4 +121,18 @@ SimpleCache::size() const
|
||||
std::shared_lock lck{mtx_};
|
||||
return map_.size();
|
||||
}
|
||||
float
|
||||
SimpleCache::getObjectHitRate() const
|
||||
{
|
||||
if (!objectReqCounter_)
|
||||
return 1;
|
||||
return ((float)objectHitCounter_) / objectReqCounter_;
|
||||
}
|
||||
float
|
||||
SimpleCache::getSuccessorHitRate() const
|
||||
{
|
||||
if (!successorReqCounter_)
|
||||
return 1;
|
||||
return ((float)successorHitCounter_) / successorReqCounter_;
|
||||
}
|
||||
} // namespace Backend
|
||||
|
||||
@@ -18,6 +18,13 @@ class SimpleCache
|
||||
Blob blob;
|
||||
};
|
||||
|
||||
// counters for fetchLedgerObject(s) hit rate
|
||||
mutable std::atomic_uint32_t objectReqCounter_;
|
||||
mutable std::atomic_uint32_t objectHitCounter_;
|
||||
// counters for fetchSuccessorKey hit rate
|
||||
mutable std::atomic_uint32_t successorReqCounter_;
|
||||
mutable std::atomic_uint32_t successorHitCounter_;
|
||||
|
||||
std::map<ripple::uint256, CacheEntry> map_;
|
||||
mutable std::shared_mutex mtx_;
|
||||
uint32_t latestSeq_ = 0;
|
||||
@@ -62,6 +69,12 @@ public:
|
||||
|
||||
size_t
|
||||
size() const;
|
||||
|
||||
float
|
||||
getObjectHitRate() const;
|
||||
|
||||
float
|
||||
getSuccessorHitRate() const;
|
||||
};
|
||||
|
||||
} // namespace Backend
|
||||
|
||||
@@ -90,6 +90,9 @@ doServerInfo(Context const& context)
|
||||
cache["is_full"] = context.backend->cache().isFull();
|
||||
cache["latest_ledger_seq"] =
|
||||
context.backend->cache().latestLedgerSequence();
|
||||
cache["object_hit_rate"] = context.backend->cache().getObjectHitRate();
|
||||
cache["successor_hit_rate"] =
|
||||
context.backend->cache().getSuccessorHitRate();
|
||||
|
||||
if (admin)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user