[Zope3-dev] thread.local & da-connection

Stuart Bishop stuart at stuartbishop.net
Fri Sep 2 00:42:53 EDT 2005


Garanin Michael wrote:
> Hello!
> I have situation: 
> 1) I have PostgreSQL database: max-connection == 5
> 2) I have one IZopeDatabaseAdapter
> 2) I create 10 threads and join's (!!!)  to main thread
> 2.1) In each thread i get IZopeConnection from IZopeDatabaseAdapter
> 2.2) execute simple select-statement & call transaction.commit
> 
> Result: sometimes (~ 1/10) i get exception "connection limit exceeded". 
> I think: problem is safety stopped threads (and his locals) in memory
> along short time => connections also in memory short time and not
> destroed and not closed. Of course, i can call 'disconnect' every time,
> but it's bad.
> 
> May be make connections-pool (only da with threadsafety==2) and after
> transaction.commit\abort move connection to connections-pool for use in
> other threads?

I would wrap pyPgSql instead and put your connection pool in at this level.
Other database adapters (such as psycopg2 I believe) already have connection
pooling and ensure that the connections are properly reset before being
reused. Your pyPgSql with connection pooling can then be used for other
Python applications, and you don't have to reengineer special
ZopeDatabaseAdapters to handle threadsafety>2 drivers.

(In fact, there is probably a generic connection pooling wrapper already
written)

You still have the issue of what to do when Zope needs the 6th connection -
block or raise an exception?

-- 
Stuart Bishop <stuart at stuartbishop.net>
http://www.stuartbishop.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://mail.zope.org/pipermail/zope3-dev/attachments/20050902/f073418e/signature.bin


More information about the Zope3-dev mailing list