Docs · Context Runtime
Extend the runtime.
Most extensions are modules, and a module can hook into far more than its own methods. The scheduler is the one major extension point that is not a module. This page lists what you can extend, what it costs, and how each piece is wired in.
- Module hooks
- container callbacks
- Scheduler
- runtime.local_sched
- Monitoring
- clio-run monitor, dashboard, debug telemetry
Extension points
| To change | Extend | Needs |
|---|---|---|
| What the runtime can do | A new ChiMod | An out-of-tree build; a runtime restart to load the library |
| Where tasks run | A scheduler | A source change to the runtime and a rebuild |
| How the scheduler sees your tasks | The module's task statistics | One container override |
| What the dashboard shows | Routes and a viz/ directory | One container override, static files |
| Behavior when nodes join, move or fail | Expand, Migrate, Recover, ScheduleRecover | Container overrides |
| How many requests become one | AggregateIn | A container override and a collective PoolQuery |
Custom modules
A module is the normal way to extend CLIO Core. Usage builds one end to end, and Write a chain operator builds one that sits in the storage chain. The sections below are hooks a module can add on top of its methods.
Write a scheduler
The scheduler decides which worker runs each task. It is a C++ class derived from the runtime's Scheduler base, created by name at startup from runtime.local_sched (default unless set). Two ship today: default, which books tasks by predicted hold time and grows the worker pool on demand, and local, which maps tasks by a hash of the submitting process and thread and never rebalances.
A scheduler implements these responsibilities:
- DivideWorkers
- Called once after the worker threads exist. Assigns roles (scheduler, network send and receive, GPU polling, general) and any core pinning.
- RuntimeMapTask
- The hot path: given the submitting worker, a task and its resolved container, return the id of the worker whose lane gets the task. It must be cheap; it runs for every task.
- LoadBalance
- Called by the monitor thread about every 500 ms, never on a worker. This is where liveness lives: detect workers stuck in one task, move their backlog, rebalance, retire idle extra workers.
- StealWork
- Called when a worker's lane is empty; may move a bounded number of tasks from busier lanes using the steal-safe pop.
- AdjustPolling
- Adapts the interval of periodic tasks that did no work, to save CPU.
- Optional
RecordCompletionreceives each task's measured CPU and wall time;GrowPooladds a worker when the mapper found no room;PickAltWorkerbreaks a worker's push onto its own full lane; getters return the network and GPU workers.
To add one, implement the class in context-runtime/src/scheduler/ with its header in include/clio_runtime/scheduler/, add its name to SchedulerFactory::Get, rebuild and reinstall the runtime, and set:
runtime:
local_sched: "my_sched" # unknown names fall back to "default" with a warningLiveness is your job. The default scheduler's monitor is what keeps one blocking or mislabeled task from wedging a worker forever. A replacement that drops LoadBalance or StealWork also drops that guarantee. Start from default_sched.cc and change the mapping, not the safety net.
Report task costs
The default scheduler predicts how long a task will hold a worker from a per-method linear model: a coefficient times the task's size. A container learns its coefficients from measured run times, and they are saved per module, pool, node and container and restored after a restart.
The size comes from the container's GetTaskStats, which by default reports zero. A module whose tasks carry variable payloads, such as a write of n bytes, should override it to report the real I/O size and compute estimate. Without it, every task of a method looks the same, and a 4 KiB write and a 1 GiB write are booked alike.
Monitor performance
clio-run monitor
Prints per-worker statistics from the admin module's Monitor method: tasks processed, queued, blocked, periodic and in retry, the estimated load, whether the worker is running and active, and its idle and suspend state.
$ clio-run monitor # refresh every second
$ clio-run monitor -i 5 # every 5 seconds
$ clio-run monitor --once --jsonThe dashboard
The node's dashboard shows the cluster, every pool and the configuration. Its JSON endpoints are usable from scripts: /api/health, /api/topology, /api/pools, /api/config, /api/chimods, and /api/routes, which lists every route including those modules added. See Navigate the dashboard.
Scheduler telemetry
With CTP_LOG_LEVEL=debug, the default scheduler logs every few seconds a histogram of observed task run times (under 10 µs up to over 1 s), the number of stalls detected, and the eight pool.method pairs with the most total wall time, with their counts, average and worst times. This is the quickest way to find which method of which module is slow.
Add dashboard pages
A module can extend the dashboard in two ways. Files in a viz/ directory shipped with the module are served at /viz/<module>. Overriding the container's RegisterViz adds REST routes, conventionally under /api/mod/<module>/, that those pages fetch.
RegisterVizruns at load time on a throwaway prototype container, so neither it nor its handlers may read container state or capturethis. Capture by value and reach state through a client or the managers.- Handlers run on the dashboard's own threads, not on workers. They may submit a task and wait on it, but they are not coroutines.
- The first registration of a method and path wins, so repeated calls are harmless.
Elasticity and recovery
A module that keeps state must implement these callbacks; the defaults do nothing beyond re-initialising.
- Expand
- A node joined the cluster (
clio-run start --induct). Re-partition data if ownership depends on the node count. - Migrate
- Move this container's state to another node (
clio-run migrate). - Recover
- Rebuild this container after a restart or on a new node, for example by replaying the module's own log.
- ScheduleRecover
- Choose which node rebuilds a lost container.
Collective aggregation
With a ManyToOne or AllToOne pool query, identical requests from many submitters are parked at a leader for a short window and run once. The module decides how inputs combine by overriding AggregateIn; the single result is copied back to every submitter. Use it for requests that thousands of ranks issue at once, such as a metadata lookup at job start.
GPU containers
A module built with GPU support gets a device-side container for each pool, and GPU kernels submit tasks through a device ring that a dedicated worker polls. PostGpuContainerCreate runs after the device container is allocated. Memory expansion is the main user.
Install and upgrade modules
- Install. Put the module's runtime library where the runtime looks (its own library directory,
CLIO_REPO_PATHorLD_LIBRARY_PATH) and restart the runtime once. It is scanned at startup. - Compose live. Once loaded, pools of the module are created and destroyed while the runtime serves, with
clio-run compose startandstopor from a client. Other pools are unaffected. - Upgrade. Replace the library and restart the runtime with
clio-run stopandclio-run start. No machine reboot is needed. Clients notice the restart, wait and reconnect; compose files in the restart log and durable pools are recreated, and each container'sRecoverreloads its state. - Not yet: in-place swap. The runtime's container handles are built to allow replacing a pool's code without a restart, but that path is currently dormant.