Skip to content

Commit 68f03dd

Browse files
committed
perf(metrics): reduce prefetch I/O metrics overhead
1 parent 6158ed2 commit 68f03dd

13 files changed

Lines changed: 180 additions & 104 deletions

docs/source/user_guide/metrics.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@ Prefetch I/O
8787
------------
8888

8989
``PrefetchIoMetrics`` describes only I/O that passes through the prefetch reader's instrumented
90-
input streams. It is not a whole-query or whole-table I/O total. All counters and histograms
91-
accumulate for the reader lifetime and are retained across ``SetReadSchema()`` and cache reset.
90+
input streams. It is not a whole-query or whole-table I/O total. All counters accumulate for the
91+
reader lifetime and are retained across ``SetReadSchema()`` and cache reset. Latency uses relaxed
92+
atomic count and sum counters instead of per-I/O histograms to reduce hot-path cost. Collection is
93+
disabled by default; set ``prefetch.io-metrics.enabled`` to ``true`` in the read options to enable
94+
it. When disabled, these per-I/O metrics are absent and the input streams have no metrics
95+
instrumentation.
9296
``io.async.pending`` is current state and returns to zero when all callbacks complete.
9397
These metrics are C++-only and have no counterparts in Java Paimon.
9498

@@ -100,11 +104,13 @@ These metrics are C++-only and have no counterparts in Java Paimon.
100104
"io.read.requested-bytes", "counter", "bytes", "Bytes requested by synchronous reads"
101105
"io.read.physical-bytes", "counter", "bytes", "Bytes returned by successful synchronous reads"
102106
"io.read.failed", "counter", "requests", "Failed synchronous reads"
103-
"io.read.latency-us", "histogram", "microseconds", "Synchronous read latency"
107+
"io.read.latency.count", "counter", "requests", "Completed synchronous read latency samples"
108+
"io.read.latency.sum-us", "counter", "microseconds", "Sum of synchronous read latency"
104109
"io.async.requests", "counter", "requests", "Asynchronous read requests"
105110
"io.async.requested-bytes", "counter", "bytes", "Bytes requested by asynchronous reads"
106111
"io.async.physical-bytes", "counter", "bytes", "Bytes attributed to successful asynchronous reads"
107112
"io.async.completed", "counter", "requests", "Successful asynchronous reads"
108113
"io.async.failed", "counter", "requests", "Failed asynchronous reads"
109114
"io.async.pending", "gauge", "requests", "Asynchronous callbacks not yet completed"
110-
"io.async.latency-us", "histogram", "microseconds", "Asynchronous callback latency"
115+
"io.async.latency.count", "counter", "requests", "Completed asynchronous callback latency samples"
116+
"io.async.latency.sum-us", "counter", "microseconds", "Sum of asynchronous callback latency"

include/paimon/defs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ struct PAIMON_EXPORT Options {
204204
/// for the target bucket when rebuilding the cache. Default value is true.
205205
static const char SCAN_MANIFEST_ENTRY_LAZY_DECODE_ENABLED[];
206206

207+
/// "prefetch.io-metrics.enabled" - Whether to collect per-I/O metrics for prefetch reads.
208+
/// Default value is false.
209+
static const char PREFETCH_IO_METRICS_ENABLED[];
210+
207211
/// "read.batch-size" - Read batch size for any file format if it supports.
208212
/// The default value is 1024.
209213
static const char READ_BATCH_SIZE[];

include/paimon/reader/prefetch_file_batch_reader.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@ class PAIMON_EXPORT PrefetchIoMetrics {
5656
static constexpr char READ_REQUESTED_BYTES[] = "io.read.requested-bytes";
5757
static constexpr char READ_PHYSICAL_BYTES[] = "io.read.physical-bytes";
5858
static constexpr char READ_FAILED[] = "io.read.failed";
59-
static constexpr char READ_LATENCY_US[] = "io.read.latency-us";
59+
static constexpr char READ_LATENCY_COUNT[] = "io.read.latency.count";
60+
static constexpr char READ_LATENCY_SUM_US[] = "io.read.latency.sum-us";
6061
static constexpr char ASYNC_REQUESTS[] = "io.async.requests";
6162
static constexpr char ASYNC_REQUESTED_BYTES[] = "io.async.requested-bytes";
6263
static constexpr char ASYNC_PHYSICAL_BYTES[] = "io.async.physical-bytes";
6364
static constexpr char ASYNC_COMPLETED[] = "io.async.completed";
6465
static constexpr char ASYNC_FAILED[] = "io.async.failed";
6566
static constexpr char ASYNC_PENDING[] = "io.async.pending";
66-
static constexpr char ASYNC_LATENCY_US[] = "io.async.latency-us";
67+
static constexpr char ASYNC_LATENCY_COUNT[] = "io.async.latency.count";
68+
static constexpr char ASYNC_LATENCY_SUM_US[] = "io.async.latency.sum-us";
6769
};
6870

6971
/// The prefetch file batch reader extends the basic FileBatchReader interface for prefetch read,

src/paimon/common/defs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const char Options::SCAN_MANIFEST_ENTRY_CACHE_MAX_SNAPSHOTS[] =
6161
"scan.manifest-entry-cache.max-snapshots";
6262
const char Options::SCAN_MANIFEST_ENTRY_LAZY_DECODE_ENABLED[] =
6363
"scan.manifest-entry.lazy-decode.enabled";
64+
const char Options::PREFETCH_IO_METRICS_ENABLED[] = "prefetch.io-metrics.enabled";
6465
const char Options::READ_BATCH_SIZE[] = "read.batch-size";
6566
const char Options::WRITE_BATCH_SIZE[] = "write.batch-size";
6667
const char Options::WRITE_BUFFER_SIZE[] = "write-buffer-size";

src/paimon/common/file_index/bitmap/apply_bitmap_index_batch_reader_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ class ApplyBitmapIndexBatchReaderTest : public ::testing::Test,
9797
prefetch_batch_count, batch_size, prefetch_batch_count * 2,
9898
/*enable_adaptive_prefetch_strategy=*/false, executor_,
9999
/*initialize_read_ranges=*/true,
100-
/*read_ahead_cache_enabled=*/true, CacheConfig(), pool_));
100+
/*read_ahead_cache_enabled=*/true, CacheConfig(),
101+
/*enable_io_metrics=*/false, pool_));
101102
} else {
102103
file_batch_reader =
103104
std::make_unique<MockFileBatchReader>(data, target_type_, batch_size);

0 commit comments

Comments
 (0)