Re: Multithreaded connection pooling support for ZODB databases?
Etienne Robillard <[email protected]> Mon, 16 Apr 2018 04:15:55 -0400
| Newsgroups | gmane.comp.web.zope.zodb |
|---|---|
| Message-ID | <[email protected]> |
Hi Chris!
Thanks for your input. :)
I needed to make an api to support multiple ZODB database(s)
connection(s) to multiple ZODB backends.
Here's a updated version of my code so far using threading.local :
from threading import local
from notmm.dbapi.orm import ClientStorageProxy
class ThreadedConnectionPool(object):
def __init__(self, d, debug=True):
if debug:
assert isinstance(d, dict) == True
local.pool = d
for key,value in local.pool.iteritems():
log.debug("Initializing db: %s" % key)
local.pool[key] = ClientStorageProxy(value)
self.pool = local.pool
def __getitem__(self, key):
try:
v = self.pool[key]
except KeyError:
return None
return v
Usage:
>>> pool = ThreadedConnectionPool({
>>> 'db_default': '127.0.0.1:4343',
>>> 'db_blog': '127.0.0.1:4545',
>>> })
>>> db = pool['db_default']
Kind regards,
Etienne
Le 2018-04-16 à 02:21, Christopher Lozinski a écrit :
>
>
>> On Apr 15, 2018, at 8:17 PM, Etienne Robillard <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>> I would like to define a `ThreadedConnectionPoll` class to allow
>> multithreaded caching of ZODB databases into memory.
>
> Why would you want to do that. What is wrong with the current approach?
>
> Each cache consumes memory. So there is a price. Is it worth it?
>
> Why not use multiple ZEO clients?
>
> It is really good to provide motivation for what you want to do.
> Maybe there is an easier way.
>
> Chris
>
--
Etienne Robillard
[email protected]
https://www.isotopesoftware.ca/
--
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.