Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d9a896d
Checkpoint paton
michaeldiamant Jan 5, 2023
f8406c5
Add example benchmarks
michaeldiamant Jan 5, 2023
5076418
Run paton on all PRs
michaeldiamant Jan 5, 2023
120c774
Fix deprecation
michaeldiamant Jan 5, 2023
1ac9826
Retrieve older git commits on clone
michaeldiamant Jan 5, 2023
1030449
Fix syntax
michaeldiamant Jan 5, 2023
1981235
Get all the branches and tags
michaeldiamant Jan 5, 2023
e0c4093
Fix file reference
michaeldiamant Jan 5, 2023
844537a
Install more dependencies
michaeldiamant Jan 5, 2023
63a086b
Install more dependencies
michaeldiamant Jan 5, 2023
32c1d23
Install more dependencies
michaeldiamant Jan 5, 2023
1bbe7e7
Install more dependencies
michaeldiamant Jan 5, 2023
4b91b6c
Debug CI failure
michaeldiamant Jan 5, 2023
fc2612d
Cache go dependencies
michaeldiamant Jan 5, 2023
3a381ad
Output more diagnostics
michaeldiamant Jan 5, 2023
f0fc972
Slow down benchmark
michaeldiamant Jan 5, 2023
01831b6
Make it slower
michaeldiamant Jan 5, 2023
0bf8da6
Make it slower
michaeldiamant Jan 5, 2023
ad1df74
Make it slower
michaeldiamant Jan 5, 2023
97b4da6
Try to fix it
michaeldiamant Jan 5, 2023
8eedac0
Try to fix it
michaeldiamant Jan 5, 2023
dc1e470
Warm up caches
michaeldiamant Jan 5, 2023
daa8e4e
Warm up caches
michaeldiamant Jan 5, 2023
2dadad4
Try to fix it
michaeldiamant Jan 5, 2023
4070384
Install current jc version
michaeldiamant Jan 5, 2023
22a21de
Remove intermediate files
michaeldiamant Jan 5, 2023
9b75cbd
Worsen benchmark performance
michaeldiamant Jan 5, 2023
aa94745
Try to make commenting work
michaeldiamant Jan 5, 2023
fc28289
Fix syntax
michaeldiamant Jan 5, 2023
b7e7ac3
Revert performance regression
michaeldiamant Jan 5, 2023
3fc98f2
Cache libsodium
michaeldiamant Jan 5, 2023
d5bec10
Skip adding comment on fork
michaeldiamant Jan 5, 2023
29e141d
Degrade performance for 1 benchmark
michaeldiamant Jan 5, 2023
f9d5fff
Try different commenting approach
michaeldiamant Jan 6, 2023
7c88ffe
Try commit comment
michaeldiamant Jan 6, 2023
086ac69
Try PR comment
michaeldiamant Jan 6, 2023
04c60ac
Hardcode PR number
michaeldiamant Jan 6, 2023
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
38 changes: 38 additions & 0 deletions .github/workflows/paton-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "paton comment"
on:
workflow_run:
workflows: ["paton benchmark"]
types:
- completed

jobs:
paton-comment:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- id: download-artifact
uses: dawidd6/action-download-artifact@v2
with: paton.yml
name: alerting_benchmarks.json
path: /tmp/alerting_benchmarks.json
- name: Run benchmark
run: if [ ! -s /tmp/alerting_benchmarks.json ]; then rm /tmp/alerting_benchmarks.json
shell: bash
- name: Check files
id: check_files
uses: andstor/file-existence-action@v1
with:
files: "/tmp/alerting_benchmarks.json"
- uses: peter-evans/create-or-update-comment@v2
with:
issue-number: 5 # TODO Provide dynamically
body-file: /tmp/alerting_benchmarks.json

