_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

Connection Pooling

27. 04. 2024 1 min read intermediate

Každé DB spojení stojí ~10MB RAM. Bez poolingu vytvoříte stovky spojení a DB se zhroutí.

Proč pooling

  • TCP handshake + TLS = ~100ms per connection
  • PostgreSQL fork per connection = ~10MB RAM
  • Max connections limit (default 100)
  • Connection reuse = dramaticky nižší latence

SQLAlchemy pool

from sqlalchemy import create_engine engine = create_engine( “postgresql://user:pass@localhost/db”, pool_size=20, max_overflow=10, pool_timeout=30, pool_recycle=1800, # Recyklace po 30 min )

PgBouncer

pgbouncer.ini

[databases] mydb = host=localhost port=5432 dbname=mydb [pgbouncer] pool_mode = transaction # Doporučeno max_client_conn = 1000 default_pool_size = 25

Key Takeaway

Vždy poolujte. SQLAlchemy pool_size=20, PgBouncer pro sdílení poolu mezi aplikacemi.

databaseconnection poolpostgresqlperformance
Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.