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

Create an example microservice using WebAssembly #38

Open
8 tasks
Gedochao opened this issue Jan 22, 2025 · 1 comment
Open
8 tasks

Create an example microservice using WebAssembly #38

Gedochao opened this issue Jan 22, 2025 · 1 comment

Comments

@Gedochao
Copy link

Gedochao commented Jan 22, 2025

  • example microservice representative for a cloud-native app compiled from Scala 3 to WebAssembly
  • fulfill performance requirements
    • cold start <100ms
    • response time for a running app <50ms
    • <100mb memory usage
    • <1mb used per thread
    • compiling and linking <10 minutes
  • test under traffic typical for a business application
@Gedochao Gedochao added this to the [Task 3] WebAssembly support milestone Jan 22, 2025
@Gedochao Gedochao changed the title Create an example microservice using the solution Create an example microservice using WebAssembly Jan 22, 2025
@tanishiking
Copy link

tanishiking commented Jan 23, 2025

There are multiple ways to deploy Wasm applications in cloud environments.

deploy to JS environemnt

One approach is the one mentioned in this blog post, (mentioned by @tgodzik) where only the business logic of the application is converted to Wasm, while communication with external systems is handled by JavaScript.
This can be used with any FaaS that supports JavaScript, such as AWS Lambda, or platforms like Cloudflare Workers that utilize V8 isolates.

With this method, it is possible to achieve deployment using the current Scala.js Wasm backend. However, the I don't see advantages over deploying Scala.js applications compiled to JavaScript (instead of Wasm). Perhaps the Wasm part might be slightly faster or the binary size slightly smaller, but the differences would be negligible.

Server side Wasm

Another approach involves converting applications into stand-alone Wasm (also known as "server-side Wasm") binaries and deploying them.

Stand-alone Wasm binaries are independent of JavaScript and interact with the system (e.g., HTTP communication or file access) through the WASI.

In this case, we can deploy these binaries

Currently, AFAIK, cloud providers such as GCP, AWS, and Azure do not offer FaaS specifically designed for server-side Wasm. As a result, deployment on them requires using Kubernetes.

One significant advantage of this approach is that it avoids the cold start delays caused by hypervisor-based OS startup, which is typical in environments like Lambda [1].

[1]: Comparative Performance Study of Lightweight Virtualization Used in Serverless Computing

On the other hand, the challenge lies in the fact that our current implementation of server-side Wasm for Scala.js relies on WASI preview 2 (Component Model). Unfortunately, the implementation status of this proposal in VM runtimes is still incomplete, and there is no VM at present capable of running our applications properly.

  • wasmtime: Supports the Component Model but lacks support for Exception Handling.
  • wasmedge: Supports Exception Handling but lacks support for the Component Model.

It comes down to two possible approaches we can take:

  • Use the current implementation to build applications for JavaScript environments (however, I don't see much value in this approach).
  • Although it will take time, continue working on the server-side Wasm implementation with the goal of deploying it to environments like Kubernetes. Over time, VMs are likely to implement both the Component Model and Exception Handling 🤞

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

No branches or pull requests

2 participants