-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathrun_benchmark.sh
executable file
·121 lines (101 loc) · 3.07 KB
/
run_benchmark.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
#!/usr/bin/env bash
RECOMPILE_PGCAT=0
PGCAT_ONLY=0
PGBOUNCER_ONLY=0
for ((i=1;i<=$#;i++));
do
if [ ${!i} = "--pgcat-only" ]
then
PGCAT_ONLY=1
elif [ ${!i} = "--pgbouncer-only" ]
then
PGBOUNCER_ONLY=1
elif [ ${!i} = "--recompile" ]
then
RECOMPILE_PGCAT=1
fi
done;
drop_and_recreate_database() {
docker compose stop proxy &> /dev/null # Avoid errors if proxy is connected to the database
docker compose exec --env PGPASSWORD=main_user postgres psql -p 5432 -h 127.0.0.1 -U main_user -d postgres -c "DROP DATABASE shard0" &> /dev/null
docker compose exec --env PGPASSWORD=main_user postgres psql -p 5432 -h 127.0.0.1 -U main_user -d postgres -c "CREATE DATABASE shard0" &> /dev/null
docker compose start proxy &> /dev/null
wait_for_proxy
}
run_benchmark() {
docker compose exec --env PGPASSWORD=main_user proxy pgbench -p $1 -h 127.0.0.1 -U main_user -i shard0
docker compose exec --env PGPASSWORD=main_user proxy pgbench -t 25000 -c 128 -j 2 -p $1 -h 127.0.0.1 -U main_user -S --protocol extended shard0
}
wait_for_proxy() {
until docker compose exec --env PGPASSWORD=main_user proxy psql -p 6432 -h 127.0.0.1 -U main_user -d shard0 -c "select 1" &> /dev/null
do
echo "Waiting for postgres server"
sleep 1
done
sleep 2
}
benchmark_pgbouncer() {
echo "======================"
echo "Running Pgbouncer Test"
echo "======================"
cd pgbouncer
docker compose down -v # Remove any stored data from previous runs
docker compose up -d &> /dev/null
wait_for_proxy
echo ""
echo "================================================"
echo "[Pgbouncer] Running test directly against the DB"
echo "================================================"
drop_and_recreate_database
run_benchmark 5432
echo ""
echo "=========================================="
echo "[Pgbouncer] Running test against the proxy"
echo "=========================================="
drop_and_recreate_database
run_benchmark 6432
echo ""
echo ""
cd ..
}
benchmark_pgcat() {
echo "=========="
echo "Pgcat Test"
echo "=========="
cd pgcat
if [ $RECOMPILE_PGCAT = 1 ];
then
echo "Recompiling Pgcat"
docker compose build proxy --no-cache
fi
docker compose down -v # Remove any stored data from previous runs
docker compose up -d &> /dev/null
wait_for_proxy
echo ""
echo "============================================"
echo "[Pgcat] Running test directly against the DB"
echo "============================================"
drop_and_recreate_database
run_benchmark 5432
echo ""
echo "======================================"
echo "[Pgcat] Running test against the proxy"
echo "======================================"
drop_and_recreate_database
run_benchmark 6432
echo ""
echo ""
cd ..
}
if [ $PGCAT_ONLY = 1 ]
then
benchmark_pgcat
exit 0
fi
if [ $PGBOUNCER_ONLY = 1 ]
then
benchmark_pgbouncer
exit 0
fi
benchmark_pgbouncer
benchmark_pgcat