building something similar to workerd for fun and learning purposes.
- deploy functions written in Rust (see
fx-sdkfor sdk andappsfor examples) compiled to wasm (wasm32-unknown-unknown). - functions can be triggered by http requests, messages from Kafka topics or by cron schedule.
- functions are async and can handle requests concurrently.
- function input and output can be a stream.
- KV storage.
- sql databases powered by sqlite.
- functions can call other functions via RPC (callee is run in the same thread, so no networking is involved resulting in very low latency).
log,fetch,random,timeapis.- livereload functions.
still, note that this is a toy project with a lot of apis missing. it is also missing handling for various edge cases/errors.
use { fx_sdk::{self as fx, handler, HttpRequest, HttpResponse}, tracing::info };
#[handler]
pub async fn http(req: HttpRequest) -> fx::Result<HttpResponse> {
info!("this function is compiled to wasm and is running within fx: {}", req.url);
Ok(HttpResponse::new().body("hello fx!\n"))
}see apps for more examples.
fx performs on par with Node.js and at 46% of native Rust.
| Runtime | Requests/sec | Latency |
|---|---|---|
| fx | 17,499 | 455μs |
| axum (native Rust) | 37,963 | 221μs |
| Node.js | 17,200 | 465μs |
Benchmark: TechEmpower Fortunes on Hetzner CCX23. See docs/benchmarking.md for details.
build hello world example (alternatively, compile your own function to .wasm):
just app-hello-worldthen run function using fx:
cargo run -p fx-runtime -- run target/wasm32-unknown-unknown/release/fx_app_hello_world exampleexpected output:
target/wasm32-unknown-unknown/release/fx_app_hello_world | {"message": Text("hello from fx!")}