Skip to content

Commit 5810f47

Browse files
committed
Give the measured cost of sessions in the guide
Figures from examples/bench_sessions.erl on an unloaded machine, with throughput per start mode and the isolation step of Temporal's and Restate's SDKs on the same workflow.
1 parent b27cdc4 commit 5810f47

1 file changed

Lines changed: 29 additions & 22 deletions

File tree

‎docs/sessions.md‎

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -182,29 +182,36 @@ started with.
182182

183183
## What it costs
184184

185-
Measured with `examples/bench_sessions.erl`, new + first call + close,
186-
p50. Run it on your machine for your own figures: the cost of a fork grows
187-
with the size of the prepared process.
185+
Measured with `examples/bench_sessions.erl` on Apple silicon (macOS 27,
186+
Python 3.14, 14 cores), p50 of new + first call + close. Run it on your
187+
machine for your own figures: the cost of a fork grows with the size of
188+
the prepared process.
188189

189-
| How the session starts | macOS 27, Python 3.14 | Linux (container), Python 3.11 |
190-
|---|---|---|
191-
| `reimport` (one run, worker or owngil context) | ~1 ms | |
192-
| `fork` | ~4 ms | ~4 ms |
193-
| `spawn` with a `warm` pool that keeps up | ~2 ms | ~2 ms |
194-
| `spawn` | ~60 ms | ~45 ms |
195-
| a plain isolated context, for reference | ~60 ms | ~40 ms |
196-
197-
Re-import runs on worker contexts share one GIL; on owngil contexts they
198-
run in parallel (about 3,500 runs a second with 8 callers on four
199-
contexts, against about 900 on worker contexts). One zygote forks one
200-
session at a time. On Linux it served about 1,000
201-
sessions a second with 8 or more callers; add `zygotes` when sessions are
202-
opened faster than one zygote forks them.
203-
204-
A call inside a session costs what it costs in any isolated context, since
205-
it crosses the same socket. `examples/bench_sessions_sdks.py` measures the
206-
isolation step of Temporal's workflow sandbox and Restate's SDK on the same
207-
workflow module.
190+
| How the session starts | Time to a used and closed session |
191+
|---|---|
192+
| `reimport` (one run, worker or owngil context) | 0.25 ms |
193+
| `spawn` with a `warm` pool that keeps up | 0.6 ms |
194+
| `fork` | 3.5 ms |
195+
| `spawn` | 65 ms |
196+
| a plain isolated context, for reference | 60 ms |
197+
198+
| Throughput, 8 callers | |
199+
|---|---|
200+
| `fork`, one zygote | about 650 sessions a second (Linux: about 1,000) |
201+
| `reimport` on four owngil contexts | about 13,500 runs a second |
202+
| `reimport` on four worker contexts (one GIL) | about 3,500 runs a second |
203+
204+
One zygote forks one session at a time; add `zygotes` when sessions are
205+
opened faster than one zygote forks them. A call inside a session costs
206+
what it costs in any isolated context (30 us p50, 70 us for a call that
207+
calls back into the session), since it crosses the same socket. A call in
208+
a re-import run stays in the process.
209+
210+
`examples/bench_sessions_sdks.py` measures the isolation step of Temporal's
211+
workflow sandbox (0.5 ms for a standard-library workflow, 4.6 ms when it
212+
defines a pydantic model, since the module is imported again each run) and
213+
of Restate's SDK (under a microsecond: it does not isolate invocations) on
214+
the same workflow module.
208215

209216
## Limits
210217

0 commit comments

Comments
 (0)