Fit millions of actors in one process

On Node.js a started actor takes about 530 bytes and a hibernated one about 120, so four million fit in one process. Each operation costs about the same at four million actors as at two.

Let the host grow its memory

A host keeps the actors of each compiled image in one block of memory, its region. When one of its pools fills, actors or timers for instance, the host copies the region into a larger one.

A host given no sizes starts with room for 64 actors, and grows as the population does.

Set where each pool starts

The system map of the config option gives each new region its first sizes, in whole numbers. An absent key, or 0, keeps the default.

KeyDefaultWhat it counts
maxActors64actors, hibernated ones included
maxEvents256events waiting in the actors' queues
maxTimers64pending delayed sends
maxRequests16running invocations (child charts and services)
workspaces4actors in the middle of a step at once (a sender keeps its workspace until its send is handled); never refused: an actor waits for one, and the host adds more
instanceBytesderived from the image and maxActorsthe actors' variables and states
stringBytes16384 + 16 × maxActorsstrings the actors hold
ticksPerSecond1,000,000,000the host's clock rate

A size is where a pool starts, and the host still grows it. A pool that fills grows between runs, and the other pools stay as they were.

  • A pool doubles, or grows up to 16 times at once when doubling would add under a quarter of the region. So a small pool beside a large region grows in a few copies.
  • A grown region never shrinks.
  • maxActors is at most 8,388,606. A run or an input is refused with TA_ERROR_NO_MEMORY only at a pool's largest size, or when the allocator refuses memory.

See how full each pool is

await host.hostStats() answers with pools, one entry per region still in use (Inspecting a host). An entry's segment is its image's place among new Host's charts, or what addImage returned.

Each pool reports its capacity, what it holds in used, and the most it held at once in highWater.

The pools are actors, events, timers, workspaces, requests and slabBytes, the memory for the actors' variables and strings.

A thousand idle actors grow a host that starts at the default 64, and fit in one sized for 1000. Each region grows on its own, so a second image is a second entry.

stats.mjsjavascript
import { compileCharts, Host } from '@tinyactors/node';

const compiled = compileCharts([{ name: 'idle.scxml', text: `
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0"
       datamodel="ecmascript" name="idle"><state id="waiting"/></scxml>` }]);
const image = compiled.image;
compiled.close();

for (const system of [{}, { maxActors: 1000 }]) {
  const host = new Host(image, { system: 'demo', config: { system } });
  const before = (await host.hostStats()).pools[0].actors;
  for (let i = 0; i < 1000; i++) host.spawn('idle');
  const after = (await host.hostStats()).pools[0].actors;
  console.log(`maxActors ${system.maxActors ?? 'default'}: capacity ${before.capacity}, ` +
    `then ${after.used} used, high water ${after.highWater}, grown: ${after.capacity > before.capacity}`);

  host.addImage(image);
  console.log('segments reported:', (await host.hostStats()).pools.map((pool) => pool.segment).join(', '));
  host.close();
}
output
maxActors default: capacity 64, then 1000 used, high water 1000, grown: true
segments reported: 0, 1
maxActors 1000: capacity 1000, then 1000 used, high water 1000, grown: false
segments reported: 0, 1

A migration's old and new versions are two entries too, one per image.

Size a host for a known population

Run a realistic load, read the high-water marks, and give the next host those sizes. A host sized for its load makes no copies, and no pool grows past what the load needs.

Count every actor in maxActors, since a hibernated one keeps its slot and its record, about 64 bytes. Size instanceBytes and stringBytes for the resident actors only.

The repository's hibernation gate sizes a host this way for two million counters of a few variables, 1000 resident at most. host.hostConfig() answers the sizes, every default filled in.

size.mjsjavascript
import { Host } from '@tinyactors/node';

const N = 2_000_000; // actors
const R = 1000;      // resident at most
const room = 64;
const host = new Host([], { system: 'big', config: { system: {
  maxActors: N + room, maxEvents: 4096,
  instanceBytes: 2048 * (R + room), stringBytes: 16384 + 64 * (R + room),
} } });
console.log((await host.hostConfig()).system.maxActors);
host.close();
output
2000064

A chart with more variables or longer strings needs more per resident actor. slabBytes.highWater under load shows how much.

Leave room for pools that fill together

A pending delayed send holds a timer and an event, and one falling due briefly holds a second event. So N actors that each wait on a delayed send need maxTimers of N and maxEvents above it.

Actors that become runnable together each hold a workspace, against a default of 4. Timers due in the same tick do, and so do actors sending to each other.

On @tinyactors/wasm a pool that runs out costs most: the region is copied inside WebAssembly memory, which keeps its peak.

PoolsMemory per actor
maxTimers N, maxEvents N and a sixteenth, workspaces 1024605 B
the default workspaces, room for 4,000 events beyond N1,142 B, grown within ten seconds
A million actors on @tinyactors/wasm 0.4.0, each waiting on a delayed send, in the website's measurement lab. Measured 2026-11-21 on an Intel Xeon at 2.10 GHz, 4 CPUs, 16 GiB, Linux; Node.js 22.23.5.

