Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions Framework/Core/scripts/dpl-tune/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# dpl-tune

Tunes the runtime configuration of a DPL workflow from a short probe run.
It runs the workflow on a few input files with `--resources-monitoring`, reads
the driver's `performanceMetrics.json`, and proposes the DPL options that
should raise the throughput within a memory budget.
Python 3 standard library only.

## What it tunes, and from which metrics

| option | changed when | metrics used |
|---|---|---|
| `--aod-memory-rate-limit` | the devices are mostly idle and few TFs are in flight | `total-timeframes-in-flight`, `table-bytes-*-created`, `total_wall_time_ms` |
| `--pipeline dev:N` | one device is the slowest by at least 1.3x and can be pipelined | `total_wall_time_ms`, `cpuUsedAbsolute` |
| `--readers` | the AOD reader becomes the slowest device | `total_wall_time_ms`, `aod-file-read-info` |
| `--timeframes-rate-limit` | an explicit limit would cap the TFs in flight | `total-timeframes-in-flight` |
| `--shm-segment-size` | only raised, to twice the in-flight data | sampled shared memory, `arrow-bytes-delta` |

The steady state is taken from the first to the last completed TF
(`total-timeframes-consumed`). The throughput is modelled as limited by the
slowest lane, by the CPU (CPU seconds per TF over the cores) or by the TFs in
flight (Little's law); each step is checked against the memory budget.
`tuning.md` gives each change with the numbers behind it.

By default the tuned configuration is then run on the probe inputs
(verification). If it fails (non-zero exit, fewer TFs, a hang, memory above the
budget) the riskiest change is backed off and the run repeated; if it is not
faster, the changes are withdrawn. `--no-verify` skips this.

## Usage

Dump the topology with the usual command line, adding
`--dump-workflow --dump-workflow-file` to the last executable of the pipe:

```bash
o2-analysis-a ... | o2-analysis-b ... -b --aod-file @inputs.txt \
--dump-workflow --dump-workflow-file workflow.json
```

The JSON is run again by piping it into that last executable, so only that one
can be the driver (`o2-dpl-run` only if it was the last stage).

Probe, tune and verify, for a budget of 2 GB per core on 8 cores:

```bash
dpl-tune tune workflow.json --inputs inputs.txt --probe-files 1 \
--mem-budget 2G --per-core --cores 8 -o out \
[--env env.sh] [--stage configuration.json ...] [--set=--max-tf=8] [--lock FILE]
```

- `--env` is sourced before each run (e.g. the environment of a reproducer),
`--stage` copies files into each run directory, `--clone-dir` clones a whole directory.
- `--set=OPT=VALUE` overrides an option wherever it already appears.
- `--lock FILE` runs each DPL run under an exclusive `flock()` on FILE, waiting
while another process (e.g. `lockf` or `flock` on the same file) holds it.
- Every run uses `-b` and a fresh run directory (`out/probe`, `out/verify*`).

Tune from an existing `performanceMetrics.json` (e.g. from a Grid job), without running:

```bash
dpl-tune tune [workflow.json] --from-metrics performanceMetrics.json \
[--mem-samples mem.tsv] --mem-budget 16G --cores 8 -o out \
[--driver "exe --aod-memory-rate-limit ... --shm-segment-size ..."]
```

Run a topology, with or without a tuning, to compare them:

```bash
dpl-tune run workflow.json --inputs inputs.txt --files 4 -o run-base
dpl-tune run workflow.json --inputs inputs.txt --files 4 --tuning out/tuning.json -o run-tuned
```

`run` writes `summary.json` (exit code, wall time, TFs, TF/s, peak memory) in the run directory.

Install with `pip install ./Framework/Core/scripts/dpl-tune/` to get a
`dpl-tune` command, or run `python3 dpl_tune.py` directly.

## Outputs

- `tuning.md`: the changes with the numbers behind them, the observations, the
prediction, a per-device table.
- `tuning.json`: the same, machine readable (`knobs`, `changes`, `extra_args`, `analysis`).
- `workflow.tuned.json`: the topology with the options applied to every data processor.
- `run-tuned.sh`: the driver command running `workflow.tuned.json`.
- `probe/`, `verify*/`: the run directories (`run.log`, `performanceMetrics.json`, `mem.tsv`).

## Limitations

- **Memory on macOS**: `performanceMetrics.json` has no RSS/PSS on macOS, so
the memory of every process is sampled once per second (`phys_footprint`,
plus the resident size of the shared-memory segment). The sum is an upper
bound: shared pages are counted once per process touching them. On Linux PSS
is read from `/proc/<pid>/smaps_rollup`, which counts them once.
- **Reconstruction**: only `--pipeline` is tuned, and only when a device is
busy most of the time. The TFs in flight, the shared memory free and the
dropped messages are not in `performanceMetrics.json`, so
`--timeframes-rate-limit` and `--shm-segment-size` cannot be tuned for
reconstruction without more metrics.
- **Readers guard**: in the O2 versions tested, `--readers` > 1 combined with
`--aod-memory-rate-limit` deadlocked (the readers wait for AOD memory offers
that never come). When a verification with both fails, the extra readers are
backed off first. `--no-readers-guard` disables this once O2 is fixed.
- The extrapolated shared memory is a lower bound; the verification run
measures the real peak against the budget.
- The output content is not compared: check it separately.
Loading