Skip to content

refactor(diskann): decouple from libaio via dlopen#532

Open
richyreachy wants to merge 19 commits into
alibaba:mainfrom
richyreachy:refactor/diskann_dlopen
Open

refactor(diskann): decouple from libaio via dlopen#532
richyreachy wants to merge 19 commits into
alibaba:mainfrom
richyreachy:refactor/diskann_dlopen

Conversation

@richyreachy

@richyreachy richyreachy commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Currently, DiskAnn ships as a separate runtime-loaded .so (libzvec_diskann_plugin.so) file which requires a hard build-time dependency on libaio-dev.

This PR improves with a simpler, more robust design. Probing libaio.so file, a thread-safe singleton dlopens it and caches the syscall pointers. If libaio is absent, it will fall back to degrade to synchronous pread() with a warning.

The following shows the performance comparison on Cohere 1M between pread w/ and w/o AIO enabled. (Aliyun g9i, PL0, 10000 IOPS)

Pread w/ AIO Enabled

Result FP32-100 FP32-300 FP32-500 FP16-100 FP16-300 FP16-500
Search Mem(4 thread) 503M 503M 503M 486M 486M 486M
Recall@1 96.1% 98.9% 99% 95.3% 97.8% 98.4%
Recall@10 96.14% 98.6% 98.94% 95.86% 98.1% 98.63%
Recall@50 93.394% 97.782% 98.598% 93.452% 97.354% 98.188%
QPS(1 thread) 32.6 11.2 6.7 32.3 11.1 6.7
QPS(2 thread) 65.2 22.3 13.5 64.5 22.4 13.4
QPS(4 thread) 106.4 36.6 22.1 106.4 36.6 22.1

Pread w/o AIO Enabled

Result FP32-100 FP32-300 FP32-500 FP16-100 FP16-300 FP16-500
Search Mem(4 thread) 503M 503M 503M 486M 486M 486M
Recall@1 96.1% 98.9% 99% 95.3% 97.8% 98.4%
Recall@10 96.14% 98.6% 98.94% 95.86% 98.1% 98.63%
Recall@50 93.394% 97.782% 98.598% 93.452% 97.354% 98.188%
QPS(1 thread) 18.4 6.3 3.8 18.3 6.3 3.8
QPS(2 thread) 36.8 12.6 7.5 36.5 12.6 7.6
QPS(4 thread) 73.1 25.2 15.2 72.5 25.1 15.2

@richyreachy richyreachy requested a review from egolearner June 30, 2026 08:54
@iaojnh

iaojnh commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

可以把workflow里,打包相关的libaio-devel依赖,在这个PR里移除

Comment thread python/tests/test_collection_diskann.py Outdated
Comment thread src/binding/python/exports.map Outdated
# so these exports are no longer needed for runtime plugin loading,
# but they are still required for the C API and for C++ consumers
# that link against the shared module.
extern "C++" {

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.

我建议删掉除了判断diskann with aio available的接口外,任何diskann plugin的接口。

站在用户侧,只需要关注当前runtime是否支持libaio的diskann就够了。

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.

已经清理

// on these symbols; they may change or be removed in future releases. On
// hosts missing libaio the bring-up fails cleanly and only DiskAnn becomes
// unavailable — other index types (HNSW / IVF / Flat / Vamana) keep working.
// on these symbols; they may change or be removed in future releases.

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.

这个头文件还有必要留着吗?可能只需要放一个static标记位就可以了

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.

diskann plugin命名歧义,已经去掉了改成diskann runtime,并只保留了load aio检测判断的必要代码。

sudo apt-get install -y clang libomp-dev
shell: bash

- name: Install AIO

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.

ci移除了aio,如何验证w aio的情况?这里w aio和w/o aio的情况都要测

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.

add a job to test w/ libaio, since main job is test on default env

transform(log_level.begin(), log_level.end(), log_level.begin(), ::tolower);
if (LOG_LEVEL.find(log_level) != LOG_LEVEL.end()) {
IndexLoggerBroker::SetLevel(LOG_LEVEL[log_level]);
zvec::ailego::LoggerBroker::SetLevel(LOG_LEVEL[log_level]);

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.

这行是干啥的?

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.

去掉了,之前的没有生效,改成了新的log库

transform(log_level.begin(), log_level.end(), log_level.begin(), ::tolower);
if (LOG_LEVEL.find(log_level) != LOG_LEVEL.end()) {
IndexLoggerBroker::SetLevel(LOG_LEVEL[log_level]);
zvec::ailego::LoggerBroker::SetLevel(LOG_LEVEL[log_level]);

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.

这行是干啥的?

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.

去掉了,之前的没有生效,改成了新的log库

Comment thread thirdparty/arrow/CMakeLists.txt Outdated

set(CONFIGURE_ENV_LIST "")
if(USE_OSS_MIRROR)
set(_OSS_BASE "https://zvec-bj.oss-cn-beijing.aliyuncs.com/thirdparty")

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.

去掉吧

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.

done

--no-build-isolation \
--config-settings='cmake.define.BUILD_TOOLS=ON' \
--config-settings='cmake.define.ENABLE_WERROR=ON' \
--config-settings='cmake.define.CMAKE_C_COMPILER_LAUNCHER=ccache' \

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.

为啥要新开一个yml文件,理论上编译过程和03-macos-linux-build完全一样吧?没必要重复编译吧

sudo apt-get update
sudo apt-get install -y --no-install-recommends \
lcov libaio-dev
lcov

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.

coverage可以不用去掉吧?不然也测不到diskann代码的覆盖度了?

Comment thread pyproject.toml
# libaio-devel lives in BaseOS; disable EPEL so a flaky EPEL mirror cannot
# break metadata refresh.
before-all = "dnf install -y --disablerepo=epel libaio-devel"
# libaio is loaded at runtime via dlopen (no build-time dependency).

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.

这句注释也去掉好了,没有上下文看到这句话也挺让人疑惑的,或者把注释写完整一些也行

namespace zvec {

// Return codes for InitDiskAnnRuntime().
enum DiskAnnRuntimeStatus {

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.

这里的接口如何考虑后续给diskann引入io uring?

//
// The ``path`` parameter is retained for API compatibility but is ignored.
int InitDiskAnnRuntime(const std::string &path = "");

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.

这里要放在core层的interface吗?作为db层需要用到这个吗?

c api是不是没调整?

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.

4 participants