From 05977d5c26fb7468937f0a34a36d23a17691d22e Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 9 Nov 2023 10:22:12 +0100 Subject: [PATCH] Added boot time performance test to CI refs https://github.com/TryGhost/DevOps/issues/105 - this will run a small benchmark on the boot time for Ghost, and push the stats to another repository which has GitHub Pages enabled, so we can visualise the change over time - will only run on pushes to `main` so we don't pollute the stats with commits from PRs - just a test for now to see if we get stable numbers --- .github/workflows/ci.yml | 46 ++++++++++++++++++++++++++++++++++++++++ ghost/core/core/boot.js | 5 +++++ 2 files changed, 51 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb0620a720..f289ec0b7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -359,6 +359,52 @@ jobs: path: ghost/core/playwright-report retention-days: 30 + job_perf-tests: + runs-on: + labels: ubuntu-latest-4-cores + needs: [job_get_metadata, job_install_deps] + if: needs.job_get_metadata.outputs.changed_core == 'true' && needs.job_get_metadata.outputs.is_main == 'true' + name: Performance tests + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + env: + FORCE_COLOR: 0 + with: + node-version: '18.12.1' + + - name: Restore caches + uses: ./.github/actions/restore-cache + env: + DEPENDENCY_CACHE_KEY: ${{ needs.job_install_deps.outputs.dependency_cache_key }} + + - name: Install hyperfine + run: | + export HYPERFINE_VERSION=1.18.0 + wget https://github.com/sharkdp/hyperfine/releases/download/v$HYPERFINE_VERSION/hyperfine-v$HYPERFINE_VERSION-x86_64-unknown-linux-gnu.tar.gz + tar -zxvf hyperfine-v$HYPERFINE_VERSION-x86_64-unknown-linux-gnu.tar.gz + mv hyperfine-v$HYPERFINE_VERSION-x86_64-unknown-linux-gnu/hyperfine /usr/local/bin + chmod +x /usr/local/bin/hyperfine + + - name: Run hyperfine on boot + working-directory: ghost/core + run: hyperfine --warmup 3 'NODE_ENV=production GHOST_CI_SHUTDOWN_AFTER_BOOT=1 node index.js' --export-json boot-perf.json + + - name: Convert data + working-directory: ghost/core + run: | + jq '[{ name: "Boot time", unit: "s", value: .results[0].median, range: ((.results[0].max - .results[0].min) | tostring) }]' < boot-perf.json > boot-perf-formatted.json + + - name: Run analysis + uses: benchmark-action/github-action-benchmark@v1.18.0 + with: + tool: 'customSmallerIsBetter' + output-file-path: ghost/core/boot-perf-formatted.json + benchmark-data-dir-path: "" + gh-repository: github.com/TryGhost/Ghost-Benchmarks + github-token: ${{ secrets.CANARY_DOCKER_BUILD }} + auto-push: true + job_unit-tests: runs-on: ubuntu-latest needs: [job_get_metadata, job_install_deps] diff --git a/ghost/core/core/boot.js b/ghost/core/core/boot.js index 3b7bfe6118..bc79b9d7c8 100644 --- a/ghost/core/core/boot.js +++ b/ghost/core/core/boot.js @@ -543,6 +543,11 @@ async function bootGhost({backend = true, frontend = true, server = true} = {}) // Step 7 - Init our background services, we don't wait for this to finish initBackgroundServices({config}); + // If we pass the env var, kill Ghost + if (process.env.GHOST_CI_SHUTDOWN_AFTER_BOOT) { + process.exit(0); + } + // We return the server purely for testing purposes if (server) { debug('End Boot: Returning Ghost Server');