Skip to content

Commit

Permalink
Add spill stats reporting to PeriodicStatsReporter
Browse files Browse the repository at this point in the history
  • Loading branch information
tanjialiang committed May 14, 2024
1 parent b29d933 commit 6ca5d25
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions velox/common/base/Counters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,5 +421,11 @@ void registerVeloxMetrics() {
// flushed due to memory reclaiming.
DEFINE_METRIC(
kMetricFileWriterEarlyFlushedRawBytes, facebook::velox::StatType::SUM);

// The current spilling memory usage in bytes.
DEFINE_METRIC(kMetricSpillMemoryBytes, facebook::velox::StatType::AVG);

// The peak spilling memory usage in bytes.
DEFINE_METRIC(kMetricSpillPeakMemoryBytes, facebook::velox::StatType::AVG);
}
} // namespace facebook::velox
6 changes: 6 additions & 0 deletions velox/common/base/Counters.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ constexpr folly::StringPiece kMetricSpillFlushTimeMs{
constexpr folly::StringPiece kMetricSpillWriteTimeMs{
"velox.spill_write_time_ms"};

constexpr folly::StringPiece kMetricSpillMemoryBytes{
"velox.spill_memory_bytes"};

constexpr folly::StringPiece kMetricSpillPeakMemoryBytes{
"velox.spill_peak_memory_bytes"};

constexpr folly::StringPiece kMetricFileWriterEarlyFlushedRawBytes{
"velox.file_writer_early_flushed_raw_bytes"};

Expand Down
13 changes: 13 additions & 0 deletions velox/common/base/PeriodicStatsReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ void PeriodicStatsReporter::start() {
"report_arbitrator_stats",
[this]() { reportArbitratorStats(); },
options_.arbitratorStatsIntervalMs);
addTask(
"report_spill_stats",
[this]() { reportSpillStats(); },
options_.spillStatsIntervalMs);
}

void PeriodicStatsReporter::stop() {
Expand Down Expand Up @@ -228,4 +232,13 @@ void PeriodicStatsReporter::reportCacheStats() {
lastCacheStats_ = cacheStats;
}

void PeriodicStatsReporter::reportSpillStats() {
const auto spillMemoryStats = velox::memory::spillMemoryPool()->stats();
LOG(INFO) << "Spill memory usage: current["
<< velox::succinctBytes(spillMemoryStats.currentBytes) << "] peak["
<< velox::succinctBytes(spillMemoryStats.peakBytes) << "]";
RECORD_METRIC_VALUE(kMetricSpillMemoryBytes, spillMemoryStats.currentBytes);
RECORD_METRIC_VALUE(kMetricSpillPeakMemoryBytes, spillMemoryStats.peakBytes);
}

} // namespace facebook::velox
4 changes: 4 additions & 0 deletions velox/common/base/PeriodicStatsReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#pragma once

#include <folly/experimental/ThreadedRepeatingFunctionRunner.h>
#include "velox/common/base/SpillStats.h"
#include "velox/common/caching/AsyncDataCache.h"
#include "velox/common/caching/SsdFile.h"
#include "velox/common/memory/MemoryArbitrator.h"
Expand Down Expand Up @@ -50,6 +51,8 @@ class PeriodicStatsReporter {
const memory::MemoryArbitrator* arbitrator{nullptr};
uint64_t arbitratorStatsIntervalMs{60'000};

uint64_t spillStatsIntervalMs{60'000};

std::string toString() const {
return fmt::format(
"allocatorStatsIntervalMs:{}, cacheStatsIntervalMs:{}, "
Expand Down Expand Up @@ -90,6 +93,7 @@ class PeriodicStatsReporter {
void reportCacheStats();
void reportAllocatorStats();
void reportArbitratorStats();
void reportSpillStats();

const velox::memory::MemoryAllocator* const allocator_{nullptr};
const velox::cache::AsyncDataCache* const cache_{nullptr};
Expand Down
6 changes: 6 additions & 0 deletions velox/docs/monitoring/metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ Spilling
* - file_writer_early_flushed_raw_bytes
- Sum
- Number of bytes pre-maturely flushed from file writers because of memory reclaiming.
* - spill_memory_bytes
- Avg
- The current spilling memory usage in bytes.
* - spill_peak_memory_bytes
- Avg
- The peak spilling memory usage in bytes.

Hive Connector
--------------
Expand Down

0 comments on commit 6ca5d25

Please sign in to comment.