How to Warm Up Connection Pool ?

442 views
Skip to first unread message

mkmo...@gmail.com

unread,
Aug 23, 2022, 1:54:31 PM8/23/22
to sqlalchemy
As stated in the docs:

> All SQLAlchemy pool implementations have in common that none of them “pre create” connections - all implementations wait until first use before creating a connection

Is it possible to warm up, or pre create, the connections in the pool?

When I start my server, the connection pool is initially empty. I'm using Oracle and connection initialization has a lot of overhead. I'm seeing as high as 4 seconds sometimes.

The only way I can think of is to spawn a lot of threads that all check out a connection and release it after ~10 seconds. Is there a built in solution for this?

Thanks and best regards,

Matthew

Mike Bayer

unread,
Aug 23, 2022, 2:00:43 PM8/23/22
to noreply-spamdigest via sqlalchemy


On Tue, Aug 23, 2022, at 1:54 PM, mkmo...@gmail.com wrote:
As stated in the docs:

> All SQLAlchemy pool implementations have in common that none of them “pre create” connections - all implementations wait until first use before creating a connection

Is it possible to warm up, or pre create, the connections in the pool?

sure do a pre-connect like this:

conns = [engine.connect() for i in range(num_of_connections_you_want)]
for c in conns:
    c.close()

the connections are all made at the same time so that will establish individual connections in the pool.


When I start my server, the connection pool is initially empty. I'm using Oracle and connection initialization has a lot of overhead. I'm seeing as high as 4 seconds sometimes.

The only way I can think of is to spawn a lot of threads that all check out a connection and release it after ~10 seconds. Is there a built in solution for this?

Thanks and best regards,

Matthew


--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages