Skip to content
GitHubBlueskydev.toRSS

07Distributed task execution

Try distributed task execution on your machine

See one run spread over several workers, on your laptop, before you touch CI.

Terminal window
export VX_DTE_RUN=$(uuidgen)
vx run build test lint --all
Read
tasksoutputsvx runyour shellrelaythis machineworker 1git worktreeworker 2git worktreecachethis machinetasksoutputsvx runyour shellrelaythis machineworker 1git worktreeworker 2git worktreecachethis machine
Everything stays on your machine: one relay, one worktree per worker, one cache.

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.

.vx/workspace.ts
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.

Terminal window
bun add -d @vzn/vx-dte
vx lock

You can now declare workers in five lines, with no CI and nothing to host.

Workers see what git tracks, your edits included. So git add new files first, then name the run with VX_DTE_RUN:

Terminal window
git add -A
export VX_DTE_RUN=$(uuidgen)
vx run build test lint --all
The same build, twice

1. First run: workers share the tasks

Terminal window
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#test

Read 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

Terminal window
cache ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰
local 6✓
workers none started: no task needed one

Every 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 worker builds from what git tracks. A file git does not know fails the task and names it:

Terminal window
┌─ @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.

prepare runs once per worktree, before its worker starts. Point it at what your workspace needs:

adapter: local({ prepare: 'bun install --frozen-lockfile' }),

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
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'
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.
  • 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.

NextSpread a CI run over several machines →

The same run, with workers your CI starts.

Turborepo, Nx and other product names are trademarks of their owners. vx is not affiliated with or endorsed by them.