-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-gha.sh
executable file
·146 lines (127 loc) · 4.15 KB
/
run-gha.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# this is designed for the GH Action, but can be run locally. it assumes you
# are logged into AWS and Docker as needed (for S3 download/upload or ECR
# access), and have `aws` and `docker` in your path and Docker is running.
set -eux
# inputs
: "${BENCHMARK:=warehouse-1G}"
: "${REPO:=ghcr.io/hydradatabase/hydra}"
: "${TAG:=latest}"
: "${VARIANT:=zstd}"
# settings
: "${CONTAINER_NAME:=hydra-benchmark}"
: "${RUNTIME:=now}"
: "${BASE_IMAGE:=$( [[ $REPO =~ "ghcr.io" ]] && echo "postgres" || echo "spilo" )}"
: "${BENCHER_PROJECT:=hydra-$BASE_IMAGE}"
: "${BENCHER_TESTBED:=localhost}"
# required to be manually set or passed in if you want to use bencher
# BENCHER_API_TOKEN=
# features
: "${DOWNLOAD_DATA:=true}"
: "${UPLOAD_RESULTS_TO_S3:=true}"
: "${UPLOAD_RESULTS_TO_BENCHER:=true}"
: "${CLEANUP_FILES:=false}"
: "${USE_BENCHER_BACKDATE:=false}"
# internal settings
BENCHER_ADAPTER=json
if [ "$(uname -s)" = Darwin ]; then
# need gnu date for consistency; 'brew install date'
DATE=gdate
else
DATE=date
fi
setup_data_dir() {
if [ ! -e "$BENCHMARK" ]; then
benchmark_src="$(echo $BENCHMARK | cut -f 1 -d -)"
if [ "$BENCHMARK" != "$benchmark_src" ]; then
ln -s $benchmark_src $BENCHMARK
fi
fi
mkdir -p $BENCHMARK/data
}
prepare_data() {
pushd $BENCHMARK/data
for f in *.gz; do
target="$(basename $f .gz)"
if [ ! -e $target ]; then
mkfifo $target
fi
if [ -p $target ]; then
gzip -d -c $f >$target &
fi
done
popd
}
download_data() {
aws s3 cp --no-progress --recursive s3://hydra-benchmarks/data/$BENCHMARK ./$BENCHMARK/data
}
upload_result_to_s3() {
aws s3 cp --no-progress ./results.json s3://hydra-benchmarks/results/$BASE_IMAGE-$BENCHMARK-$VARIANT-$TAG.json
aws s3 cp --no-progress ./bencher-with-metadata.json s3://hydra-benchmarks/bencher-results/$BASE_IMAGE-$BENCHMARK-$VARIANT-$TAG.json
}
upload_result_to_bencher() {
set +u
if [ $USE_BENCHER_BACKDATE = true ]; then
bencher run \
--if-branch "$GITHUB_REF_NAME" \
--else-if-branch "$GITHUB_BASE_REF" \
--else-if-branch main \
--backdate $(cat unix-timestamp.txt) \
--project "$BENCHER_PROJECT" \
--adapter "$BENCHER_ADAPTER" \
"cat ./analyze-bencher.json"
else
bencher run \
--if-branch "$GITHUB_REF_NAME" \
--else-if-branch "$GITHUB_BASE_REF" \
--else-if-branch main \
--project "$BENCHER_PROJECT" \
--adapter "$BENCHER_ADAPTER" \
"cat ./analyze-bencher.json"
fi
set -u
}
run_benchmark() {
docker run -d -e POSTGRES_HOST_AUTH_METHOD=trust -v $PWD:/benchmarks -m 12288m --cpus=4 --shm-size=1024m --name=$CONTAINER_NAME $REPO:$TAG
trap "stop_docker; exit 1" SIGINT ERR
sleep 15
docker exec $CONTAINER_NAME /bin/sh -c "RUNTIME=$RUNTIME /benchmarks/run-benchmark.sh -z -b $BENCHMARK -v $VARIANT -u postgres"
stop_docker
trap - SIGINT ERR
}
stop_docker() {
docker stop $CONTAINER_NAME
docker rm $CONTAINER_NAME
}
analyze_results() {
docker inspect $REPO:$TAG | jq ".[0] | { metadata: { timestamp: .Created, repo: \"$REPO\", tag: \"$TAG\", benchmark: \"$BENCHMARK\", testbed: \"$BENCHER_TESTBED\" } }" >./metadata.json
$DATE -d $(jq -r .metadata.timestamp ./metadata.json) +%s >./unix-timestamp.txt
./analyze.js ./results/$BENCHMARK/$VARIANT/$RUNTIME > ./analyze.json
./analyze-bencher.js ./results/$BENCHMARK/$VARIANT/$RUNTIME $BENCHMARK >./analyze-bencher.json
jq -s '.[0] * .[1]' ./analyze.json ./metadata.json >./results.json
jq -s '.[0] * .[1]' ./analyze-bencher.json ./metadata.json >./bencher-with-metadata.json
}
cleanup_files() {
rm -f analyze.json analyze-bencher.json results.json bencher-with-metadata.json unix-timestamp.txt metadata.json
# cleanup pipes
for f in $BENCHMARK/data/*; do
if [ -p $f ]; then
rm $f
fi
done
# cleanup symlink
if [ -L $BENCHMARK ]; then
rm $BENCHMARK
fi
}
run() {
setup_data_dir
[ $DOWNLOAD_DATA = true ] && download_data || true
prepare_data
run_benchmark
analyze_results
[ $UPLOAD_RESULTS_TO_S3 = true ] && upload_result_to_s3 || true
[ $UPLOAD_RESULTS_TO_BENCHER = true ] && upload_result_to_bencher || true
[ $CLEANUP_FILES = true ] && cleanup_files || true
}
${1:-run}