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

Wasmer 4 High CPU Usage Crashing PCs #4320

Closed
gluax opened this issue Nov 21, 2023 · 5 comments
Closed

Wasmer 4 High CPU Usage Crashing PCs #4320

gluax opened this issue Nov 21, 2023 · 5 comments
Labels
📦 lib-wasi About wasmer-wasi performance priority-medium Medium priority issue
Milestone

Comments

@gluax
Copy link

gluax commented Nov 21, 2023

Describe the bug

We are upgrading to wasmer version 4 from wasmer version 3 as a rust dependency. But when we do so the CPU difference is massive, enough to crash computers.

I'm running on windows 10. However, we've noticed the same problem on MacOS as well.

wasmer -vV; rustc -vV

wasmer 4.2.3 (7cb550d 2023-10-27)
binary: wasmer-cli
commit-hash: 7cb550db60656352cc527eaf869981d39448e38d
commit-date: 2023-10-27
host: x86_64-pc-windows-msvc
compiler: singlepass,cranelift,llvm
rustc 1.74.0 (79e9716c9 2023-11-13)
binary: rustc
commit-hash: 79e9716c980570bfd1f666e3b16ac583f0168962
commit-date: 2023-11-13
host: x86_64-pc-windows-msvc
release: 1.74.0
LLVM version: 17.0.4

Steps to reproduce

We built a minimal reproduction here.
You can build and run the same program, but with different wasmer versions.

Note: our use case is spinning up wasm VMs across threads for parallel execution.

Expected behavior

I would not expect wasmer 4 to use nearly as much CPU usage as it does in the same use case we used wasmer 3.

Actual behavior

Here's the CPU usage of wasmer3.
image

I'm trying to get a screenshot of wasmer4 CPU usage... but its crashing my PC before I can even get one ☠️.
I will update the issue if I can manage to get one.

image

Windows doesn't show CPU usage over 100%, but my coworkers on Macos have stated a CPU percentage of 155~%.

Note, this requires us to hard kill the program now, as ctrl-c(I don't remember what signal this sends off the top of my head) is unresponsive. It needs a SIGKILL or for Windows task manager since the terminal app itself becomes unresponsive.

Note This problem doesn't occur until each wasmer after compiling our example wasm. I don't mean building the wasm from rust, but when wasmer compiles the wasm module. Those both use about 2.5% CPU usage on my machine.

Additional context

Does this have to do with the internals of wasmer4 now using Rayon? I didn't go super deep, but it looked like it was spinning up its thread pool now. If that's true... it seems to break the use case of wanting to spin up running multiple wasms on different threads.

@gluax gluax changed the title Wasmer 4 High CPU Usage Wasmer 4 High CPU Usage Crashing PC Nov 21, 2023
@gluax gluax changed the title Wasmer 4 High CPU Usage Crashing PC Wasmer 4 High CPU Usage Crashing PCs Nov 21, 2023
@theduke
Copy link
Contributor

theduke commented Nov 23, 2023

@gluax we are currently investigating some related performance issues.

But an important bit of context if you want to run multiple instances is to share the Runtime between the instances, which means they will share a common thread pool.

You will want to manually construct a PluggableRuntime, and then use it with WasiEnvBuilder::runtime(my_rt).

@gluax
Copy link
Author

gluax commented Nov 23, 2023

@theduke we have done that approach as well. But the result is the same with the cpu maxing out and crashing.

@Arshia001 Arshia001 added 📦 lib-vm About wasmer-vm priority-medium Medium priority issue performance labels Nov 28, 2023
@Arshia001 Arshia001 added this to the v4.3 milestone Nov 28, 2023
@Arshia001 Arshia001 added 📦 lib-wasi About wasmer-wasi and removed 📦 lib-vm About wasmer-vm labels Nov 28, 2023
@maminrayej
Copy link
Contributor

@gluax Can you confirm the CPU usage is reduced on the master branch in your use case?

I can see the improvement on my local machine using your minimal reproduction example.

@gluax
Copy link
Author

gluax commented Nov 29, 2023

@maminrayej Can confirm on both windows and macos, the CPU usage is now less than the old wasmer3 version actually when using that branch!

@maminrayej
Copy link
Contributor

Excellent.

@theduke I'm closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 lib-wasi About wasmer-wasi performance priority-medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

4 participants