Skip to content
Closed
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
15 changes: 8 additions & 7 deletions .claude/ci/benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

**Source:**
- `.gitlab/generate-package.php` — declares `include: .gitlab/benchmarks.yml` and the pipeline stages
- `.gitlab/benchmarks.yml` — all benchmark job definitions (if present; may be in the `DataDog/benchmarking-platform` repo instead)
- `.gitlab/benchmarks.yml` — all benchmark job definitions; the microbenchmark
steps, container and gate configs live in `.gitlab/benchmarks/` (see
`.gitlab/benchmarks/README.md`)

| CI Job | Image | What it does |
|--------|-------|--------------|
| `benchmarks-tracer` | `486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:dd-trace-php-82-dev` | Runs PHP tracer microbenchmarks via the `benchmarking-platform` framework; skips automatically if no tracer-relevant files changed |
| `benchmarks-tracer` | `$MICROBENCHMARKS_CI_IMAGE` (see `.gitlab/benchmarks.yml`; built in-repo from `.gitlab/benchmarks/container/`) | Runs PHP tracer microbenchmarks via the Benchmarking Platform framework; skips automatically if no tracer-relevant files changed |
| `benchmarks-appsec` | same | Runs appsec microbenchmarks; produces `candidate.tar.gz` and `baseline.tar.gz` artifacts |
| `benchmarks-profiler` | same | Runs profiler microbenchmarks |
| `macrobenchmarks: [{PHP_VERSION}]` | `486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:php_laravel-realworld` | Runs a Laravel Realworld application under k6 load at three traffic levels; PHP 7.4 and 8.1 |
Expand All @@ -34,7 +36,7 @@ Runner: `runner:apm-k8s-tweaked-metal` (microbenchmarks); `runner:apm-k8s-same-c
## What It Tests

Microbenchmarks measure overhead of the tracer, appsec, and profiler components
using the `DataDog/benchmarking-platform` framework (`dd-trace-php` branch). The
using the Benchmarking Platform framework (steps in `.gitlab/benchmarks/`). The
scenario name is passed as `BP_SCENARIO` to `bp-runner`.

Macrobenchmarks run a realistic PHP application (Laravel Realworld) under k6 load
Expand All @@ -55,7 +57,7 @@ dev container.

### Running the benchmarks

The `benchmarking-platform` repo (branch `dd-trace-php`) is only the
The `.gitlab/benchmarks/` directory is only the
CI orchestrator — it calls `make benchmarks` and friends. You do not
need `bp-runner` for local runs. Three approaches, from simplest to
most flexible:
Expand Down Expand Up @@ -179,8 +181,7 @@ Or filter them out:
## Investigating a Regression

When `check-big-regressions` fails, download the `reports/` artifact from the
`benchmarks-tracer` job. The gate runs `bp-runner.fail-on-regression.yml` from the
`benchmarking-platform` repo (cloned into `/platform`). To read the job log directly:
`benchmarks-tracer` job. The gate runs `.gitlab/benchmarks/bp-runner.fail-on-regression.yml`. To read the job log directly:

```bash
curl -s -H "PRIVATE-TOKEN: $GITLAB_PERSONAL_ACCESS_TOKEN" \
Expand All @@ -196,7 +197,7 @@ curl -s -H "PRIVATE-TOKEN: $GITLAB_PERSONAL_ACCESS_TOKEN" \

- The macrobenchmark image (`php_laravel-realworld`) is maintained on the
`php/laravel-realworld` branch of `DataDog/benchmarking-platform`, distinct from
the microbenchmark image (`dd-trace-php` branch).
the microbenchmark image (built in-repo from `.gitlab/benchmarks/container/`).

- The PHP extension dir (`/opt/php/...`) is outside the overlayfs
project tree, so `ddtrace.so` must be installed into it on every
Expand Down
60 changes: 0 additions & 60 deletions .gitlab/BENCHMARKS.md

This file was deleted.

42 changes: 26 additions & 16 deletions .gitlab/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
include:
- project: 'DataDog/benchmarking-platform-tools'
file: 'images/templates/gitlab/build-ci-images.template.yml'
- project: 'DataDog/benchmarking-platform-tools'
file: 'images/templates/gitlab/check-slo-breaches.template.yml'
- project: 'DataDog/benchmarking-platform-tools'
Expand Down Expand Up @@ -105,16 +107,28 @@ php-wordpress-parallel-upload-results:
rules: *macrobenchmarks-rules

