Host performance

The Host agent reconciles its Host on a loop: it collects container and process inventory, publishes the heartbeat, replays the Agent Run outbox and applies desired state (grants, workspace Internet policy, Project Docker sidecars, workspace guides, services). This page describes what that loop costs, what it caches and how a server keeps devctrl's control plane responsive when sessions saturate the CPU.

Reconciliation tick

Pause between ticks

The pause after each tick follows the host-load bands of background session indexing (apps/host-agent/src/host-tick-pacing.ts, thresholds in session-search-idle.ts):

Band Condition (one-minute load per core, PSI some avg10) Pause
calm load < 0.7 and pressure < 10 % 5 s
reduced between the two bands 15 s
busy load > 1.0 or pressure > 25 %; calm again after 3 samples 30 s

A dispatched command caps the current or next pause at 5 s, and the pause never drops below 5 s, so a stream of commands cannot run ticks back to back. Commands do not wait for the tick: the independent command poll still runs every 3 s. During a pause longer than 5 s the agent sends its cheap liveness ping every 5 s, so Core keeps seeing the Host, and the inventory keepalive waits pause + 20 s instead of 20 s before it publishes fresh inventory on its own (still inside Core's 90 s inventory window).

Inventory probes

Probe Before Now
docker stats per sampled container streaming sample (the daemon waits about 1 s for a second sample) one-shot=true; CPU percent from the previous sample of the same container
Nested Docker accounting (node -e inside a DinD-enabled workspace) every tick cached 30 s per container ID and start time; only workspaces with a running Project Docker sidecar on their network are probed
Sidecar process accounting (DinD) every tick, a fork per process and tree level cached 25 s per sidecar (inventory drops samples older than 30 s); shell builtins only, one /proc table pass
Session process tree usage ps plus, per agent, a /proc walk forking per process and tree level descendants from the same ps listing; per-process counters read with shell builtins
Context-tool and runtime-tool observations 60 s / 5 min caches unchanged

All of these are telemetry. No admission, ownership or authorization decision reads a cached probe value, and a restarted container (new start time) is probed again at once.

Desired-state lane

Per workspace the lane reconciles the Internet policy, the Project Docker sidecar and the workspace guide. It now keeps a fingerprint of its inputs: the context Core sent (without runtime counters and other observed fields), the ID, state and start time of the workspace's containers and of the shared gateway, and the size and modification time of images.lock.json.

Lane planning reads each workspace's shared-gateway use once per tick; the per-grant check at effect time stays live.

Other per-tick work

Cost model

Per running workspace with S sessions, P processes in the workspace container and a 5 s calm tick (W workspaces):

Work per tick and workspace Before Now (steady state)
Docker exec creations 1 ps + S tree probes + 1 nested node -e (DinD) + 1 sidecar walk 1 ps + S tree probes; nested and sidecar probes about every 6th tick
Forks inside the workspace for the process trees about S × depth × P × 2 about S × 15
docker stats latency about 1 s of daemon sampling one-shot
Lane Docker calls (listContainers, inspect, image inspect, egress prepare) about 6 lists + 5 inspects + 2 execs + file reads none while unchanged; the gateway route check only
Guide writes every tick at most every 60 s
Grant/service state POSTs one per grant and service on change or every 60 s
Outbox directory scans 4 1
journalctl runs 2 2 per minute
Host /proc reads for OOM mapping every PID of every session container 2 per session process

Under host load the tick also runs 3–6 times less often (15 s or 30 s pauses).

Metrics

Each accepted normal heartbeat carries the last completed tick's duration, the pause chosen after it and the Docker Engine requests the agent issued since the previous heartbeat. Core records them in the Host's host:<id> scope (metrics (source access required)): host.tick.ms, host.tick.pause.ms, host.docker.exec, host.docker.stats and host.docker.top. Keepalive inventory publications never repeat them.

CPU isolation

Docker's weights alone are relative between sibling cgroups. The control plane used to run with cpu_shares: 4096 beside every workload in Docker's default parent (system.slice), so it competed with each sibling at 4:1 and with nothing else (dockerd, BuildKit, other slices) at all. The layout is now:

Where What Weight
devctl-control.slice (opt-in) Core (controller) and web slice CPUWeight=1000
Docker's default parent Host agent cpu_shares: 4096
Docker's default parent workspace containers, Project Docker sidecars, sibling workloads --cpu-shares 256 (new containers)
devctl-workloads.slice (opt-in) session-search embedding service slice CPUWeight=20, plus --cpu-shares 128 and nice 10

Core also gets oom_score_adj: -500, so the kernel OOM killer prefers workloads (rootful templates; rootless Docker cannot lower it).

The Host agent deliberately stays in Docker's default parent. Finite operator worker admission measures that parent through the agent's own container (devctl.operator-host.parent), and workspace containers must share the parent that proof describes. For the same reason workspace containers are not moved into the workloads slice; within the default parent the agent's 4096 shares outweigh each workload's 256 sixteen to one.

A weight never caps anything: on an idle Host every workload still uses every free core.

Enabling the slices (one time, per server)

Opt-in until the slices exist: the templates leave cgroup_parent empty (Docker's default parent) unless DEVCTL_CONTROL_CGROUP_PARENT / DEVCTL_WORKLOADS_CGROUP_PARENT are set. With Docker's systemd cgroup driver on cgroup v2:

docker info --format '{{.CgroupDriver}} {{.CgroupVersion}}'   # expect: systemd 2
sudo install -m 0644 docker/devctl-control.slice.example /etc/systemd/system/devctl-control.slice
sudo install -m 0644 docker/devctl-workloads.slice.example /etc/systemd/system/devctl-workloads.slice
sudo systemctl daemon-reload
sudo systemctl start devctl-control.slice devctl-workloads.slice
systemctl show -p CPUWeight devctl-control.slice devctl-workloads.slice   # 1000 and 20

Then place the services (follow control-plane maintenance for draining and replacing Core):

Verify:

docker inspect -f '{{.Name}} {{.HostConfig.CgroupParent}} {{.HostConfig.OomScoreAdj}}' devctl-controller-1 devctl-web-1 devctl-session-search-embeddings
cat /sys/fs/cgroup/devctl-control.slice/cpu.weight /sys/fs/cgroup/devctl-workloads.slice/cpu.weight
systemd-cgls --no-pager -u devctl-control.slice

With Docker's cgroupfs driver a cgroup parent is a path (for example /devctl-control); its cpu.weight must then be written after every boot, so the systemd slices are the supported setup. Rootless Docker needs slices inside the delegated user tree and is not covered here.

Rollback: remove the variables (or the compose keys) and recreate the services; the slice units may stay installed.

Session-search CPU budget

Background indexing never uses more than its Host CPU budget: a fifth of the Host's cores (at least one) unless DEVCTL_SESSION_SEARCH_CPU_BUDGET sets whole cores on the Host agent, and half of it while the Host is in the reduced band (session search). The gate keeps using load per core and PSI; it does not read Core's event-loop delay, which the Host cannot observe and which live diagnostics traced to Core's own routes rather than CPU starvation.