Git Product home page Git Product logo

wow's Introduction

WebAssembly-flavored OpenWhisk

A WebAssembly-based container runtime for the Apache OpenWhisk serverless platform.

Why?

The cold start problem is well-known in serverless platforms. The first invocation of a function requires provisioning all the resources necessary for its execution. Typically that means starting a docker container, i.e. a node.js container to then inject some JavaScript code for execution. This process can take hundreds of milliseconds and is thus unacceptable for latency-critical tasks. This project is an evaluation of using WebAssembly instead of Docker containers to implement serverless functions. The simple idea is that WebAssembly is a lighter-weight sandboxing mechanism so the cold start latency should be much smaller. It builds on top of Apache OpenWhisk as the serverless platform. There are three repositories relevant to this:

  • This repository, which implements the WebAssembly-based container runtime.
  • The OpenWhisk fork that implements the runtimes support on the OpenWhisk side
  • The diploma thesis repository, which contains the thesis describing the motivation, background, design and evaluation of this idea.

Crates Overview

The project is split into multiple crates, which are:

  • ow-common contains common types such as the WasmRuntime trait or types that represent OpenWhisk payloads.
  • ow-executor implements the actual container runtime and the OpenWhisk runtime protocol.
  • ow-wamr implements the WasmRuntime trait for the WebAssembly Micro Runtime.
  • ow-wasmer implements the WasmRuntime trait for Wasmer.
  • ow-wasmtime implements the WasmRuntime trait for Wasmtime.
  • ow-wasm-action contains abstractions for building WebAssembly serverless functions ("actions" in jOpenWhisk terminology) and has a number of example actions.
  • ow-wasmtime-precompiler implements Ahead-of-Time compilation for wasmtime (which is part of the runtime as of version 0.26), making this crate obsolete once ow-wasmtime is migrated to that version.
  • ow-evaluation contains some tests used for evaluating the performance of the system, such as concurrency tests and cold start tests.

Tutorial with Wasmtime

As a small tutorial, let's build the wasmtime executor and run one of the examples.

  1. To build the executor with wasmtime run the following command from the root of this repository:
cargo build --manifest-path ./ow-executor/Cargo.toml --release --features wasmtime_rt
  1. Next we build the add example for the wasm32-wasi target with:
cargo build --manifest-path ./ow-wasm-action/Cargo.toml --release --example add --target wasm32-wasi --no-default-features --features wasm

# Optional step to optimize the compiled Wasm if `wasm-opt` is installed
# On Ubuntu it can be installed with `sudo apt install binaryen`
wasm-opt -O4 -o ./target/wasm32-wasi/release/examples/add.wasm ./target/wasm32-wasi/release/examples/add.wasm
  1. Precompile the example for efficient execution with wasmtime:
cargo run --manifest-path ./ow-wasmtime-precompiler/Cargo.toml --release --bin wasmtime ./target/wasm32-wasi/release/examples/add.wasm
  1. Install wsk-cli from https://github.com/apache/openwhisk-cli/releases/tag/1.2.0

  2. Clone the openwhisk repo, checkout the appropriate branch and run OpenWhisk in a separate terminal:

git clone [email protected]:PhilippGackstatter/openwhisk.git
git checkout invoker-wasm
./gradlew core:standalone:bootRun

This will print something like the following:

[ WARN  ] Configure wsk via below command to connect to this server as [guest]

wsk property set --apihost 'http://172.17.0.1:3233' --auth '23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP'

Execute this command.

  1. Run the executor in a separate terminal. OpenWhisk will forward execution requests for Wasm to it:
./target/release/executor
  1. Upload the example zip to OpenWhisk:
wsk action create --kind wasm:0.1 add ./target/wasm32-wasi/release/examples/add-wasmtime.zip
  1. Run the action. We need to provide the correct parameters for this action, which are defined in our action source file ow-wasm-action/examples/add.rs. Let's see what the result of 2+2 is:
wsk action invoke --blocking add --param param1 2 --param param2 2

which prints:

{
  "activationId": "b67ca8877a494fcdbca8877a494fcd73",
  "annotations": [
    {
      "key": "path",
      "value": "guest/add"
    },
    {
      "key": "waitTime",
      "value": 23
    },
    {
      "key": "kind",
      "value": "wasm:0.1"
    },
    {
      "key": "timeout",
      "value": false
    },
    {
      "key": "limits",
      "value": {
        "concurrency": 1,
        "logs": 10,
        "memory": 256,
        "timeout": 60000
      }
    },
    {
      "key": "initTime",
      "value": 3
    }
  ],
  "duration": 5,
  "end": 1655918974484,
  "logs": [],
  "name": "add",
  "namespace": "guest",
  "publish": false,
  "response": {
    "result": {
      "result": {
        "result": 4
      },
      "status": "success",
      "status_code": 0,
      "success": true
    },
    "size": 73,
    "status": "success",
    "success": true
  },
  "start": 1655918974479,
  "subject": "guest",
  "version": "0.0.1"
}

And we get 4 as a result. And that's it, we've run a serverless function with WebAssembly! Try running one of the other examples in ow-wasm-action/examples/, the appropriate compilation commands and features can be found in the justfile.

Building

We can also use just to make building a bit easier. The recipes are defined in the justfile. If you don't want to install this tool, you can copy the commands from there into your terminal.

The just commands generally run operations for all three runtimes, but if not all tools for all Wasm runtimes are installed, some of the steps can be skipped.

To build the executor with the wasmtime runtime, run just build-amd64 wasmtime_rt. Other possible values for the runtime argument are wasmer_rt and wamr_rt to use wasmer or wamr respectively.

To build example actions use just build-wasm-examples. This requires binaryen's wasm-opt to be present in your PATH, which optimizes the produced wasm. For convenience you can also skip this part. To precompile the examples use just precompile, which requires wasmer and wamrc to be installed or in your PATH. Of course only one of the precompilation steps is necessary to run a given module for a certain runtime, so you can skip some of these steps as well.

wow's People

Contributors

philippgackstatter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wow's Issues

Error on precompiling "add"

I got an error while trying to follow the tutorial on readme.md

COMMAND:
cargo run --manifest-path ./ow-wasmtime-precompiler/Cargo.toml --release --bin wasmtime ./target/wasm32-wasi/release/examples/add.wasm

ERROR:

Finished release [optimized] target(s) in 0.11s
     Running `target/release/wasmtime ./target/wasm32-wasi/release/examples/add.wasm`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: expected at least one module field
     --> ./target/wasm32-wasi/release/examples/add.wasm:1:1
      |
    1 |
      | ^', ow-wasmtime-precompiler/src/bin/wasmtime.rs:11:72
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Can you please help me out?

An error occured when i execute ‘./gradlew core:standalone:bootRun’

Execution failed for task ':core:standalone:bootRun'.

Process 'command '/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.345.b01-1.el7_9.x86_64/bin/java'' finished with non-zero exit value 1
Caused by: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.345.b01-1.el7_9.x86_64/bin/java'' finished with non-zero exit value 1
looking forward to your help,thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.