variables:
BASE_CI_IMAGE: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:dd-trace-php-82-dev
# The Dockerfile to this image is located at:
# https://github.com/DataDog/benchmarking-platform/tree/dd-trace-php
# Microbenchmarks CI image, consumed by the benchmark jobs below. Repin to the
# tag pushed by a `build-benchmark-ci-images` run after changing anything in
# `.gitlab/benchmarks/container/` (see `.gitlab/benchmarks/README.md`).
MICROBENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-php-152770667
# The Dockerfile is located at: .gitlab/benchmarks/container/Dockerfile
# Image build, consumed by the included build-ci-images template. The per-pipeline
# suffix pins each build to a unique tag so a rebuild can't shift what older
# pipelines pulled.
BASE_CI_IMAGE_SUFFIX: dd-trace-php-${CI_PIPELINE_ID}
BASE_CI_IMAGE_CONTAINER_DIR: .gitlab/benchmarks/container
MACROBENCHMARKS_CI_IMAGE: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:php_laravel-realworld
# The Dockerfile to this image is located at:
# https://github.com/DataDog/benchmarking-platform/tree/php/laravel-realworld
DSM_THROUGHPUT_CI_IMAGE: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:dd-trace-php-dsm
# The Dockerfile to this image is located at:
# https://github.com/DataDog/benchmarking-platform/tree/php/data-streams-monitoring

# The template puts this job in the ci-image stage; run it next to the
# benchmarks it builds for instead.
build-benchmark-ci-images:
stage: benchmarks

workflow:
auto_cancel:
on_new_commit: interruptible
Expand Down Expand Up @@ -201,7 +215,7 @@ workflow:
tags: ["runner:apm-k8s-tweaked-metal"]
needs: []
image:
name: $BASE_CI_IMAGE
name: $MICROBENCHMARKS_CI_IMAGE
timeout: 90m
script:
- export ARTIFACTS_DIR="$(pwd)/reports" && (mkdir "${ARTIFACTS_DIR}" || :)
Expand All @@ -219,15 +233,15 @@ workflow:
fi
echo "Tracer-related file changes detected - proceeding with benchmarks"
fi
- git clone --branch dd-trace-php https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/DataDog/benchmarking-platform /platform && cd /platform
- ./steps/capture-hardware-software-info.sh
- export PATH="$PATH:${CI_PROJECT_DIR}/.gitlab/benchmarks/steps"
- capture-hardware-software-info.sh
# Keep submodules at the selected candidate and baseline revisions.
- >-
GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=submodule.recurse GIT_CONFIG_VALUE_0=true
BP_SCENARIO=$SCENARIO bp-runner bp-runner.yml --debug -t
- ./steps/analyze-results.sh
- "./steps/upload-results-to-s3.sh || :"
- "./steps/post-pr-comment.sh || :"
BP_SCENARIO=$SCENARIO bp-runner "${CI_PROJECT_DIR}/.gitlab/benchmarks/bp-runner.yml" --debug -t
- analyze-results.sh
- "upload-results-to-s3.sh || :"
- "post-pr-comment.sh || :"
artifacts:
name: "reports"
paths:
Expand Down Expand Up @@ -336,12 +350,8 @@ check-big-regressions:
else
echo "Reports directory found with content - running regression check"
export ARTIFACTS_DIR="$(pwd)/reports/"
if [[ -n "$CI_JOB_TOKEN" ]]; then
git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/DataDog/".insteadOf "https://github.com/DataDog/"
fi
git clone --branch dd-trace-php https://github.com/DataDog/benchmarking-platform /platform
export PATH="$PATH:/platform/steps"
bp-runner /platform/bp-runner.fail-on-regression.yml --debug
export PATH="$PATH:${CI_PROJECT_DIR}/.gitlab/benchmarks/steps"
bp-runner "${CI_PROJECT_DIR}/.gitlab/benchmarks/bp-runner.fail-on-regression.yml" --debug
fi
variables:
# Gitlab and BP specific env vars. Do not modify.
Expand Down
186 changes: 186 additions & 0 deletions .gitlab/benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# Microbenchmarks

The microbenchmark jobs run the PHP tracer's, AppSec's and the profiler's
benchmark suites inside the Datadog
[Benchmarking Platform](https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/2419261562/Benchmarking+Platform)
and compare the results against a baseline to detect performance regressions
on every PR.

This directory holds everything the microbenchmark jobs need:

