Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
#!/bin/sh
#
# src/test/performance/cfs/pgbench_readwrite.sh
#
# Phase 13 / A13.1 -- read-write pgbench harness for CFS.
#
# Same matrix as pgbench_readonly.sh, but each transaction UPDATEs a random
# row.  This stresses the CFS write path (compress + append to .cfp + journal)
# and accumulates dead records; the dead counters are exact at
# checkpoints only (run one before reading them), which is the input for the
# background compactor (A8.5).
#
# Usage / environment: identical to pgbench_readonly.sh.
 
set -eu
 
HERE=$(cd "$(dirname "$0")" && pwd)
 
: "${PG_BINDIR:?PG_BINDIR must point at the postgres bin directory}"
: "${SCALE:=10000}"
: "${PAYLOAD_LEN:=320}"
: "${CLIENTS:=1 8 32 64}"
: "${DURATION:=15}"
: "${PGPORT:=55413}"
: "${LICENSE_FILE:=/tmp/license.xml}"
 
PSQL="$PG_BINDIR/psql"
PGBENCH="$PG_BINDIR/pgbench"
 
TABLES="perf_plain perf_lz4_1 perf_zstd_1 perf_zstd_3"
 
STARTED_CLUSTER=0
PGDATA="${1:-}"
 
cleanup()
{
    if [ "$STARTED_CLUSTER" = 1 ]; then
        "$PG_BINDIR/pg_ctl" -D "$PGDATA" -m fast stop >/dev/null 2>&1 || true
    fi
}
trap cleanup EXIT INT TERM
 
if [ -n "$PGDATA" ]; then
    export PGHOST=127.0.0.1
    if [ ! -d "$PGDATA" ]; then
        "$PG_BINDIR/initdb" -D "$PGDATA" --license "$LICENSE_FILE" --auth trust --no-locale -E UTF8 >/dev/null
    fi
    "$PG_BINDIR/pg_ctl" -D "$PGDATA" -l "$PGDATA/perf.log" \
        -o "-p $PGPORT -c shared_buffers=256MB -c max_connections=200" start >/dev/null 2>&1
    STARTED_CLUSTER=1
fi
 
export PGDATABASE=postgres
PSQLARGS="-h ${PGHOST:-127.0.0.1} -p ${PGPORT} -v ON_ERROR_STOP=1"
PGBARGS="-h ${PGHOST:-127.0.0.1} -p ${PGPORT}"
 
"$PSQL" $PSQLARGS -v rows="$SCALE" -v payload_len="$PAYLOAD_LEN" \
    -f "$HERE/cfs_perf_setup.sql"
"$PGBENCH" $PGBARGS -i -s 1 >/dev/null 2>&1 || true
 
printf '\n=== CFS read-write pgbench (scale=%s rows, payload=%s chars, %ss runs) ===\n\n' \
    "$SCALE" "$PAYLOAD_LEN" "$DURATION"
printf '%-14s %-8s %12s %12s\n' TABLE CLIENTS TPS lat_avg_ms
printf '%-14s %-8s %12s %12s\n' ----- ------ --- ----------
 
for tbl in $TABLES; do
    for c in $CLIENTS; do
        out=$("$PGBENCH" $PGBARGS -n -c "$c" -j "$c" -T "$DURATION" \
            -f "$HERE/pgbench_readwrite.sql" \
            -D "scale=$SCALE" -D "table=$tbl" 2>&1)
        tps=$(printf '%s\n' "$out" | awk '/^tps = / {print $3}')
        lat_ms=$(printf '%s\n' "$out" | awk '/latency average = / {print $4}')
        printf '%-14s %-8s %12s %12s\n' "$tbl" "$c" "${tps:-0}" "${lat_ms:-0}"
    done
done
 
echo
"$PSQL" $PSQLARGS -f "$HERE/cfs_perf_report.sql"