Re: overhead of ZEO connection

Tres Seaver <[email protected]>
Newsgroups gmane.comp.web.zope.zodb
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/06/2016 09:33 AM, Sanjay Rao wrote:

> In this post I want to understand the overhead of creating database 
> connections in a zope application what is overhead of creating a new 
> connection to ZEO ?
> 
> which one is recommended ?
> 
> - Create a connection - Use this connection for each transaction 
> commit (one transaction commit could be bounded into one function) - 
> Close connection when application terminates
> 
> OR
> 
> - Create one separate connection for each transaction commit - Commit 
> transaction - Close connection .....

You definitely don't want to *destroy* the connection at transaction
boundaries:  each connection holds a cache (in RAM) of objects retrieved
from the database.  The `ZODB.DB.DB` object, which holds onto the
storage, also maintains a connection pool.  The usual pattern would be:

- ------------------------- %< -------------------------
# At startup
from ZODB.DB import DB
from ZEO.ClientStorage impport ClientStorage

storage = ClientStoraget((192.168.1.200, 9876))
db = DB(storage)

# Whenever you need a connection
conn = db.open()  # checks it out of the pool
root = conn.root()

# Use the root object to do work
try:
    do_something_with(root)
except Exception:
    transaction.abort()
    raise
else:
    transaction.commit()

conn.close()  # return 'conn' to the pool
- ------------------------- %< -------------------------

Zope follows this pattern for each HTTP request it serves.  Hope that helps,


Tres.
- -- 
===================================================================
Tres Seaver          +1 540-429-0999          [email protected]
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBAgAGBQJXLKPaAAoJEPKpaDSJE9HYtm4QAI/ZDu8GiEG4egEcl8zXzThK
/yDeq8ciIIPDWPUCsCRC26IQIhonq/GXUsEde7LCIbeLNfvTns/W6Kv4glCpX8zx
Ap+MYmpx2Dozj7dipiHJgCgZbbx9LZbTwKS2MbaNU1KgLEetk5EkdYPxj3tBV3Ad
KxGZ5zdLWKeh9YhBnkEJNBBfyvjRXO/jSvNEVL40o0LT49JvzvcMkJn9c6qudjNE
6bAjqLr1MVrw62+U8xn9MuBEPv5wqSVEH2+kb7x8MqrW2yhdWi3UjgjpubRoqlHK
u1Xf8wojF6dxyWuOJ7X2aiO/qlDYPpIaTIBkWcZWzYLybXnPqveSIzi8Y5T8rw0Y
4meZKUkoNsqUmSpIp/8mxOX4j2ZkicLLITEezFQwC76VyUmbuD03Doyl+bJzBRh5
kAvIR/7BzW6pa3TMnEfteUClHG0NwloqVHIsSp9/mtO6OdEa/6bvMdVUD2lwC80X
PMQumfAG2CEnQTwVssFCj+BVxBK7Fp6iIgMppUifeiRTX+2+jFT5DpCU6mp73jm4
2EgJeDFbzbm0P5UwrTcUlVWpU3iglwKUfvXn80WXtL5CE9hU/k/g6HYadIz2lxQj
wS4rYcM4lPuodwYwYhj4iTcCoIkQ7QH2kI8mhYoiWTV0Pgjm7Iun/C86t48CGF4L
49zxIkN8tM5BgCnrPgCU
=C0Cx
-----END PGP SIGNATURE-----

-- 
You received this message because you are subscribed to the Google Groups "zodb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.