Slide 1

Slide 1 text

WebAssembly beyond the browser Mete Atamel Developer Advocate at Google @meteatamel atamel.dev speakerdeck.com/meteatamel

Slide 2

Slide 2 text

What, Why? 01

Slide 3

Slide 3 text

What is WebAssembly? WebAssembly (Wasm) is a binary instruction format for a stack-based virtual machine Wasm is designed as a portable compilation target for programming languages webassembly.org

Slide 4

Slide 4 text

What is WebAssembly? The original use cases were focused on augmenting Javascript in the browser to run native code in a fast, portable, and secure way for games, 3D graphics, etc. Supported by all major browsers webassembly.org

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

CNCF 2022 Annual Survey

Slide 7

Slide 7 text

Wasm outside the browser There’s an attempt to get WebAssembly run outside the browser with the WASI project Instead of running apps as VMs or containers, you can run them as faster, smaller, more secure, and more portable WebAssembly modules

Slide 8

Slide 8 text

Faster ⇒ Wasm apps start faster than containers with no cold-start Smaller ⇒ A HelloWorld Rust app in Wasm is smaller than in an OCI container More secure ⇒ Containers execute in an allow-by-default model whereas Wasm apps execute in a deny-by-default sandbox More portable ⇒ A container built for linux/amd64 won’t work on linux/arm64 whereas a wasm32/wasi module can run on any host with a Wasm runtime

Slide 9

Slide 9 text

Hardware VM Hardware VM Container VM Container 2010 2000 2020 Wasm Is this the future?

Slide 10

Slide 10 text

Use cases www.fermyon.com/blog/four-domains-wasm

Slide 11

Slide 11 text

Wasm runtimes WASI 02

Slide 12

Slide 12 text

Wasm is a portable compilation target

Slide 13

Slide 13 text

Wasm modules run across CPU architectures

Slide 14

Slide 14 text

Wasm runtimes Many runtimes exist, some of the popular ones are: ● wasmtime: A Bytecode Alliance project ● wasmedge: A CNCF project ● wasmer: From a startup github.com/appcypher/awesome-wasm-runtimes

Slide 15

Slide 15 text

WebAssembly System Interface wasi.dev

Slide 16

Slide 16 text

POSIX-inspired Preview1 with a limited number of functions ● Read and write files (sandboxed) ● Program arguments ● Environment variables ● Hardware clock ● Random ● Sockets (limited) WebAssembly System Interface wasi.dev

Slide 17

Slide 17 text

But… A lot of WASI is still in proposals and limited ⇒ e.g. no socket support yet Some runtimes implement their own sockets ⇒ e.g. wasmedge has extensions for sockets in Rust, JavaScript, C Some projects try to enhance WASI ⇒ e.g. WAGI adds HTTP handlers around WASI ⇒ e.g. WASIX adds full POSIX but only supported on wasmer runtime No Garbage collection yet but there’s a proposal ⇒ github.com/WebAssembly/gc wasi.dev

Slide 18

Slide 18 text

Demo: Compile code to Wasm+Wasi and run on a Wasm runtime github.com/meteatamel/wasm-basics/tree/main/samples/rust-wasm github.com/meteatamel/wasm-basics/tree/main/samples/dotnet8-wasm github.com/meteatamel/wasm-basics/tree/main/samples/go-wasm github.com/jamesward/hello-kotlin-wasm/tree/wasi

Slide 19

Slide 19 text

Running WASI in Docker 03

Slide 20

Slide 20 text

Why take something smaller, faster, and more portable than a container and run it inside Docker? To combine the benefits of Wasm with the benefits of existing ecosystem with Docker, Kubernetes, etc.

Slide 21

Slide 21 text

runwasi Project to facilitate running Wasm managed by containerd Starting in 4.15, Docker uses runwasi to run Wasm with wasmedge, wasmtime, spin, and slight Azure AKS is also previewing Wasm node pools using runwasi with spin and slight on wasmtime WebAssembly and containerd: How it works by Nigel Poulton

Slide 22

Slide 22 text

Demo: Running Wasm in Docker github.com/meteatamel/wasm-basics/tree/main/samples/rust-wasm-docker

Slide 23

Slide 23 text

WAGI WASIX 04

Slide 24

Slide 24 text

WAGI allows you to run WASI binaries as HTTP handlers Write a command line application that prints a few headers, and compile it to wasm32/wasi Add an entry to the modules.toml matching URL to the Wasm module and that’s it WebAssembly Gateway Interface github.com/deislabs/wagi

Slide 25

Slide 25 text

WASIX – Extends WASI with most of the missing POSIX features wasix.org

Slide 26

Slide 26 text

Demo: Running WASI binaries as HTTP handlers with WAGI github.com/meteatamel/wasm-basics/tree/main/samples/hello-wagi

Slide 27

Slide 27 text

Frameworks Languages 05

Slide 28

Slide 28 text

Frameworks Lots of Wasm frameworks out there with different capabilities Spin by Fermyon seems to be the most comprehensive and relevant for Wasm services Handles the HTTP request/response using WAGI. Spin SDKs are available in Rust, Go and .NET. and all Wasi-compatible languages are supported github.com/fermyon/spin

Slide 29

Slide 29 text

Demo: Running Python with Spin on Wasm github.com/meteatamel/wasm-basics/tree/main/samples/python-spin-wasm

Slide 30

Slide 30 text

Language support for Wasm + WASI Rust Good support (but no Tokio or async) C, C++ Good support (but no C++ exceptions or threads) Go Support via TinyGo (but reflection is not supported) and Go 1.21 RC JavaScript Support via Shopify’s Javy on QuickJS? C#/.NET Support via experimental WASI SDK in .NET 7, wasi-experimental workload in .NET 8 preview Java Support via a fork by Fermyon of TeaVM (Java to Javascript compiler)? Kotlin Support via kowasm and Node experimental WASI API Python Support via CPython on wasm32-wasi Ruby Support via ruby.wasm www.fermyon.com/wasm-languages/webassembly-language-support enarx.dev/docs/WebAssembly/Introduction

Slide 31

Slide 31 text

Conclusions Wasm outside the browser is a fast changing space Standards and language support need to mature for Wasm microservices Will it replace containers? Possibly Exciting time to learn this new technology!

Slide 32

Slide 32 text

Thank you! Mete Atamel Developer Advocate at Google @meteatamel atamel.dev speakerdeck.com/meteatamel github.com/meteatamel/wasm-basics Feedback? bit.ly/atamel