Config API changes (src/preempt.rs, src/runtime.rs):
- preempt: promote ALLOC_INTERVAL and TIMESLICE_CYCLES from bare consts to
DEFAULT_ALLOC_INTERVAL / DEFAULT_TIMESLICE_CYCLES; store active values in
thread-locals set on each actor resume so multiple runtimes can use
different settings concurrently.
- runtime: add alloc_interval / timeslice_cycles fields to Config; add
Config::alloc_interval(n) and Config::timeslice_cycles(c) builder methods;
thread the values through RuntimeInner to the reset_timeslice() call in
schedule_loop.
Bench changes:
- Add bench_cfg(threads) helper to general/tokio_favored/smarm_favored that
wraps Config::exact and reads SMARM_ALLOC_INTERVAL / SMARM_TIMESLICE_CYCLES
env vars, so the sweep script can vary knobs without recompiling.
Sweep tooling (benches/sweep.py):
- 'run': run the 3-file bench suite once; --save-baseline persists JSON
- 'regress': compare current run against baseline.json, exit 1 on any bench
that regresses >10% vs stored medians
- 'sweep': run the full SWEEP_GRID (10 points), print comparison table,
optional --save-csv; binaries pre-built so no recompile per point
Sweep results (10-point grid, 1-CPU sandbox):
- The preemption knobs have very little effect on this single-CPU machine.
Most benches move <5% across the entire grid.
- Longer timeslices (tc=600k, tc=1200k) reliably hurt spawn_storm_busy
(+11-15%) and catch_unwind_panics (+10-12%) because actors hold the
scheduler mutex longer per timeslice, stalling the storm of joinable tasks.
- Shorter timeslices (tc=150k) give a small improvement on many_timers
(-3-4%) and a wash everywhere else.
- yield_in_hot_loop and uncontended_channel are essentially flat across all
knobs — both are scheduling-dominated and call yield_now explicitly, so
the RDTSC-driven preemption path is irrelevant.
- Conclusion: the knobs matter primarily under contention (multi-core).
Re-run sweep on a multi-core machine before drawing tuning conclusions.
127 lines
8.3 KiB
Plaintext
127 lines
8.3 KiB
Plaintext
smarm general benchmarks
|
||
available parallelism: 1 threads
|
||
ITERS=15 (+1 warmup, discarded)
|
||
CHAIN_DEPTH=1000, YIELD_TASKS=200×1000, PRIME_N=400000/64 workers, PP_ROUNDS=1000
|
||
|
||
================================================================================
|
||
chained_spawn: depth 1000
|
||
================================================================================
|
||
runtime | result | median µs | min µs | max µs
|
||
--------------------------------------------------------------------------------
|
||
smarm 1-thread | 1000 | 8574 | 8421 | 8729
|
||
smarm 1-thread | 1000 | 8675 | 8401 | 12686
|
||
tokio current_thread | 1000 | 125 | 125 | 148
|
||
tokio multi-thread | 1000 | 188 | 184 | 291
|
||
|
||
================================================================================
|
||
yield_many: 200 tasks × 1000 yields
|
||
================================================================================
|
||
runtime | result | median µs | min µs | max µs
|
||
--------------------------------------------------------------------------------
|
||
smarm 1-thread | 200000 | 42389 | 41316 | 46466
|
||
smarm 1-thread | 200000 | 41776 | 41342 | 48940
|
||
tokio current_thread | 200000 | 15168 | 15094 | 15658
|
||
tokio multi-thread | 200000 | 15953 | 15862 | 17408
|
||
|
||
================================================================================
|
||
fan_out_compute: primes in [2, 400000) across 64
|
||
================================================================================
|
||
runtime | result | median µs | min µs | max µs
|
||
--------------------------------------------------------------------------------
|
||
smarm 1-thread | 33860 | 29680 | 29572 | 30661
|
||
smarm 1-thread | 33860 | 29816 | 29597 | 30401
|
||
tokio current_thread | 33860 | 28657 | 28581 | 29488
|
||
tokio multi-thread | 33860 | 34837 | 34529 | 37270
|
||
|
||
================================================================================
|
||
ping_pong_oneshot: 1000 rounds
|
||
================================================================================
|
||
runtime | result | median µs | min µs | max µs
|
||
--------------------------------------------------------------------------------
|
||
smarm 1-thread | 1000 | 16735 | 16601 | 17444
|
||
smarm 1-thread | 1000 | 16702 | 16500 | 17184
|
||
tokio current_thread | 1000 | 898 | 873 | 994
|
||
tokio multi-thread | 1000 | 4343 | 4241 | 4448
|
||
smarm tokio-favored benchmarks
|
||
available parallelism: 1 threads
|
||
ITERS=15 (+1 warmup, discarded)
|
||
STORM_BACKGROUND=8, STORM_SPAWN=10000, MPSC=32×10000, TIMER_ACTORS=10000 (1–10 ms), SCALING_N=400000/64
|
||
|
||
================================================================================
|
||
spawn_storm_busy: 8 bg yielders + 10000 zero-work spawns
|
||
================================================================================
|
||
runtime | result | median µs | min µs | max µs
|
||
--------------------------------------------------------------------------------
|
||
smarm 1-thread | 10000 | 128408 | 126199 | 133268
|
||
smarm 1-thread | 10000 | 131599 | 129387 | 135080
|
||
tokio current_thread | 10000 | 2718 | 2661 | 2981
|
||
tokio multi-thread | 10000 | 7264 | 4608 | 11583
|
||
|
||
================================================================================
|
||
mpsc_contention: 32 producers × 10000 msgs → 1 consumer
|
||
================================================================================
|
||
runtime | result | median µs | min µs | max µs
|
||
--------------------------------------------------------------------------------
|
||
smarm 1-thread | 320000 | 9289 | 9039 | 9751
|
||
smarm 1-thread | 320000 | 9510 | 9157 | 9677
|
||
tokio current_thread | 320000 | 17550 | 17290 | 18578
|
||
tokio multi-thread | 320000 | 18336 | 17527 | 18989
|
||
|
||
================================================================================
|
||
many_timers: 10000 actors sleeping 1–10 ms
|
||
================================================================================
|
||
runtime | result | median µs | min µs | max µs
|
||
--------------------------------------------------------------------------------
|
||
smarm 1-thread | 10000 | 139111 | 136105 | 146606
|
||
smarm 1-thread | 10000 | 137302 | 133316 | 141350
|
||
tokio current_thread | 10000 | 13720 | 13455 | 14607
|
||
tokio multi-thread | 10000 | 14964 | 14546 | 15400
|
||
|
||
================================================================================
|
||
multi_thread_scaling: primes in [2, 400000) across 64 workers
|
||
================================================================================
|
||
runtime | result | median µs | min µs | max µs
|
||
--------------------------------------------------------------------------------
|
||
smarm 1-thread | 33860 | 30048 | 29705 | 31530
|
||
tokio multi 1-thread | 33860 | 28894 | 28682 | 30094
|
||
smarm smarm-favored benchmarks
|
||
available parallelism: 1 threads
|
||
ITERS=15 (+1 warmup, discarded)
|
||
RECURSE_DEPTH=500, HOT_YIELDS=500000×2, UNCONT_MSGS=1000000, PANIC_TASKS=10000
|
||
|
||
================================================================================
|
||
deep_recursion: depth 500
|
||
================================================================================
|
||
runtime | result | median µs | min µs | max µs
|
||
--------------------------------------------------------------------------------
|
||
smarm 1-thread | 1 | 93 | 81 | 161
|
||
smarm 1-thread | 1 | 103 | 80 | 178
|
||
tokio current_thread | 1 | 25 | 25 | 28
|
||
tokio multi-thread | 1 | 53 | 47 | 74
|
||
|
||
================================================================================
|
||
yield_in_hot_loop: 2 actors × 500000 yields (single thread)
|
||
================================================================================
|
||
runtime | result | median µs | min µs | max µs
|
||
--------------------------------------------------------------------------------
|
||
smarm 1-thread | 1000000 | 188726 | 187640 | 192658
|
||
tokio current_thread | 1000000 | 149332 | 148133 | 155745
|
||
|
||
================================================================================
|
||
uncontended_channel: 1→1, 1000000 msgs (single thread)
|
||
================================================================================
|
||
runtime | result | median µs | min µs | max µs
|
||
--------------------------------------------------------------------------------
|
||
smarm 1-thread | 1000000 | 27630 | 27086 | 29749
|
||
tokio current_thread | 1000000 | 54225 | 53355 | 56307
|
||
|
||
================================================================================
|
||
catch_unwind_panics: 10000 tasks, 50% panic
|
||
================================================================================
|
||
runtime | result | median µs | min µs | max µs
|
||
--------------------------------------------------------------------------------
|
||
smarm 1-thread | 10000 | 144934 | 143038 | 163552
|
||
smarm 1-thread | 10000 | 146614 | 143653 | 151325
|
||
tokio current_thread | 10000 | 266330 | 263523 | 271639
|
||
tokio multi-thread | 10000 | 274729 | 266323 | 285114
|