forked from aeyakovenko/percolator-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeasure-cu-scaling.sh
More file actions
executable file
·105 lines (88 loc) · 2.64 KB
/
measure-cu-scaling.sh
File metadata and controls
executable file
·105 lines (88 loc) · 2.64 KB
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
#!/bin/bash
# Measure CU scaling with 1.4M compute budget
# Creates accounts in tiers and measures keeper-crank CU
set -e
CLI="node dist/index.js"
SLAB="3K1P8KXJHg4Uk2upGiorjjFdSxGxq2sjxrrFaBjZ34D9"
ORACLE="HovQMDrbAgAYPCmHVSrezcSmkMtXSSUsLDFANExrZh2J"
FEE=1000000
CU_LIMIT=1400000
# Tiers to test
TIERS=(256 300 350 400 500 600 700 800 1000 1200 1400 1600 2000 2500 3000 3500 4096)
get_account_count() {
node -e "
const { Connection, PublicKey } = require('@solana/web3.js');
async function main() {
const conn = new Connection('https://api.devnet.solana.com');
const slabPk = new PublicKey('$SLAB');
const info = await conn.getAccountInfo(slabPk);
const data = info.data;
const engineOff = 208;
let totalBits = 0;
for (let wordIdx = 0; wordIdx < 64; wordIdx++) {
const off = engineOff + wordIdx * 8;
const word = data.readBigUInt64LE(off);
const bits = word.toString(2).split('1').length - 1;
totalBits += bits;
}
console.log(totalBits);
}
main();
" 2>&1 | grep -E "^[0-9]+$"
}
measure_crank_cu() {
local cu=$($CLI keeper-crank \
--slab $SLAB \
--oracle $ORACLE \
--compute-units $CU_LIMIT \
--simulate 2>&1 | grep -v "bigint:" | grep "Compute Units" | awk '{print $3}' | tr -d ',')
echo "$cu"
}
create_accounts() {
local target=$1
local current=$(get_account_count)
local needed=$((target - current))
if [ $needed -le 0 ]; then
echo "Already have $current accounts (>= $target)" >&2
return 0
fi
echo "Creating $needed accounts to reach $target..." >&2
for i in $(seq 1 $needed); do
$CLI init-user --slab $SLAB --fee $FEE 2>&1 | grep -v "bigint:" > /dev/null
if [ $((i % 50)) -eq 0 ]; then
echo " Created $i / $needed" >&2
fi
done
echo "Done. Now have $(get_account_count) accounts" >&2
}
echo "==========================================="
echo "CU SCALING TEST (1.4M CU Budget)"
echo "==========================================="
echo ""
echo "accounts,cu_consumed,percent_of_max"
# Measure current
current=$(get_account_count)
cu=$(measure_crank_cu)
pct=$((cu * 100 / CU_LIMIT))
echo "$current,$cu,$pct%"
# For each tier
for tier in "${TIERS[@]}"; do
create_accounts $tier
sleep 2 # Wait for devnet to settle
actual=$(get_account_count)
cu=$(measure_crank_cu)
if [ -z "$cu" ]; then
echo "$actual,ERROR,N/A"
continue
fi
pct=$((cu * 100 / CU_LIMIT))
echo "$actual,$cu,$pct%"
# Stop if we hit 95% of budget
if [ $cu -gt 1330000 ]; then
echo ""
echo "WARNING: Approaching 1.4M CU limit. Stopping." >&2
break
fi
done
echo ""
echo "Done!"