Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Profiling resources

Built: a step holds what its flow config’s resources says, or what its tool asks for, and with enforcement that is a limit. Each step that runs is measured in a cgroup of its own, with no limits unless enforcement sets them: its peak memory, every process together, how many CPUs it kept busy on average and at its most, and its peak disk. --rerun=STEP,..., --no-store and --no-cache say which steps run whether they are cached or not, and whether they are stored (see The cache). Each run adds what its steps used to the measurement store, doris measurements import adds other machines’ runs, doris gc removes old ones, and doris resources suggests memory, disk and threads from them, for each step and the tool it runs. A step with services is measured, given values and suggested them for each part, its command and each service, and holds their sum.

This page is the design for working out what each step needs from measurements, keeping them, and writing what they show into a repo’s flow configs. A repo starts with no resources at all, and gets them as runs show what each step needs: the more runs, the tighter the values.

The loop

  1. Every run measures, as it does now: each step in a cgroup of its own.
  2. Measurements are kept, in a store that outlives the run and collects them from every machine that runs the repo, CI among them.
  3. doris profile fills the gaps: it sweeps a step’s threads to find how many it can use, and what each one is worth.
  4. doris resources says what each step should hold, from the store, and with --write writes it into the flow configs, for review in a pull request like any other change.

The store

Built: see The measurement store. It differs from the first design in three ways, each to keep what was built simple until a real need shows:

  • Recency is a count, not a weight. Only a step’s newest 50 records count. Weighting a record by whether its cache key still matches the step’s would mean working out every key, and a key changes with every edit to a design’s inputs, so few records would ever match.
  • Tool versions are not recorded on their own: the cache key covers them.
  • Whether a step ran alone is not recorded. Only threads would use it, and only once wall time is compared, which the thread sweep does under its own control.

A database, such as SQLite, would answer queries faster, but it can’t be shared safely on a network filesystem and can’t be merged by copying files. If reading every file gets slow, an index can be built from them, and thrown away.

Profiling threads

How many threads a step can use is not something normal runs show: each step is given the threads it holds, and runs beside others. doris profile finds it:

doris profile testrig my_core --step build --step run
  1. It runs the flow once with each profiled step given every CPU and running alone, and the rest as usual. The parallelism measured is how many threads the step can use: its ceiling.
  2. It sweeps down from the ceiling, halving: 16, 8, 4, 2, 1. Each point reruns the profiled step, alone, with that many threads, and repeats it if the times are far apart. It stops once a point is more than twice as slow as the best.
  3. It fits two curves: wall time against threads, and peak memory against threads. Memory is fitted as a + b × threads. A build that runs a compiler per thread has a large b. A simulator that shares one model between its threads has a small one.

A profiled step’s upstream steps are taken from the cache, as in any run, unless they are profiled too. Profiled steps are swept one at a time, in the order they run, so each point of one step’s sweep has the same inputs. Downstream steps are not run: profiling stops after the last profiled step, as with --until.

Thread counts are not part of a cache key, so a sweep runs each point as --rerun=STEP --no-store would: the cache already has its result.

What a thread is worth

The suggested threads is the knee of the time curve: the fewest threads whose time is within 10% of the best, resources.knee. A step that runs as fast on 4 threads as on 16 holds 4, and the other 12 run other steps. A step that runs alone, such as one build every run waits for, can be given more with a lower knee.

Suggesting values

Built, from runs alone: see Suggested resources. What the sweep adds:

CONFIG                                  STEP   POOL     NOW  SUGGESTED  RECORDS  FROM
cores/my_core/dv/testrig/testrig.hjson  build  threads  -    8          4 sweep  knee at 8: 6% slower than 16
                                               memory   -    12G        31       p95 9.4G + 25%; 1.1G + 1.0G/thread
                                        run    threads  -    2          2 sweep  knee at 2
  • Threads are the knee of the sweep, where there is one. Without, they stay the 95th percentile of the CPUs a step kept busy, marked from runs: no sweep.
  • Where memory depends on threads, the value suggested is for the threads suggested, and the fit is shown. A flow config could instead give memory as "1G + 1G/thread", worked out for the threads a step is given. That is only worth adding if the sweeps show it matters for real steps.
  • A design far from the rest is shown as such. Its own flow config gets its own value, as any design’s does.

Writing them

doris resources FLOW --write writes the suggested values into each flow config’s resources, and changes nothing else. The repo’s own process takes it from there: a branch, a pull request, a review. --diff prints what it would change, and writes nothing.

Only the resources table is rewritten, in the file’s own format and indentation, and its comments are kept. A TOML file is edited with toml_edit. An HJSON or JSON file has its resources object found and replaced in the text, with a key added at the end if there is none. A value that was written by hand and has a comment beside it is listed, not changed, unless --force is given.

The values go into the flow config files themselves, not a file beside them. Configuration has one rule for where a value is: each key in one kind of file, and no overrides. A generated file that a hand-written value overrides would break it.

The order to build it in

  1. The store, doris measurements import, and doris resources without --write: built.
  2. doris profile and the thread sweep.
  3. --write, for TOML, then HJSON and JSON.