March Docs

Scheduler

Scheduler: runtime observability for the actor/task scheduler.

These counters are the load-shedding substrate: a supervisor or ingress actor polls them to decide when to shed. Interpreted backend reports the subset that is meaningful without the C scheduler (live actor count); unknown/unsupported indices read 0 on both backends.

Every value is an instantaneous reading of the running program, so the examples below compare readings rather than pinning them.

Functions

fndropped_messagesdropped_messages() : Int do sched_stat(4) end#

Messages dropped by bounded-mailbox overflow policies (see Actor.set_queue_limit), summed over every actor for the program lifetime.

let dropped = Scheduler.dropped_messages()
if dropped > last_dropped do alert(dropped - last_dropped) else () end
fnlive_procslive_procs() : Int do sched_stat(0) end#

Green-thread processes currently alive (actors + tasks + main). The interpreter counts live actors only.

let before = Scheduler.live_procs()
let pid = spawn(Worker)
Scheduler.live_procs() - before   -- 1 while the worker lives
fnrunq_depthrunq_depth() : Int do sched_stat(2) end#

Cross-thread global run-queue depth (instantaneous). Compiled backend only; the interpreter reads 0.

if Scheduler.runq_depth() > 1000 do shed(req) else serve(req) end
fnstatstat(i : Int) : Int#

Raw stat by index:

  • 0 live procs
  • 1 total spawned
  • 2 global runq depth
  • 3 stack-alloc failures
  • 4 messages dropped by mailbox policy
  • 5 stacks recycled
  • 6 pending timers
  • 7 execution contexts released at proc death
  • 8 dead proc structs freed
  • 9 dead proc structs retired and still waiting for their grace period
  • 10 dead actors' metadata freed
  • 11 dead actors' metadata retired and still waiting for its grace period

An unknown index (including a negative one) reads 0, as does a counter the interpreter does not track.

Examples

march> Scheduler.stat(99)
0
march> Scheduler.stat(1) >= Scheduler.stat(0)
true
fntotal_spawnedtotal_spawned() : Int do sched_stat(1) end#

Processes ever spawned over the program lifetime. Never decreases, and is never below live_procs().

Examples

march> Scheduler.total_spawned() >= Scheduler.live_procs()
true