Skip to content

Parquet hedged reads - #2979

Draft
ianton-ru wants to merge 3 commits into
antalya-26.8from
feature/antalya-26.8/parquet-hedged-reads
Draft

ianton-ru wants to merge 3 commits into
antalya-26.8from
feature/antalya-26.8/parquet-hedged-reads

Conversation

@ianton-ru

Copy link
Copy Markdown

Part of #2181 (Parquet v3 reader): hedged reads. This part works on its own.

A single slow S3 GET on 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 large ParquetFetchWaitTimeMicroseconds. 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. A GET of 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: ParquetPrefetcherHedgedReads counts the duplicate reads, and ParquetPrefetcherHedgedWins counts 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):

  • Experimental Feature

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_bytes and input_format_parquet_hedged_read_max_inflight for 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 events ParquetPrefetcherHedgedReads and ParquetPrefetcherHedgedWins.

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 in ProfileEvents.cpp.

CI/CD Options

Exclude tests:

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Unit tests
  • Performance tests
  • Aarch64 tests
  • All with ASAN
  • All with TSAN
  • All with MSAN
  • All with UBSAN
  • All with Coverage
  • All Regression
  • Disable CI Cache

Regression jobs to run:

  • Fast suites (mostly <1h)
  • Aggregate Functions (2h)
  • Alter (1.5h)
  • Benchmark (30m)
  • CAS (content-addressed storage; Antalya only)
  • ClickHouse Keeper (1h)
  • Iceberg (2h)
  • LDAP (1h)
  • OAuth (5m)
  • Parquet (1.5h)
  • RBAC (1.5h)
  • SSL Server (1h)
  • S3 (2h)
  • S3 Export (2h)
  • Swarms (30m)
  • Tiered Storage (2h)

UnamedRus and others added 3 commits November 30, 2026 16:55
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>
@ianton-ru ianton-ru added antalya performance Antalya Roadmap: Performance port-antalya PRs to be ported to all new Antalya releases antalya-26.8 labels Nov 30, 2026
@github-actions

Copy link
Copy Markdown

Workflow [PR], commit [000b174]

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

antalya antalya-26.8 performance Antalya Roadmap: Performance port-antalya PRs to be ported to all new Antalya releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants