MishkaCmsCore. Runtime. Handlers. CompileGate
(Mishka CMS Core v0.0.5-alpha.5)
Copy Markdown
View Source
Per-node concurrency limiter for runtime module compilation.
Compiling is CPU-bound, so allowing more compiles at once than the node has cores only
thrashes the scheduler and the (single) code server — it does NOT add resources. This gate
caps concurrent compiles to System.schedulers_online() (one per core, the measured sweet
spot); extra compiles wait in a FIFO queue and start as slots free. So a cold-start burst of
many distinct pages can't saturate the node and stall live requests.
Every compile funnels through run/1, called by the one
MishkaCmsCore.Runtime.Handlers.ModuleCompilerHandler worker a module has — covering boot,
lazy first-request, and Oban-worker compiles. The callers waiting for that worker hold no slot.
Per-node by design: CPU is a per-node resource, so each node throttles its own compiles with
zero cluster coordination. The limit is overridable via
config :mishka_cms_core, :compile_gate_limit.
A compile that has to wait for a slot emits [:mishka_cms, :runtime, :compile_gate, :queued] from
the gate's process, with how many are waiting as its measurement and the waiting pid as its
metadata, once that compile has its place in the queue.
Summary
Functions
Returns a specification to start this module under a supervisor.
How many compiles this node runs at once.
Run fun once a compile slot is free — blocking the caller until one opens — then release the
slot. The holder is monitored, so if fun raises or the caller is killed the slot is still
reclaimed (see handle_info/2); a slot is never leaked.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec limit() :: pos_integer()
How many compiles this node runs at once.
Run fun once a compile slot is free — blocking the caller until one opens — then release the
slot. The holder is monitored, so if fun raises or the caller is killed the slot is still
reclaimed (see handle_info/2); a slot is never leaked.