Skip to content

Commit

Permalink
feat: add sync-v2 benchmark to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
glevco committed Jul 12, 2024
1 parent 7c7c261 commit 4278024
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 19 deletions.
38 changes: 38 additions & 0 deletions .github/actions/setup-hathor-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: setup-hathor-env
description: Setup Hathor node environment
inputs:
python:
description: The python version
os:
description: The OS name
runs:
using: composite
steps:
- name: Install Poetry
shell: bash
run: pipx install poetry

- name: Set up Python ${{ inputs.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python }}
cache: 'poetry'

- name: Install Ubuntu dependencies
if: startsWith(inputs.os, 'ubuntu')
run: |
sudo apt-get -qy update
sudo apt-get -qy install graphviz librocksdb-dev libsnappy-dev liblz4-dev
shell: bash

- name: Install macOS dependencies
if: startsWith(inputs.os, 'macos')
run: |
brew cleanup -q
# brew update -q
brew install -q graphviz rocksdb pkg-config
shell: bash

- name: Install Poetry dependencies
run: poetry install -n --no-root
shell: bash
34 changes: 34 additions & 0 deletions .github/workflows/base_benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# yamllint disable rule:line-length
name: benchmarking
on: # yamllint disable-line rule:truthy
push:
branches:
- master

jobs:
benchmark_base_branch:
name: Continuous Benchmarking base branch
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: bencherdev/bencher@main
- name: Install hyperfine
run: |
wget https://github.com/sharkdp/hyperfine/releases/download/v1.12.0/hyperfine_1.12.0_amd64.deb
sudo dpkg -i hyperfine_1.12.0_amd64.deb
- uses: ./.github/actions/setup-hathor-env
name: Setup Hathor node environment
with:
python: 3.11
os: ubuntu-22.04
- name: Track base branch benchmarks with Bencher
run: |
bencher run \
--project hathor-core \
--token '${{ secrets.BENCHER_API_TOKEN }}' \
--branch master \
--testbed ubuntu-22.04 \
--adapter shell_hyperfine \
--err \
--file bench_results.json \
'./extras/benchmarking/benchmark_sync_v2.sh'
23 changes: 4 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,11 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Poetry
run: pipx install poetry
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
- uses: ./.github/actions/setup-hathor-env
name: Setup Hathor node environment
with:
python-version: ${{ matrix.python }}
cache: 'poetry'
- name: Install Ubuntu dependencies
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get -qy update
sudo apt-get -qy install graphviz librocksdb-dev libsnappy-dev liblz4-dev
- name: Install macOS dependencies
if: startsWith(matrix.os, 'macos')
run: |
brew cleanup -q
# brew update -q
brew install -q graphviz rocksdb pkg-config
- name: Install Poetry dependencies
run: poetry install -n --no-root
python: ${{ matrix.python }}
os: ${{ matrix.os }}
- name: Cache mypy
uses: actions/cache@v3
with:
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/pr_benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# yamllint disable rule:line-length
name: benchmarking
on: # yamllint disable-line rule:truthy
pull_request:
branches:
- master

jobs:
benchmark_pr_branch:
name: Continuous Benchmarking PRs
# DO NOT REMOVE: For handling Fork PRs see Pull Requests from Forks
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
permissions:
pull-requests: write
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: bencherdev/bencher@main
- name: Install hyperfine
run: |
wget https://github.com/sharkdp/hyperfine/releases/download/v1.12.0/hyperfine_1.12.0_amd64.deb
sudo dpkg -i hyperfine_1.12.0_amd64.deb
- uses: ./.github/actions/setup-hathor-env
name: Setup Hathor node environment
with:
python: 3.11
os: ubuntu-22.04
- name: Track PR Benchmarks with Bencher
run: |
bencher run \
--project hathor-core \
--token '${{ secrets.BENCHER_API_TOKEN }}' \
--branch '${{ github.head_ref }}' \
--branch-start-point '${{ github.base_ref }}' \
--branch-start-point-hash '${{ github.event.pull_request.base.sha }}' \
--testbed ubuntu-22.04 \
--adapter shell_hyperfine \
--err \
--github-actions '${{ secrets.GITHUB_TOKEN }}' \
--file bench_results.json \
'./extras/benchmarking/benchmark_sync_v2.sh'
45 changes: 45 additions & 0 deletions extras/benchmarking/benchmark_sync_v2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
N_BLOCKS=100
CACHE_SIZE=100000
TESTNET_DATA_DIR=server-data
TCP_PORT=40403
AWAIT_INIT_DELAY=10
N_RUNS=2
BENCH_FILE=bench_results.json
BENCH_DATA_DIR=bench-data

BLUE='\033[0;34m'
NO_COLOR='\033[0m'

echo "${BLUE}Downloading testnet data...${NC}"
mkdir $TESTNET_DATA_DIR
poetry run hathor-cli quick_test --testnet --data $TESTNET_DATA_DIR --quit-after-n-blocks $N_BLOCKS > /dev/null 2>&1

echo "${BLUE}Running server node in the background...${NC}"
poetry run hathor-cli run_node \
--testnet \
--data $TESTNET_DATA_DIR \
--cache \
--cache-size $CACHE_SIZE \
--x-localhost-only \
--listen tcp:$TCP_PORT \
> /dev/null 2>&1 &

# Await initialization
sleep $AWAIT_INIT_DELAY

echo "${BLUE}Running benchmark...${NC}"
hyperfine \
--runs $N_RUNS \
--export-json $BENCH_FILE \
--command-name "sync-v2 (up to $N_BLOCKS blocks)" \
--prepare "rm -rf $BENCH_DATA_DIR && mkdir $BENCH_DATA_DIR" \
"
poetry run hathor-cli quick_test \
--testnet \
--data $BENCH_DATA_DIR \
--cache \
--cache-size $CACHE_SIZE \
--x-localhost-only \
--bootstrap tcp://localhost:$TCP_PORT \
--quit-after-n-blocks $N_BLOCKS
"

0 comments on commit 4278024

Please sign in to comment.