07Distributed task execution
Try distributed task execution on your machine
See one run spread over several workers, on your laptop, before you touch CI.
export VX_DTE_RUN=$(uuidgen)vx run build test lint --allAdd local()
Section titled “Add local()”Give dte() one group of workers, here named linux. local() starts each worker as a process in its own git worktree: a second checkout of your workspace, made by git.
import { defineWorkspace } from '@vzn/vx/config'import { dte, local } from '@vzn/vx-dte'import { bun } from '@vzn/vx-lockfile'
export default defineWorkspace({ plugins: [ bun(), dte({ workers: { linux: { machines: { cpu2: { max: 3, cpu: 2, memory: '8GB', }, }, }, }, adapter: local({ prepare: 'bun install' }), }), ],})Read it as: up to 3 workers (max), each counted as 2 cores and 8GB. prepare installs packages in each worktree.
bun add -d @vzn/vx-dtevx lockYou can now declare workers in five lines, with no CI and nothing to host.
Watch a run spread
Section titled “Watch a run spread”Workers see what git tracks, your edits included. So git add new files first, then name the run with VX_DTE_RUN:
git add -Aexport VX_DTE_RUN=$(uuidgen)vx run build test lint --all1. First run: workers share the tasks
Tasks status cache ±usual time cpu mem outputs blocks worker task success miss — 204ms 99% 119MB 80B 2 linux.cpu2#1 @demo/ui#build success miss — 93ms 57% 78MB 0B 0 linux.cpu2#1 @demo/ui#lint success miss — 58ms 77% 78MB 0B 0 linux.cpu2#1 @demo/web#lint success miss — 533ms 93% 111MB 0B 0 linux.cpu2#1 @demo/ui#test success miss — 162ms 99% 113MB 123B 0 linux.cpu2#1 @demo/web#build success miss — 428ms 113% 138MB 0B 0 linux.cpu2#3 @demo/web#test workers linux.cpu2#1 left 5 done · warm-up 0.2s linux.cpu2#2 left 0 done · warm-up 0.3s linux.cpu2#3 stopped 1 done · warm-up 0.3s · @demo/web#testRead the worker column: linux.cpu2#1 is worker 1 of the linux.cpu2 machines. It ran five tasks while #3 ran @demo/web#test. #2 joined, found nothing left and left.
2. Again, nothing changed: no worker starts
cache ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰ local 6✓ workers none started: no task needed oneEvery task came from the cache, so there was no work to hand out.
Check yourself You run vx run build --all without VX_DTE_RUN. What happens?
The run stays on this machine, as always. VX_DTE_RUN is what turns workers on here. On GitHub
Actions the run names itself, so you never set it there.
You can now spread a run over workers and read who ran each task.
PatternsCommon setups
A new file the task reads
Section titled “A new file the task reads”A worker builds from what git tracks. A file git does not know fails the task and names it:
┌─ @demo/ui#build > failed (exit 1)
packages/ui $ vite build
├─ OUTPUT ────────────────────────────────────────────────────
[vx] @demo/ui#build: plugin '@vzn/vx-dte' (executor 'dte') failed in execute: @demo/ui#build keys packages/ui/src/theme.ts, which git does not track, so no worker has it: git add it (and commit it for workers on CI), or leave it out of the task's inputs
└─ @demo/ui#build · dte ── (0ms) failed (exit 1)Fix: git add packages/ui/src/theme.ts, then run again.
A slow install
Section titled “A slow install”prepare runs once per worktree, before its worker starts. Point it at what your workspace needs:
adapter: local({ prepare: 'bun install --frozen-lockfile' }),More workers at once
Section titled “More workers at once”Raise max. Each worker is a full process, so stay near your core count:
workers: { linux: { machines: { cpu2: { max: 4, cpu: 2, memory: '8GB' }, }, },},You can now fix an untracked file, a custom install and the worker count.
DetailsEvery option
local(options?)
Section titled “local(options?)”| Option | What it does | Default | Example |
|---|---|---|---|
prepare |
A shell line each worktree runs before its worker starts. A non-zero exit fails that worker and prints why. | none | 'bun install' |
What turns it on
Section titled “What turns it on”| Name | What it does |
|---|---|
VX_DTE_RUN |
Names the run and turns distribution on. A random UUID, so no one can guess the run: uuidgen prints one. Any other value is refused. Unset, vx run stays on this machine. |
What a worker sees
Section titled “What a worker sees”- A worktree of your tracked files as the run saw them at its start, uncommitted edits included.
- The bytes git stores, with git’s filters undone: line endings,
ident, LFS. A task whose input differs on disk, such as a CRLF checkout, fails and names the file. - A relay on this machine that
local()starts and stops with the run. Nothing to deploy. - The same cache as the run, so outputs come home at once.
dte()’s own options (workers, relay, unmeasured and the rest): Spread a CI run over several machines.