Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

WebAssembly Compute Jobs

Run code compiled to WebAssembly on GridGain 9 cluster nodes, including runtime configuration, instance caching, and building modules in Rust, Go, WebAssembly text format, and Python.

You can run your code compiled to WebAssembly with GridGain 9 Compute API. By default, WASM code will be compiled into JVM bytecode for faster execution. You can configure this behavior in the compute configuration.

Use JobExecutorType.WASM_EMBEDDED to load WebAssembly binaries as deployment units and execute the code on cluster nodes.

Before submitting your compute job, ensure that the required code is deployed to the nodes where it will execute.

  • GridGain 9 uses Chicory 1.5.1 WebAssembly runtime.

  • See supported Wasm features here: https://webassembly.org/features/

Runtime and configuration

By default, WebAssembly code is compiled to JVM bytecode at runtime for faster execution (Chicory runtime).

You can control this behavior with the compute.wasm.enableCompiler setting in the compute configuration.

Instance Caching

To reduce the startup overhead of module loading and initialization, especially noticeable with some runtimes (for example, Go), GridGain 9 caches WebAssembly instances.

  • Instances are cached per deployment unit and file name, avoiding repeated loading and initialization.

  • Cached instances are automatically cleared when the corresponding deployment unit is undeployed.

Configuration Example

Add the following snippet to your gridgain-config.conf to define module memory, cache size and TTL parameters.

WebAssembly Modes

GridGain 9 supports two execution modes for WebAssembly modules:

  • Reactor mode - Calls specific exported functions from the module.

  • Command mode - Runs the module as a standalone program that reads input from stdin and writes output to stdout.

The sections below show how you can use these modes, and the recommended platforms for them.

WebAssembly Reactor Mode

The following sections explain how to build and deploy modules in Rust, Go, and WebAssembly Text Format (Wat).

Rust

  1. Make sure Rust and Cargo are installed.

  2. Install wasm-pack:

  1. Create a new Rust library project:

  1. Replace the contents of Cargo.toml with:

  1. Replace the contents of src/lib.rs with:

  1. Build the project with wasm-pack build. This will create a pkg directory with the compiled Wasm module and JavaScript bindings. We only need one .wasm file from this directory: pkg/hello_wasm_bg.wasm.

  2. Deploy the .wasm file as part of a Deployment Unit to your cluster.

  3. Run your Rust job using Compute API:

For more details, refer to Wasm documentation for Rust:

Go

  1. Make sure Go is installed.

  2. Create a new directory for your project:

  1. Initialize a new Go module:

  1. Create a new file hello.go with the following contents:

  1. Build the project:

  1. Deploy the .wasm file as part of a Deployment Unit to your cluster.

  2. Run your Go job using Compute API:

For more details, refer to Wasm documentation for Go:

  • https://go.dev/wiki/WebAssembly

WebAssembly Text Format

  1. Go to https://webassembly.github.io/wabt/demo/wat2wasm/ and paste the following code into the left pane:

  1. Click the Download button.

  2. Deploy the downloaded .wasm file as part of a Deployment Unit to the cluster.

  3. Invoke the functions with Compute API:

For more details, refer to Wasm documentation for WebAssembly:

  • https://developer.mozilla.org/en-US/docs/WebAssembly/Guides/Understanding_the_text_format

WebAssembly Command Mode

Some languages and toolchains do not support exported functions. Python with py2wasm is one such example.

Command mode provides a simpler interaction pattern via stdin/stdout, but is less efficient, because the module has to be started again on every job execution.

only String input and output types are supported in command mode.

The following section describes how to build and deploy modules with py2wasm (experimental, requires Python 3.11).

Python

  1. Install py2wasm:

  1. Create a Python script, for example:

  1. Build the WebAssembly module:

  1. Deploy the created hello.wasm file as part of a Deployment Unit to the cluster.

  2. Run your Python job using Compute API with command mode:

The commandBuilder() method automatically configures the job to use command mode execution. The input string is passed to the program's stdin, and the output is captured from stdout.

This page is: Copyright © 2026 MariaDB. All rights reserved.

Last updated

Was this helpful?