Skip to content

docs: ADR 0012, pool pre-ping is off and postgres_retry recovers dead connections - #56

Merged
lesnik512 merged 1 commit into
mainfrom
docs/adr-pre-ping-off
Oct 16, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
docs/adr-pre-ping-off

Conversation

@lesnik512

Copy link
Copy Markdown
Member

ADR 0012 records why pool_pre_ping is off (#54). The record also states the rule that pays for the decision: every query a retried use case runs must be inside its Transaction block.

Measurements behind the ADR

chat-app main at 31eee00 (db-retry 0.8.0). The app (granian, 1 worker), Postgres 17 and an httpx load generator ran as containers on one Docker network on Docker Desktop. Only DB_POOL_PRE_PING differed between runs. Each run had a 5 s warm-up and a 10 s window, the API was recreated at each switch, and on and off alternated. No run had errors.

Postgres's statement log for 500 GET /api/auth/me/ requests shows each request making two pool checkouts, one for the token-revocation check and one for the use case. With pre-ping on there were 2002 BEGINs and 1001 ROLLBACKs, against 1002 and 1 with it off. The ; ping itself isn't logged.

Local network, 3 rounds (req/s per round, median p50 and p99):

endpoint clients on req/s off req/s on p50 off p50 on p99 off p99
GET /api/auth/me/ 1 543 / 612 / 553 748 / 759 / 707 1.80 ms 1.30 ms 2.27 ms 1.84 ms
GET /api/auth/me/ 20 1026 / 977 / 1034 1210 / 1201 / 1219 18.89 ms 15.67 ms 39.50 ms 33.91 ms
GET /api/chats/{id}/messages/ 1 543 / 474 / 550 583 / 580 / 580 1.80 ms 1.70 ms 2.50 ms 2.23 ms
GET /api/chats/{id}/messages/ 20 727 / 616 / 725 805 / 801 / 812 27.10 ms 23.95 ms 50.59 ms 45.52 ms

tc qdisc add dev eth0 root netem delay 1ms on the db container, 2 rounds:

endpoint clients on req/s off req/s on p50 off p50 on p99 off p99
GET /api/auth/me/ 1 24 / 24 40 / 41 41.96 ms 25.15 ms 51.96 ms 32.14 ms
GET /api/auth/me/ 20 170 / 171 403 / 398 117.44 ms 50.25 ms 188.37 ms 82.83 ms
GET /api/chats/{id}/messages/ 1 20 / 20 33 / 32 50.50 ms 30.33 ms 58.06 ms 42.82 ms
GET /api/chats/{id}/messages/ 20 160 / 161 332 / 334 124.26 ms 60.02 ms 177.83 ms 89.71 ms

@lesnik512
lesnik512 merged commit d174f7e into main Oct 16, 2026
4 checks passed
@lesnik512
lesnik512 deleted the docs/adr-pre-ping-off branch October 16, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant