• Stars
    star
    177
  • Rank 215,436 (Top 5 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Serverless Web Assembly framework

Serverless WASM

Why?

For fun.

But why?

but why?

This is a small demo of Web Assembly's potential outside of browsers. It has been designed with client side execution in mind, but there's nothing preventing it from running in other platforms. There are people working on running WASM binaries from a shell, and putting WASM code inside kernels.

Here are some benefits of Web Assembly's design:

  • maps well to CPU assembly (with Just In Time compilation in mind)
  • the virtual machine does not require garbage collection, only small memory areas that will be handled by the guest code
  • meant to be sandboxed

And here's the best part: it is meant to be a target language, a lot of other languages will compile to WASM. You can already write C or C++ and compile to WASM with emscripten. Rust's compiler natively supports it. There are demos in Go, Haskell and Ruby.

The network effects are huge: the major browsers implement it and can run any WASM app, and every language wants to run on the client side.

Now, what happens when you leverage these advantages to build a server platform? You get a system that can run a lot of small, sandboxed, resource limited applications, written in a lot of different languages.

You do not care about how to start it, you don't need to map it to filesystems and common runtimes like containers do. You just have some bytecode that imports a few functions, and runs well isolated.

This is a bit like the serverless promise, the ability to run arbitrarily small functions, but without even caring about the startup time or the state size, this will be the smallest you can think of.

What works

Currently, the server is able to load a pre built web assembly binary, exports some function that it can use for logging, to build a response and connect to other servers, and handle requests using that wasm file (as long as it exports a "handle" function).

How to run it

Requirements for WASM applications

the WASM application must export a handle function that takes no arguments and returns no arguments.

The virtual machine currently exposes the following functions, that you can use to build your response:

extern {
  fn log(ptr: *const u8, size: u64);

  fn response_set_status_line(status: u32, ptr: *const u8, size: u64);
  fn response_set_header(name_ptr: *const u8, name_size: u64, value_ptr: *const u8, value_size: u64);
  fn response_set_body(ptr: *const u8, size: u64);

  fn tcp_connect(ptr: *const u8, size: u64) -> i32;
  fn tcp_read(fd: i32, ptr: *mut u8, size: u64) -> i64;
  fn tcp_write(fd: i32, ptr: *const u8, size: u64) -> i64;
}

Configuration file

You define which WASM binary will handle which requests through a TOML configuration file:

listen_address = "127.0.0.1:8080"

[[applications]]
file_path = "./samples/testfunc.wasm"
method = "GET"
url_path = "/hello"

[[applications]]
file_path = "./samples/testbackend.wasm"
method = "GET"
url_path = "/backend"

Running it

You can build and launch the server as follows:

cargo build && ./target/debug/serverless-wasm ./samples/config.toml

Current features

  • load web assembly file to handle requests
  • logging function available from WASM
  • API to build a response from WASM
  • (blocking) TCP connections to backend servers or databases
  • routing to mutiple apps depending on the request
  • set up initial state via "environment variables"
  • proper error handling (the server will panic even if you give it the side eye)
  • (in progress) asynchronous event loop to receive connections and handle backend TCP connections
  • file system abstraction (loading files from S3 or other providers?)
  • (in progress) "standard API" for functions exported by the VM

Prior art

While I was building this, I heard of IceCore, which looks quite cool, with JIT support, etc. It's quite nice to see multiple platforms attempting this. Maybe we'll be able to agree onthe "web assembly standard API" so WASM apps can run on any of those :)

More Repositories

1

rust_on_mobile

Objective-C
171
star
2

rust-syslog

Send syslog messages from Rust
Rust
97
star
3

lovecraft

You've met with a terrible fate, haven't you?
Rust
59
star
4

PilotSSH-scripts

A collection of scripts usable with the PilotSSH iOS app
Shell
54
star
5

tracing_allocator

This custom Rust allocator logs all memory actions for further analysis
Rust
54
star
6

pgo-rust

Testing LLVM's profile guided optimization with Rust
Assembly
45
star
7

cargo-external-doc

integrate markdown files with your rustdoc generated documentation
Rust
37
star
8

sbt-clojure

SBT plugin building Clojure code
Scala
31
star
9

mutguard

Run a function after some data was mutably borrowed
Rust
30
star
10

grad

aggregate, store, query and visualize your metrics, all in one tool
Rust
29
star
11

pod

POD the PHP preprocessor
PHP
25
star
12

