Hot-Reloading Stateful WebAssembly at 10 Mpps Without Dropping Packets

Updating Code While Packets Keep Arriving

One advantage of using WebAssembly in networking is that it simplifies the old and complex problem of hot-upgrading of stateful networking code significantly. This article describes how we made this work in Wabrix. Also, we were curious to test the performance limits of this approach: Can this approach sustain 10 Mpps per core?

A network policy update has two continuity requirements: packets must keep moving, and the new code must pick up the state left by the old code. Losing a sequence counter is enough to corrupt loss measurements. Losing a connection table can break thousands of established sessions even when the packet queues stay intact.

During a reload, we prepare a new replacement instance of a WebAssembly (WASM) component while keeping the worker with its pipeline nodes, including the old WASM instance, AF_XDP sockets, and packet memory running. Persistent state for the WASM instance lives in host-owned shared memory. The replacement WASM instance attaches to those same shared memory pages, and the worker switches instances at a boundary between completed packet batches.

That design removes compilation, instance construction, state snapshotting, and runtime teardown from the switchover itself. It is how we make loss-free updates possible under load. Sustaining line rate still requires enough processing and queue headroom for the brief switchover.

In Wabrix the host provides AF_XDP packet I/O, shared packet memory, pipeline execution, and runtime lifecycle management. The component defines the processing behavior and, when continuity is required, the persistent state layout. The component artifact is the unit of deployment: a new version can be installed while the host's workers, sockets, and frame ownership remain in service.

Our Experiment at a Glance


Measured Throughput:                   10 Mpps
Generated packets:                      3 Billion
Missing packets:                        0
Runtime switchover:                 1.851 µs
(measured in separate run)
Persistent state:                 about 1 KB                 

One WASM component replacement during a sustained 10 Mpps packet-processing run.
One generator worker and one inspector worker operating each at a 3.4 GHz core.
Turbo mode was disabled. Cores were isolated from OS tasks.
Intel Core™ i7-14700K, no Hyper-Threading, Intel 2x25G E830 NIC, Linux kernel 7.0 
 

A Small Pause Becomes a Large Packet Backlog

At 10 million packets per second, a two-millisecond interruption corresponds to 20,000 arriving packets. Rebuilding a runtime on a packet worker, waiting for a compiler, or destroying an old Wasmtime instance can turn an ordinary update into a burst of queue overflow.

There is a second problem with copying state. A snapshot taken while the old component instance continues processing is immediately stale. Pausing the old instance to serialize its entire state introduces a pause whose duration grows with that state.

Our reload path keeps the expensive preparation in the background and keeps the persistent bytes in place.

Keep the Packet-Processing Machinery Alive

The reload replaces the component instance held by the pipeline node (its Wasmtime store and component bindings). The surrounding packet-processing machinery stays in service:

ResourceDuring a component reload
Worker thread and CPU affinityContinue running
AF_XDP sockets and ringsRemain open
UMEM and frame registryRetain their buffers and ownership
Pipeline routes and node identityRemain attached to the same node
Host-side packet counts and telemetryStay with the existing node; profiling tick totals are retained when enabled
Node shared-state backingRemains mapped into both component instances
Guest heap, stack, and mailboxAre private to each component instance

Packets already processed in an iteration finish with the active component instance. Work after activation uses the replacement instance. There is no need to close sockets, re-register UMEM, or move queued packets into another worker.

This hot reload replaces a component instance within the existing graph. Changes that require a different worker layout, UMEM configuration, or a rebuilt pipeline graph still require a full restart.

Prepare, Validate, Switch, Retire

We start one shared staging thread and one runtime reaper before packet workers enter their processing loops. Sending a reload request therefore does not create a new thread from a pinned worker.


Time --->

Control plane       UpdateConfiguration(wasm_file_path)
                              |
Staging thread       [load / compile / instantiate / init]----candidate ready
                                                               |
