2021-10-01 14:20:58 +02:00
name : Benchmark
on :
pull_request :
branches : [ '*' ]
2022-07-06 16:03:01 +02:00
paths :
- .github/workflows/benchmark.yml
2021-10-01 14:20:58 +02:00
schedule :
- cron : '0 4 * * 1-5' # Mon-Fri 4AM UTC
2021-10-05 11:16:55 +02:00
workflow_dispatch : {}
2021-10-01 14:20:58 +02:00
concurrency : 'benchmarks' # Ensure only one of this runs at a time
jobs :
run-benchmarks :
name : Clickhouse queries
runs-on : ubuntu-20.04
environment : clickhouse-benchmarks
# Benchmarks are expensive to run so we only run them (periodically) against master branch and for PRs labeled `performance`
2023-11-13 12:29:10 +01:00
if : ${{ github.repository == 'PostHog/posthog' && (github.ref == 'refs/heads/master' || contains(github.event.pull_request.labels.*.name, 'performance')) }}
2021-10-01 14:20:58 +02:00
env :
2022-07-06 16:03:01 +02:00
DATABASE_URL : 'postgres://posthog:posthog@localhost:5432/posthog'
2021-10-01 14:20:58 +02:00
REDIS_URL : 'redis://localhost'
DEBUG : '1'
CLICKHOUSE_DATABASE : posthog
CLICKHOUSE_HOST : ${{ secrets.BENCHMARKS_CLICKHOUSE_HOST }}
CLICKHOUSE_USER : ${{ secrets.BENCHMARKS_CLICKHOUSE_USER }}
CLICKHOUSE_PASSWORD : ${{ secrets.BENCHMARKS_CLICKHOUSE_PASSWORD }}
CLICKHOUSE_SECURE : 'false'
CLICKHOUSE_VERIFY : 'false'
SECRET_KEY : '6b01eee4f945ca25045b5aab440b953461faf08693a9abbf1166dc7c6b9772da' # unsafe - for testing only
2022-01-05 12:11:33 +01:00
BENCHMARK : '1'
2021-10-01 14:20:58 +02:00
steps :
2022-10-26 20:40:00 +02:00
- uses : actions/checkout@v3
2021-10-01 14:20:58 +02:00
with :
# Checkout repo with full history
fetch-depth : 0
- name : Check out PostHog/benchmarks-results repo
2022-10-26 20:40:00 +02:00
uses : actions/checkout@v3
2021-10-01 14:20:58 +02:00
with :
path : ee/benchmarks/results
repository : PostHog/benchmark-results
token : ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
2022-07-06 16:03:01 +02:00
- name : Stop/Start stack with Docker Compose
run : |
2022-11-29 21:50:42 +01:00
docker compose -f docker-compose.dev.yml down
docker compose -f docker-compose.dev.yml up -d
2022-07-06 16:03:01 +02:00
- name : Set up Python
2024-01-02 16:02:29 +01:00
uses : actions/setup-python@v5
2021-10-01 14:20:58 +02:00
with :
2024-06-27 23:16:27 +02:00
python-version : 3.11 .9
2024-01-02 16:02:29 +01:00
cache : 'pip'
cache-dependency-path : '**/requirements*.txt'
2023-02-06 12:36:00 +01:00
token : ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
2021-10-01 14:20:58 +02:00
2024-04-08 11:54:08 +02:00
# uv is a fast pip alternative: https://github.com/astral-sh/uv/
- run : pip install uv
2021-10-01 14:20:58 +02:00
2022-07-06 16:03:01 +02:00
- name : Install SAML (python3-saml) dependencies
shell : bash
run : |
sudo apt-get update
sudo apt-get install libxml2-dev libxmlsec1-dev libxmlsec1-openssl
2021-10-01 14:20:58 +02:00
- name : Install python dependencies
run : |
2024-04-08 11:54:08 +02:00
uv pip install --system -r requirements-dev.txt
uv pip install --system -r requirements.txt
2021-10-01 14:20:58 +02:00
- name : Install asv
2024-04-08 11:54:08 +02:00
run : uv pip install --system asv==0.5.1 virtualenv
2021-10-01 14:20:58 +02:00
- name : Set up PostHog
run : |
2022-01-18 20:32:28 +01:00
python manage.py migrate & wait
2021-10-01 14:20:58 +02:00
python manage.py setup_dev --no-data
- name : Configure benchmarks
run : asv machine --config ee/benchmarks/asv.conf.json --yes --machine ci-benchmarks
- name : Run benchmarks
run : asv run --config ee/benchmarks/asv.conf.json --show-stderr --strict
- name : Compare results
run : |
2021-10-08 09:51:11 +02:00
asv compare $(cat ee/benchmarks/results/last-master-commit) HEAD --config ee/benchmarks/asv.conf.json --factor 1.2 | tee pr_vs_master.txt
asv compare $(cat ee/benchmarks/results/last-master-commit) HEAD --config ee/benchmarks/asv.conf.json --factor 1.2 --only-changed | tee pr_vs_master_changed.txt
2021-10-01 14:20:58 +02:00
- name : Save last benchmarked commit
if : ${{ github.ref == 'refs/heads/master' }}
run : echo "${{ github.sha }}" | tee ee/benchmarks/results/last-master-commit
- name : Generate HTML report of results
if : ${{ github.ref == 'refs/heads/master' }}
run : asv publish --config ee/benchmarks/asv.conf.json
- name : Commit update for benchmark results
if : ${{ github.repository == 'PostHog/posthog' && github.ref == 'refs/heads/master' }}
2024-01-23 14:13:50 +01:00
uses : stefanzweifel/git-auto-commit-action@v5
2021-10-01 14:20:58 +02:00
with :
repository : ee/benchmarks/results
branch : master
commit_message : 'Save benchmark results'
commit_user_name : PostHog Bot
commit_user_email : hey@posthog.com
commit_author : PostHog Bot <hey@posthog.com>
- name : Upload results as artifacts
2022-10-26 20:40:00 +02:00
uses : actions/upload-artifact@v3
2021-10-01 14:20:58 +02:00
with :
name : benchmarks
path : |
pr_vs_master.txt
pr_vs_master_changed.txt
- name : Read benchmark output
if : ${{ github.event_name == 'pull_request' }}
id : pr_vs_master_changed
2024-03-11 17:08:38 +01:00
uses : juliangruber/read-file-action@v1
2021-10-01 14:20:58 +02:00
with :
path : pr_vs_master_changed.txt
- name : Read benchmark output (full)
if : ${{ github.event_name == 'pull_request' }}
id : pr_vs_master
2024-03-11 17:08:38 +01:00
uses : juliangruber/read-file-action@v1
2021-10-01 14:20:58 +02:00
with :
path : pr_vs_master.txt
- name : Find Comment
if : ${{ github.event_name == 'pull_request' }}
2024-01-03 10:12:03 +01:00
uses : peter-evans/find-comment@v2
2021-10-01 14:20:58 +02:00
id : fc
with :
issue-number : ${{ github.event.number }}
comment-author : 'github-actions[bot]'
body-includes : ClickHouse query benchmark results from GitHub Actions
- name : Create or update comment
if : ${{ github.event_name == 'pull_request' }}
2024-01-23 14:13:17 +01:00
uses : peter-evans/create-or-update-comment@v3
2021-10-01 14:20:58 +02:00
with :
comment-id : ${{ steps.fc.outputs.comment-id }}
issue-number : ${{ github.event.number }}
body : |
ClickHouse query benchmark results from GitHub Actions
Lower numbers are good, higher numbers are bad. A ratio less than 1
means a speed up and greater than 1 means a slowdown. Green lines
beginning with `+` are slowdowns (the PR is slower then master or
master is slower than the previous release). Red lines beginning
with `-` are speedups. Blank means no changes.
Significantly changed benchmark results (PR vs master)
```diff
${{ steps.pr_vs_master_changed.outputs.content }}
```
<details>
<summary>Click to view full benchmark results</summary>
```diff
${{ steps.pr_vs_master.outputs.content }}
```
</details>
edit-mode : replace