Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opt-in use of async_io::block_on in bevy_tasks #9625

Closed
BigWingBeat opened this issue Aug 29, 2023 · 0 comments · Fixed by #9626
Closed

Opt-in use of async_io::block_on in bevy_tasks #9625

BigWingBeat opened this issue Aug 29, 2023 · 0 comments · Fixed by #9626
Labels
A-Tasks Tools for parallel and async work C-Feature A new feature, making something new possible

Comments

@BigWingBeat
Copy link
Contributor

What problem does this solve or what need does it fill?

bevy_tasks currently uses the block_on method provided by futures-lite. If you are using async-io and bevy_tasks is the only async runtime in your application, async-io experiences extreme latency spikes (Upwards of hundreds of ms), as io events only get processed by the fallback thread, which uses an exponential backoff strategy. async-io provides its own block_on method which processes io events when idle, and is the intended way of avoiding this issue.

What solution would you like?

Add async-io as an optional dependency for bevy_tasks, which replaces uses of futures-lite's block_on method with async-io's when enabled. This solution is already used by async-global-executor to solve the same problem (Quote from their readme):

async-io: if enabled, async-global-executor will use async_io::block_on instead of futures_lite::future::block_on internally. this is preferred if your application also uses async-io.

What alternative(s) have you considered?

  • Using tokio or async-std alongside bevy_tasks, and letting them fight over system resources

Additional context

I encountered this issue while adding a bevy_tasks backend to Quinn, so I could use it in Bevy without having multiple async runtimes competing with eachother, which from what I understand is undesirable at best. (Quinn currently lets you choose between tokio or async-std.)

@BigWingBeat BigWingBeat added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Aug 29, 2023
@alice-i-cecile alice-i-cecile added A-Tasks Tools for parallel and async work and removed S-Needs-Triage This issue needs to be labelled labels Aug 29, 2023
github-merge-queue bot pushed a commit that referenced this issue Sep 25, 2023
# Objective

Fixes #9625

## Solution

Adds `async-io` as an optional dependency of `bevy_tasks`. When enabled,
this causes calls to `futures_lite::future::block_on` to be replaced
with calls to `async_io::block_on`.

---

## Changelog

- Added a new `async-io` feature to `bevy_tasks`. When enabled, this
causes `bevy_tasks` to use `async-io`'s implemention of `block_on`
instead of `futures-lite`'s implementation. You should enable this if
you use `async-io` in your application.
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this issue Jan 9, 2024
# Objective

Fixes bevyengine#9625

## Solution

Adds `async-io` as an optional dependency of `bevy_tasks`. When enabled,
this causes calls to `futures_lite::future::block_on` to be replaced
with calls to `async_io::block_on`.

---

## Changelog

- Added a new `async-io` feature to `bevy_tasks`. When enabled, this
causes `bevy_tasks` to use `async-io`'s implemention of `block_on`
instead of `futures-lite`'s implementation. You should enable this if
you use `async-io` in your application.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Tasks Tools for parallel and async work C-Feature A new feature, making something new possible
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants