feat: coordinate timeout chain and add failover load profile

HAProxy checks get fastinter 500ms and timeout check 2.5s (hung replica
detected within 6.5 s), http-reuse never with uvicorn keep-alive 60 s so
the LB closes idle replica connections, and app connections set
idle_in_transaction_session_timeout so a frozen replica releases its
idempotency key. The bench stand runs behind HAProxy with N replicas and
gains the failover profile (make bench_failover / bench_failover_quick):
constant-rate writes with a key and reads while each replica is stopped,
killed or paused, with per-second timeline, detection and recovery time
and write reconciliation. Driver commands idle-conns and hang-key check
the keep-alive and hung-transaction decisions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 23:21:12 +03:00
co-authored by Claude Opus 5.5
parent b76a666621
commit 459f84c75c
25 changed files with 2400 additions and 269 deletions
+12 -4
View File
@@ -37,6 +37,17 @@ class BoundedCloseConnection(asyncpg.Connection):
def create_engine(database: Database) -> AsyncEngine:
"""Engine с ограниченным пулом и таймаутами из `[database]`."""
server_settings = {
"application_name": DB_APPLICATION_NAME,
"statement_timeout": str(database.statement_timeout_ms),
}
if database.idle_in_transaction_timeout_ms:
# транзакцию замороженного процесса (docker pause) PostgreSQL
# прерывает сам: TCP-соединение живо, и иначе её блокировки, в
# том числе ключа идемпотентности, держались бы до разморозки
server_settings["idle_in_transaction_session_timeout"] = str(
database.idle_in_transaction_timeout_ms,
)
return create_async_engine(
database.url,
pool_size=database.pool_size,
@@ -55,10 +66,7 @@ def create_engine(database: Database) -> AsyncEngine:
connect_args={
"timeout": database.connect_timeout_seconds,
"connection_class": BoundedCloseConnection,
"server_settings": {
"application_name": DB_APPLICATION_NAME,
"statement_timeout": str(database.statement_timeout_ms),
},
"server_settings": server_settings,
},
)