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

Allow blocking for realtime #4739

Merged
merged 7 commits into from
May 23, 2024

Conversation

daichifukui
Copy link
Contributor

Hi,

I'd like to resolve #4738 with the two commits involved in this PR.

I'd be happy if you could review this and merge it if the changes are satisfactory.

Thanks.

lib/wasix/src/state/env.rs Outdated Show resolved Hide resolved
lib/wasix/src/syscalls/wasi/poll_oneoff.rs Outdated Show resolved Hide resolved
@john-sharratt
Copy link
Contributor

@daichifukui you can use these methods to enable blocking sleeps (its off by default now)

let mut ctx = WasiFunctionEnv::new();
ctx.data_mut().capabilities.threading.enable_blocking_sleep = true;

or

WasiEnvBuilder::capabilities/capabilities_mut

@syrusakbary syrusakbary merged commit e921a04 into wasmerio:main May 23, 2024
61 checks passed
@daichifukui
Copy link
Contributor Author

Thanks for merging this.
With the upstream Wasmer merged with this PR, the experimental result looks fine as expected.

$ cargo run --example wasi-manual-setup --release --features "cranelift,wasi,tokio,backend,wasi"
   Compiling wasmer-workspace v4.3.1 (/home/daichi/proj/00_research/wasmer)
    Finished release [optimized] target(s) in 10.09s
     Running `target/release/examples/wasi-manual-setup`
Compiling module...
Starting `tokio` runtime...
Creating `WasiEnv`...
Instantiating module with WASI imports...
Attach WASI memory...
Call WASI `_start` function...
Time elapsed is: 1.000473704s
Time elapsed is: 1.000321374s
Time elapsed is: 1.000355565s
Time elapsed is: 1.000525461s
Time elapsed is: 1.000523367s
Time elapsed is: 1.000522247s
Time elapsed is: 1.000340287s
Time elapsed is: 1.000248193s
Time elapsed is: 1.000456189s
Time elapsed is: 1.000468035s

daichifukui and others added 3 commits May 25, 2024 07:20
A WasiEnv now has a flag that signifies if it's allowed
to block the current thread and the flag is expected to
be referenced when the current thread can be blocked for
optimising the performance. In addition, the flag is set
true when wasm modules are invoked via the CLI. wasmer-wasix
uses a tokio runtime for many things according to wasmerio#4299, but
tokio does not always bring the best performance in Wasmer
as described in wasmerio#4738, hence this update.

Signed-off-by: Daichi Fukui <daichi1.fukui@toshiba.co.jp>
Allow different sleep form of poll_oneoff, which
just sleeps for relative time using std::thread::sleep.
That form of poll_oneoff is only available if there is
only one subscription and it is allowed to block
the current thread, contributing to more consistent
sleep times. This update would help improve
the real-time performance of wasmer.

Closes: wasmerio#4738

Signed-off-by: Daichi Fukui <daichi1.fukui@toshiba.co.jp>
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.

Low real-time performance with simple test
3 participants