[ZODB-Dev] Opening your own parallel transactions/database connections in Zope

Christian Theune ct at gocept.com
Tue Feb 24 03:14:09 EST 2004


On Sat, 2004-02-21 at 09:45, Dieter Maurer wrote:
> Christian Theune wrote at 2004-2-17 20:49 +0000:
> > ...
> >Now, in the loop of the thread I handle database connectivity in this
> >way (copy of the code, a little bit simplified, there are some sleep()
> >and application relevant lines missing):
> >
> >
> >-----
> >    def run2(self):
> >        # try to get a zodb connection
> >        work = None
> >        app=Zope.bobo_application()
> >        while 1:
> >            if work:
> >                work = 0
> >                try:
> >                    get_transaction().commit()
> >                except:
> >                    get_transaction().abort()
> >                    check_app._p_jar.sync()
> >                continue
> 
> This is a funny place for "commit/abort".
> 
> I think your code should look like:
> 
> 	while 1:
> 	      self.doInTransaction(self.checkAndProcess)
> 
> With "doInTransaction" like:
> 
> 	def doInTransaction(self,f):
> 	    while 1:
> 		  self.connection.sync()
> 		  try:
> 			f()
> 			get_transaction().commit()
> 		  except ConflictError:
> 			get_transaction().abort()
> 			# maybe retries controlled
> 			continue
> 		  except:
> 			get_transaction().abort()
> 			raise
> 		  else:	return


Ok, I already refactored the code after finding that getting a handle to
a connection works better when using get_module_info from the
ZPublisher.

I don't know if I need the connection.sync() call -- it seems to work
without and I don't actually know where it's for.

> The ZODB helds locks only within internal processing.
> Only transaction clients should be able to extend the time period
> the locks are held. Than can happen when e.g. the connection
> to a database hangs (due to network problems).
> Huge commits (which may later be aborted in the second commit phase)
> may also cause extended locking time.

I have had some hangs when the thread works with a single database
connection for each transaction, it seems to allocate too much or so. Is
there a limit on the concurrent connections to the database? Making it
use the connection for the whole thread works stable.

Cheers,
Christian

-- 
Christian Theune, gocept gmbh & co. kg
http://www.gocept.com - ct at gocept.com
fon: 03496 3099112 fax: 03496 3099118 mobile: 0179 7808366
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://mail.zope.org/pipermail/zodb-dev/attachments/20040224/2ca2e712/attachment.bin


More information about the ZODB-Dev mailing list