# - name: Slack Notification
# env:
# SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
# run: |
# curl -X POST --data-urlencode "payload={\"text\": \"Benchmark workflow failed. ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} \"}" $SLACK_WEBHOOK
# if: ${{ failure() && (contains(github.ref_name, 'rel/nightly') || contains(github.ref_name, 'rel/beta') || contains(github.ref_name, 'rel/stable') || contains(github.ref_name, 'master')) }}
58 changes: 58 additions & 0 deletions .github/workflows/paton.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: "paton benchmark"
on:
push:
branches:
- master
pull_request:
# For demonstration purposes, allow paton to run on all PRs.
# branches:
# - master
permissions:
contents: write
deployments: write
jobs:
paton:
name: paton
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
cache: true
- name: Restore libsodium from cache
id: cache-libsodium
uses: actions/cache@v3
with:
path: crypto/libs
key: libsodium-fork-v1-${{ runner.os }}-${{ hashFiles('crypto/libsodium-fork/**') }}
- run: go install golang.org/x/perf/cmd/benchstat@latest
- run: sudo apt-get update
- run: sudo apt-get -y -q install jq python3-pip
- run: pip3 install jc # Use pip to install jc because aptitude is stale (https://repology.org/project/jc/versions).
- run: ./scripts/configure_dev.sh
shell: bash
- run: ./scripts/buildtools/install_buildtools.sh
shell: bash
- run: ./scripts/travis/before_build.sh # Installs libsodium.
shell: bash
- name: Run benchmark
run: ./scripts/paton.sh --alert-threshold-pct 10 --test-cmd "-run XXX -benchtime 5s -bench BenchmarkControl ./data/transactions/logic"
shell: bash
- uses: actions/upload-artifact@v3
with:
name: alerting_benchmarks.json
path: /tmp/alerting_benchmarks.json
# - name: Check files
# id: check_files
# uses: andstor/file-existence-action@v1
# with:
# files: "/tmp/alerting_benchmarks.json"
# - name: Slack Notification
# env:
# SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
# run: |
# curl -X POST --data-urlencode "payload={\"text\": \"Benchmark workflow failed. ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} \"}" $SLACK_WEBHOOK
# if: ${{ failure() && (contains(github.ref_name, 'rel/nightly') || contains(github.ref_name, 'rel/beta') || contains(github.ref_name, 'rel/stable') || contains(github.ref_name, 'master')) }}
23 changes: 23 additions & 0 deletions data/transactions/logic/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"strconv"
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -3727,6 +3728,28 @@ main:
}
}

func BenchmarkControl1(b *testing.B) {
var arr []int
for i := 0; i < b.N; i++ {
time.Sleep(225 * time.Millisecond)
arr = make([]int, 50)
}
if b.N < 0 {
fmt.Println(arr)
}
}

func BenchmarkControl2(b *testing.B) {
var arr []int
for i := 0; i < b.N; i++ {
time.Sleep(45 * time.Millisecond)
arr = make([]int, 25)
}
if b.N < 0 {
fmt.Println(arr)
}
}

func BenchmarkByteLogic(b *testing.B) {
benches := [][]string{
{"b&", "", "byte 0x012345678901feab; byte 0x01ffffffffffffff; b&; pop", "int 1"},
Expand Down
84 changes: 84 additions & 0 deletions scripts/paton.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash

set -euxf -o pipefail

# Primarily intended for continuous benchmarking, paton.sh compares Go
# benchmarks between 2 git commits and outputs the comparison in a format
# compatible with https://github.com/benchmark-action/github-action-benchmark.
#
# paton.sh is inspired by https://github.com/knqyf263/cob. cob minimizes
# benchmarking variance by running provided benchmarks against 2 commits in 1
# invocation rather than comparing against a previously stored result.
# Comparing against a previously stored result requires a stable benchmark
# environment across time. Particularly in fully managed CI environments, a
# stable benchmark environment cannot be guaranteed.
#
# paton.sh's namesake is https://en.wikipedia.org/wiki/Paton_Bridge.
#
# paton.sh requires these dependencies. No attempt is made to install prerequisites:
# * https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
# * https://github.com/stedolan/jq
# * https://github.com/kellyjonbrazil/jc

if [[ $# -lt 1 ]]; then
echo "Must provide required flags"
exit 1
fi

# Argument parsing crafted with help from https://stackoverflow.com/a/14203146.
while [[ $# -gt 0 ]]; do
case $1 in
-c|--test-cmd)
GO_TEST_CMD=("$2")
shift # past argument
shift # past value
;;
-a|--alert-threshold-pct)
ALERT_THRESHOLD_PCT="$2"
shift # past argument
shift # past value
;;
*)
echo "Unknown flag"
exit 1
;;
esac
done

BASE="HEAD~1"
COMPARE="HEAD"

COMPARE_COMMIT=$(git rev-parse "$COMPARE")

git -c advice.detachedHead=false checkout "$BASE"
go test ${GO_TEST_CMD[*]} | tee /tmp/base.txt

git -c advice.detachedHead=false checkout "$COMPARE_COMMIT"
go test ${GO_TEST_CMD[*]} | tee /tmp/compare.txt

benchstat -delta-test none /tmp/base.txt /tmp/compare.txt | tee /tmp/benchstat.txt

cat /tmp/benchstat.txt |
awk '/old time\/op/{f=1} /^$/{f=0} f' |
jc -p --asciitable |
# Remove symbols (+, %) preventing conversion to JavaScript number.
sed '/delta/s/+//g' |
sed '/delta/s/%//g' |
tee /tmp/benchstat_time.json

cat /tmp/benchstat_time.json |
jq '.[] | {
name: .name,
old_time_op: .old_time_op,
new_time_op: .new_time_op,
delta: .delta | tonumber
}' |
jq -s > /tmp/benchstat_time_jq.json

cat /tmp/benchstat_time_jq.json |
jq ".[] | select(.delta >= ${ALERT_THRESHOLD_PCT})" |
tee /tmp/alerting_benchmarks.json

#if [ ! -s /tmp/alerting_benchmarks.json ]; then
# rm /tmp/alerting_benchmarks.json
#fi