That host reached 35 workspaces at once. A million actors sending to each other reached 92.

Measure what one actor costs

The memory program measures what one more actor, message or delayed send adds to a process, part by part. Run it with your chart, on your runtime and datamodel, the engine chart code runs in: native or quickjs.

shell
node examples/memory/main.mjs --counts 1000000 --datamodel native
runtime, datamodelactor, startedactor, after an eventactor, hibernatedmessage waitingdelayed send pending
node, native532 B673 B118 B309 B353 B
bun, native601 B781 B93 B386 B448 B
node, quickjs1036 B1634 B92 B309 B358 B
bun, quickjs1041 B1645 B90 B313 B356 B
What the process holds more for each thing, at a million. Measured 2026-11-25 on an Intel Xeon at 2.10 GHz, 4 CPUs, 16 GiB, Linux; Node.js 22.23.5 and Bun 1.4.1. A counter chart with one <data>, messages of {"text": "hello"}, tracing on; the hibernated column keeps at most 1000 actors resident and the rest in a store.

On Node.js a started actor takes 532 B of the process at a million, and a hibernated one 118 B.

The core's region and quickjs's heap account for part of it, the same on Node.js and Bun. On the native datamodel most of the rest is the JavaScript engine's heap.

datamodelactor, startedactor, after an eventactor, hibernatedmessage waitingdelayed send pending
native196 B196 B82 B106 B151 B
quickjs796 B1372 B82 B284 B329 B
What the core's reservation, the host's other allocations and quickjs's heap account for, at a million, the same run.

The host's and the engine's fixed costs spread over the population, so an actor costs less in a larger one.

10,000100,0001,000,0002,000,0004,000,000
per actor, started803 B720 B532 B510 B495 B
per actor, after an event1446 B870 B673 B654 B639 B
per actor, hibernated637 B269 B118 B100 B91 B
per message waiting602 B392 B309 B293 B285 B
per delayed send pending737 B489 B353 B338 B331 B
The process's bytes per thing at each population, Node.js on the native datamodel, the same run.

The run's CSV holds every part of every row, at every population and on every runtime.

  • A started actorholds its variables in the datamodel and its records in the region: 196 B reserved for this chart at a million (81 B, its instance and its strings), 179 B of it used.
  • After an eventan actor keeps that event as _event until the next one. On quickjs the event's record, 106 B, stays in the region too.
  • A hibernated actoruses 81 B of records in the region, and its blob is in your store: 145 B on the native datamodel and 147 B on quickjs, for this chart.
  • A messagecosts 106 B in the region (57 B with tracing off) and its data in the datamodel.
  • A delayed sendholds its message until it falls due: 151 B in the region (102 B with tracing off).
  • On quickjsthe engine keeps every actor's variables in its own heap, bounded by quickjs.memoryLimit, 1 GiB unless the host sets another. A million resident actors after an event need about 1.2 GB of it, so the run above sets 8 GiB (the quickjs sandbox).

A chart's scripts add nothing per actor. Their functions are the chart's, made once, and a top-level var is one more variable (Writing charts).

Check that costs hold as actors double

The scaling program, tools/scale.mjs, times every operation on N actors and on 2N, each host in its own process. It fails an operation that costs more than 1.5 times as much at 2N.

An operation on one actor is timed per call, and one on the whole population per actor.

In the first run most actors are hibernated in SQLite, and one in a hundred runs an invoked service. In the second every actor is resident.

Every operation passed. Each cell is the cost at N, then at 2N, in microseconds, and their ratio.

operationunitnode, nativenode, quickjsbun, nativebun, quickjs
populate (spawn and hibernate)µs per actor10.88 → 10.56 (0.97)7.43 → 7.56 (1.02)7.52 → 7.81 (1.04)6.26 → 6.02 (0.96)
spawnµs per call5.25 → 5.19 (0.99)2.62 → 2.60 (0.99)4.11 → 4.16 (1.01)2.43 → 2.45 (1.01)
terminateµs per call0.867 → 0.786 (0.91)0.571 → 0.575 (1.01)0.952 → 0.893 (0.94)0.751 → 0.720 (0.96)
sendµs per call3.79 → 3.64 (0.96)1.90 → 1.77 (0.93)3.19 → 3.00 (0.94)2.12 → 2.06 (0.97)
sendManyµs per event3.98 → 3.86 (0.97)2.18 → 2.04 (0.93)2.87 → 2.83 (0.99)2.01 → 1.85 (0.92)
send (hibernated: woken from the store)µs per call32.27 → 27.93 (0.87)28.29 → 27.92 (0.99)24.71 → 25.96 (1.05)33.43 → 33.10 (0.99)
hibernateµs per call5.41 → 4.93 (0.91)4.21 → 4.17 (0.99)3.56 → 3.44 (0.97)4.07 → 3.86 (0.95)
wakeµs per call6.94 → 6.38 (0.92)3.90 → 3.69 (0.95)6.91 → 7.27 (1.05)4.19 → 4.43 (1.06)
actor (by name)µs per call3.96 → 4.01 (1.01)3.96 → 3.88 (0.98)1.32 → 1.20 (0.91)1.13 → 1.12 (0.99)
actorStateµs per call4.26 → 4.01 (0.94)4.15 → 4.11 (0.99)3.90 → 3.73 (0.96)3.66 → 3.58 (0.98)
hostStatsµs per call25.65 → 25.05 (0.98)24.49 → 23.49 (0.96)19.35 → 19.60 (1.01)18.96 → 18.23 (0.96)
I/O processor round tripµs per call10.11 → 10.16 (1.01)6.81 → 6.73 (0.99)7.09 → 6.87 (0.97)5.77 → 5.54 (0.96)
transport round tripµs per call30.55 → 31.31 (1.02)25.92 → 26.36 (1.02)25.19 → 26.15 (1.04)22.05 → 23.06 (1.05)
delayed send and its timerµs per call6.28 → 6.19 (0.98)3.09 → 3.01 (0.97)4.95 → 5.15 (1.04)3.35 → 3.37 (1.01)
invoked service round tripµs per call13.52 → 13.93 (1.03)10.33 → 10.12 (0.98)10.13 → 10.66 (1.05)9.15 → 9.79 (1.07)
sweep (every actor)µs per actor0.006 → 0.005 (0.87)0.006 → 0.005 (0.87)0.006 → 0.006 (0.95)0.006 → 0.006 (0.91)
migrate (one session)µs per call24.09 → 25.32 (1.05)16.51 → 16.95 (1.03)35.62 → 20.64 (0.58)16.90 → 16.30 (0.96)
snapshotµs per actor0.100 → 0.092 (0.92)0.079 → 0.084 (1.07)0.081 → 0.087 (1.08)0.101 → 0.092 (0.92)
restore (and its first turn)µs per actor0.291 → 0.298 (1.02)0.217 → 0.215 (0.99)0.223 → 0.217 (0.98)0.198 → 0.192 (0.97)
closeµs per actor0.114 → 0.128 (1.13)0.120 → 0.157 (1.31)0.126 → 0.127 (1.01)0.120 → 0.139 (1.16)
Hibernated: 2,000,000 and 4,000,000 actors, at most 1000 counters resident, 20,000 and 40,000 actors each running an invoked service. One run, alone on the machine, 2026-11-20: an Intel Xeon at 2.10 GHz, 4 CPUs, 16 GiB, Linux; Node.js 22.23.5 and Bun 1.4.1.
operationunitnode, nativenode, quickjsbun, nativebun, quickjs
populate (spawn, the segment growing)µs per actor5.42 → 5.52 (1.02)4.28 → 3.85 (0.90)4.23 → 4.14 (0.98)3.76 → 3.63 (0.97)
spawnµs per call4.84 → 4.86 (1.00)2.47 → 2.34 (0.95)4.06 → 4.14 (1.02)2.47 → 2.36 (0.95)
sendµs per call5.82 → 5.89 (1.01)3.88 → 3.97 (1.02)4.88 → 4.90 (1.00)4.01 → 4.19 (1.05)
hibernateµs per call6.29 → 6.54 (1.04)6.89 → 6.31 (0.92)4.54 → 4.92 (1.09)6.78 → 6.85 (1.01)
wakeµs per call7.48 → 7.37 (0.99)2.85 → 2.59 (0.91)5.08 → 5.45 (1.07)3.19 → 3.14 (0.98)
snapshotµs per actor4.49 → 4.23 (0.94)5.51 → 5.65 (1.03)3.50 → 3.20 (0.91)6.11 → 5.59 (0.92)
migrate (a chart, every actor)µs per actor17.99 → 17.80 (0.99)11.44 → 10.58 (0.93)14.38 → 14.06 (0.98)11.59 → 9.99 (0.86)
restore (and its first turn)µs per actor13.04 → 12.69 (0.97)4.35 → 4.96 (1.14)7.32 → 6.98 (0.95)4.57 → 4.79 (1.05)
closeµs per actor0.310 → 0.309 (0.99)1.71 → 1.53 (0.90)0.296 → 0.323 (1.09)1.74 → 1.56 (0.90)
All resident: 1,000,000 and 2,000,000 actors, the same run.

Two million resident actors take up to 5.2 GiB on quickjs, the most of any run. So four million resident do not fit in 16 GiB beside the scenario's other work.

runtime, datamodelhibernatedall resident
node, native1733 / 25791706 / 3007
node, quickjs1773 / 33822555 / 5274
bun, native1680 / 32512271 / 3828
bun, quickjs1345 / 25542517 / 5278
Peak resident memory at N and 2N, in MiB, the same run.

mise run scale in tinyactors-napi writes every operation and sample to build/scale-*.json. This run's files are in tools/results/2026-11-20.

The repository's rules for published numbers say when to run it again, before each release among them.