On Jun 24, 2011, at 11:01 AM, Tarek Ziadé wrote:

> Hello
> 
> I was wondering if there's a simple way to do per-host pooling.
> 
> Here's my use case: I have several hosts and on each one of them has
> several databases hosted in mysql.
> 
> the engine is tied to a specific database when you create it, so the
> default pool will pool connection on a specific database.
> 
> what I'd like to do is share the same pool of connectors across all
> engines that are working with a given host.f
> 
> Example in pseudo-code:
> 
> pool_server1 = Pool('mysql://server1', size=10)
> 
> engine1 = create_engine('mysql://server1/database1', pool=pool_server1)
> engine2 = create_engine('mysql://server1/database2', pool=pool_server1)
> 
> The goal is to reduce the number of sockets open for every host
> 
> Is there a way to do it with the existing pools ?   If not, I guess
> I'll work on a custom Pool,

well a pool is geared towards one specific connection which already has a 
"database" set up on it.    I guess maybe you'd use pool events to switch the 
"database" on checkout.

You can share a pool between engines using the "pool" argument to 
create_engine(), but one problem with that right now is that the dialect which 
is per-engine uses the "on first checkout" event to handle some important 
dialect initialization.  That step would have to be accommodated in some way.

Also this solution is only local to one Python process, not even a fork.  You 
might have a simpler time limiting TCP connections using a product like 
PGBouncer, and turn pooling way down or off for each SQLAlchemy pool, that way 
you can truly limit connections per host.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to