apache / apache/iggy

Disk polling: investigate excess read bytes for small responses

Open
#4,175 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
4.9k
Forks
432
Avg merge
2d 10h
Merged PRs (30d)
173

Description

Part of #4174, which records the shared benchmark setup, revisions and evaluation criteria.

[DiskReadPlan::read_disk](https://github.com/apache/iggy/blob/8f1c0e260076f9fbe49539e904e43895bc24c3fe/core/partitions/src/poll_plan.rs) starts with a 1 MiB chunk, capped by remaining persisted bytes. Requested message count does not affect this size: the buffer is allocated and read before records are selected. A poll for one small message can therefore read beyond the complete batch it needs, and adjacent polls may revisit overlapping ranges.

Historical profiles measured the following CPU time in `__arch_copy_to_user`, the kernel function that copies data into application buffers:

| Workload | Baseline sampled CPU, µs per poll | Candidate sampled CPU, µs per poll |
| --- | ---: | ---: |
| Explicit offset, without concurrent writes | 46.973 | 45.758 |
| Explicit offset, with concurrent writes | 57.175 | 62.033 |

These old samples motivate inspecting copying, but do not show what fraction is avoidable or predict a latency saving. The shared sampling method and workload limits are in #4174.

1. Count file bytes requested, bytes returned, read calls, repeated ranges and rereads caused by incomplete batches. Record batch sizes and sparse index starting positions to distinguish necessary reads from excess bytes.
2. Evaluate one change to initial read sizing. The decoder needs complete batches, and the existing path grows the chunk and rereads when one does not fit. Smaller chunks can therefore trade fewer bytes for more calls and repeated work.
3. Validate through actual polling across small and larger responses, large batches, active and sealed segments, and concurrent writes. Measure read amplification alongside elapsed time, CPU and memory, with larger polls as a guardrail.

Share counters with #4176 while keeping implementation comparisons separate: fewer read bytes need not mean fewer verified batches. File descriptors and sealed indexes are already cached, and read buffers are allocated without zeroing.

Preserve partial read handling and corruption behavior along with the parent's correctness requirements. If buffer reuse is introduced, bound retained memory and define its behavior during segment growth, purge, truncation and history changes.

Contributor guide

Open the contributing guide

Research direction

Start with DiskReadPlan::read_disk in core/partitions/src/poll_plan.rs and read the shared benchmark setup, revisions, and evaluation criteria in #4174. Measure requested and returned bytes, read calls, rereads, batch sizes, and sparse-index positions across the listed workloads, then compare an initial read-sizing change while preserving partial-read and corruption behavior. Done means read amplification, elapsed time, CPU, and memory are measured for small and larger polls, with larger polls as a guardrail.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.