Skip to content

feat: add compio support for aya-log#1272

Closed
Sherlock-Holo wants to merge 4 commits intoaya-rs:mainfrom
Sherlock-Holo:async_compio
Closed

feat: add compio support for aya-log#1272
Sherlock-Holo wants to merge 4 commits intoaya-rs:mainfrom
Sherlock-Holo:async_compio

Conversation

@Sherlock-Holo
Copy link
Copy Markdown

@Sherlock-Holo Sherlock-Holo commented May 30, 2025

compio is a completion IO based async runtime, specially it provide io-uring for Linux user

adding compio support can allow user use aya-log in another async runtime, not just tokio


This change is Reviewable

@netlify
Copy link
Copy Markdown

netlify Bot commented May 30, 2025

Deploy Preview for aya-rs-docs failed.

Built without sensitive environment variables

Name Link
🔨 Latest commit 8897b57
🔍 Latest deploy log https://app.netlify.com/projects/aya-rs-docs/deploys/683b253229ab310009a59708

@mergify mergify Bot added aya This is about aya (userspace) aya-log Relating to aya-log labels May 30, 2025
In previous version, user can enable async_tokio and async_std features,
however when both of them are enabled, tokio will be ignored.

After add async_compio feature, when two or three async features are enabled,
user may confuse which one will be used. IMO the better way is make
these async features are mutual exclusivity, user should only enable
one, if more than async feautres are enabled, will compile fail with
compile_error! macro. Also if none of the async feature is enabled in
aya-log, will compile fail too
@Sherlock-Holo
Copy link
Copy Markdown
Author

In previous version, user can enable async_tokio and async_std features, however when both of them are enabled, tokio will be ignored.

After add async_compio feature, when two or three async features are enabled, user may confuse which one will be used. IMO the better way is make these async features are mutual exclusivity, user should only enable one, if more than async feautres are enabled, will compile fail with compile_error! macro. Also if none of the async feature is enabled in aya-log, will compile fail too

Copy link
Copy Markdown
Member

@vadorovsky vadorovsky left a comment

Choose a reason for hiding this comment

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

Amazing stuff, thanks for your contribution! 🙏

Would you be interested in adding compio support to integration tests? So far they are using only tokio.

I think making this one work with compio would be enough:

#[test(tokio::test)]
async fn log() {

Comment thread aya-log/src/lib.rs

// check async feature mutual exclusivity
#[cfg(all(feature = "async_tokio", feature = "async_std"))]
compile_error!("Cannot enable both async_tokio and async_std features at the same time");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's a very good change, thanks for doing that! I agree that async* features should be mutually exclusive.

The CI jobs are red, because they use cargo hack with --feature-powerset flag, which tries out all combinations of features. To make it work, you will need to add the

--mutually-exclusive-features async_compio,async_tokio,async_std

flag in the following places:

- name: Run miri
run: |
set -euxo pipefail
cargo +nightly hack miri test --all-targets --feature-powerset \
--exclude aya-ebpf \
--exclude aya-ebpf-bindings \
--exclude aya-log-ebpf \
--exclude integration-ebpf \
--exclude integration-test \
--workspace

- name: Build
run: |
set -euxo pipefail
cargo hack build --all-targets --feature-powerset \
--exclude aya-ebpf \
--exclude aya-ebpf-bindings \
--exclude aya-log-ebpf \
--exclude integration-ebpf \
--exclude xtask \
--workspace

- name: Test
env:
RUST_BACKTRACE: full
run: |
set -euxo pipefail
cargo hack test --all-targets --feature-powerset \
--exclude aya-ebpf \
--exclude aya-ebpf-bindings \
--exclude aya-log-ebpf \
--exclude integration-ebpf \
--exclude integration-test \
--exclude xtask \
--workspace

- name: Doctests
env:
RUST_BACKTRACE: full
run: |
set -euxo pipefail
cargo hack test --doc --feature-powerset \
--exclude aya-ebpf \
--exclude aya-ebpf-bindings \
--exclude aya-log-ebpf \
--exclude init \
--exclude integration-ebpf \
--exclude integration-test \
--exclude xtask \
--workspace

- name: Build
env:
CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.bpf_target_arch }}
run: |
set -euxo pipefail
cargo +nightly hack build \
--target ${{ matrix.target }} \
-Z build-std=core \
--package aya-ebpf \
--package aya-log-ebpf \
--feature-powerset

