Skip to content

Commit 378c96e

Browse files
authored
Profiling utils (#595)
* Profiling utils * Fix CI trigger
1 parent 59627b9 commit 378c96e

File tree

13 files changed

+149
-11
lines changed

13 files changed

+149
-11
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: ci
22
on:
33
push:
4+
branches:
5+
- main
46
pull_request:
57
types: [opened, synchronize, reopened]
68

cli.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
#
3+
# Dev CLI.
4+
#
5+
6+
# Connect to the admin database.
7+
function admin() {
8+
PGPASSWORD=pgdog psql -h 127.0.0.1 -p 6432 -U admin admin
9+
}
10+
11+
# Run pgbench.
12+
#
13+
# Arguments:
14+
#
15+
# - protocol: simple|extended|prepared
16+
#
17+
function bench() {
18+
PGPASSWORD=pgdog pgbench -h 127.0.0.1 -p 6432 -U pgdog pgdog --protocol ${1:-simple}
19+
}
20+
21+
# Parse command
22+
case "$1" in
23+
admin)
24+
admin
25+
;;
26+
bench)
27+
bench $1
28+
;;
29+
*)
30+
echo "Usage: $0 {admin} {bench}"
31+
exit 1
32+
;;
33+
esac

integration/pgbench/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ run_pgdog
77
wait_for_pgdog
88

99
bash ${SCRIPT_DIR}/dev.sh
10+
bash ${SCRIPT_DIR}/stress.sh
1011

1112
stop_pgdog

integration/pgbench/stress.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
#
3+
# This will create a decent amount of churn on the network & message
4+
# buffers, by generating different size responses.
5+
#
6+
set -e
7+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
8+
export PGPASSWORD=pgdog
9+
10+
pushd ${SCRIPT_DIR}
11+
pgbench -h 127.0.0.1 -U pgdog -p 6432 pgdog -t 100 -c 10 --protocol simple -f stress.sql -P 1
12+
popd

integration/pgbench/stress.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
\set response_size (random(2, 1000000))
2+
3+
-- Generate large response from server.
4+
-- Range: 2 bytes to 1M
5+
SELECT
6+
string_agg(substr('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', (random()*61+1)::int, 1), '')
7+
FROM generate_series(1, :response_size);

pgdog/tests/flame/base/pgdog.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[[databases]]
2+
name = "pgdog"
3+
host = "127.0.0.1"
4+
5+
[admin]
6+
password = "pgdog"

pgdog/tests/flame/base/users.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[[users]]
2+
name = "pgdog"
3+
password = "pgdog"
4+
database = "pgdog"

pgdog/tests/flame/profile.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
#
3+
# Utils for performance testing.
4+
#
5+
set -e
6+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
7+
export PGDOG_BIN=${SCRIPT_DIR}/../../../target/release/pgdog
8+
export PGPASSWORD=pgdog
9+
export PGUSER=pgdog
10+
export PGDATABASE=pgdog
11+
export PGHOST=127.0.0.1
12+
export PGPORT=6432
13+
14+
if [ ! -f ${PGDOG_BIN} ]; then
15+
echo "PgDog is not compiled in release mode (target/release/pgdog is missing)"
16+
echo "Please compile PgDog with:"
17+
echo
18+
printf "\tcargo build --release"
19+
echo
20+
echo
21+
exit 1
22+
fi
23+
24+
if ! which samply > /dev/null; then
25+
echo "Samply profiler is not installed on this system"
26+
echo "Please install Samply with:"
27+
echo
28+
printf "\tcargo install samply"
29+
echo
30+
echo
31+
exit 1
32+
fi
33+
34+
paranoid=$(cat /proc/sys/kernel/perf_event_paranoid)
35+
36+
if [ ! "$paranoid" -eq "-1" ]; then
37+
echo "\"/proc/sys/kernel/perf_event_paranoid\" need to be set to -1 for sampling profiler to work"
38+
echo "Please set it manually by running:"
39+
echo
40+
printf "\techo '-1' | sudo tee /proc/sys/kernel/perf_event_paranoid"
41+
echo
42+
echo
43+
exit 1
44+
fi
45+
46+
function profile_pgdog() {
47+
pushd $1
48+
samply record ${PGDOG_BIN} &
49+
pid=$!
50+
51+
while ! pg_isready > /dev/null; do
52+
sleep 1
53+
done
54+
55+
pgbench -i
56+
pgbench -c 10 -t 1000000 -S -P 1 --protocol extended
57+
58+
kill -TERM $pid
59+
popd
60+
}
61+
62+
if [ ! -d "$1" ]; then
63+
echo "Benchmark $1 doesn't exist."
64+
echo "Available benchmarks:"
65+
echo "$(ls -d */)"
66+
exit 1
67+
fi
68+
69+
profile_pgdog $1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[[databases]]
2+
name = "pgdog"
3+
host = "127.0.0.1"
4+
5+
[[databases]]
6+
name = "pgdog"
7+
host = "127.0.0.1"
8+
role = "replica"
9+
10+
[admin]
11+
password = "pgdog"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[[users]]
2+
name = "pgdog"
3+
password = "pgdog"
4+
database = "pgdog"

0 commit comments

Comments
 (0)