All 191 automatic W3C tests pass
That is 158 mandatory tests and 33 optional ones, BasicHTTP included.
A started actor takes about 530 bytes and a hibernated one about 120. Four million fit in one process, and each operation costs about the same at four million actors as at two.
Pick a scenario and a population, and one host runs it in a Worker on this page.
A host on this device runs a colony of cells that eat, give food to neighbours, divide and die, or a fixed population of up to four million actors that wait, get events, message each other, sleep in a store or hold timers. Charts follow the actors alive, births and deaths, events a second, time per event and memory over the whole run.
Every cell in the colony runs this chart, and dies in one of its two final states.
<?xml version="1.0" encoding="UTF-8"?>
<!-- A cell. Every simulated second it ages and burns one unit of energy.
The light (urn:lab) feeds it now and then and names a neighbour. A
cell with energy to spare gives some to that neighbour; one that has
doubled its store divides, and the light spawns the daughter with half
the energy. A cell dies of hunger, or of age when its life is over:
both are final states, and the host removes it. -->
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0"
datamodel="ecmascript" name="cell" initial="alive">
<datamodel>
<data id="energy" expr="20"/>
<data id="age" expr="0"/>
<data id="life" expr="60"/>
<data id="first" expr="'1s'"/>
<data id="neighbour" expr="0"/>
</datamodel>
<state id="alive" initial="hungry">
<onentry>
<send event="tick" delayexpr="first"/>
</onentry>
<transition event="tick" cond="energy <= 1" target="starved"/>
<transition event="tick" cond="age + 1 >= life" target="aged"/>
<transition event="tick" type="internal">
<assign location="energy" expr="energy - 1"/>
<assign location="age" expr="age + 1"/>
<send event="tick" delay="1s"/>
</transition>
<transition event="feed" type="internal">
<assign location="energy" expr="energy + _event.data.food"/>
<assign location="neighbour" expr="_event.data.neighbour"/>
</transition>
<transition event="gift" type="internal">
<assign location="energy" expr="energy + _event.data.energy"/>
</transition>
<!-- A neighbour that has died: the gift is lost. -->
<transition event="error.communication" type="internal"/>
<state id="hungry">
<transition cond="energy >= 30" target="thriving"/>
</state>
<state id="thriving">
<transition cond="energy >= 40" target="dividing"/>
<transition cond="energy < 30" target="hungry"/>
<!-- Fed while it has energy to spare: it gives a fifth of the meal on. -->
<transition event="feed" cond="_event.data.neighbour !== 0" type="internal">
<assign location="energy" expr="energy + _event.data.food - Math.ceil(_event.data.food / 5)"/>
<assign location="neighbour" expr="_event.data.neighbour"/>
<send event="gift" targetexpr="'#_scxml_' + neighbour">
<param name="energy" expr="Math.ceil(_event.data.food / 5)"/>
</send>
</transition>
</state>
<state id="dividing">
<onentry>
<send type="urn:lab" event="divide">
<param name="energy" expr="Math.floor(energy / 2)"/>
</send>
<assign location="energy" expr="energy - Math.floor(energy / 2)"/>
</onentry>
<transition target="hungry"/>
</state>
</state>
<final id="starved">
<donedata><content expr="'starved'"/></donedata>
</final>
<final id="aged">
<donedata><content expr="'aged'"/></donedata>
</final>
</scxml>Each cell is the memory one more actor, message or delayed send adds to a process holding a million.
| runtime, datamodel | actor, started | actor, after an event | actor, hibernated | message waiting | delayed send pending |
|---|---|---|---|---|---|
| node, native | 532 B | 673 B | 118 B | 309 B | 353 B |
| bun, native | 601 B | 781 B | 93 B | 386 B | 448 B |
| node, quickjs | 1036 B | 1634 B | 92 B | 309 B | 358 B |
| bun, quickjs | 1041 B | 1645 B | 90 B | 313 B | 356 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 | 803 B | 720 B | 532 B | 510 B | 495 B |
| per actor, after an event | 1446 B | 870 B | 673 B | 654 B | 639 B |
| per actor, hibernated | 637 B | 269 B | 118 B | 100 B | 91 B |
| per message waiting | 602 B | 392 B | 309 B | 293 B | 285 B |
| per delayed send pending | 737 B | 489 B | 353 B | 338 B | 331 B |
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();2000064hostStats reports each pool's capacity, what it uses and its high water mark:
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, 1Each row times one operation of the API on two million actors and on four million. Each cell gives both costs and their ratio, and 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 | 10.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 call | 5.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 call | 0.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 call | 3.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 event | 3.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 call | 32.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 call | 5.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 call | 6.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 call | 3.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 call | 4.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 call | 25.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 call | 10.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 call | 30.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 call | 6.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 call | 13.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 actor | 0.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 call | 24.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 actor | 0.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 actor | 0.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 actor | 0.114 → 0.128 (1.13) | 0.120 → 0.157 (1.31) | 0.126 → 0.127 (1.01) | 0.120 → 0.139 (1.16) |
The core passes the W3C's SCXML test suite, and every binding runs it too.
That is 158 mandatory tests and 33 optional ones, BasicHTTP included.
The conformance suite runs the W3C tests and its own scenarios against each binding, on each of its datamodels.
Source:tinyactors-test, README.md