- name: Test
env:
CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.bpf_target_arch }}
RUST_BACKTRACE: full
run: |
set -euxo pipefail
cargo hack test \
--doc \
--package aya-ebpf \
--package aya-log-ebpf \
--feature-powerset

Copy link
Copy Markdown
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

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

Reviewed 8 of 8 files at r1, 4 of 4 files at r2, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @Sherlock-Holo)


aya/Cargo.toml line 25 at r1 (raw file):

bitflags = { workspace = true }
bytes = { workspace = true }
compio = { workspace = true, optional = true, features = ["default"] }

what is "default"? can we just use the features we need?


aya/Cargo.toml line 40 at r1 (raw file):

async_std = ["dep:async-io"]
async_tokio = ["tokio/net"]
async_compio = ["dep:compio"]

here we should activate the appropriate features of async-global-executor

Code quote:

async_std = ["dep:async-io"]
async_tokio = ["tokio/net"]
async_compio = ["dep:compio"]

aya-log/src/lib.rs line 188 at r1 (raw file):

            #[cfg(all(not(feature = "async_tokio"), feature = "async_std"))]
            {
                async_global_executor::spawn(fut).detach();

we can just always use this, right? we should be selecting the correct features of async-global-executor to handle the different runtimes internally.

@Sherlock-Holo
Copy link
Copy Markdown
Author

Amazing stuff, thanks for your contribution! 🙏

Would you be interested in adding compio support to integration tests? So far they are using only tokio.

I think making this one work with compio would be enough:

#[test(tokio::test)]
async fn log() {

Should I add features

+[features]
+default = ["async_tokio"]
+async_tokio = ["dep:tokio", "aya-log/async_tokio"]
+async_compio = ["dep:compio", "aya-log/async_compio"]

to make this test function work with tokio and compio? Because we make the async features mutual exclusivity

compio should only enable the runtime feature, and just enable the io-uring feature in aya-log test
@Sherlock-Holo
Copy link
Copy Markdown
Author

Reviewed 8 of 8 files at r1, 4 of 4 files at r2, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @Sherlock-Holo)

aya/Cargo.toml line 25 at r1 (raw file):

bitflags = { workspace = true }
bytes = { workspace = true }
compio = { workspace = true, optional = true, features = ["default"] }

what is "default"? can we just use the features we need?

yes, we should just enable runtime feature

aya/Cargo.toml line 40 at r1 (raw file):

async_std = ["dep:async-io"]
async_tokio = ["tokio/net"]
async_compio = ["dep:compio"]

here we should activate the appropriate features of async-global-executor

Code quote:

async_std = ["dep:async-io"]
async_tokio = ["tokio/net"]
async_compio = ["dep:compio"]

yes, we should enable async-global-executor/async-io in aya-log, and consider aya doesn't depend on async-global-executor directly, I think we should keep aya only depend on async-io

aya-log/src/lib.rs line 188 at r1 (raw file):

            #[cfg(all(not(feature = "async_tokio"), feature = "async_std"))]
            {
                async_global_executor::spawn(fut).detach();

we can just always use this, right? we should be selecting the correct features of async-global-executor to handle the different runtimes internally.

It seems even we use async-global-executor with tokio feature, the future is still running in async-global-executor runtime, not in tokio runtime, also the IO job will finish in tokio driver, but it starts 2 runtime: async-global-executor and tokio runtime

@tamird
Copy link
Copy Markdown
Member

tamird commented Jul 5, 2025

I haven't forgotten about this; I think we should first remove the tokio dependency from aya-log so that it can be more-or-less agnostic to the user's chosen executor. I sent #1288 to do this.

Regarding mutually-exclusive features, see https://doc.rust-lang.org/cargo/reference/features.html#mutually-exclusive-features. I'm not sure we should do that. Currently in aya we arbitrarily pick tokio over async-io, but we should probably go the other way since async-io spins a thread, so its futures would work with any executor, including tokio.

@tamird
Copy link
Copy Markdown
Member

tamird commented Jul 8, 2025

With #1288 merged, I think we can close this. We are moving away from supporting individual async runtimes. You can use aya-log with compio using https://docs.rs/compio/latest/compio/fs/struct.AsyncFd.html similarly to the manner in which the example code uses tokio.

See also #1292.

@tamird
Copy link
Copy Markdown
Member

tamird commented Jul 9, 2025

Closing. Please let us know if your needs remain unmet.

@tamird tamird closed this Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aya This is about aya (userspace) aya-log Relating to aya-log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants