This project implements a serverless execution platform for WebAssembly (WASM) functions with execution metrics tracking.
-
Install the WebAssembly (WASM) compiler:
rustup target add wasm32-wasip1
-
Install the latest Wasmtime engine:
curl https://wasmtime.dev/install.sh -sSf | bash
-
Add your function:
Place the function you want to execute into the
src/savedWasmFunctions
folder. -
Build and start the server:
cargo run
After running this command, visit http://127.0.0.1:8080/ to verify that the server is working.
Execute a WASM function with optional parameters:
curl -X POST http://localhost:8080/execute \
-H "Content-Type: application/json" \
-d '{
"fn_name": "add.wasm",
"params": ["5", "7"]
}'
Upload a new WASM function to the server:
curl -X POST http://localhost:8080/upload \
-H "Content-Type: multipart/form-data" \
-F "fn_name=sample2.wasm" \
-F "wasm_file=@/path/to/your/wasm/file.wasm"
The platform automatically tracks execution metrics for all WASM functions, including execution time, memory usage, and execution count.
curl http://localhost:8080/metrics
curl http://localhost:8080/metrics/add.wasm
Function metrics are stored in a JSON file (function_metrics.json
) at the root of the project with the following structure:
{
"function_name.wasm": {
"name": "function_name.wasm",
"memory_used_bytes": 123456,
"total_execution_time_ms": 42,
"execution_count": 3
}
}
The project includes sample WASM functions in the src/savedWasmFunctions
directory that you can use for testing.
curl -X POST http://localhost:8080/execute \
-H "Content-Type: application/json" \
-d '{"fn_name": "sample.wasm", "params": []}'
Thank you!