nomfun

experimental new design for nom parser combinators
Rust
21
star
13

android-wireguard

Java
17
star
14

rust-vlc-demux

C
15
star
15

crates_you_should_do

list of Rust crates ideas you could take as first project
15
star
16

vlc_module.rs

Helper library to write VLC modules in Rust
Rust
14
star
17

proust

single node kafka implementation
Rust
14
star
18

gif.rs

Rust
13
star
19

mutant

Mutation testing for Rust
Rust
13
star
20

rust-ebpf-demo

Rust
11
star
21

Unpapered

An unhosted Instapaper clone
JavaScript
10
star
22

rust-csv

A CSV parser for Rust
Rust
10
star
23

sbt-clojure-example

Example code for https://github.com/Geal/sbt-clojure
Scala
9
star
24

rust-wasm-canvas

JavaScript
8
star
25

typedopts

Type aware command line parser in Rust
Rust
8
star
26

pestvsnom

C
7
star
27

generic-http-client

a Rust HTTP client that uses whatever transport you give it
Rust
7
star
28

langsec-2017-hackathon-code

Rust
7
star
29

rustfix

Automated fixes to follow Rust's recent developments
Python
7
star
30

cargo-plugin

compile time plugins for your Rust projects
Rust
7
star
31

Squeak-VM

A Git repository of the Squeak virtual machine, not synchronized with SVN repository anymore. For up to date code, see https://github.com/OpenSmalltalk/opensmalltalk-vm
C
6
star
32

dataexponential

a naive datalog implementation that probably does not run in logarithmic time
Rust
6
star
33

cargo-real-deps

Cargo subcommand to check which crates are built depending on features
Rust
5
star
34

the-regexperiment

making a safe cross language regular expression library
4
star
35

langsec-2017-Writing-Parsers-Like-it-is-2017

JavaScript
4
star
36

nom-specialized

more advanced versions of some nom combinators
Rust
4
star
37

DevoxxFR-2022-University-Comprendre_GraphQL

JavaScript
4
star
38

rust-plugin-test

nothing to see here (yet)
Rust
3
star
39

rust-devoxx2016

Java
3
star
40

Curator

A PHP library designed to help you validate user input
PHP
3
star
41

archlinux-pharo-image

Docker image for Pharo Smalltalk
Shell
3
star
42

wai.rs

experiment reproducing the Haskell WAI in Rust
Rust
3
star
43

trailer

Store a type with an associated buffer in contiguous memory
Rust
3
star
44

Head-Hunter-Hunter

Ruby
2
star
45

rate_limit

Ruby
2
star
46

hakyll-search-prototype

An example hakyll used to hack a bit
JavaScript
2
star
47

Journal.js

a small and versatile logging framework
JavaScript
2
star
48

bittorrent

Rust implementation of the BitTorrent Protocol: http://www.bittorrent.org/beps/bep_0003.html
Rust
2
star
49

generic-http-server

Rust
2
star
50

async-alloc-counter

count allocations in Rust futures
Rust
2
star
51

pharsec

A parser combinator library for PHP
PHP
2
star
52

nom_in_c

Experiments around calling nom parsers from C code
M4
2
star
53

Pyssenlit

A Python IDE storing the source code in database, inspired by Omnibrowser and Monticello
Python
2
star
54

archlinux-rust

Shell
2
star
55

Chef-Presentation

Slides for Riviera.rb presentation (April 2012)
JavaScript
1
star
56

Privacy-preserving-social-buttons

JavaScript
1
star
57

Sandpit

A sandboxing application for Windows
C
1
star
58

nom_colored_hexdump

Rust
1
star
59

fn_box

box up yo FnOnces
Rust
1
star
60

build-metadata

embed repository metadata in your code at compile time
Rust
1
star
61

todo-cpp

C++
1
star
62

MockCA

A simple web application designed to create and revoke certificate authorities and certificate.
Ruby
1
star
63

biscuit-node-express

express middleware for Biscuit tokens
JavaScript
1
star
64

bencoders

A simple rust library for parsing bencode, written using nom.
Rust
1
star
65

pharo-seaside-docker-example

Smalltalk
1
star
66

pilotssh.com

Pilotssh.com website
JavaScript
1
star
67

cpp-course

1
star
68

macro-parser

Rust
1
star
69

varargs

Rust
1
star
70

hv

Rust
1
star
71

Worst-Case-Messaging-Protocol

C++
1
star