Skip to content

Commit d8dca2c

Browse files
committed
feat: add pgcat to benchmark
1 parent 2edf736 commit d8dca2c

File tree

5 files changed

+167
-16
lines changed

5 files changed

+167
-16
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#
2+
# PgCat config example.
3+
#
4+
5+
#
6+
# General pooler settings
7+
[general]
8+
# What IP to run on, 0.0.0.0 means accessible from everywhere.
9+
host = "0.0.0.0"
10+
11+
# Port to run on, same as PgBouncer used in this example.
12+
port = 6434
13+
14+
# Whether to enable prometheus exporter or not.
15+
enable_prometheus_exporter = true
16+
17+
# Port at which prometheus exporter listens on.
18+
prometheus_exporter_port = 9930
19+
20+
# How long to wait before aborting a server connection (ms).
21+
connect_timeout = 5000
22+
23+
# How much time to give `SELECT 1` health check query to return with a result (ms).
24+
healthcheck_timeout = 1000
25+
26+
# How long to keep connection available for immediate re-use, without running a healthcheck query on it
27+
healthcheck_delay = 30000
28+
29+
# How much time to give clients during shutdown before forcibly killing client connections (ms).
30+
shutdown_timeout = 60000
31+
32+
# For how long to ban a server if it fails a health check (seconds).
33+
ban_time = 60 # seconds
34+
35+
# If we should log client connections
36+
log_client_connections = false
37+
38+
# If we should log client disconnections
39+
log_client_disconnections = false
40+
41+
# TLS
42+
# tls_certificate = "server.cert"
43+
# tls_private_key = "server.key"
44+
45+
# Credentials to access the virtual administrative database (pgbouncer or pgcat)
46+
# Connecting to that database allows running commands like `SHOW POOLS`, `SHOW DATABASES`, etc..
47+
admin_username = "cipherstash"
48+
admin_password = "password"
49+
50+
# pool
51+
# configs are structured as pool.<pool_name>
52+
# the pool_name is what clients use as database name when connecting
53+
# For the example below a client can connect using "postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded"
54+
[pools.cipherstash]
55+
# Pool mode (see PgBouncer docs for more).
56+
# session: one server connection per connected client
57+
# transaction: one server connection per client transaction
58+
pool_mode = "session"
59+
60+
# If the client doesn't specify, route traffic to
61+
# this role by default.
62+
#
63+
# any: round-robin between primary and replicas,
64+
# replica: round-robin between replicas only without touching the primary,
65+
# primary: all queries go to the primary unless otherwise specified.
66+
default_role = "any"
67+
68+
# Query parser. If enabled, we'll attempt to parse
69+
# every incoming query to determine if it's a read or a write.
70+
# If it's a read query, we'll direct it to a replica. Otherwise, if it's a write,
71+
# we'll direct it to the primary.
72+
query_parser_enabled = false
73+
74+
# If the query parser is enabled and this setting is enabled, we'll attempt to
75+
# infer the role from the query itself.
76+
query_parser_read_write_splitting = false
77+
78+
# If the query parser is enabled and this setting is enabled, the primary will be part of the pool of databases used for
79+
# load balancing of read queries. Otherwise, the primary will only be used for write
80+
# queries. The primary can always be explicitly selected with our custom protocol.
81+
primary_reads_enabled = true
82+
83+
# So what if you wanted to implement a different hashing function,
84+
# or you've already built one and you want this pooler to use it?
85+
#
86+
# Current options:
87+
#
88+
# pg_bigint_hash: PARTITION BY HASH (Postgres hashing function)
89+
# sha1: A hashing function based on SHA1
90+
#
91+
sharding_function = "pg_bigint_hash"
92+
93+
# Credentials for users that may connect to this cluster
94+
[pools.cipherstash.users.0]
95+
username = "cipherstash"
96+
password = "password"
97+
# Maximum number of server connections that can be established for this user
98+
# The maximum number of connection from a single Pgcat process to any database in the cluster
99+
# is the sum of pool_size across all users.
100+
pool_size = 100
101+
min_pool_size = 20
102+
103+
# Maximum query duration. Dangerous, but protects against DBs that died in a non-obvious way.
104+
statement_timeout = 0
105+
106+
# Shard 0
107+
[pools.cipherstash.shards.0]
108+
109+
servers = [["host.docker.internal", 5532, "primary"]]
110+
111+
database = "cipherstash"

tests/benchmark/mise.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ mise --env tcp run postgres:setup
8888
mise run benchmark:setup
8989
9090
mise --env tcp run pgbouncer:up --extra-args "--detach --wait"
91+
mise --env tcp run pgcat:up --extra-args "--detach --wait"
9192
mise --env tcp run proxy:up proxy --extra-args "--detach --wait"
9293
mise --env tcp run test:wait_for_postgres_to_quack --port 6432 --max-retries 20
9394
@@ -101,6 +102,7 @@ echo
101102
# # Extended protocol with default script
102103
mise run benchmark_service --target=postgres --protocol=extended --port=5532 --time=5
103104
mise run benchmark_service --target=pgbouncer --protocol=extended --port=6433 --time=5
105+
mise run benchmark_service --target=pgcat --protocol=extended --port=6434 --time=5
104106
mise run benchmark_service --target=proxy --protocol=extended --port=6432 --time=5
105107
106108
@@ -112,6 +114,7 @@ echo
112114
113115
mise run benchmark_service --target=postgres --transaction=plaintext --protocol=extended --port=5532 --time=5
114116
mise run benchmark_service --target=pgbouncer --transaction=plaintext --protocol=extended --port=6433 --time=5
117+
mise run benchmark_service --target=pgcat --transaction=plaintext --protocol=extended --port=6434 --time=5
115118
mise run benchmark_service --target=proxy --transaction=plaintext --protocol=extended --port=6432 --time=5
116119
117120
@@ -156,9 +159,16 @@ rm -rf {{config_root}}/results/*.csv
156159
"""
157160

158161
[tasks."pgbouncer:up"]
159-
alias = 'u'
160162
description = "Run pgbouncer"
161163
run = """
162164
set -e
163165
echo docker compose up --build {{arg(name="service",default="pgbouncer")}} {{option(name="extra-args",default="")}} | bash
164166
"""
167+
168+
169+
[tasks."pgcat:up"]
170+
description = "Run pgcat"
171+
run = """
172+
set -e
173+
echo docker compose up --build {{arg(name="service",default="pgcat")}} {{option(name="extra-args",default="")}} | bash
174+
"""

tests/benchmark/plot.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,48 @@
55

66

77
MARKERS = {
8-
"proxy-extended-default": "o",
9-
"proxy-extended-plaintext": "o",
10-
"proxy-extended-encrypted": "o",
8+
"proxy-extended-default": "*",
9+
"proxy-extended-plaintext": "*",
10+
"proxy-extended-encrypted": "*",
1111

1212
"postgres-extended-default": ".",
1313
"postgres-extended-plaintext": ".",
1414

15+
"pgcat-extended-default": "o",
16+
"pgcat-extended-plaintext": "o",
17+
1518
"pgbouncer-extended-default": "s",
1619
"pgbouncer-extended-plaintext": "s",
1720
}
1821

1922
LINES = {
20-
"proxy-extended-default": "-",
21-
"proxy-extended-plaintext": "-",
23+
"proxy-extended-default": ":",
24+
"proxy-extended-plaintext": "--",
2225
"proxy-extended-encrypted": "-",
2326

2427
"postgres-extended-default": ":",
25-
"postgres-extended-plaintext": ":",
28+
"postgres-extended-plaintext": "--",
29+
30+
"pgcat-extended-default": "-",
31+
"pgcat-extended-plaintext": "--",
2632

2733
"pgbouncer-extended-default": "-",
28-
"pgbouncer-extended-plaintext": "-",
34+
"pgbouncer-extended-plaintext": "--",
2935
}
3036

3137
COLORS = {
32-
"proxy-extended-default": "xkcd:light pink",
33-
"proxy-extended-plaintext": "xkcd:pink",
34-
"proxy-extended-encrypted": "xkcd:hot pink",
38+
"proxy-extended-default": "xkcd:grey",
39+
"proxy-extended-plaintext": "xkcd:bright blue",
40+
"proxy-extended-encrypted": "xkcd:red orange",
3541

36-
"postgres-extended-default": "xkcd:sky blue",
42+
"postgres-extended-default": "xkcd:grey",
3743
"postgres-extended-plaintext": "xkcd:blue",
3844

39-
"pgbouncer-extended-default": "xkcd:light green",
40-
"pgbouncer-extended-plaintext": "xkcd:green",
45+
"pgcat-extended-default": "xkcd:grey",
46+
"pgcat-extended-plaintext": "xkcd:ocean blue",
47+
48+
"pgbouncer-extended-default": "xkcd:grey",
49+
"pgbouncer-extended-plaintext": "xkcd:cornflower blue",
4150
}
4251

4352

tests/benchmark/tasks/benchmark_service.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#USAGE flag "--time <time>" help="Time for each run"
66
#USAGE flag "--clients <clients>" help="Number of clients to run"
77
#USAGE flag "--target <target>" help="Target service" {
8-
#USAGE choices "postgres" "proxy" "pgbouncer"
8+
#USAGE choices "postgres" "proxy" "pgbouncer" "pgcat"
99
#USAGE }
1010
#USAGE flag "--protocol <protocol>" default="simple" help="Procol to use" {
1111
#USAGE choices "simple" "extended" "prepared"

tests/docker-compose.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ services:
128128
ports:
129129
- 6433:6433
130130
pull_policy: build
131-
build: benchmark/docker/pgbouncer
131+
build: ./benchmark/docker/pgbouncer
132132
networks:
133133
- postgres
134134
extra_hosts:
@@ -139,6 +139,27 @@ services:
139139
cpus: ${CPU_LIMIT_PGBOUNCER:-4}
140140
memory: ${CONTAINER_RAM_LIMIT_PGBOUNCER:-8g}
141141

142+
pgcat:
143+
image: ghcr.io/postgresml/pgcat:v1.2.0
144+
container_name: pgcat
145+
pull_policy: always
146+
ports:
147+
- 6434:6434
148+
command:
149+
- pgcat
150+
- /etc/pgcat/pgcat.toml
151+
volumes:
152+
- ./benchmark/docker/pgcat/pgcat.toml:/etc/pgcat/pgcat.toml
153+
networks:
154+
- postgres
155+
extra_hosts:
156+
- host.docker.internal:host-gateway
157+
deploy:
158+
resources:
159+
limits:
160+
cpus: ${CPU_LIMIT_PGCAT:-4}
161+
memory: ${CONTAINER_RAM_LIMIT_PGCAT:-8g}
162+
142163
networks:
143164
postgres:
144165
driver: bridge

0 commit comments

Comments
 (0)