mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-24 13:45:52 +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_)
|
if (!full_)
|
||||||
return {};
|
return {};
|
||||||
std::shared_lock{mtx_};
|
std::shared_lock{mtx_};
|
||||||
|
successorReqCounter_++;
|
||||||
if (seq != latestSeq_)
|
if (seq != latestSeq_)
|
||||||
return {};
|
return {};
|
||||||
auto e = map_.upper_bound(key);
|
auto e = map_.upper_bound(key);
|
||||||
if (e == map_.end())
|
if (e == map_.end())
|
||||||
return {};
|
return {};
|
||||||
|
successorHitCounter_++;
|
||||||
return {{e->first, e->second.blob}};
|
return {{e->first, e->second.blob}};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,11 +83,13 @@ SimpleCache::get(ripple::uint256 const& key, uint32_t seq) const
|
|||||||
if (seq > latestSeq_)
|
if (seq > latestSeq_)
|
||||||
return {};
|
return {};
|
||||||
std::shared_lock lck{mtx_};
|
std::shared_lock lck{mtx_};
|
||||||
|
objectReqCounter_++;
|
||||||
auto e = map_.find(key);
|
auto e = map_.find(key);
|
||||||
if (e == map_.end())
|
if (e == map_.end())
|
||||||
return {};
|
return {};
|
||||||
if (seq < e->second.seq)
|
if (seq < e->second.seq)
|
||||||
return {};
|
return {};
|
||||||
|
objectHitCounter_++;
|
||||||
return {e->second.blob};
|
return {e->second.blob};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,4 +121,18 @@ SimpleCache::size() const
|
|||||||
std::shared_lock lck{mtx_};
|
std::shared_lock lck{mtx_};
|
||||||
return map_.size();
|
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
|
} // namespace Backend
|
||||||
|
|||||||
@@ -18,6 +18,13 @@ class SimpleCache
|
|||||||
Blob blob;
|
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_;
|
std::map<ripple::uint256, CacheEntry> map_;
|
||||||
mutable std::shared_mutex mtx_;
|
mutable std::shared_mutex mtx_;
|
||||||
uint32_t latestSeq_ = 0;
|
uint32_t latestSeq_ = 0;
|
||||||
@@ -62,6 +69,12 @@ public:
|
|||||||
|
|
||||||
size_t
|
size_t
|
||||||
size() const;
|
size() const;
|
||||||
|
|
||||||
|
float
|
||||||
|
getObjectHitRate() const;
|
||||||
|
|
||||||
|
float
|
||||||
|
getSuccessorHitRate() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Backend
|
} // namespace Backend
|
||||||
|
|||||||
@@ -90,6 +90,9 @@ doServerInfo(Context const& context)
|
|||||||
cache["is_full"] = context.backend->cache().isFull();
|
cache["is_full"] = context.backend->cache().isFull();
|
||||||
cache["latest_ledger_seq"] =
|
cache["latest_ledger_seq"] =
|
||||||
context.backend->cache().latestLedgerSequence();
|
context.backend->cache().latestLedgerSequence();
|
||||||
|
cache["object_hit_rate"] = context.backend->cache().getObjectHitRate();
|
||||||
|
cache["successor_hit_rate"] =
|
||||||
|
context.backend->cache().getSuccessorHitRate();
|
||||||
|
|
||||||
if (admin)
|
if (admin)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user