Documentation
¶
Overview ¶
Package heavy keeps the heavy checks agents run (go build and test, vitest, playwright, tsc, eslint) from taking a shared machine away from the people working on it. harnessly puts a small launcher under each of those names on the agents' PATH; it runs `harnessly heavy <tool> ARGS…`, and this package runs the real tool:
- a light call (go env, go list, tsc --version) runs at once, as if there were no launcher;
- a heavy call first takes one of the machine's shared slots (a flock on <dir>/slot<n>, for every user of the machine), waits for one up to a limit, and runs under nice and ionice with fewer threads (GOMAXPROCS, -p);
- when no slot frees up in time it does not run: it says so in words an agent acts on and exits with 75.
The number of slots follows the cores: 1 up to 4, 2 up to 16, one per 8 above. A call inside a slot already held ($HARNESSLY_HEAVY_SLOT, e.g. go test running go build) runs at once. Every heavy call is one line of <dir>/events, which `harnessly heavy stats` counts.
Index ¶
Constants ¶
const ExitBusy = 75
ExitBusy is the exit code of a heavy call that found no free slot in time (EX_TEMPFAIL).
const HelpText = `` /* 2085-byte string literal not displayed */
HelpText is `harnessly heavy --help`.
const Marker = "harnessly heavy"
Marker is in every launcher harnessly writes; a file carrying it is never taken for the real tool.
Variables ¶
var ErrBusy = errBusy
ErrBusy is Hold's answer when no slot freed up within the wait.
var Tools = []string{"go", "vitest", "playwright", "tsc", "eslint", "npx", "npm", "pnpm"}
Tools are the names harnessly puts a launcher under.
Functions ¶
func Dir ¶
Dir is the folder of the slots: $HARNESSLY_HEAVY_DIR, else /var/lib/harnessly-heavy when the machine has one, else /tmp/harnessly-heavy. It is the same for every user of the machine.
func Hold ¶
Hold takes one of the machine's shared slots for work the caller runs itself (a draft render of a 3D scene), waiting up to wait for one. The returned function frees the slot; call it once the work is over. When the slots cannot be kept at all (a read-only folder) the work is let through unheld, as the launcher does. A slot is one of the same flocks the launchers take, so a draft render waits for builds and tests and they for it.
Types ¶
type Env ¶
type Env struct {
Getenv func(string) string
Environ func() []string
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
// CPUs is the number of cores; 0 is runtime.NumCPU.
CPUs int
// Poll is how often a waiting call tries the slots again; 0 is 2 s.
Poll time.Duration
// Now is the clock; nil is time.Now.
Now func() time.Time
// Exec replaces the process with the tool for a light call; nil is syscall.Exec.
Exec func(path string, argv, env []string) error
// Getwd is the folder the call runs in; nil is os.Getwd.
Getwd func() (string, error)
}
Env is what a run depends on outside its arguments; tests replace the parts.
type Stats ¶
type Stats struct {
Dir string `json:"dir"`
Slots int `json:"slots"`
Since string `json:"since"`
// Ran took a slot at once; Waited took one after waiting; Refused found none in time and did not run; Remote ran
// on the machine of HARNESSLY_HEAVY_REMOTE.
Ran int `json:"ran"`
Waited int `json:"waited"`
Refused int `json:"refused"`
Remote int `json:"remote"`
// WaitP50Ms and WaitMaxMs are over the calls that waited or were refused.
WaitP50Ms int64 `json:"wait_p50_ms"`
WaitMaxMs int64 `json:"wait_max_ms"`
ByTool map[string]int `json:"by_tool"`
}
Stats counts the heavy calls of <dir>/events since a moment.