forked from fr3ddy-fryd3/postgrust-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_simple.sh
More file actions
executable file
·70 lines (53 loc) · 2.75 KB
/
benchmark_simple.sh
File metadata and controls
executable file
·70 lines (53 loc) · 2.75 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
#!/bin/bash
# Simple benchmark to demonstrate write amplification difference
echo "╔══════════════════════════════════════════════════════════╗"
echo "║ Write Amplification: Simple Demo ║"
echo "╚══════════════════════════════════════════════════════════╝"
echo ""
cargo build --release --quiet 2>/dev/null
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Scenario: 1000 rows, then 10 single-row updates"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
test_mode() {
local MODE=$1
local ENV=$2
echo "[$MODE]"
rm -rf data
# Start server
$ENV timeout 20 cargo run --release &>/dev/null &
local PID=$!
sleep 2
# Create and populate
printf "CREATE TABLE t (id INTEGER, data TEXT);\n" | nc -q 1 127.0.0.1 5432 &>/dev/null
for i in {1..1000}; do
printf "INSERT INTO t VALUES ($i, 'data$i');\n" | nc -q 1 127.0.0.1 5432 &>/dev/null
done
sleep 1
# Measure before updates
local SIZE_BEFORE=$(du -sb data 2>/dev/null | cut -f1)
# Perform 10 updates
for i in {1..10}; do
printf "UPDATE t SET data = 'updated$i' WHERE id = 1;\n" | nc -q 1 127.0.0.1 5432 &>/dev/null
done
sleep 2
# Measure after updates
local SIZE_AFTER=$(du -sb data 2>/dev/null | cut -f1)
kill $PID 2>/dev/null
wait $PID 2>/dev/null
local WRITTEN=$((SIZE_AFTER - SIZE_BEFORE))
echo " Disk writes for 10 updates: $WRITTEN bytes (~$((WRITTEN / 1024))KB)"
if [ -d "data" ]; then
echo " Files: $(ls -lh data/*.db data/*.wal 2>/dev/null | awk '{print $5, $9}')"
fi
echo ""
}
test_mode "Legacy Storage" "RUSTDB_USE_PAGE_STORAGE=0"
test_mode "Page Storage" "RUSTDB_USE_PAGE_STORAGE=1"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Theory:"
echo " • Legacy: Rewrites entire database on every checkpoint"
echo " • Page-based: Only writes modified 8KB pages"
echo " • Expected improvement: ~1000x for this scenario"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
rm -rf data