Packet worker   [old instance: process batches and timers......| next timer poll
                                                               | poll_ready
                                                               | check candidate
                                                               | install candidate
                                                               [new instance...]

Runtime reaper                                             [destroy old...]
 

The control plane compares the current and target configurations. A changed wasm_file_path becomes an UpdateConfiguration event addressed to the existing WasmEngine node, hosting the WASM instance. Its worker queues a staging job and continues processing with the active component instance.

The stager reads and compiles or loads the component artifact, creates a fresh component instance, maps its packet and state regions, and calls init-data to initialize the WASM instance. Compilation, instantiation, and initialization must succeed before that candidate can be activated. The component cache uses the artifact path and a SHA-256 content hash.

The background threads use the controller's allowed CPU affinity - which excludes the worker cores - and normal SCHED_OTHER scheduling. They do not inherit a packet worker's restricted single-core mask or real-time policy.

Each WasmEngine node has a one-job staging mailbox. A newer queued request replaces its stale predecessor, and generation counters prevent a superseded result from being activated. An already-running build may finish, but its obsolete candidate is discarded off the packet-processing thread.

A changed wasm_file_path in UpdateConfiguration starts asynchronous staging; receiving that event does not itself switch the component. The worker continues using the active instance while staging runs in the background.

After the worker finishes the ingress batches for an iteration, it checks whether the configured timer-poll interval has elapsed. On that timer tick, the runner polls the reload controller for a potential switchover. If staging is not finished yet, the active instance remains in use and the next timer-poll tick checks again. A candidate becoming ready does not interrupt packet processing or wake the worker; activation waits for this polling point.

State Continuity Comes From Shared Pages

Each worker-local pipeline node running a stateful component owns one dedicated state region. During reload, the active and staged component instances for that same node map the same memfd-backed pages:


  +---------------------------+     +---------------------------+
  | Active component instance |     | Staged component instance |
  | Private heap and mailbox  |     | Private heap and mailbox  |
  +-------------+-------------+     +-------------+-------------+
                |                                 |
                +----------------+----------------+
                                 |
                   +-------------v-------------+
                   | Same per-node state pages |
                   | Header + fixed payload    |
                   +---------------------------+

  During staging: only the active instance accesses the live payload.
  After switchover: only the replacement accesses the live payload.
 

The shared region is separate from packet UMEM. Other nodes and workers receive their own state regions.

State cannot become stale while the replacement instance is compiling. The active instance keeps updating the actual pages that the replacement will use. There is no snapshot to catch up or restore.

The single-writer rule is a component contract. While the active instance is running, staged initialization must not modify or try to read the live payload. After the switchover, the replacement instance becomes the only writer.

What Our Example WASM Instance Preserves

The inspector component we used in the experiment described below keeps its packet and byte counters, the latency histogram, expected UDP sequence number, and sequence anomaly counters in the shared payload. Replacing its component instance therefore keeps both the counters and the history needed to interpret the next packet.

The replacement instance still initializes configuration such as MAC addresses and tsc-frequency. Persistent operational state and runtime-local configuration have different lifetimes.

Other stateful components must explicitly adopt this contract. State left only in a guest's private heap is lost when that instance is retired. Connection tables and timer state need a component-defined persistent representation and must fit within the reserved shared memory capacity; existing component code does not acquire state continuity merely by being reloadable.

The Runtime Switchover: One Active Writer

The worker performs the switchover only at a timer tick after finishing its current packet batch, when the active component instance is no longer running. The staged candidate already maps the same shared pages.

If both component versions use a compatible state layout, the replacement can immediately continue using the existing payload. Wabrix does not copy or serialize the persistent state.

During the switchover, Wabrix replaces the Wasmtime store and component bindings inside the existing WasmEngine pipeline node. The node itself, its pipeline connections, and its host-side counters and telemetry remain in place.

The retired runtime is then submitted to the reaper with a nonblocking send. Wasmtime's destruction work stays off the packet-processing thread.

This mechanism currently assumes compatible persistent-state layouts between component versions. Handling incompatible state schemas and migrating persistent state across versions is a separate problem.

Applying an Update

Deploy the candidate at a new, immutable artifact path. In the existing node's target configuration, change its effective Wasm path, for example:


hot_args = { wasm_file_path = "/opt/wabrix/inspector-v2.wasm" }
 

Then use the running CLI:


apply /etc/wabrix/inspector-v2.toml
 

Watch the staging and activation messages for each worker: accepting a configuration request is earlier than completing its asynchronous activation.

Each worker switches independently. A rollout can briefly contain both code versions, so cross-worker behavior must tolerate that overlap. This mechanism does not provide a simultaneous, globally atomic policy switch.

A Recorded Switchover Under Load

The following experiment shows how we deployed a replacement inspector component artifact while a packet generator was running. Two worker threads are running on two performance cores. However, cores were locked at the nominal frequency of 3.4 GHz, to prevent the frequency variability associated with turbo operation. Turbo mode can result in a long latency tail which could hide the impact of the switchover, if any.

This is why we chose to run the test at a moderate 10 Mpps. Worker 0 runs the packet generator pipe, timestamps the packets and adds a sequence number. Worker 1 runs the packet inspector pipeline. Its WasmEngine node loads the inspector_engine.wasm component artifact. The resulting component instance measures packet latency, counts packets, checks sequence numbers, and records the maximum latency over the last five seconds.

The packet path and worker placement for this run were:


Worker 0 · core 2 · 3.4 GHz (turbo off)

[Generator component: timestamp + sequence]

                 │ UDP · 10 Mpps
                 ▼
                 
[TX: enp2s0f0np0 · E830VDA2 port 0]

                 │ DAC
                 ▼
                 
[RX: enp2s0f1np1 · E830VDA2 port 1] 

                 │
                 ▼
                
Worker 1 · core 3 · 3.4 GHz (turbo off)

[BatchRxNode] → [FastParserNode] → [Inspector WasmEngine] → [DropNode]
                                       │
                         latency, sequence, 5-second max
                          

Wabrix applied the new configuration at 18:00:03Z. It staged the inspector_engine_new.wasm component artifact, created a component instance, and activated that instance in the existing pipeline without restarting it. For this test, the replacement artifact contains a copy of the old component's code. The replacement instance attaches to the same shared pages, preserving the old instance's state, including all 101 latency-histogram slots.

The generator completed 3,000,000,000 packets in 299,999,907 microseconds, about 10,000,003 packets per second.

The inspector counted 3,000,000,023 packets, 23 more than the generator transmitted. These additional packets did not belong to the generated sequence and were excluded from the packet-loss accounting. Their origin is still unknown; they may be packets injected by the operating system or NIC environment. The generated sequence showed zero missing packets throughout the run.

In the corresponding Grafana capture, the sequence-missing and software-drop counters stay at zero through the switchover. The five-second maximum latency stays around 140–160 microseconds at the switchover, with no visible spike in the five-second maximum-latency metric. The log uses UTC; the dashboard shows local time, so the 18:00:03Z activation aligns with the annotation at about 19:00.

Grafana dashboard showing maximum packet latency, latency distribution, inspected packets, sequence-missing packets, and software drops during the switch

The cyan annotation marks activation of the replacement component instance. The sequence-missing and software-drop panels remain at zero across the displayed interval.

Wabrix log showing the inspector component staged and activated while the packet generator runs

The activation message confirms that the replacement component instance was activated without restarting the pipeline. The run then completed its three-billion packet generation workload.

A Follow-Up Timing Measurement of the Switchover

To quantify the overhead of the reload mechanism independently of the sustained-load experiment, we performed a second run with detailed timing instrumentation.

PhaseTime
Staging queue wait32.009 µs
Artifact load, compile, and validation1.492 ms
Component instantiation364.625 ms
init-data78.663 µs
Total staging, from worker start to candidate ready366.240 ms
Request to candidate ready, including queue wait366.272 ms
Shared-state layout validation, within init-data0.562 µs
Runtime switchover1.851 µs
Reaper queue wait before old-runtime destruction9.605 µs
Old component runtime destruction92.750 ms

The artifact preparation, instantiation, and init-data figures are phases within the total staging time; the remaining roughly 45 µs is other candidate setup. All 366.240 ms of staging, including the 364.625 ms component instantiation, ran on the background stager while the old instance continued processing packets. The state-layout validation is included in init-data.

On the packet worker, the runtime swap took 1.851 µs. The sequence-missing and software-drop counters remained at zero also during this run.

The old runtime took about 93 ms to destroy on the background reaper, after 9.605 µs of queue wait, so its destruction did not hold up the packet worker.

Implementation and Contracts

The implementation is available in Wabrix, with plugin bindings and examples in wabrix_api. The relevant pieces are the reload controller and background service, the runtime installation, and the shared-state contract.