-
Notifications
You must be signed in to change notification settings - Fork 53
381 lines (342 loc) · 15 KB
/
benchmark-prs.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
name: PR Benchmarks
on: pull_request
env:
CARGO_INCREMENTAL: "0"
RUST_BACKTRACE: 1
CLIENT_DATA_PATH: /home/runner/.local/share/autonomi/client
NODE_DATA_PATH: /home/runner/.local/share/autonomi/node
jobs:
benchmark-cli:
name: Compare autonomi_cli benchmarks to main
# right now only ubuntu, running on multiple systems would require many pushes...\
# perhaps this can be done with one consolidation action in the future, pulling down all results and pushing
# once to the branch..
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
continue-on-error: true
########################
### Setup ###
########################
- run: cargo install cargo-criterion
- name: install ripgrep
run: sudo apt-get -y install ripgrep
- name: Download 95mb file to be uploaded with the safe client
shell: bash
run: wget https://sn-node.s3.eu-west-2.amazonaws.com/the-test-data.zip
# As normal user won't care much about initial client startup,
# but be more alerted on communication speed during transmission.
# Meanwhile the criterion testing code includes the client startup as well,
# it will be better to execute bench test with `local`,
# to make the measurement results reflect speed improvement or regression more accurately.
- name: Build binaries
run: cargo build --release --features local --bin antnode --bin ant
timeout-minutes: 30
- name: Start a local network
uses: maidsafe/ant-local-testnet-action@main
env:
ANT_LOG: "all"
with:
action: start
enable-evm-testnet: true
node-path: target/release/antnode
platform: ubuntu-latest
build: true
- name: Check ANT_PEERS was set
shell: bash
run: echo "The ANT_PEERS variable has been set to $ANT_PEERS"
- name: export default secret key
run: echo "SECRET_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" >> $GITHUB_ENV
shell: bash
#########################
### Upload large file ###
#########################
- name: Start a client instance to compare memory usage
shell: bash
run: ./target/release/ant --log-output-dest=data-dir file upload "./the-test-data.zip"
env:
ANT_LOG: "all"
timeout-minutes: 5
- name: Cleanup uploaded_files folder to avoid pollute download benchmark
shell: bash
run: |
ls -l $CLIENT_DATA_PATH
rm -rf $CLIENT_DATA_PATH/uploaded_files
###########################
### Client Mem Analysis ###
###########################
### The peak limit shall be restored back to 50MB,
### Once client side chunking/quoting flow got re-examined.
- name: Check client memory usage
shell: bash
run: |
client_peak_mem_limit_mb="1500" # mb
client_avg_mem_limit_mb="512" # mb
peak_mem_usage=$(
rg '"memory_used_mb":[^,]*' $CLIENT_DATA_PATH/logs --glob ant.* -o --no-line-number --no-filename |
awk -F':' '/"memory_used_mb":/{print $2}' |
sort -n |
tail -n 1
)
echo "Peak memory usage: $peak_mem_usage MB"
if (( $(echo "$peak_mem_usage > $client_peak_mem_limit_mb" | bc -l) )); then
echo "Client peak memory usage exceeded threshold: $client_peak_mem_limit_mb MB"
exit 1
fi
total_mem=$(
rg '"memory_used_mb":[^,]*' $CLIENT_DATA_PATH/logs --glob ant.* -o --no-line-number --no-filename |
awk -F':' '/"memory_used_mb":/ {sum += $2} END {printf "%.0f\n", sum}'
)
num_of_times=$(
rg "\"memory_used_mb\"" $CLIENT_DATA_PATH/logs --glob ant.* -c --stats |
rg "(\d+) matches" |
rg "\d+" -o
)
echo "num_of_times: $num_of_times"
echo "Total memory is: $total_mem"
average_mem=$(($total_mem/$(($num_of_times))))
echo "Average memory is: $average_mem"
if (( $(echo "$average_mem > $client_avg_mem_limit_mb" | bc -l) )); then
echo "Client average memory usage exceeded threshold: $client_avg_mem_limit_mb MB"
exit 1
fi
# Write the client memory usage to a file
echo '[
{
"name": "client-peak-memory-usage-during-upload",
"value": '$peak_mem_usage',
"unit": "MB"
},
{
"name": "client-average-memory-usage-during-upload",
"value": '$average_mem',
"unit": "MB"
}
]' > client_memory_usage.json
- name: check client_memory_usage.json
shell: bash
run: cat client_memory_usage.json
- name: Alert for client memory usage
uses: benchmark-action/github-action-benchmark@v1
with:
name: "Memory Usage of Client during uploading large file"
tool: "customSmallerIsBetter"
output-file-path: client_memory_usage.json
# Where the previous data file is stored
external-data-json-path: ./cache/client-mem-usage.json
# Workflow will fail when an alert happens
fail-on-alert: true
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Enable alert commit comment
comment-on-alert: true
# 200% regression will result in alert
alert-threshold: "200%"
# Enable Job Summary for PRs
summary-always: true
# ########################
# ### Benchmark ###
# ########################
# - name: Bench `safe` cli
# shell: bash
# # Criterion outputs the actual bench results to stderr "2>&1 tee output.txt" takes stderr,
# # passes to tee which displays it in the terminal and writes to output.txt
# run: |
# cargo criterion --features=local --message-format=json 2>&1 -p sn_cli | tee -a output.txt
# cat output.txt | rg benchmark-complete | jq -s 'map({
# name: (.id | split("/"))[-1],
# unit: "MiB/s",
# value: ((if .throughput[0].unit == "KiB/s" then (.throughput[0].per_iteration / (1024*1024*1024)) else (.throughput[0].per_iteration / (1024*1024)) end) / (.mean.estimate / 1e9))
# })' > files-benchmark.json
# timeout-minutes: 15
# - name: Confirming the number of files uploaded and downloaded during the benchmark test
# shell: bash
# run: |
# ls -l $CLIENT_DATA_PATH
# ls -l $CLIENT_DATA_PATH/uploaded_files
# ls -l $CLIENT_DATA_PATH/safe_files
# - name: Store benchmark result
# uses: benchmark-action/github-action-benchmark@v1
# with:
# # What benchmark tool the output.txt came from
# tool: "customBiggerIsBetter"
# output-file-path: files-benchmark.json
# # Where the previous data file is stored
# external-data-json-path: ./cache/benchmark-data.json
# # Workflow will fail when an alert happens
# fail-on-alert: true
# # GitHub API token to make a commit comment
# github-token: ${{ secrets.GITHUB_TOKEN }}
# # Enable alert commit comment
# comment-on-alert: true
# # 200% regression will result in alert
# alert-threshold: "200%"
# # Enable Job Summary for PRs
# summary-always: true
# - name: Start a client to carry out download to output the logs
# shell: bash
# run: target/release/safe --log-output-dest=data-dir files download --retry-strategy quick
# - name: Start a client to simulate criterion upload
# shell: bash
# run: |
# ls -l target/release
# target/release/safe --log-output-dest=data-dir files upload target/release/faucet --retry-strategy quick
#########################
### Stop Network ###
#########################
- name: Stop the local network
if: always()
uses: maidsafe/ant-local-testnet-action@main
with:
action: stop
log_file_prefix: safe_test_logs_benchmark
platform: ubuntu-latest
build: true
#########################
### Node Mem Analysis ###
#########################
# The large file uploaded will increase node's peak mem usage a lot
- name: Check node memory usage
shell: bash
run: |
node_peak_mem_limit_mb="250" # mb
peak_mem_usage=$(
rg '"memory_used_mb":[^,]*' $NODE_DATA_PATH/*/logs/* -o --no-line-number --no-filename |
awk -F':' '/"memory_used_mb":/{print $2}' |
sort -n |
tail -n 1
)
echo "Memory usage: $peak_mem_usage MB"
if (( $(echo "$peak_mem_usage > $node_peak_mem_limit_mb" | bc -l) )); then
echo "Node memory usage exceeded threshold: $peak_mem_usage MB"
exit 1
fi
# Write the node memory usage to a file
echo '[
{
"name": "node-memory-usage-through-safe-benchmark",
"value": '$peak_mem_usage',
"unit": "MB"
}
]' > node_memory_usage.json
- name: check node_memory_usage.json
shell: bash
run: cat node_memory_usage.json
- name: Alert for node memory usage
uses: benchmark-action/github-action-benchmark@v1
with:
tool: "customSmallerIsBetter"
output-file-path: node_memory_usage.json
# Where the previous data file is stored
external-data-json-path: ./cache/node-mem-usage.json
# Workflow will fail when an alert happens
fail-on-alert: true
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Enable alert commit comment
comment-on-alert: true
# Comment on the PR
comment-always: true
# 200% regression will result in alert
alert-threshold: "200%"
# Enable Job Summary for PRs
summary-always: true
###########################################
### Swarm_driver handling time Analysis ###
###########################################
- name: Check swarm_driver handling time
shell: bash
run: |
num_of_times=$(
rg "SwarmCmd handled in [0-9.]+ms:" $NODE_DATA_PATH/*/logs/* --glob antnode.* -c --stats |
rg "(\d+) matches" |
rg "\d+" -o
)
echo "Number of long cmd handling times: $num_of_times"
total_long_handling_ms=$(
rg "SwarmCmd handled in [0-9.]+ms:" $NODE_DATA_PATH/*/logs/* --glob antnode.* -o --no-line-number --no-filename |
awk -F' |ms:' '{sum += $4} END {printf "%.0f\n", sum}'
)
echo "Total cmd long handling time is: $total_long_handling_ms ms"
average_handling_ms=$(($total_long_handling_ms/$(($num_of_times))))
echo "Average cmd long handling time is: $average_handling_ms ms"
total_long_handling=$(($total_long_handling_ms))
total_num_of_times=$(($num_of_times))
num_of_times=$(
rg "SwarmEvent handled in [0-9.]+ms:" $NODE_DATA_PATH/*/logs/* --glob antnode.* -c --stats |
rg "(\d+) matches" |
rg "\d+" -o
)
echo "Number of long event handling times: $num_of_times"
total_long_handling_ms=$(
rg "SwarmEvent handled in [0-9.]+ms:" $NODE_DATA_PATH/*/logs/* --glob antnode.* -o --no-line-number --no-filename |
awk -F' |ms:' '{sum += $4} END {printf "%.0f\n", sum}'
)
echo "Total event long handling time is: $total_long_handling_ms ms"
average_handling_ms=$(($total_long_handling_ms/$(($num_of_times))))
echo "Average event long handling time is: $average_handling_ms ms"
total_long_handling=$(($total_long_handling_ms+$total_long_handling))
total_num_of_times=$(($num_of_times+$total_num_of_times))
average_handling_ms=$(($total_long_handling/$(($total_num_of_times))))
echo "Total swarm_driver long handling times is: $total_num_of_times"
echo "Total swarm_driver long handling duration is: $total_long_handling ms"
echo "Total average swarm_driver long handling duration is: $average_handling_ms ms"
total_num_of_times_limit_hits="30000" # hits
total_long_handling_limit_ms="400000" # ms
average_handling_limit_ms="20" # ms
if (( $(echo "$total_num_of_times > $total_num_of_times_limit_hits" | bc -l) )); then
echo "Swarm_driver long handling times exceeded threshold: $total_num_of_times hits"
exit 1
fi
if (( $(echo "$total_long_handling > $total_long_handling_limit_ms" | bc -l) )); then
echo "Swarm_driver total long handling duration exceeded threshold: $total_long_handling ms"
exit 1
fi
if (( $(echo "$average_handling_ms > $average_handling_limit_ms" | bc -l) )); then
echo "Swarm_driver average long handling time exceeded threshold: $average_handling_ms ms"
exit 1
fi
# Write the node memory usage to a file
echo '[
{
"name": "swarm_driver long handling times",
"value": '$total_num_of_times',
"unit": "hits"
},
{
"name": "swarm_driver long handling total_time",
"value": '$total_long_handling',
"unit": "ms"
},
{
"name": "swarm_driver average long handling time",
"value": '$average_handling_ms',
"unit": "ms"
}
]' > swarm_driver_long_handlings.json
- name: check swarm_driver_long_handlings.json
shell: bash
run: cat swarm_driver_long_handlings.json
- name: Alert for swarm_driver long handlings
uses: benchmark-action/github-action-benchmark@v1
with:
tool: "customSmallerIsBetter"
output-file-path: swarm_driver_long_handlings.json
# Where the previous data file is stored
external-data-json-path: ./cache/swarm_driver_long_handlings.json
# Workflow will fail when an alert happens
fail-on-alert: true
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Enable alert commit comment
comment-on-alert: true
# Comment on the PR
comment-always: true
# 200% regression will result in alert
alert-threshold: "200%"
# Enable Job Summary for PRs
summary-always: true