Repository navigation
Parquet hedged reads - #2979
Draft
ianton-ru wants to merge 3 commits into
Draft
Parquet hedged reads#2979ianton-ru wants to merge 3 commits into
ianton-ru wants to merge 3 commits into
Conversation
Standard S3 GET has a fat tail (p50 ~5 ms vs p99 100+ ms), so a single slow read on the critical path stalls a decode task (visible as large ParquetFetchWaitTimeMicroseconds). Hedging: if a read a consumer is blocked on doesn't finish within a threshold, issue a duplicate read and use whichever returns first (S3 GET is idempotent). Phase A (this commit) runs the hedge synchronously on the already-blocked consumer thread: getRangeData waits up to the threshold via a new CompletionNotification::wait_for, then reads the same range into task->hedge_buf and serves from it, notifying so sharers wake. This has no async-lifetime hazard - the hedge finishes before the PrefetchHandle is released. A fully async race (Phase B) is deferred: it would need decreaseTaskRefcount to defer freeing hedge_buf until an in-flight hedge finishes (the refcount/Deallocated path assumes a single reader), which risks a use-after-free if done naively. Scope: remote (RandomRead) reads only, no larger than a size cap (latency, not throughput), one hedge per task, bounded by a concurrency cap (cost control). Settings (all experimental, off by default): * input_format_parquet_hedged_read_threshold_ms (0 = off) * input_format_parquet_hedged_read_max_bytes (default 4 MiB) * input_format_parquet_hedged_read_max_inflight (default 4) ProfileEvents: ParquetPrefetcherHedgedReads, ParquetPrefetcherHedgedWins. Signed-off-by: UnamedRus <dtitmoav@gmail.com>
The existing `input_format_parquet_hedged_read_threshold_ms` hedges a remote Parquet read once its *total* time exceeds a budget. On object storage that conflates two very different situations: a connection that has stalled (no bytes yet) and a large transfer that is streaming normally but simply takes a while. Budgeting on total time either hedges healthy large reads (wasteful duplicate GETs) or sets the budget so high it no longer cuts the stall tail. Add `input_format_parquet_hedged_read_ttfb_threshold_ms`: fire the hedge when the primary read has not received its *first byte* within the threshold. Time-to-first-byte is largely independent of read size, so this isolates a stalled/slow frontend from a slow-but-progressing transfer. When set (> 0) it takes precedence over the total-time threshold; both remain bounded by `input_format_parquet_hedged_read_max_bytes` and `input_format_parquet_hedged_read_max_inflight`. Mechanism: the primary read now passes a progress callback into `readBigAt` that notifies a new per-task `first_byte` latch on the first reported bytes; `hedgeReadSync` waits on `first_byte` (TTFB mode) instead of `completion`. `first_byte` is also notified unconditionally when the primary finishes, so a read that produced no progress callback (cached region, split path) never leaves a hedge waiting. Measured on a synthetic wide-Iceberg table (62x1 GiB files, q reads ~690 MiB across part-sized S3 GETs, v3 + parallel Iceberg metadata): ttfb_ms p50ms maxms readMiB hedges wins 0(off) 6558 7499 690 0 0 5 6149 6490 1075 158 158 20 5987 6179 1043 133 133 40 5341 5942 749 21 21 At 40 ms: p50 -19%, tail max -21%, +9% bytes (21 hedges, all winning) - the trigger fires only on genuinely stalled frontends. Result is unchanged with the hedge on (identical output hash across thresholds); the loser read is discarded. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: UnamedRus <dtitmoav@gmail.com>
Reads an S3 Parquet file with hedging off, with the total-time trigger, with the first-byte trigger, with the size cap and with no concurrent hedges allowed. The result must not change. `ParquetPrefetcherHedgedReads` must be zero unless hedging is enabled and within the caps, and positive with the total-time trigger. The first-byte trigger cannot be forced on a local S3 emulator, so only the unchanged result and `ParquetPrefetcherHedgedWins` not exceeding `ParquetPrefetcherHedgedReads` are checked for it. Related: #2181 Related: #2966 Co-authored-by: Cursor <cursoragent@cursor.com>
13 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #2181 (Parquet v3 reader): hedged reads. This part works on its own.
A single slow S3
GETon the critical path stalls a decode task. Typical S3 latency has a long tail (p50 around 5 ms, p99 above 100 ms), which shows up as a largeParquetFetchWaitTimeMicroseconds. With hedging, when a read that a consumer is blocked on does not finish within a threshold, the reader issues a duplicate read of the same range and uses the one that finishes first. AGETof a byte range is idempotent, so the duplicate is safe. The slower read is discarded.The hedge runs synchronously on the consumer thread that is already blocked, so it finishes before the task buffer is released. A fully asynchronous race is not part of this PR: it would need the task refcount path to defer freeing the hedge buffer until an in-flight hedge finishes.
Hedging applies only to remote (random-access) reads, to reads no larger than a size cap (it targets latency, not throughput), at most once per read task, and with a cap on concurrent hedges to bound the extra traffic. New experimental settings, all off by default:
input_format_parquet_hedged_read_threshold_ms(default 0, off): hedge a read that has not finished within this many milliseconds.input_format_parquet_hedged_read_ttfb_threshold_ms(default 0, off): hedge a read whose first byte has not arrived within this many milliseconds, which tells a stalled connection from a large transfer that streams normally. When set, it takes precedence over the total-time threshold.input_format_parquet_hedged_read_max_bytes(default 4 MiB): do not hedge reads larger than this. 0 means no limit.input_format_parquet_hedged_read_max_inflight(default 4): the maximum number of hedges running at once.New profile events:
ParquetPrefetcherHedgedReadscounts the duplicate reads, andParquetPrefetcherHedgedWinscounts the hedges whose result was used.The code comes from two commits of #2181 by UnamedRus: the hedged reads and the time-to-first-byte trigger. Measurements in the second commit, on a synthetic wide Iceberg table (62 files of 1 GiB, a query reading about 690 MiB in part-sized
GETs): with the first-byte threshold at 40 ms, the median query time fell by 19% and the maximum by 21%, with 9% more bytes read (21 hedges, all of them used). I did not repeat those measurements here. The test checks that results are unchanged with hedging on, that hedges are issued only when enabled, and that the size and concurrency caps hold. It cannot force the first-byte trigger to fire, because on a local S3 emulator the first byte usually arrives in time, so that trigger is checked only for unchanged results.Related: #2181
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Added the experimental settings
input_format_parquet_hedged_read_threshold_ms,input_format_parquet_hedged_read_ttfb_threshold_ms,input_format_parquet_hedged_read_max_bytesandinput_format_parquet_hedged_read_max_inflightfor the Parquet v3 reader. A remote read that is slow, or whose first byte is late, is duplicated and the first result is used, which cuts the tail latency of object-storage reads. They are off by default. Added the profile eventsParquetPrefetcherHedgedReadsandParquetPrefetcherHedgedWins.Documentation entry for user-facing changes
The settings are documented in their declarations (
input_format_parquet_hedged_read_*), and the profile events in their descriptions inProfileEvents.cpp.CI/CD Options
Exclude tests:
Regression jobs to run: