WebAssembly is neither Web nor Assembly. This may sound odd at first, but makes a lot of sense if you look at some of its core features: Fast, efficient, sandboxed. Something we want from container technologies!
In this talk, we look at WASM as an alternative for your everyday container. We develop and deploy applications that run in WASM, not in the browser, but everywhere, including the cloud. Together with accompanying technologies like WASI and the experimental WAGI, we see how WebAssembly can be the future for cloud apps, including serverless.
11. There are two important principles baked
into Web Assembly
12. Portability
• WebAssembly is an assembly language for a conceptual machine, not a
physical one. It needs a runtime on top of a real machine to execute.
This is why it can run across a variety of different machine architectures
13. Security
• WebAssembly is sandboxed. This means that code can’t talk directly to
the OS. The host needs to provide functions to access OS capabilities.
The host can limit what the sandbox is able to do.
• In the best case, exceptions are made explicit!
14. Just as WebAssembly is a language for a
conceptual machine, it needs a system
interface for a conceptual operating system
26. WebAssembly in Host environments
• WebAssembly makes native code extensions less complicated.
• Think Node, Ruby, Python not compiling C/C++ Code to their native
host, but rather use a WASM file
• Rust, Go, C++ can use WASM to safely run extensions that don’t interfere
with its own memory.
29. use pulldown_cmark::{html, Parser};
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn render(input: &str) -> String {
let parser = Parser::new(input);
let mut html_output = String::new();
html::push_html(&mut html_output, parser);
return html_output;
}
main.rs
A Markdown module we
want to use cross env
Find all demos at
https://github.com/bytecodealliance/wasmtime-demos
30. import process from 'process';
import wasm_interface_types from 'wasm-interface-types';
import { promisify } from 'util';
import { readFile } from 'fs';
const baseURL = new URL(`${process.cwd()}/`, 'file://');
export async function resolve(specifier, parentModuleURL = baseURL, defaultResolver) {
if (specifier.endsWith(".wasm")) {
return {
url: new URL(specifier, parentModuleURL).href,
format: 'dynamic',
};
} else {
return await defaultResolver(specifier, parentModuleURL.toString());
}
}
const readFileAsync = promisify(readFile);
loader.mjs - part 1
31. // Dynamically instantiates a wasm module with interface types included after
// processing it with `wasm-interface-types`. Note that this executes
// `wasm-interface-types` in Node itself (which is itself WebAssembly).
export async function dynamicInstantiate(url) {
const wasmBytes = await readFileAsync(new URL(url).pathname);
const wasm = await wasm_interface_types.process(wasmBytes);
return {
exports: Object.keys(wasm),
execute: exports => {
for (const key in wasm) {
exports[key].set(wasm[key]);
}
},
}
}
loader.mjs - part 12
32. import { render } from './markdown.wasm';
console.log(render("# Hello, node!"));
main.mjs
Load it like a JS file!
You might know that
pattern from Webpack
$ $ node --experimental-wasm-mv --experimental-modules --loader ./loader.mjs ./main.mjs
33. # Import our Python extension `wasmtime_py` which loads the ability to load wasm
# modules natively within Python.
import wasmtime
# Next up, loader our `markdown.wasm` file. This is loaded by the `wasmtime_py`
# extension above and hooked up into the Python module system.
import markdown
# And now we can use the markdown file!
print(markdown.render('# Hello, Python!'))
38. Care about servers, less
Scale-out happens automatically
No infrastructure management
Consumption based billing
Examples
Google Cloud Run
AWS Fargate
Write less servers
Focus on business logic
Stateless development mindset
Glue logic between services
Examples
AWS Lambda
Azure Functions
AUTOSCALING FUNCTIONS AS A SERVICE
39. Care about servers, less
Scale-out happens automatically
No infrastructure management
Consumption based billing
Examples
Google Cloud Run
AWS Fargate
Write less servers
Focus on business logic
Stateless development mindset
Glue logic between services
Examples
AWS Lambda
Azure Functions
AUTOSCALING FUNCTIONS AS A SERVICE
"
52. Fastly’s Compute@Edge
• Fastly allows to execute WASM workloads on their edge infrastructure
• As of recent you also can run JavaScript workloads
• They run in Spidermonkey and are compiled ahead of time
• How? Run JS in Spidermonkey at build time, initialise and save memory
snapshot!
61. “A common gateway interface enables web
servers to execute an external program, to
process user requests”
62. Server
CGI Script
(Perl, PHP, C)
HTML/JSON
Response
Maybe a DB
Common Gateway Interface (est. 1996)
HTTP
CGI Gateway Query
STDOUT
Per Request Execution!