Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions velox/common/base/Counters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ void registerVeloxMetrics() {
DEFINE_METRIC(
kMetricMemoryCacheSumEvictScore, facebook::velox::StatType::SUM);

// Number of lookups since last counter retrieval.
DEFINE_METRIC(kMetricMemoryCacheNumLookups, facebook::velox::StatType::SUM);

// Number of hits (saved IO) since last counter retrieval. The first hit to a
// prefetched entry does not count.
DEFINE_METRIC(kMetricMemoryCacheNumHits, facebook::velox::StatType::SUM);
Expand Down
3 changes: 3 additions & 0 deletions velox/common/base/Counters.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ constexpr std::string_view kMetricMemoryCacheTotalPrefetchBytes{
constexpr std::string_view kMetricMemoryCacheSumEvictScore{
"velox.memory_cache_sum_evict_score"};

constexpr std::string_view kMetricMemoryCacheNumLookups{
"velox.memory_cache_num_lookups"};

constexpr std::string_view kMetricMemoryCacheNumHits{
"velox.memory_cache_num_hits"};

Expand Down
1 change: 1 addition & 0 deletions velox/common/base/PeriodicStatsReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ void PeriodicStatsReporter::reportCacheStats() {
// Memory cache cumulative stats.
const auto deltaCacheStats = cacheStats - lastCacheStats_;

REPORT_IF_NOT_ZERO(kMetricMemoryCacheNumLookups, deltaCacheStats.numLookup);
REPORT_IF_NOT_ZERO(kMetricMemoryCacheNumHits, deltaCacheStats.numHit);
REPORT_IF_NOT_ZERO(kMetricMemoryCacheHitBytes, deltaCacheStats.hitBytes);
REPORT_IF_NOT_ZERO(kMetricMemoryCacheNumNew, deltaCacheStats.numNew);
Expand Down
7 changes: 5 additions & 2 deletions velox/common/base/tests/StatsReporterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ TEST_F(PeriodicStatsReporterTest, basic) {
ASSERT_EQ(
counterMap.count(std::string(kMetricMemoryAllocatorTotalUsedBytes)), 1);
// Check deltas are not reported
ASSERT_EQ(counterMap.count(std::string(kMetricMemoryCacheNumLookups)), 0);
ASSERT_EQ(counterMap.count(std::string(kMetricMemoryCacheNumHits)), 0);
ASSERT_EQ(counterMap.count(std::string(kMetricMemoryCacheHitBytes)), 0);
ASSERT_EQ(counterMap.count(std::string(kMetricMemoryCacheNumNew)), 0);
Expand Down Expand Up @@ -536,7 +537,8 @@ TEST_F(PeriodicStatsReporterTest, basic) {
newSsdStats->readWithoutChecksumChecks = 10;
newSsdStats->entriesRecovered = 10;
cache.updateStats(
{.numHit = 10,
{.numLookup = 10,
.numHit = 10,
.hitBytes = 10,
.numNew = 10,
.numEvict = 10,
Expand All @@ -559,6 +561,7 @@ TEST_F(PeriodicStatsReporterTest, basic) {
// Check delta stats are reported
{
std::lock_guard<std::mutex> l(reporter_->m);
ASSERT_EQ(counterMap.count(std::string(kMetricMemoryCacheNumLookups)), 1);
ASSERT_EQ(counterMap.count(std::string(kMetricMemoryCacheNumHits)), 1);
ASSERT_EQ(counterMap.count(std::string(kMetricMemoryCacheHitBytes)), 1);
ASSERT_EQ(counterMap.count(std::string(kMetricMemoryCacheNumNew)), 1);
Expand Down Expand Up @@ -604,7 +607,7 @@ TEST_F(PeriodicStatsReporterTest, basic) {
counterMap.count(std::string(kMetricSsdCacheRecoveredEntries)), 1);
ASSERT_EQ(
counterMap.count(std::string(kMetricSsdCacheReadWithoutChecksum)), 1);
ASSERT_EQ(counterMap.size(), 56);
ASSERT_EQ(counterMap.size(), 57);
}
}

Expand Down
3 changes: 3 additions & 0 deletions velox/common/caching/AsyncDataCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ CachePin CacheShard::findOrCreate(
{
std::lock_guard<std::mutex> l(mutex_);
++eventCounter_;
++numLookup_;
auto it = entryMap_.find(key);
if (it != entryMap_.end()) {
auto* foundEntry = it->second;
Expand Down Expand Up @@ -549,6 +550,7 @@ void CacheShard::updateStats(CacheStats& stats) {
++stats.numTinyEntries;
}
}
stats.numLookup += numLookup_;
stats.numHit += numHit_;
stats.hitBytes += hitBytes_;
stats.numNew += numNew_;
Expand Down Expand Up @@ -638,6 +640,7 @@ bool CacheShard::removeFileEntries(

CacheStats CacheStats::operator-(const CacheStats& other) const {
CacheStats result;
result.numLookup = numLookup - other.numLookup;
result.numHit = numHit - other.numHit;
result.hitBytes = hitBytes - other.hitBytes;
result.numNew = numNew - other.numNew;
Expand Down
4 changes: 4 additions & 0 deletions velox/common/caching/AsyncDataCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ struct CacheStats {

/// ============= Cumulative stats =============

/// Number of lookups.
int64_t numLookup{0};
/// Number of hits (saved IO). The first hit to a prefetched entry does not
/// count.
int64_t numHit{0};
Expand Down Expand Up @@ -668,6 +670,8 @@ class CacheShard {
uint32_t eventCounter_{0};
// Maximum retainable entry score(). Anything above this is evictable.
int32_t evictionThreshold_{kNoThreshold};
// Cumulative count of cache lookups.
uint64_t numLookup_{0};
// Cumulative count of cache hits.
uint64_t numHit_{0};
// Cumulative Sum of bytes in cache hits.
Expand Down
3 changes: 3 additions & 0 deletions velox/docs/monitoring/metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ Cache
- Sum
- Sum of scores of evicted entries. This serves to infer an average lifetime
for entries in cache.
* - memory_cache_num_lookups
- Sum
- Number of lookups since last counter retrieval.
* - memory_cache_num_hits
- Sum
- Number of hits (saved IO) since last counter retrieval. The first hit to a
Expand Down
Loading