-
Notifications
You must be signed in to change notification settings - Fork 17
executable file
·204 lines (184 loc) · 8.44 KB
/
benchmark.yml
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
name: BENCHMARK
on:
workflow_dispatch:
inputs:
cpus:
description: 'docker cpus '
default: 2
require: true
memory:
description: 'docker memory'
default: '4g'
require: true
benchmark-time:
description: 'Benchmark time(h/m/s)'
default: 30m
require: true
indexerVersion:
description: 'indexer version'
default: 'latest'
require: true
deployment:
description: 'Deployment'
default: 'QmUiVCsuBKrPetipdQBDBPLZFqm87gzyRPQsYEfzzS3jzt' #Archway starter project
require: false
network-endpoint:
description: 'Network endpoint'
default: 'https://rpc.mainnet.archway.io:443'
require: true
use-network-api-key:
description: 'Use api endpoint key'
default: false
required: true
batch-size:
description: 'batch-size'
default: 30
require: false
workers:
description: 'workers'
default: 4
require: false
others:
description: 'Other flags'
require: false
jobs:
# Label of the container job
container-job:
# Containers must run in Linux based operating systems
runs-on: ubuntu-latest
# Docker Hub image that `container-job` executes in
container: node:18
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres:12-alpine
# Provide the password for postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
#Check out
- uses: actions/checkout@v4
with:
fetch-depth: 100
token: ${{ secrets.REPO_TOKEN }}
- name: Prepare Network Endpoint
id: prepare-network-endpoint
run: |
if [ "${{ github.event.inputs.use-network-api-key }}" = "true" ]; then
NETWORK_ENDPOINT="${{ github.event.inputs.network-endpoint }}${{ secrets.BENCHMARK_ONF_API_KEY }}"
else
NETWORK_ENDPOINT="${{ github.event.inputs.network-endpoint }}"
fi
echo "::set-output name=network-endpoint::${NETWORK_ENDPOINT}"
echo "::add-mask::${NETWORK_ENDPOINT}"
# Store the prepared NETWORK_ENDPOINT in an environment variable
echo "NETWORK_ENDPOINT=${NETWORK_ENDPOINT}" >> $GITHUB_ENV
- name: Install Docker inside the container
run: |
apt-get update
apt-get install -y docker.io
- name: Install PostgreSQL client
run: |
apt-get install --yes postgresql-client
# Install bc used in convert time in seconds
- name: Install bc
run: apt-get install -y bc
# queries database with postgres client
- name: Setup historical database
run: psql -h postgres -d postgres -U postgres -c 'CREATE EXTENSION IF NOT EXISTS btree_gist;'
env:
PGPASSWORD: postgres
- name: Ensure clean reports directory
run: |
output_dir="output/benchmark/"
chmod +x .github/workflows/scripts/benchmark/cleanHistory.sh
.github/workflows/scripts/benchmark/cleanHistory.sh $output_dir
- name: Clean container && rebuild indexer
run: |
docker rmi my_indexer:latest || true
CONTAINER_NAME="my_container"
docker stop $CONTAINER_NAME || true
docker rm -f $CONTAINER_NAME || true
VOLUME_NAME="${CONTAINER_NAME}_data"
docker volume rm $VOLUME_NAME || true
docker build -t my_indexer --build-arg input_indexer_version=${{github.event.inputs.indexerVersion}} .github/workflows/scripts/benchmark/
- name: Benchmarking
id: app
run: |
docker run --cpus=${{github.event.inputs.cpus}} --memory=${{github.event.inputs.memory}} --network ${{ job.container.network }} --name my_container -v "${PWD}/output/benchmark:/app/output/benchmark" my_indexer ${{github.event.inputs.benchmark-time}} ${{ github.event.inputs.deployment }} ${{ env.NETWORK_ENDPOINT }} ${{ github.event.inputs.batch-size }} ${{ github.event.inputs.workers }} ${{ github.event.inputs.others }}
docker cp my_container:/app/output/benchmark/indexing.log output/benchmark/
- name: Stop and remove the benchmark container
run: docker stop my_container && docker rm my_container
- name: Query metadata get processed height
id: query_meta
env:
PGPASSWORD: postgres
run: |
chmod +x .github/workflows/scripts/benchmark/queryMeta.sh
.github/workflows/scripts/benchmark/queryMeta.sh ${{github.event.inputs.benchmark-time}}
- name: Pre-save running specs
run: |
echo "benchmark-time=${{github.event.inputs.benchmark-time}}" > output/benchmark/benchmark.log
echo "indexer=${{steps.query_meta.outputs.runner_node}}" >> output/benchmark/benchmark.log
echo "indexerVersion=${{steps.query_meta.outputs.indexer_version}}" >> output/benchmark/benchmark.log
echo "deployment=${{github.event.inputs.deployment}}" >> output/benchmark/benchmark.log
if [ "${{ github.event.inputs.use-network-api-key }}" = "false" ]; then
echo "network-endpoint=${{github.event.inputs.network-endpoint}}" >> output/benchmark/benchmark.log
fi
echo "batch-size=${{github.event.inputs.batch-size}}" >> output/benchmark/benchmark.log
echo "workers=${{github.event.inputs.workers}}" >> output/benchmark/benchmark.log
if [ -n "${{github.event.inputs.others}}" ]; then
echo "others=${{github.event.inputs.others}}" >> output/benchmark/benchmark.log
fi
echo "Start Height: ${{steps.query_meta.outputs.start_height}}" >> output/benchmark/benchmark.log
echo "Last Processed Height: ${{steps.query_meta.outputs.last_processed_height}}" >> output/benchmark/benchmark.log
echo "------------------------------------" >> output/benchmark/benchmark.log
- name: Prepare benchmark log
run: |
if grep -qi "benchmark" output/benchmark/indexing.log; then
grep -i "benchmark" output/benchmark/indexing.log >> output/benchmark/benchmark.log
cat output/benchmark/benchmark.log
else
echo "No lines containing 'benchmark' found in output/benchmark/indexing.log" >> output/benchmark/benchmark.log
fi
- name: Get current time
uses: josStorer/get-current-time@v2
id: current-time
with:
format: YYYYMMDD-HHmm
utcOffset: "+12:00"
- name: Upload reports
uses: actions/upload-artifact@v3
with:
name: benchmark-${{steps.current-time.outputs.formattedTime}}-${{steps.query_meta.outputs.indexer_version}}
path: output/benchmark/
- name: Post to a Slack channel
id: slack
uses: slackapi/[email protected]
with:
# Slack channel id, channel name, or user id to post message.
# See also: https://api.slack.com/methods/chat.postMessage#channels
# channel for sq-benchmark
channel-id: 'C05JF51F1MJ'
# For posting a rich message using Block Kit
payload: |
{
"text": "Benchmark result ${{steps.current-time.outputs.formattedTime}}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Results: ${{ job.status }} with ${{steps.query_meta.outputs.bps}} bps\n Performance: Block [${{steps.query_meta.outputs.start_height}}-${{steps.query_meta.outputs.last_processed_height}}], total ${{steps.query_meta.outputs.total_height}} blocks in ${{github.event.inputs.benchmark-time}}\n More details: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\n Indexer: ${{steps.query_meta.outputs.runner_node}}@${{steps.query_meta.outputs.indexer_version}}\n Deployment: ${{github.event.inputs.deployment}}\n CPUs: ${{github.event.inputs.cpus}}\n Memory: ${{github.event.inputs.memory}}\n Workers: ${{github.event.inputs.workers}}\n Batch-size: ${{github.event.inputs.batch-size}}"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}