-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.sh
executable file
·286 lines (239 loc) · 6.59 KB
/
bench.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
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
#!/bin/bash
cargo="$1"
timings="$PWD/timings.dat"
speed=0
rate=0
if [ ! -e "$timings" ]; then
echo "project depth size implementation metric speed rate time" > "$timings"
fi
for x in */Cargo.toml; do
if [[ $x = "*/Cargo.toml" ]]; then
echo "Error: no benchmarks"
exit 1
fi
done
function bench() {
category=$1
shift
dir="$1"
shift
trace="no"
tmp="/tmp/cargo-bench-git-$dir"
# make sure we have a clean starting point
rm -rf "$tmp" 2>/dev/null
# isolate cargo
# export "CARGO_LOG=debug"
export "CARGO_HOME=$tmp"
export "CARGO_TARGET_DIR=$PWD/target"
export "RUST_BACKTRACE=1"
function maybe_trace() {
uniq=$1
shift
f=~/Desktop/cargo-prefetch-$dir-$uniq.trace
rm -rf "$f"
if [[ $trace = "yes" ]]; then
xcrun xctrace record --template "Time Profiler" --output "$f" --target-stdout - --launch -- "$cargo" -Zhttp-registry --color always "$@"
else
"$cargo" -Zhttp-registry "$@"
fi
}
function run() {
metric=$1
# use start/end, not time, to avoid capturing output
# which tends to mess up detection of terminal and such
start=$(gdate +%s.%N)
maybe_trace "$@" > /dev/null
end=$(gdate +%s.%N)
took=$(echo "$end - $start" | bc -l)
took_s=$(echo "$took" | sed 's/\..*//')
if [[ -z $took_s ]]; then
took_s="0"
fi
depth=$(awk '{print $1}' .dep-meta)
size=$(awk '{print $2}' .dep-meta)
echo "$dir $depth $size $category $metric $speed $rate $took" >> "$timings"
if ((took_s > 60)); then
min=$((took_s / 60))
sec=$(echo "$took - $min * 60.0" | bc -l)
echo " .. took: ${min}m ${sec}s"
else
echo "took: ${took}s"
fi
}
pushd "$dir" >/dev/null
# remove the injected dependency if it was there
sed -i .bpk '/^blank /d' Cargo.toml
rm -f Cargo.lock > /dev/null
echo " -> pull & discard to warm intermediate caches"
"$cargo" -Zhttp-registry "$@" update -p stub
rm -rf "$tmp"
echo " -> fresh build"
run fresh "$@" update -p stub
echo " -> fresh build with lockfile"
rm -rf "$tmp"
run fresh-locked "$@" update -p stub
echo " -> rebuild with lockfile"
run rerun-locked "$@" update -p stub
echo " -> rebuild"
rm Cargo.lock
run rerun "$@" update -p stub
echo " -> rebuild w/o update"
rm Cargo.lock
run rerun-no-upd "$@" -Zno-index-update update -p stub
echo " -> update with lockfile"
run update-locked "$@" update
echo " -> add blank with lockfile"
echo "blank = '0.1'" >> Cargo.toml
run incr-locked "$@" update -p stub
popd >/dev/null
# and clean up
rm -rf "$tmp" 2>/dev/null
}
# first, we figure out the depth + size of each crate's dependency graph
echo ":: tree inspection time"
for ct in */Cargo.toml; do
echo "==> skipping for now"
break
dir=$(dirname "$ct")
[[ $dir != "stub" ]] || continue
echo "==> $dir"
# use standard cargo here
rm -r "$dir/.cargo" 2>/dev/null
pushd "$dir" > /dev/null
depth=$(cargo tree | sed 's/[^│]//g' | sed 's/./x/g' | perl -ne 'print(length($_), "\n")' | awk 'BEGIN { depth = 0; } { if ($1 > depth) { depth = $1 }
} END {print depth}')
size=$(cargo tree | sed 's/.*─ //g' | grep ' v' | sed 's/ (.*)$//' | sort | uniq | wc -l)
echo "$depth $size" > .dep-meta
popd > /dev/null
done
echo
echo ":: CloudFlare HTTP-based registry benchmarks"
speed=0
rate=0
# then, benchmark each against CloudFront
for ct in */Cargo.toml; do
dir=$(dirname "$ct")
[[ $dir != "stub" ]] || continue
echo "==> $dir"
# make crates-io use our local checkout
rm -r "$dir/.cargo" 2>/dev/null
mkdir -p "$dir/.cargo"
cat > "$dir/.cargo/config.toml" <<EOF
[source.crates-io]
registry = 'https://wut'
replace-with = 'the-http-one'
[source.the-http-one]
registry = 'sparse+https://crates-io-index-temp.rust-lang.org/6887cde41199f4e2934e64646c02e76f8061365e/'
EOF
# and fly!
bench http-cloudfront "$dir"
echo " -> breaking after first thing"
done
# then, benchmark each against CloudFlare
for ct in */Cargo.toml; do
echo "==> skipping CloudFlare for now"
break;
dir=$(dirname "$ct")
[[ $dir != "stub" ]] || continue
echo "==> $dir"
# make crates-io use our local checkout
rm -r "$dir/.cargo" 2>/dev/null
mkdir -p "$dir/.cargo"
cat > "$dir/.cargo/config.toml" <<EOF
[source.crates-io]
registry = 'https://wut'
replace-with = 'the-http-one'
[source.the-http-one]
registry = 'sparse+https://lib.rs/registry-proxy/'
EOF
# and fly!
bench http-cloudflare "$dir"
done
for s in 625k 1250k; do
echo "==> skipping local benchmarks for now"
break
speed=$s
for r in 17 150; do
rate=$r
echo " === ${s}Bps @ ${r}r/s =="
sed -i .bkp "s/limit_rate .*;/limit_rate $s;/" /usr/local/etc/nginx/nginx.conf
sed -i .bkp "/limit_req_zone/ s/rate=[0-9]*r/rate=${r}r/" /usr/local/etc/nginx/nginx.conf
nginx -s reload
# give it time
sleep 1
if [[ $r = 150 ]]; then
echo
echo ":: git-based registry benchmarks"
# then, benchmark each with standard API
for ct in */Cargo.toml; do
dir=$(dirname "$ct")
[[ $dir != "stub" ]] || continue
# we only care about checking git for one
# "big" project -- all the others will look
# the same.
if [[ $dir = "empty" || $dir = "one-dep" || $dir = "cargo-like" ]]; then
:
else
continue
fi
echo "==> $dir"
# make crates-io use our local checkout
rm -r "$dir/.cargo" 2>/dev/null
mkdir -p "$dir/.cargo"
cat > "$dir/.cargo/config.toml" <<EOF
[source.crates-io]
registry = 'https://wut'
replace-with = 'the-http-one'
[source.the-http-one]
registry = 'http://localhost:8080/git/'
EOF
# and fly!
bench git "$dir"
done
fi
if [[ $s = 1250k && $r != 17 ]]; then
echo
echo ":: http-based registry benchmarks (no changelog)"
# then, rewire all to use HTTP API and bench again
for ct in */Cargo.toml; do
dir=$(dirname "$ct")
[[ $dir != "stub" ]] || continue
echo "==> $dir"
# make crates-io use HTTP API
rm -r "$dir/.cargo" 2>/dev/null
mkdir -p "$dir/.cargo"
cat > "$dir/.cargo/config.toml" <<EOF
[source.crates-io]
registry = 'https://wut'
replace-with = 'the-http-one'
[source.the-http-one]
registry = 'sparse+http://localhost:8080/'
EOF
# and fly!
bench http "$dir"
done
echo
echo ":: http-based registry benchmarks (empty changelog)"
# finally, run again with -Z assume-empty-changelog
for ct in */Cargo.toml; do
echo "==> skipping"
break
dir=$(dirname "$ct")
[[ $dir != "stub" ]] || continue
echo "==> $dir"
# make crates-io use HTTP API
rm -r "$dir/.cargo" 2>/dev/null
mkdir -p "$dir/.cargo"
cat > "$dir/.cargo/config.toml" <<EOF
[source.crates-io]
registry = 'https://wut'
replace-with = 'the-http-one'
[source.the-http-one]
registry = 'sparse+http://localhost:8080/'
EOF
# and fly!
bench http-changelog "$dir" -Z assume-empty-changelog
done
fi
done
done