Skip to content

perf(diskann): async I/O overlap and dynamic beam - #617

Open
richyreachy wants to merge 12 commits into
alibaba:mainfrom
richyreachy:refactor/diskann_perf_improve
Open

perf(diskann): async I/O overlap and dynamic beam#617
richyreachy wants to merge 12 commits into
alibaba:mainfrom
richyreachy:refactor/diskann_perf_improve

Conversation

@richyreachy

Copy link
Copy Markdown
Collaborator

Optimizes DiskANN beam search to overlap CPU computation with disk I/O, reducing query latency on disk-bound workloads. By introducing the following improvement:

Add async I/O submit/get_completed pattern to allow CPU work to proceed while disk reads still in progress.
Add dynamic beam width to ensure sufficient I/O parallelism while preventing excessive concurrent I/Os.
Fix Visit-filter deduplication to avoid redundant candidate insertions for already-visited nodes.

@richyreachy
richyreachy requested a review from iaojnh July 24, 2026 03:13

uint32_t num_ios = 0;

uint32_t effective_beam_width =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sector_buffer_ 可能会因为这个改动越界。比如这个值是32,要写入4096维的FP32,sector = ceil(16788 / 4096) = 5,32 * 5就会超过kMaxSectorReadNum = 128

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


int ret = LibAioLoader::Instance().io_submit(ctx, (int64_t)n_ops,
batch.cb_ptrs.data());
if (ret == (int)n_ops) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果还有正在异步处理的请求,这个条件不满足,不应该被视为失败降级pread

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


for (int i = 0; i < ret; i++) {
uint32_t idx = (uint32_t)(uintptr_t)evts[i].data;
if ((int64_t)evts[i].res != (int64_t)batch.cbs[idx].u.c.nbytes) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该是要异常处理的,不能直接往completed_indices里丢。必要时可能要考虑降级。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

if (min_req < 1) min_req = 1;

std::vector<io_event_t> evts(n_remaining);
int ret = LibAioLoader::Instance().io_getevents(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning here leaves submitted AIO requests unquiesced. For example, -EINTR may occur while requests are still in flight; they can later overwrite the shared sector buffer or leave completion events that the next PendingBatch misattributes to its own requests. Retry EINTR; for permanent failures, drain or destroy/recreate the AIO context before returning.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants