Small actors, flat costs.
What an actor costs in memory, how to size a host, and how each operation's cost holds as the population doubles. Every number comes from a program in the repository that you can run.
What an actor costs.
One more actor, message or delayed send, measured as resident memory in a process with a million of them.
| runtime, datamodel | actor, started | actor, after an event | actor, hibernated | message waiting | delayed send pending |
|---|---|---|---|---|---|
| node, native | 531 B | 671 B | 124 B | 315 B | 357 B |
| bun, native | 618 B | 800 B | 101 B | 386 B | 456 B |
| node, quickjs | 1041 B | 1639 B | 97 B | 312 B | 364 B |
| bun, quickjs | 1049 B | 1653 B | 99 B | 318 B | 364 B |
{"text": "hello"}, tracing on.A host's fixed costs spread over its actors, so an actor costs less in a larger population.
| 10,000 | 100,000 | 1,000,000 | 2,000,000 | 4,000,000 | |
|---|---|---|---|---|---|
| per actor, started | 1327 B | 774 B | 531 B | 519 B | 501 B |
| per actor, after an event | 1956 B | 920 B | 671 B | 665 B | 644 B |
| per actor, hibernated | 1147 B | 326 B | 124 B | 103 B | 92 B |
| per message waiting | 1146 B | 444 B | 315 B | 296 B | 286 B |
| per delayed send pending | 1296 B | 544 B | 357 B | 341 B | 332 B |
Size a host.
A host grows on its own, but each growth copies its memory. A host that will hold a known population is better sized for it.
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();2000064Read what a host uses at any time:
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();
}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, 1Costs stay flat.
Every operation of the API, timed on a host of two million actors and on one of four million. Each cell is the cost at two million, then at four, and their ratio. A test fails when a ratio passes 1.5.
| operation | unit | node, native | node, quickjs | bun, native | bun, quickjs |
|---|---|---|---|---|---|
| populate (spawn and hibernate) | µs per actor | 11.71 → 11.62 (0.99) | 7.16 → 7.36 (1.03) | 8.64 → 8.51 (0.99) | 6.74 → 6.58 (0.98) |
| spawn | µs per call | 5.47 → 5.43 (0.99) | 2.45 → 2.54 (1.04) | 4.82 → 5.59 (1.16) | 2.92 → 2.70 (0.92) |
| terminate | µs per call | 0.755 → 0.733 (0.97) | 0.565 → 0.560 (0.99) | 0.925 → 0.889 (0.96) | 0.758 → 0.742 (0.98) |
| send | µs per call | 4.44 → 4.41 (0.99) | 2.06 → 2.15 (1.04) | 3.71 → 3.61 (0.97) | 2.28 → 2.33 (1.02) |
| sendMany | µs per event | 4.84 → 4.79 (0.99) | 2.38 → 2.29 (0.96) | 3.50 → 3.40 (0.97) | 2.38 → 2.13 (0.89) |
| send (hibernated: woken from the store) | µs per call | 34.97 → 30.14 (0.86) | 33.20 → 40.71 (1.23) | 27.13 → 29.38 (1.08) | 34.26 → 35.97 (1.05) |
| hibernate | µs per call | 5.94 → 5.78 (0.97) | 4.50 → 4.55 (1.01) | 4.22 → 4.20 (0.99) | 4.37 → 4.32 (0.99) |
| wake | µs per call | 7.07 → 7.34 (1.04) | 3.84 → 4.02 (1.05) | 7.93 → 7.57 (0.95) | 4.85 → 4.75 (0.98) |
| actor (by name; measured as actorByName, its direct call) | µs per call | 0.532 → 0.507 (0.95) | 0.415 → 0.426 (1.03) | 0.426 → 0.415 (0.98) | 0.304 → 0.300 (0.99) |
| actorState | µs per call | 4.63 → 4.38 (0.95) | 4.34 → 4.80 (1.11) | 4.13 → 4.37 (1.06) | 3.95 → 4.20 (1.06) |
| hostStats | µs per call | 19.28 → 19.47 (1.01) | 19.32 → 19.76 (1.02) | 19.45 → 16.84 (0.87) | 14.51 → 14.14 (0.97) |
| I/O processor round trip | µs per call | 13.30 → 12.54 (0.94) | 8.47 → 8.33 (0.98) | 9.89 → 9.46 (0.96) | 7.88 → 6.48 (0.82) |
| transport round trip | µs per call | 34.01 → 34.13 (1.00) | 25.85 → 28.06 (1.09) | 27.99 → 31.32 (1.12) | 22.87 → 22.52 (0.98) |
| delayed send and its timer | µs per call | 7.19 → 7.48 (1.04) | 3.39 → 3.44 (1.02) | 5.93 → 5.97 (1.01) | 3.87 → 3.79 (0.98) |
| invoked service round trip | µs per call | 14.28 → 15.49 (1.08) | 10.86 → 11.78 (1.08) | 11.54 → 13.32 (1.15) | 9.84 → 10.34 (1.05) |
| sweep (every actor) | µs per actor | 0.008 → 0.007 (0.97) | 0.007 → 0.007 (0.98) | 0.008 → 0.007 (0.94) | 0.007 → 0.008 (1.03) |
| migrate (one session) | µs per call | 32.02 → 28.74 (0.90) | 20.00 → 16.20 (0.81) | 24.48 → 24.95 (1.02) | 17.45 → 20.93 (1.20) |
| snapshot | µs per actor | 0.110 → 0.105 (0.96) | 0.075 → 0.077 (1.04) | 0.090 → 0.080 (0.89) | 0.084 → 0.082 (0.97) |
| restore (and its first turn) | µs per actor | 0.313 → 0.297 (0.95) | 0.200 → 0.200 (1.00) | 0.236 → 0.234 (0.99) | 0.193 → 0.199 (1.03) |
| close | µs per actor | 0.081 → 0.102 (1.26) | 0.078 → 0.087 (1.11) | 0.079 → 0.106 (1.35) | 0.087 → 0.104 (1.19) |
Correct by the standard.
The core passes all 191 automatic tests of the W3C's SCXML test suite. Every binding runs the same conformance suite, on each of its datamodels.