- **`container/`** — Dockerfile for the `MICROBENCHMARKS_CI_IMAGE` CI image,
built in-repo via the
[`build-ci-images.template.yml`](https://github.com/DataDog/benchmarking-platform-tools/blob/main/images/templates/gitlab/build-ci-images.template.yml)
include (see [How to rebuild the CI Docker image](#how-to-rebuild-the-ci-docker-image)).
- **`steps/`** — the run, analyze, upload and PR-comment scripts the jobs call
(copied from the former `dd-trace-php` branch of
[benchmarking-platform](https://github.com/DataDog/benchmarking-platform)).
- **`bp-runner.yml`** — [bp-runner](https://github.com/DataDog/benchmarking-platform-tools/tree/main/bp-runner)
experiment definition: starts a local Datadog agent, then runs
`steps/run-benchmarks.sh` on pinned CPUs.
- **`bp-runner.fail-on-regression.yml`** — gate config used by
`check-big-regressions` to fail the pipeline on regressions above its
threshold.

The jobs themselves (`benchmarks-tracer`, `benchmarks-appsec`,
`benchmarks-profiler`, `check-big-regressions`) are defined in
[`.gitlab/benchmarks.yml`](../benchmarks.yml), which runs as a child pipeline
of `package-trigger` (the stage list it validates against is generated by
`.gitlab/generate-package.php`).

Execution flow on each PR:

1. Each benchmark job sets `SCENARIO` (`tracer`, `appsec` or `profiler`),
collects hardware/software info, and runs
`bp-runner .gitlab/benchmarks/bp-runner.yml`.
2. `run-benchmarks.sh` clones the candidate commit and the baseline
(the PR's merge-target branch, at the merge base), runs each checkout's
`benchmark/` suite, and saves the results as `reports/` artifacts.
3. `analyze-results.sh` converts the results with the benchmark analyzer,
`upload-results-to-s3.sh` archives them to S3, and
`upload-results-to-benchmarking-api.sh` pushes them to the Benchmarking
Platform API so results land on the project's trend series.
4. `check-big-regressions` gates the pipeline on regressions above the
threshold in `bp-runner.fail-on-regression.yml`, and `post-pr-comment.sh`
comments the comparison on the PR.

## How to add a new microbenchmark

Where a benchmark lives depends on the scenario it belongs to:

- **tracer / appsec** (`benchmarks-tracer`, `benchmarks-appsec`): PHPBench
suites in [`tests/Benchmarks/`](../../tests/Benchmarks/) —
tracer benchmarks in the default groups, AppSec ones under the
`frameworks` group (`BENCHMARK_EXTRA="--group=frameworks"`).
- **tracer, tea** (`benchmarks-tracer`): C++ Google Benchmark suite in
[`tea/benchmarks/`](../../tea/benchmarks/).
- **profiler** (`benchmarks-profiler`): sirun suites in
[`profiling/benches/`](../../profiling/benches/), run through
[`benchmark/runall.sh`](../../benchmark/runall.sh) with a natively compiled
profiler.

1. Add the benchmark in the matching location, following the existing
patterns there.
2. Run it locally the same way the job does (see
[How to run the suite locally](#how-to-run-the-suite-locally)).
3. Push the branch and let the benchmark job run: new benchmarks are picked
up automatically — the scenarios are discovered from the suites' own
result files, not from a list. On the first run the baseline may not
contain the new benchmark, so it appears as candidate-only in the
comparison.

## How to update an existing microbenchmark

Edit the benchmark where it lives (see above). Keep in mind that the baseline
run executes the *baseline checkout's* copy of the suite, so a benchmark that
was renamed or removed on the candidate is still measured on the baseline;
expect a one-run mismatch on renames. If the benchmark becomes unstable while
you iterate, see
[How to mark a benchmark as known flaky](#how-to-mark-a-benchmark-as-known-flaky).

Changes that only affect CI plumbing (this directory, `.gitlab/benchmarks.yml`)
don't need a benchmark run: the benchmark jobs only auto-run when
tracer-relevant paths change, and can be triggered manually from the pipeline
otherwise.

## How to mark a benchmark as known flaky

Add it to `FLAKY_BENCHMARKS_REGEX` in the `.microbenchmarks` template's
`variables` in [`.gitlab/benchmarks.yml`](../benchmarks.yml). The benchmark
still runs and reports, but doesn't fail performance quality gates
(`check-big-regressions` here, percentage-based; `check-slo-breaches` for the
macrobenchmarks, SLO-based).

- The regex matches anywhere in the scenario name.
- `SpanBench` quarantines every `SpanBench` scenario.
- Anchor with `^...$` to target one scenario.

```yaml
FLAKY_BENCHMARKS_REGEX: "SpanBench|^webserver--laravel-realworld--baseline--none--normal_operation$"
```

Open a ticket to fix or remove it. See
[Flaky Benchmarks Monitoring](https://datadoghq.atlassian.net/wiki/spaces/APMINT/pages/7223313012/Flaky+Benchmarks+Monitoring).

## How to rebuild the CI Docker image

The `MICROBENCHMARKS_CI_IMAGE` used by the microbenchmark jobs is built from
`container/Dockerfile` in this directory. Rebuild and repin it whenever you
change anything in that directory (e.g. bumping PHP, adding system packages,
or updating `sirun`).

1. Edit the relevant file(s) under `.gitlab/benchmarks/container/`. Push the
branch and open a PR.

2. The pipeline includes
[`build-ci-images.template.yml`](https://github.com/DataDog/benchmarking-platform-tools/blob/main/images/templates/gitlab/build-ci-images.template.yml),
which defines a manual `build-benchmark-ci-images` job that builds the
image from `BASE_CI_IMAGE_CONTAINER_DIR` (`.gitlab/benchmarks/container`)
and pushes it as
`registry.ddbuild.io/ci/benchmarking-platform:$BASE_CI_IMAGE_SUFFIX`
(`dd-trace-php-<pipeline id>` — one unique tag per pipeline, so a rebuild
can't shift what older pipelines pulled).

3. Open the pipeline on
[gitlab.ddbuild.io/DataDog/dd-trace-php](https://gitlab.ddbuild.io/DataDog/dd-trace-php)
(the `package-trigger` child pipeline), play the
`build-benchmark-ci-images` job, wait for it to finish, and copy the
resulting image tag from its logs.

4. Repin `MICROBENCHMARKS_CI_IMAGE` in `.gitlab/benchmarks.yml` to that tag:

```yaml
# Built here: <paste build-benchmark-ci-images job URL>
MICROBENCHMARKS_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:dd-trace-php-<NEW_PIPELINE_ID>
```

5. Push the update. The microbenchmarks now run against the rebuilt image.
Verify a green benchmark pipeline before merging.

## How to run the suite locally

The suites themselves live in the tracer repository, so the quick feedback
loop is to run them the way `benchmark/runall.sh` does, without the
Benchmarking Platform wrapper:

- tracer / appsec (PHPBench, see `benchmark/runall.sh`):
```bash
make composer_tests_update # once, to install benchmark dependencies
make benchmarks # tracer PHPBench scenarios
make benchmarks_opcache # the same scenarios under OPCache
make benchmarks_tea # the C++ Google Benchmark suite
# AppSec adds: make install_appsec, then
# BENCHMARK_EXTRA="--group=frameworks" make call_benchmarks
```
- profiler: `SCENARIO=profiler ./benchmark/runall.sh` from the repo root
(sirun drives `profiling/benches/timeline.json` and
`profiling/benches/exceptions.json` after a natively compiled profiler —
see `benchmark/run_with_native_profiler.sh`).

To reproduce a full CI run including the baseline comparison, run the job's
steps from the repository root with the environment the CI job provides
(`SCENARIO`, `UPSTREAM_BRANCH`, `UPSTREAM_COMMIT_SHA`, `UPSTREAM_PROJECT_NAME`,
`ARTIFACTS_DIR`):

```bash
export ARTIFACTS_DIR="$(pwd)/reports"
export PATH="$PATH:$PWD/.gitlab/benchmarks/steps"
capture-hardware-software-info.sh
SCENARIO=tracer BP_SCENARIO=tracer bp-runner .gitlab/benchmarks/bp-runner.yml --debug -t
analyze-results.sh
```

Note that `bp-runner.yml` starts a real Datadog agent (the API key comes from
AWS SSM in CI, set `DD_API_KEY` yourself locally) and pins the benchmark CPUs
(26-47 on the 48-core CI runners), so a faithful local run needs a comparable
machine.

## Other benchmark suites (not in this directory)

- `macrobenchmarks` and the `linux-php-*-parallel` jobs: defined in
`.gitlab/benchmarks.yml` but their steps still live in the
`php/laravel-realworld` branch of
[benchmarking-platform](https://github.com/DataDog/benchmarking-platform)
and in [apm-sdks-benchmarks](https://github.com/DataDog/apm-sdks-benchmarks/tree/main/.gitlab).
- `dsm-throughput`: steps live in the `php/data-streams-monitoring` branch of
benchmarking-platform.
6 changes: 6 additions & 0 deletions .gitlab/benchmarks/bp-runner.fail-on-regression.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
experiments:
- name: Run regression check
steps:
- name: Regression Check
run: fail_on_regression
regression_threshold: 10.0 # percents
Loading
Loading