From dfd19f5256d218a732afa71c5cc306c106da3b07 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Thu, 10 Feb 2022 14:06:54 +0000 Subject: [PATCH 01/50] Benchmarks Nox session improvements. --- noxfile.py | 126 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 105 insertions(+), 21 deletions(-) diff --git a/noxfile.py b/noxfile.py index 8b23948677..8dd9152f8f 100755 --- a/noxfile.py +++ b/noxfile.py @@ -8,6 +8,8 @@ import hashlib import os from pathlib import Path +from tempfile import NamedTemporaryFile +from typing import Literal import nox from nox.logger import logger @@ -291,21 +293,46 @@ def linkcheck(session: nox.sessions.Session): @nox.session(python=PY_VER[-1], venv_backend="conda") @nox.parametrize( - ["ci_mode"], - [True, False], - ids=["ci compare", "full"], + "run_type", + ["overnight", "branch", "custom"], + ids=["overnight", "branch", "custom"], ) -def benchmarks(session: nox.sessions.Session, ci_mode: bool): +def benchmarks(session: nox.sessions.Session, run_type: Literal["overnight", "branch", "custom"]): """ Perform esmf-regrid performance benchmarks (using Airspeed Velocity). + All run types require a single Nox positional argument (e.g. + ``nox --session="foo" .. my_pos_arg``) - detailed in the parameters + section - and can optionally accept a series of further arguments that will + be added to session's ASV command. + Parameters ---------- session: object A `nox.sessions.Session` object. - ci_mode: bool - Run a cut-down selection of benchmarks, comparing the current commit to - the last commit for performance regressions. + run_type: {"overnight", "branch", "custom"} + * ``overnight``: benchmarks all commits between the input **first + commit** to ``HEAD``, comparing each to its parent for performance + shifts. If a commit causes shifts, the output is saved to a file: + ``performance-shifts/``. Designed for checking the + previous 24 hours' commits, typically in a scheduled script. + * ``branch``: Performs the same operations as ``overnight``, but always + on two commits only - ``HEAD``, and ``HEAD``'s merge-base with the + input **base branch**. Output from this run is never saved to a file. + Designed for testing if the active branch's changes cause performance + shifts - anticipating what would be caught by ``overnight`` once + merged. + * ``custom``: run ASV with the input **ASV command type**, without any + preset arguments - must all be supplied by the user. So just like + running ASV manually, with the convenience of re-using the session's + scripted setup steps. + + Examples + -------- + * ``nox --session="benchmarks(overnight)" .. a1b23d4`` + * ``nox --session="benchmarks(branch)" .. upstream/main`` + * ``nox --session="benchmarks(branch)" .. upstream/main --bench=regridding`` + * ``nox --session="benchmarks(custom)" .. continuous a1b23d4 HEAD --quick`` Notes ----- @@ -319,18 +346,75 @@ def benchmarks(session: nox.sessions.Session, ci_mode: bool): # Skip over setup questions for a new machine. session.run("asv", "machine", "--yes") - def asv_exec(*sub_args: str) -> None: - run_args = ["asv", *sub_args] - session.run(*run_args) - - if ci_mode: - # If on a PR: compare to the base (target) branch. - # Else: compare to previous commit. - previous_commit = os.environ.get("PR_BASE_SHA", "HEAD^1") - try: - asv_exec("continuous", "--factor=1.2", previous_commit, "HEAD") - finally: - asv_exec("compare", previous_commit, "HEAD") + # All run types require one Nox posarg. + run_type_arg = { + "overnight": "first commit", + "branch": "base branch", + "custom": "ASV command type" + } + if run_type not in run_type_arg.keys(): + message = f"Unsupported run-type: {run_type}" + raise NotImplementedError(message) + first_arg = session.posargs[0] + if not first_arg: + message = ( + f"Missing mandatory first Nox session posarg: {run_type_arg[run_type]}" + ) + raise ValueError(message) + # Optional extra arguments to be passed down to ASV. + asv_args = session.posargs[1:] + + def asv_compare(*commits): + """Run through a list of commits comparing each one to the next.""" + commits = [commit[:8] for commit in commits] + shifts_dir = Path("performance-shifts") + for i in range(len(commits) - 1): + before = commits[i] + after = commits[i + 1] + asv_command_ = f"asv compare {before} {after} --factor=1.2 --split" + session.run(*asv_command_.split(" ")) + + if run_type == "overnight": + # Record performance shifts. + # Run the command again but limited to only showing performance + # shifts. + shifts = session.run(*asv_command_.split(" "), "--only-changed", silent=True) + if shifts: + # Write the shifts report to a file. + shifts_dir.mkdir(exist_ok=True) + shifts_path = shifts_dir / after + with shifts_path.open("w") as shifts_file: + shifts_file.write(shifts) + + # Common ASV arguments used for both `overnight` and `bench` run_types. + asv_harness = "asv run {posargs} --attribute rounds=4 --interleave-rounds --strict" + + if run_type == "overnight": + first_commit = first_arg + commit_range = f"{first_commit}^^.." + asv_command = asv_harness.format(posargs=commit_range) + session.run(*asv_command.split(" "), *asv_args) + + # git rev-list --first-parent is the command ASV uses. + git_command = f"git rev-list --first-parent {commit_range}" + commit_string = session.run(*git_command.split(" "), silent=True, external=True) + commit_list = commit_string.rstrip().split("\n") + asv_compare(*reversed(commit_list)) + + elif run_type == "branch": + base_branch = first_arg + git_command = f"git merge-base HEAD {base_branch}" + merge_base = session.run(*git_command.split(" "), silent=True, external=True)[:8] + + with NamedTemporaryFile("w") as hashfile: + hashfile.writelines([merge_base, "\n", "HEAD"]) + hashfile.flush() + commit_range = f"HASHFILE:{hashfile.name}" + asv_command = asv_harness.format(posargs=commit_range) + session.run(*asv_command.split(" "), *asv_args) + + asv_compare(merge_base, "HEAD") + else: - # f5ceb808 = first commit supporting nox --install-only . - asv_exec("run", "f5ceb808..HEAD") + asv_command_type = first_arg + session.run("asv", asv_command_type, *asv_args) From 0b640fbd40ab64ed399ac8790b8602ff6d12e862 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Thu, 10 Feb 2022 14:08:18 +0000 Subject: [PATCH 02/50] Benchmarks Nox session improvements. --- noxfile.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/noxfile.py b/noxfile.py index 8dd9152f8f..1b32ecba70 100755 --- a/noxfile.py +++ b/noxfile.py @@ -297,7 +297,10 @@ def linkcheck(session: nox.sessions.Session): ["overnight", "branch", "custom"], ids=["overnight", "branch", "custom"], ) -def benchmarks(session: nox.sessions.Session, run_type: Literal["overnight", "branch", "custom"]): +def benchmarks( + session: nox.sessions.Session, + run_type: Literal["overnight", "branch", "custom"], +): """ Perform esmf-regrid performance benchmarks (using Airspeed Velocity). @@ -350,7 +353,7 @@ def benchmarks(session: nox.sessions.Session, run_type: Literal["overnight", "br run_type_arg = { "overnight": "first commit", "branch": "base branch", - "custom": "ASV command type" + "custom": "ASV command type", } if run_type not in run_type_arg.keys(): message = f"Unsupported run-type: {run_type}" @@ -358,7 +361,8 @@ def benchmarks(session: nox.sessions.Session, run_type: Literal["overnight", "br first_arg = session.posargs[0] if not first_arg: message = ( - f"Missing mandatory first Nox session posarg: {run_type_arg[run_type]}" + f"Missing mandatory first Nox session posarg: " + f"{run_type_arg[run_type]}" ) raise ValueError(message) # Optional extra arguments to be passed down to ASV. @@ -378,7 +382,9 @@ def asv_compare(*commits): # Record performance shifts. # Run the command again but limited to only showing performance # shifts. - shifts = session.run(*asv_command_.split(" "), "--only-changed", silent=True) + shifts = session.run( + *asv_command_.split(" "), "--only-changed", silent=True + ) if shifts: # Write the shifts report to a file. shifts_dir.mkdir(exist_ok=True) @@ -387,7 +393,9 @@ def asv_compare(*commits): shifts_file.write(shifts) # Common ASV arguments used for both `overnight` and `bench` run_types. - asv_harness = "asv run {posargs} --attribute rounds=4 --interleave-rounds --strict" + asv_harness = ( + "asv run {posargs} --attribute rounds=4 --interleave-rounds --strict" + ) if run_type == "overnight": first_commit = first_arg @@ -397,14 +405,18 @@ def asv_compare(*commits): # git rev-list --first-parent is the command ASV uses. git_command = f"git rev-list --first-parent {commit_range}" - commit_string = session.run(*git_command.split(" "), silent=True, external=True) + commit_string = session.run( + *git_command.split(" "), silent=True, external=True + ) commit_list = commit_string.rstrip().split("\n") asv_compare(*reversed(commit_list)) elif run_type == "branch": base_branch = first_arg git_command = f"git merge-base HEAD {base_branch}" - merge_base = session.run(*git_command.split(" "), silent=True, external=True)[:8] + merge_base = session.run( + *git_command.split(" "), silent=True, external=True + )[:8] with NamedTemporaryFile("w") as hashfile: hashfile.writelines([merge_base, "\n", "HEAD"]) From 43fa7261df2c04026e9ca0eeefa2e1ba3b929ad0 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Thu, 10 Feb 2022 23:39:20 +0000 Subject: [PATCH 03/50] GHA overnight benchmark action. --- .github/workflows/benchmark.yml | 51 ++++++++++++++++++++++++--------- noxfile.py | 10 +++++-- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index b489eba036..a12068d514 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -3,8 +3,9 @@ name: benchmark-check on: - # Triggers the workflow on push or pull request events but only for the master branch - pull_request: + # Runs every day at 23:00. + schedule: + - cron: 0 23 * * * jobs: benchmark: @@ -22,12 +23,6 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - - name: Fetch the PR base branch too - run: | - git fetch --depth=1 origin ${{ github.event.pull_request.base.ref }} - git branch _base FETCH_HEAD - echo PR_BASE_SHA=$(git rev-parse _base) >> $GITHUB_ENV - - name: Install Nox run: | pip install nox @@ -62,16 +57,45 @@ jobs: unzip -q iris-test-data.zip mkdir --parents ${GITHUB_WORKSPACE}/${IRIS_TEST_DATA_LOC_PATH} mv iris-test-data-${IRIS_TEST_DATA_VERSION} ${GITHUB_WORKSPACE}/${IRIS_TEST_DATA_PATH} - + - name: Set test data var run: | echo "OVERRIDE_TEST_DATA_REPOSITORY=${GITHUB_WORKSPACE}/${IRIS_TEST_DATA_PATH}/test_data" >> $GITHUB_ENV - - name: Run CI benchmarks + - name: Run overnight benchmarks + run: | + first_commit=$(git log --after="$(date -d "1 day ago" +"%Y-%m-%d") 23:00:00" --pretty=format:"%h" --reverse | head -n 1) + nox --session="benchmarks(overnight)" .. $first_commit + + - name: Create issues for performance shifts run: | - mkdir --parents benchmarks/.asv - set -o pipefail - nox --session="benchmarks(ci compare)" | tee benchmarks/.asv/ci_compare.txt + if [ -d .asv/performance-shifts ] + then + for commit_file in .asv/performance-shifts/* + do + pr_number=$(git log "$commit_file"^! --oneline | grep -o "#[0-9]*" | cut -c 2-) + author=$(gh pr view $pr_number --json author -q '.["author"]["login"]') + issue_title="Performance Shift(s): $commit_file" + issue_body=" + Benchmark comparison has identified performance shifts at commit + $commit_file (#$pr_number). Please review the report below and + take corrective/congratulatory action as appropriate + :slightly_smiling_face: + \n + \n
+ \nPerformance shift report + \n + \n``` + \n$(cat $commit_file) + \n``` + \n + \n
+ \n + \nGenerated by GHA run [`${{github.run_id}}`](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) + " + gh issue create --title $issue_title --body $issue_body --assignee $author --label "Bot" --label "Type: Performance" + done + fi - name: Archive asv results if: ${{ always() }} @@ -80,4 +104,3 @@ jobs: name: asv-report path: | benchmarks/.asv/results - benchmarks/.asv/ci_compare.txt diff --git a/noxfile.py b/noxfile.py index 1b32ecba70..ecd587cdfa 100755 --- a/noxfile.py +++ b/noxfile.py @@ -344,6 +344,10 @@ def benchmarks( version that is also available for ``--session=tests``. """ + # The threshold beyond which shifts are 'notable'. See `asv compare`` docs + # for more. + COMPARE_FACTOR = 1.2 + session.install("asv", "nox") session.cd("benchmarks") # Skip over setup questions for a new machine. @@ -371,11 +375,11 @@ def benchmarks( def asv_compare(*commits): """Run through a list of commits comparing each one to the next.""" commits = [commit[:8] for commit in commits] - shifts_dir = Path("performance-shifts") + shifts_dir = Path(".asv") / "performance-shifts" for i in range(len(commits) - 1): before = commits[i] after = commits[i + 1] - asv_command_ = f"asv compare {before} {after} --factor=1.2 --split" + asv_command_ = f"asv compare {before} {after} --factor={COMPARE_FACTOR} --split" session.run(*asv_command_.split(" ")) if run_type == "overnight": @@ -387,7 +391,7 @@ def asv_compare(*commits): ) if shifts: # Write the shifts report to a file. - shifts_dir.mkdir(exist_ok=True) + shifts_dir.mkdir(exist_ok=True, parents=True) shifts_path = shifts_dir / after with shifts_path.open("w") as shifts_file: shifts_file.write(shifts) From befee3ebbe211027a236bf9d59b8cb397f1f290b Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Thu, 10 Feb 2022 23:45:42 +0000 Subject: [PATCH 04/50] GHA testing. --- .github/workflows/benchmark.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index a12068d514..70e7e15722 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -5,11 +5,10 @@ name: benchmark-check on: # Runs every day at 23:00. schedule: - - cron: 0 23 * * * + - cron: 50 23 * * * jobs: benchmark: - if: "github.repository == 'SciTools/iris'" runs-on: ubuntu-latest env: From 579a3e5f7ad932b4d66677f8b535eed8e7add724 Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Thu, 10 Feb 2022 23:58:50 +0000 Subject: [PATCH 05/50] GHA testing --- .github/workflows/benchmark.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 70e7e15722..d2f8cc93ae 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -3,9 +3,9 @@ name: benchmark-check on: - # Runs every day at 23:00. - schedule: - - cron: 50 23 * * * + push: + branches: + - overnight_benchmarks jobs: benchmark: From 46f4297b4f60f29d05f793b6bad009c2ca553265 Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 00:02:03 +0000 Subject: [PATCH 06/50] Fix benchmark GHA Nox invocation. --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index d2f8cc93ae..48b14c40c0 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -64,7 +64,7 @@ jobs: - name: Run overnight benchmarks run: | first_commit=$(git log --after="$(date -d "1 day ago" +"%Y-%m-%d") 23:00:00" --pretty=format:"%h" --reverse | head -n 1) - nox --session="benchmarks(overnight)" .. $first_commit + nox --session="benchmarks(overnight)" -- $first_commit - name: Create issues for performance shifts run: | From a1064ea28ccf5dac6ff877810405b2366e13329e Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 00:08:02 +0000 Subject: [PATCH 07/50] GHA testing. --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 48b14c40c0..6590d30e95 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -63,7 +63,7 @@ jobs: - name: Run overnight benchmarks run: | - first_commit=$(git log --after="$(date -d "1 day ago" +"%Y-%m-%d") 23:00:00" --pretty=format:"%h" --reverse | head -n 1) + first_commit=$(git log --after="$(date -d "2 days ago" +"%Y-%m-%d") 23:00:00" --pretty=format:"%h" --reverse | head -n 1) nox --session="benchmarks(overnight)" -- $first_commit - name: Create issues for performance shifts From d4609f82e7edc79b8f69355f506f7156290737dd Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 08:33:16 +0000 Subject: [PATCH 08/50] GHA testing. --- .github/workflows/benchmark.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 6590d30e95..cfe31d53ba 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -63,8 +63,8 @@ jobs: - name: Run overnight benchmarks run: | - first_commit=$(git log --after="$(date -d "2 days ago" +"%Y-%m-%d") 23:00:00" --pretty=format:"%h" --reverse | head -n 1) - nox --session="benchmarks(overnight)" -- $first_commit + first_commit=$(git log --after="$(date -d "1 day ago" +"%Y-%m-%d") 23:00:00" --pretty=format:"%h" --reverse | head -n 1) + nox --session="benchmarks(overnight)" -- $first_commit --quick --bench=aux_factory - name: Create issues for performance shifts run: | From c50480b94594a563c7f35fa0769b20400c2b49eb Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 08:34:16 +0000 Subject: [PATCH 09/50] Benchmark GHA fetch entire Git history. --- .github/workflows/benchmark.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index cfe31d53ba..3f30484de4 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -21,6 +21,8 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Install Nox run: | From eb2f2015347da3058b8e2891005819b048f3f7fd Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 08:46:25 +0000 Subject: [PATCH 10/50] GHA testing. --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 3f30484de4..b3a2294312 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -66,7 +66,7 @@ jobs: - name: Run overnight benchmarks run: | first_commit=$(git log --after="$(date -d "1 day ago" +"%Y-%m-%d") 23:00:00" --pretty=format:"%h" --reverse | head -n 1) - nox --session="benchmarks(overnight)" -- $first_commit --quick --bench=aux_factory + nox --session="benchmarks(overnight)" -- $first_commit --quick --bench=aux_factory --no-interleave-rounds - name: Create issues for performance shifts run: | From ac781f3e04cefa3ddca891ac24de4b044c8f0c6d Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 08:48:35 +0000 Subject: [PATCH 11/50] GHA testing. --- lib/iris/aux_factory.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/iris/aux_factory.py b/lib/iris/aux_factory.py index f49de62b3f..87349f16c0 100644 --- a/lib/iris/aux_factory.py +++ b/lib/iris/aux_factory.py @@ -9,6 +9,7 @@ """ from abc import ABCMeta, abstractmethod +from time import sleep import warnings import cf_units @@ -578,6 +579,8 @@ def __init__(self, delta=None, sigma=None, orography=None): The coordinate providing the `orog` term. """ + # Benchmark testing. + sleep(10) # Configure the metadata manager. self._metadata_manager = metadata_manager_factory(CoordMetadata) super().__init__() From 56e13e1aae7ef89e28609c478c0a25dd83eaa907 Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 08:56:56 +0000 Subject: [PATCH 12/50] GHA benchmarks correct directory. --- .github/workflows/benchmark.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index b3a2294312..1c9da3f9c9 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -70,9 +70,9 @@ jobs: - name: Create issues for performance shifts run: | - if [ -d .asv/performance-shifts ] + if [ -d benchmarks/.asv/performance-shifts ] then - for commit_file in .asv/performance-shifts/* + for commit_file in benchmarks/.asv/performance-shifts/* do pr_number=$(git log "$commit_file"^! --oneline | grep -o "#[0-9]*" | cut -c 2-) author=$(gh pr view $pr_number --json author -q '.["author"]["login"]') From 9245cb3a0806a5d75405dfb2b855d6fb6afc02e6 Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 09:05:29 +0000 Subject: [PATCH 13/50] Benchmark GHA authenticate GH CLI. --- .github/workflows/benchmark.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 1c9da3f9c9..e802c77bf1 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -69,6 +69,8 @@ jobs: nox --session="benchmarks(overnight)" -- $first_commit --quick --bench=aux_factory --no-interleave-rounds - name: Create issues for performance shifts + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | if [ -d benchmarks/.asv/performance-shifts ] then @@ -94,7 +96,7 @@ jobs: \n \nGenerated by GHA run [`${{github.run_id}}`](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) " - gh issue create --title $issue_title --body $issue_body --assignee $author --label "Bot" --label "Type: Performance" + gh issue create --title $issue_title --body $issue_body --assignee $author --label "Bot" --label "Type: Performance" --repo $GITHUB_REPOSITORY done fi From 06165e99339caad2ff5e594b863b49f2e8aaaa62 Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 09:06:15 +0000 Subject: [PATCH 14/50] GHA testing. --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index e802c77bf1..06d6e2f84d 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -65,7 +65,7 @@ jobs: - name: Run overnight benchmarks run: | - first_commit=$(git log --after="$(date -d "1 day ago" +"%Y-%m-%d") 23:00:00" --pretty=format:"%h" --reverse | head -n 1) + first_commit=c50480b94594a563c7f35fa0769b20400c2b49eb nox --session="benchmarks(overnight)" -- $first_commit --quick --bench=aux_factory --no-interleave-rounds - name: Create issues for performance shifts From 3b4003a67965876a7406ca9413e58b1a479981d8 Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 09:12:26 +0000 Subject: [PATCH 15/50] GHA testing. --- lib/iris/aux_factory.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/iris/aux_factory.py b/lib/iris/aux_factory.py index 87349f16c0..f49de62b3f 100644 --- a/lib/iris/aux_factory.py +++ b/lib/iris/aux_factory.py @@ -9,7 +9,6 @@ """ from abc import ABCMeta, abstractmethod -from time import sleep import warnings import cf_units @@ -579,8 +578,6 @@ def __init__(self, delta=None, sigma=None, orography=None): The coordinate providing the `orog` term. """ - # Benchmark testing. - sleep(10) # Configure the metadata manager. self._metadata_manager = metadata_manager_factory(CoordMetadata) super().__init__() From f4bd66e6811e351e15891b0102038d20545f607c Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 09:13:33 +0000 Subject: [PATCH 16/50] Benchmark GHA cd into performance-shifts. --- .github/workflows/benchmark.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 06d6e2f84d..3857a667a5 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -74,7 +74,8 @@ jobs: run: | if [ -d benchmarks/.asv/performance-shifts ] then - for commit_file in benchmarks/.asv/performance-shifts/* + cd benchmarks/.asv/performance-shifts + for commit_file in .* do pr_number=$(git log "$commit_file"^! --oneline | grep -o "#[0-9]*" | cut -c 2-) author=$(gh pr view $pr_number --json author -q '.["author"]["login"]') From 5cd35c86efce948b083b44bb7761f292c008a825 Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 09:50:11 +0000 Subject: [PATCH 17/50] GHA testing. --- .github/workflows/benchmark.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 3857a667a5..df34fa082a 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -77,8 +77,8 @@ jobs: cd benchmarks/.asv/performance-shifts for commit_file in .* do - pr_number=$(git log "$commit_file"^! --oneline | grep -o "#[0-9]*" | cut -c 2-) - author=$(gh pr view $pr_number --json author -q '.["author"]["login"]') + pr_number=$(git log 8404ff64^! --oneline | grep -o "#[0-9]*" | cut -c 2-) + author=$(gh pr view $pr_number --json author -q '.["author"]["login"]' --repo SciTools/iris) issue_title="Performance Shift(s): $commit_file" issue_body=" Benchmark comparison has identified performance shifts at commit From 51fd2010e6753cb08ac181a866b92780c9ff29e0 Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 10:00:14 +0000 Subject: [PATCH 18/50] Benchmarks GHA correct file iteration. --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index df34fa082a..eddd2b18c4 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -75,7 +75,7 @@ jobs: if [ -d benchmarks/.asv/performance-shifts ] then cd benchmarks/.asv/performance-shifts - for commit_file in .* + for commit_file in * do pr_number=$(git log 8404ff64^! --oneline | grep -o "#[0-9]*" | cut -c 2-) author=$(gh pr view $pr_number --json author -q '.["author"]["login"]' --repo SciTools/iris) From a22da0df54c947b027858a78af27fec285226c86 Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 10:13:59 +0000 Subject: [PATCH 19/50] GHA testing. --- .github/workflows/benchmark.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index eddd2b18c4..7349b0a694 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -66,7 +66,7 @@ jobs: - name: Run overnight benchmarks run: | first_commit=c50480b94594a563c7f35fa0769b20400c2b49eb - nox --session="benchmarks(overnight)" -- $first_commit --quick --bench=aux_factory --no-interleave-rounds + nox --session="benchmarks(overnight)" -- $first_commit --quick --bench=aux_factory --no-interleave-rounds --steps 3 - name: Create issues for performance shifts env: @@ -78,7 +78,7 @@ jobs: for commit_file in * do pr_number=$(git log 8404ff64^! --oneline | grep -o "#[0-9]*" | cut -c 2-) - author=$(gh pr view $pr_number --json author -q '.["author"]["login"]' --repo SciTools/iris) + author=trexfeathers issue_title="Performance Shift(s): $commit_file" issue_body=" Benchmark comparison has identified performance shifts at commit From 98472b51cfaff626e496435b5f9bd30740eaf8ff Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 10:18:00 +0000 Subject: [PATCH 20/50] GHA testing. --- .github/workflows/benchmark.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 7349b0a694..73ea4b10c4 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -65,8 +65,8 @@ jobs: - name: Run overnight benchmarks run: | - first_commit=c50480b94594a563c7f35fa0769b20400c2b49eb - nox --session="benchmarks(overnight)" -- $first_commit --quick --bench=aux_factory --no-interleave-rounds --steps 3 + first_commit=06165e99339caad2ff5e594b863b49f2e8aaaa62 + nox --session="benchmarks(overnight)" -- $first_commit --quick --bench=aux_factory --no-interleave-rounds - name: Create issues for performance shifts env: From aee75074a55588598bc5f41ef74d706232cfa300 Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 10:23:37 +0000 Subject: [PATCH 21/50] GHA testing. --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 73ea4b10c4..b24784436d 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -75,6 +75,7 @@ jobs: if [ -d benchmarks/.asv/performance-shifts ] then cd benchmarks/.asv/performance-shifts + ls * for commit_file in * do pr_number=$(git log 8404ff64^! --oneline | grep -o "#[0-9]*" | cut -c 2-) @@ -97,7 +98,6 @@ jobs: \n \nGenerated by GHA run [`${{github.run_id}}`](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) " - gh issue create --title $issue_title --body $issue_body --assignee $author --label "Bot" --label "Type: Performance" --repo $GITHUB_REPOSITORY done fi From 906d5f15a4dcf908c80ff882e62cad4e4f3f93ff Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 10:29:49 +0000 Subject: [PATCH 22/50] GHA testing. --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index b24784436d..76ff0a621e 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -75,7 +75,6 @@ jobs: if [ -d benchmarks/.asv/performance-shifts ] then cd benchmarks/.asv/performance-shifts - ls * for commit_file in * do pr_number=$(git log 8404ff64^! --oneline | grep -o "#[0-9]*" | cut -c 2-) @@ -98,6 +97,7 @@ jobs: \n \nGenerated by GHA run [`${{github.run_id}}`](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) " + echo -e $issue_body done fi From c14f748ff85b6a7e4797c01a11739c0fdebe0c26 Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 10:38:02 +0000 Subject: [PATCH 23/50] GHA testing. --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 76ff0a621e..149bfb9385 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -79,7 +79,7 @@ jobs: do pr_number=$(git log 8404ff64^! --oneline | grep -o "#[0-9]*" | cut -c 2-) author=trexfeathers - issue_title="Performance Shift(s): $commit_file" + issue_title="Performance Shift(s): $(echo $commit_file)" issue_body=" Benchmark comparison has identified performance shifts at commit $commit_file (#$pr_number). Please review the report below and From d695484406803f3ca2c2163859ccba7b930377c8 Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 10:40:45 +0000 Subject: [PATCH 24/50] GHA testing. --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 149bfb9385..e4cddc14b4 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -82,7 +82,7 @@ jobs: issue_title="Performance Shift(s): $(echo $commit_file)" issue_body=" Benchmark comparison has identified performance shifts at commit - $commit_file (#$pr_number). Please review the report below and + $(echo $commit_file) (#$pr_number). Please review the report below and take corrective/congratulatory action as appropriate :slightly_smiling_face: \n From 616f4f512a9f71e290da7dd83b3b26cbceeb410e Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 10:54:31 +0000 Subject: [PATCH 25/50] GHA testing. --- .github/workflows/benchmark.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index e4cddc14b4..4f587bf6fc 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -89,9 +89,9 @@ jobs: \n
\nPerformance shift report \n - \n``` + \n\`\`\` \n$(cat $commit_file) - \n``` + \n\`\`\` \n \n
\n From ed28ffcc536db8bcbe3cb3449c5af9df0e35c9ca Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 11:42:52 +0000 Subject: [PATCH 26/50] GHA benchmark escape backticks. --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 4f587bf6fc..a943835679 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -95,7 +95,7 @@ jobs: \n \n \n - \nGenerated by GHA run [`${{github.run_id}}`](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) + \nGenerated by GHA run [\`${{github.run_id}}\`](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) " echo -e $issue_body done From 5dc7b707c58367761430d2eedbc3524beda142b5 Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 11:57:06 +0000 Subject: [PATCH 27/50] Benchmark GHA restore behaviour after testing. --- .github/workflows/benchmark.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index a943835679..c761064a89 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -78,11 +78,11 @@ jobs: for commit_file in * do pr_number=$(git log 8404ff64^! --oneline | grep -o "#[0-9]*" | cut -c 2-) - author=trexfeathers - issue_title="Performance Shift(s): $(echo $commit_file)" - issue_body=" + assignee=$(gh pr view $pr_number --json author -q '.["author"]["login"]' --repo SciTools/iris) + title="Performance Shift(s): $commit_file" + body=" Benchmark comparison has identified performance shifts at commit - $(echo $commit_file) (#$pr_number). Please review the report below and + $commit_file (#$pr_number). Please review the report below and take corrective/congratulatory action as appropriate :slightly_smiling_face: \n @@ -97,7 +97,7 @@ jobs: \n \nGenerated by GHA run [\`${{github.run_id}}\`](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) " - echo -e $issue_body + gh issue create --title $title --body $body --assignee $assignee --label "Bot" --label "Type: Performance" --repo $GITHUB_REPOSITORY done fi From f18673a1f413b26f297490f8a2e767d5b091c26e Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 12:05:08 +0000 Subject: [PATCH 28/50] Benchmark GHA correct string wrapping. --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index c761064a89..5fb51b1a7b 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -97,7 +97,7 @@ jobs: \n \nGenerated by GHA run [\`${{github.run_id}}\`](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) " - gh issue create --title $title --body $body --assignee $assignee --label "Bot" --label "Type: Performance" --repo $GITHUB_REPOSITORY + gh issue create --title "$title" --body "$body" --assignee $assignee --label "Bot" --label "Type: Performance" --repo $GITHUB_REPOSITORY done fi From 3104a3c2ef5699b149ddd40c0074dcd7af3f8b68 Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 12:26:16 +0000 Subject: [PATCH 29/50] Benchmark GHA better string formatting. --- .github/workflows/benchmark.yml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 5fb51b1a7b..f6b2ae4e39 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -81,21 +81,21 @@ jobs: assignee=$(gh pr view $pr_number --json author -q '.["author"]["login"]' --repo SciTools/iris) title="Performance Shift(s): $commit_file" body=" - Benchmark comparison has identified performance shifts at commit - $commit_file (#$pr_number). Please review the report below and - take corrective/congratulatory action as appropriate - :slightly_smiling_face: - \n - \n
- \nPerformance shift report - \n - \n\`\`\` - \n$(cat $commit_file) - \n\`\`\` - \n - \n
- \n - \nGenerated by GHA run [\`${{github.run_id}}\`](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) + Benchmark comparison has identified performance shifts at commit + $commit_file (#$pr_number). Please review the report below and + take corrective/congratulatory action as appropriate + :slightly_smiling_face: + +
+ Performance shift report + + \`\`\` + $(cat $commit_file) + \`\`\` + +
+ + Generated by GHA run [\`${{github.run_id}}\`](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) " gh issue create --title "$title" --body "$body" --assignee $assignee --label "Bot" --label "Type: Performance" --repo $GITHUB_REPOSITORY done From b631eededfd701db8e35fd29aa551646c5e16d5f Mon Sep 17 00:00:00 2001 From: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> Date: Fri, 11 Feb 2022 12:35:17 +0000 Subject: [PATCH 30/50] GHA benchmark more issue formatting. --- .github/workflows/benchmark.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index f6b2ae4e39..19a2ac5635 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -79,11 +79,11 @@ jobs: do pr_number=$(git log 8404ff64^! --oneline | grep -o "#[0-9]*" | cut -c 2-) assignee=$(gh pr view $pr_number --json author -q '.["author"]["login"]' --repo SciTools/iris) - title="Performance Shift(s): $commit_file" + title="Performance Shift(s): \`$commit_file\`" body=" - Benchmark comparison has identified performance shifts at commit - $commit_file (#$pr_number). Please review the report below and - take corrective/congratulatory action as appropriate + Benchmark comparison has identified performance shifts at commit\ + $commit_file (#$pr_number). Please review the report below and\ + take corrective/congratulatory action as appropriate\ :slightly_smiling_face:
From 8683bad2b48affc55f7c326fff6d263e1971f3b2 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Fri, 11 Feb 2022 13:13:38 +0000 Subject: [PATCH 31/50] Benchmark GHA restore correct settings after testing. --- .github/workflows/benchmark.yml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 19a2ac5635..8ba856f0e0 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -3,12 +3,13 @@ name: benchmark-check on: - push: - branches: - - overnight_benchmarks + schedule: + # Runs every day at 23:00. + - cron: 0 23 * * * jobs: benchmark: + if: "github.repository == 'SciTools/iris'" runs-on: ubuntu-latest env: @@ -65,8 +66,8 @@ jobs: - name: Run overnight benchmarks run: | - first_commit=06165e99339caad2ff5e594b863b49f2e8aaaa62 - nox --session="benchmarks(overnight)" -- $first_commit --quick --bench=aux_factory --no-interleave-rounds + first_commit=$(git log --after="$(date -d "1 day ago" +"%Y-%m-%d") 23:00:00" --pretty=format:"%h" --reverse | head -n 1) + nox --session="benchmarks(overnight)" .. $first_commit - name: Create issues for performance shifts env: @@ -77,24 +78,24 @@ jobs: cd benchmarks/.asv/performance-shifts for commit_file in * do - pr_number=$(git log 8404ff64^! --oneline | grep -o "#[0-9]*" | cut -c 2-) - assignee=$(gh pr view $pr_number --json author -q '.["author"]["login"]' --repo SciTools/iris) + pr_number=$(git log "$commit_file"^! --oneline | grep -o "#[0-9]*" | cut -c 2-) + assignee=$(gh pr view $pr_number --json author -q '.["author"]["login"]' --repo $GITHUB_REPOSITORY) title="Performance Shift(s): \`$commit_file\`" body=" Benchmark comparison has identified performance shifts at commit\ $commit_file (#$pr_number). Please review the report below and\ take corrective/congratulatory action as appropriate\ :slightly_smiling_face: - +
Performance shift report - + \`\`\` $(cat $commit_file) \`\`\` - +
- + Generated by GHA run [\`${{github.run_id}}\`](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) " gh issue create --title "$title" --body "$body" --assignee $assignee --label "Bot" --label "Type: Performance" --repo $GITHUB_REPOSITORY From b82b84601c7c59a837156c0f26c9bf1577231048 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Fri, 11 Feb 2022 13:14:58 +0000 Subject: [PATCH 32/50] Benchmark GHA minor improvements. --- .github/workflows/benchmark.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 8ba856f0e0..b4c2063156 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -66,7 +66,7 @@ jobs: - name: Run overnight benchmarks run: | - first_commit=$(git log --after="$(date -d "1 day ago" +"%Y-%m-%d") 23:00:00" --pretty=format:"%h" --reverse | head -n 1) + first_commit=$(git log --after="$(date -d "1 day ago" +"%Y-%m-%d") 23:00:00" --pretty=format:"%h" | tail -n 1) nox --session="benchmarks(overnight)" .. $first_commit - name: Create issues for performance shifts @@ -82,9 +82,9 @@ jobs: assignee=$(gh pr view $pr_number --json author -q '.["author"]["login"]' --repo $GITHUB_REPOSITORY) title="Performance Shift(s): \`$commit_file\`" body=" - Benchmark comparison has identified performance shifts at commit\ - $commit_file (#$pr_number). Please review the report below and\ - take corrective/congratulatory action as appropriate\ + Benchmark comparison has identified performance shifts at commit \ + $commit_file (#$pr_number). Please review the report below and \ + take corrective/congratulatory action as appropriate \ :slightly_smiling_face:
From f35f15a42750375a9f5aaf5cdf5a704a2347ff04 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Fri, 11 Feb 2022 13:17:42 +0000 Subject: [PATCH 33/50] Nox correct posargs syntax. --- .github/workflows/benchmark.yml | 2 +- noxfile.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index b4c2063156..935686befb 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -67,7 +67,7 @@ jobs: - name: Run overnight benchmarks run: | first_commit=$(git log --after="$(date -d "1 day ago" +"%Y-%m-%d") 23:00:00" --pretty=format:"%h" | tail -n 1) - nox --session="benchmarks(overnight)" .. $first_commit + nox --session="benchmarks(overnight)" -- $first_commit - name: Create issues for performance shifts env: diff --git a/noxfile.py b/noxfile.py index ecd587cdfa..b8d46a7e95 100755 --- a/noxfile.py +++ b/noxfile.py @@ -332,10 +332,10 @@ def benchmarks( Examples -------- - * ``nox --session="benchmarks(overnight)" .. a1b23d4`` - * ``nox --session="benchmarks(branch)" .. upstream/main`` - * ``nox --session="benchmarks(branch)" .. upstream/main --bench=regridding`` - * ``nox --session="benchmarks(custom)" .. continuous a1b23d4 HEAD --quick`` + * ``nox --session="benchmarks(overnight)" -- a1b23d4`` + * ``nox --session="benchmarks(branch)" -- upstream/main`` + * ``nox --session="benchmarks(branch)" -- upstream/main --bench=regridding`` + * ``nox --session="benchmarks(custom)" -- continuous a1b23d4 HEAD --quick`` Notes ----- From 807c35c0518b1297179da71aec4d0d2bd0307730 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Fri, 11 Feb 2022 13:19:06 +0000 Subject: [PATCH 34/50] Remove Nox benchmarks session outdated note about environments. --- noxfile.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/noxfile.py b/noxfile.py index b8d46a7e95..eeeca706dc 100755 --- a/noxfile.py +++ b/noxfile.py @@ -337,12 +337,6 @@ def benchmarks( * ``nox --session="benchmarks(branch)" -- upstream/main --bench=regridding`` * ``nox --session="benchmarks(custom)" -- continuous a1b23d4 HEAD --quick`` - Notes - ----- - ASV is set up to use ``nox --session=tests --install-only`` to prepare - the benchmarking environment. This session environment must use a Python - version that is also available for ``--session=tests``. - """ # The threshold beyond which shifts are 'notable'. See `asv compare`` docs # for more. From 4d856f9af3fc3fc1da16127c1a8786c2766a2438 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Fri, 11 Feb 2022 13:20:17 +0000 Subject: [PATCH 35/50] Nox correct posargs syntax. --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index eeeca706dc..85a98cd2f8 100755 --- a/noxfile.py +++ b/noxfile.py @@ -305,7 +305,7 @@ def benchmarks( Perform esmf-regrid performance benchmarks (using Airspeed Velocity). All run types require a single Nox positional argument (e.g. - ``nox --session="foo" .. my_pos_arg``) - detailed in the parameters + ``nox --session="foo" -- my_pos_arg``) - detailed in the parameters section - and can optionally accept a series of further arguments that will be added to session's ASV command. From 54cee4a06c0a10ec3d78b919ceb4470345798c41 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Fri, 11 Feb 2022 15:18:12 +0000 Subject: [PATCH 36/50] Benchmarks README. --- benchmarks/README.md | 70 ++++++++++++++++++++++++++++++++++++++++++++ noxfile.py | 3 +- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 benchmarks/README.md diff --git a/benchmarks/README.md b/benchmarks/README.md new file mode 100644 index 0000000000..84538463bc --- /dev/null +++ b/benchmarks/README.md @@ -0,0 +1,70 @@ +[//]: # (the final pieces of this setup are still falling into place, so have + included several TODO's) + +# Iris Performance Benchmarking + +Iris uses an [Airspeed Velocity](https://github.com/airspeed-velocity/asv) +(ASV) setup to benchmark performance. This is primarily designed to check for +performance shifts between commits using statistical analysis, but can also +be easily repurposed for manual comparative and scalability analyses. + +The benchmarks are automatically run overnight +[by a GitHub Action](../.github/workflows/benchmark.yml), with any notable +shifts in performance being flagged in a new GitHub issue. + +## Running benchmarks + +`asv ...` commands must be run from this directory. You will need to have ASV +installed, as well as Nox (see +[Benchmark environments](#benchmark-environments)). + +[Iris' noxfile](../noxfile.py) includes a `benchmarks` session that provides +conveniences for setting up, and even replicating the automated overnight run +locally. See the session docstring for detail. + +[//]: # (TODO: ### Environment variables section) + +## Writing benchmarks + +[//]: # (TODO: ### Data generation section) + +[See the ASV docs](https://asv.readthedocs.io/) for full detail. + +### ASV re-run behaviour + +Note that ASV re-runs a benchmark multiple times between its `setup()` routine. +This is a problem for benchmarking certain Iris operations such as data +realisation, since the data will no longer be lazy after the first run. +Consider writing extra steps to restore objects' original state _within_ the +benchmark itself. + +If adding steps to the benchmark will skew the result too much then re-running +can be disabled by setting an attribute on the benchmark: `number = 1`. To +maintain result accuracy this should be accompanied by increasing the number of +repeats _between_ `setup()` calls using the `repeat` attribute. +`warmup_time = 0` is also advisable since ASV performs independent re-runs to +estimate run-time, and these will still be subject to the original problem. + +### Scaling / non-Scaling Performance Differences + +When comparing performance between commits/file-type/whatever it can be helpful +to know if the differences exist in scaling or non-scaling parts of the Iris +functionality in question. This can be done using a size parameter, setting +one value to be as small as possible (e.g. a scalar `Cube`), and the other to +be significantly larger (e.g. a 1000x1000 `Cube`). Performance differences +might only be seen for the larger value, or the smaller, or both, getting you +closer to the root cause. + +## Benchmark environments + +We have disabled ASV's standard environment management, instead using an +environment built using the same Nox scripts as Iris' test environments. This +is done using ASV's plugin architecture - see +[asv_delegated_conda.py](asv_delegated_conda.py) and the extra config items in +[asv.conf.json](asv.conf.json). + +(ASV is written to control the environment(s) that benchmarks are run in - +minimising external factors and also allowing it to compare between a matrix +of dependencies (each in a separate environment). We have chosen to sacrifice +these features in favour of testing each commit with its intended dependencies, +controlled by Nox + lock-files). diff --git a/noxfile.py b/noxfile.py index 85a98cd2f8..fe998e464a 100755 --- a/noxfile.py +++ b/noxfile.py @@ -302,7 +302,7 @@ def benchmarks( run_type: Literal["overnight", "branch", "custom"], ): """ - Perform esmf-regrid performance benchmarks (using Airspeed Velocity). + Perform Iris performance benchmarks (using Airspeed Velocity). All run types require a single Nox positional argument (e.g. ``nox --session="foo" -- my_pos_arg``) - detailed in the parameters @@ -334,6 +334,7 @@ def benchmarks( -------- * ``nox --session="benchmarks(overnight)" -- a1b23d4`` * ``nox --session="benchmarks(branch)" -- upstream/main`` + * ``nox --session="benchmarks(branch)" -- upstream/mesh-data-model`` * ``nox --session="benchmarks(branch)" -- upstream/main --bench=regridding`` * ``nox --session="benchmarks(custom)" -- continuous a1b23d4 HEAD --quick`` From 3861678de290175dd20e0f4ff6849abd68502229 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Fri, 11 Feb 2022 15:33:57 +0000 Subject: [PATCH 37/50] Nox benchmarks session note about accuracy and runtime. --- noxfile.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/noxfile.py b/noxfile.py index fe998e464a..48f4218e5e 100755 --- a/noxfile.py +++ b/noxfile.py @@ -325,6 +325,8 @@ def benchmarks( Designed for testing if the active branch's changes cause performance shifts - anticipating what would be caught by ``overnight`` once merged. + **For maximum accuracy, avoid using the machine that is running this + session. Run time could be >1 hour for the full benchmark suite.** * ``custom``: run ASV with the input **ASV command type**, without any preset arguments - must all be supplied by the user. So just like running ASV manually, with the convenience of re-using the session's From 340b97561193fe5ba2d3805b9392ce688ef87cfd Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Fri, 11 Feb 2022 16:07:09 +0000 Subject: [PATCH 38/50] Benchmarks Nox improved posargs handling. --- noxfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noxfile.py b/noxfile.py index 48f4218e5e..c49aba8bc0 100755 --- a/noxfile.py +++ b/noxfile.py @@ -359,13 +359,13 @@ def benchmarks( if run_type not in run_type_arg.keys(): message = f"Unsupported run-type: {run_type}" raise NotImplementedError(message) - first_arg = session.posargs[0] - if not first_arg: + if not session.posargs: message = ( f"Missing mandatory first Nox session posarg: " f"{run_type_arg[run_type]}" ) raise ValueError(message) + first_arg = session.posargs[0] # Optional extra arguments to be passed down to ASV. asv_args = session.posargs[1:] From 41fac3e6a768658e532c1fe412593c92684cbfae Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Mon, 14 Feb 2022 10:51:59 +0000 Subject: [PATCH 39/50] Benchmark GHA cope with there being no commits since yesterday. --- .github/workflows/benchmark.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 935686befb..5e3cd38b9f 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -67,7 +67,10 @@ jobs: - name: Run overnight benchmarks run: | first_commit=$(git log --after="$(date -d "1 day ago" +"%Y-%m-%d") 23:00:00" --pretty=format:"%h" | tail -n 1) - nox --session="benchmarks(overnight)" -- $first_commit + if [ "$first_commit" != "" ] + then + nox --session="benchmarks(overnight)" -- $first_commit + fi - name: Create issues for performance shifts env: From 759e82a68c3b8e538e860b79ff1ad63feb5dcdcf Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Mon, 14 Feb 2022 20:38:36 +0000 Subject: [PATCH 40/50] Update to benchmarks README. --- benchmarks/README.md | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/benchmarks/README.md b/benchmarks/README.md index 84538463bc..a7cba3191f 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -1,6 +1,3 @@ -[//]: # (the final pieces of this setup are still falling into place, so have - included several TODO's) - # Iris Performance Benchmarking Iris uses an [Airspeed Velocity](https://github.com/airspeed-velocity/asv) @@ -15,21 +12,34 @@ shifts in performance being flagged in a new GitHub issue. ## Running benchmarks `asv ...` commands must be run from this directory. You will need to have ASV -installed, as well as Nox (see +installed, as well as Nox (see [Benchmark environments](#benchmark-environments)). [Iris' noxfile](../noxfile.py) includes a `benchmarks` session that provides -conveniences for setting up, and even replicating the automated overnight run -locally. See the session docstring for detail. +conveniences for setting up before benchmarking, and can also replicate the +automated overnight run locally. See the session docstring for detail. -[//]: # (TODO: ### Environment variables section) +### Environment variables -## Writing benchmarks +* ``DATA_GEN_PYTHON`` - required - path to a Python executable that can be +used to generate benchmark test objects/files; see +[Data generation](#data-generation). The Nox session sets this automatically, +but will defer to any value already set in the shell. +* ``BENCHMARK_DATA`` - optional - path to a directory where test files used by +the benchmarks are saved and loaded. Defaults to ``/benchmarks/.data/`` +if not set. -[//]: # (TODO: ### Data generation section) +## Writing benchmarks [See the ASV docs](https://asv.readthedocs.io/) for full detail. +### Data generation +**Important:** be sure not to use the benchmarking environment to generate any +test objects/files, as this environment changes with each commit being +benchmarked, creating inconsistent benchmark 'conditions'. The +[generate_data](./benchmarks/generate_data/__init__.py) module offers a +solution; read more detail there. + ### ASV re-run behaviour Note that ASV re-runs a benchmark multiple times between its `setup()` routine. From 339ce63748db8946802131173ae44383b17ff646 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Mon, 14 Feb 2022 20:46:57 +0000 Subject: [PATCH 41/50] Minor noxfile docstring correction. --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 379c28b1bd..3daedecc56 100755 --- a/noxfile.py +++ b/noxfile.py @@ -317,7 +317,7 @@ def benchmarks( * ``overnight``: benchmarks all commits between the input **first commit** to ``HEAD``, comparing each to its parent for performance shifts. If a commit causes shifts, the output is saved to a file: - ``performance-shifts/``. Designed for checking the + ``.asv/performance-shifts/``. Designed for checking the previous 24 hours' commits, typically in a scheduled script. * ``branch``: Performs the same operations as ``overnight``, but always on two commits only - ``HEAD``, and ``HEAD``'s merge-base with the From 74b5de55ec2854fe4352866e9ca000d5a0d8bf39 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Mon, 14 Feb 2022 20:55:40 +0000 Subject: [PATCH 42/50] Remove need for Nox benchmarks session to use Conda venv. --- noxfile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index 3daedecc56..07b737f832 100755 --- a/noxfile.py +++ b/noxfile.py @@ -291,7 +291,7 @@ def linkcheck(session: nox.sessions.Session): ) -@nox.session(python=PY_VER, venv_backend="conda") +@nox.session @nox.parametrize( "run_type", ["overnight", "branch", "custom"], @@ -358,12 +358,12 @@ def benchmarks( "nox", "--session=tests", "--install-only", - f"--python={session.python}", + f"--python={_PY_VERSION_LATEST}", ) # Find the environment built above, set it to be the data generation # environment. data_gen_python = next( - Path(".nox").rglob(f"tests*/bin/python{session.python}") + Path(".nox").rglob(f"tests*/bin/python{_PY_VERSION_LATEST}") ).resolve() session.env[data_gen_var] = data_gen_python From d0fce157b1c974a5de0dfeffb73cd716c6a00f17 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Tue, 15 Feb 2022 16:22:41 +0000 Subject: [PATCH 43/50] Benchmark GHA get the FINAL PR from the commit string. --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 69579d60bf..275dd98a2d 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -79,7 +79,7 @@ jobs: cd benchmarks/.asv/performance-shifts for commit_file in * do - pr_number=$(git log "$commit_file"^! --oneline | grep -o "#[0-9]*" | cut -c 2-) + pr_number=$(git log "$commit_file"^! --oneline | grep -o "#[0-9]*" | tail -1 | cut -c 2-) assignee=$(gh pr view $pr_number --json author -q '.["author"]["login"]' --repo $GITHUB_REPOSITORY) title="Performance Shift(s): \`$commit_file\`" body=" From a017b830c4432ff5d1635804f858bf25ea63ecdd Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Wed, 16 Feb 2022 11:24:27 +0000 Subject: [PATCH 44/50] ASV show-stderr in Nox benchmark session. --- noxfile.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index 07b737f832..07ef356079 100755 --- a/noxfile.py +++ b/noxfile.py @@ -435,9 +435,7 @@ def asv_compare(*commits): shifts_file.write(shifts) # Common ASV arguments used for both `overnight` and `bench` run_types. - asv_harness = ( - "asv run {posargs} --attribute rounds=4 --interleave-rounds --strict" - ) + asv_harness = "asv run {posargs} --attribute rounds=4 --interleave-rounds --strict --show-stderr" if run_type == "overnight": first_commit = first_arg From 0a3fb738c454636d1cea3c54c0a60584bb958032 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Wed, 16 Feb 2022 11:24:58 +0000 Subject: [PATCH 45/50] String quote benchmark GHA CRON. --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 275dd98a2d..2cd5d539f9 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -5,7 +5,7 @@ name: benchmark-check on: schedule: # Runs every day at 23:00. - - cron: 0 23 * * * + - cron: "0 23 * * *" jobs: benchmark: From 08ec07ffef883cf0f5840a92438ce9a693662672 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Wed, 16 Feb 2022 16:55:16 +0000 Subject: [PATCH 46/50] Benchmark GHA more sensible title comment. --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 2cd5d539f9..d4c01af48a 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -1,4 +1,4 @@ -# This is a basic workflow to help you get started with Actions +# Use ASV to check for performance regressions in the last 24 hours' commits. name: benchmark-check From b1fd50560a9eded3438aca4dce266bd6acc19dd2 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Wed, 16 Feb 2022 16:57:33 +0000 Subject: [PATCH 47/50] Benchmark Nox asv_command_type > asv_subcommand. --- noxfile.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index 07ef356079..2662aec561 100755 --- a/noxfile.py +++ b/noxfile.py @@ -327,7 +327,7 @@ def benchmarks( merged. **For maximum accuracy, avoid using the machine that is running this session. Run time could be >1 hour for the full benchmark suite.** - * ``custom``: run ASV with the input **ASV command type**, without any + * ``custom``: run ASV with the input **ASV sub-command**, without any preset arguments - must all be supplied by the user. So just like running ASV manually, with the convenience of re-using the session's scripted setup steps. @@ -395,7 +395,7 @@ def benchmarks( run_type_arg = { "overnight": "first commit", "branch": "base branch", - "custom": "ASV command type", + "custom": "ASV sub-command", } if run_type not in run_type_arg.keys(): message = f"Unsupported run-type: {run_type}" @@ -468,5 +468,5 @@ def asv_compare(*commits): asv_compare(merge_base, "HEAD") else: - asv_command_type = first_arg - session.run("asv", asv_command_type, *asv_args) + asv_subcommand = first_arg + session.run("asv", asv_subcommand, *asv_args) From 6a4fcf94fb2da70dbbb2d82c0afbf816ff26d062 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Wed, 16 Feb 2022 16:58:48 +0000 Subject: [PATCH 48/50] Benchmark Nox check correct run_type. --- noxfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/noxfile.py b/noxfile.py index 2662aec561..ae689d3acd 100755 --- a/noxfile.py +++ b/noxfile.py @@ -469,4 +469,5 @@ def asv_compare(*commits): else: asv_subcommand = first_arg + assert run_type == "custom" session.run("asv", asv_subcommand, *asv_args) From f69ba641d383447f3bc70d5c208786029c5a23eb Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Wed, 16 Feb 2022 17:01:48 +0000 Subject: [PATCH 49/50] Benchmark Nox clarify shifts_dir. --- noxfile.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/noxfile.py b/noxfile.py index ae689d3acd..e4d91c6bab 100755 --- a/noxfile.py +++ b/noxfile.py @@ -429,6 +429,8 @@ def asv_compare(*commits): ) if shifts: # Write the shifts report to a file. + # Dir is used by .github/workflows/benchmarks.yml, + # but not cached - intended to be discarded after run. shifts_dir.mkdir(exist_ok=True, parents=True) shifts_path = shifts_dir / after with shifts_path.open("w") as shifts_file: From 9808a9b5aeaa668d3b6f7dfd87831d41405fc064 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Wed, 16 Feb 2022 17:04:39 +0000 Subject: [PATCH 50/50] Benchmark README clarify BENCHMARK_DATA. --- benchmarks/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/benchmarks/README.md b/benchmarks/README.md index a7cba3191f..baa1afe700 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -25,9 +25,9 @@ automated overnight run locally. See the session docstring for detail. used to generate benchmark test objects/files; see [Data generation](#data-generation). The Nox session sets this automatically, but will defer to any value already set in the shell. -* ``BENCHMARK_DATA`` - optional - path to a directory where test files used by -the benchmarks are saved and loaded. Defaults to ``/benchmarks/.data/`` -if not set. +* ``BENCHMARK_DATA`` - optional - path to a directory for benchmark synthetic +test data, which the benchmark scripts will create if it doesn't already +exist. Defaults to ``/benchmarks/.data/`` if not set. ## Writing benchmarks