Granularity of Persistent Objects
Greetings. I'm developing a Zope (2.7) product, and I've got a particular persistent object that's going to be a real bottleneck, in that there will be many threads trying to change the state of the object more or less simultaneously. I'd like to "spread out" the problem by taking member fields of the object (lists, dictionaries, etc.) and making them persistent sub-objects in their own right. That way, changes made to one of them can be saved to the ZODB without causing thread conflicts with changes being made to others, removing at least some of the thred conflicts. However, I don't know how to do this. Is it as simple as using a PersistentMapping where I'd normally use a standard Python dictionary? Or shall I wrap each one in a custom class that subclasses Persistent? Does my parent object have to handle these in any special way so that the ZODB knows to give them their own DB records? I've tried looking at how ObjectManager does things, and found it less than enlightening. Thanks, ..Ian Beatty University of Massachusetts Amherst
On Thu, Jul 15, 2004 at 02:54:54PM -0400, Ian Beatty wrote:
Greetings.
I'm developing a Zope (2.7) product, and I've got a particular persistent object that's going to be a real bottleneck, in that there will be many threads trying to change the state of the object more or less simultaneously. I'd like to "spread out" the problem by taking member fields of the object (lists, dictionaries, etc.) and making them persistent sub-objects in their own right. That way, changes made to one of them can be saved to the ZODB without causing thread conflicts with changes being made to others, removing at least some of the thred conflicts.
sounds reasonable...
However, I don't know how to do this. Is it as simple as using a PersistentMapping where I'd normally use a standard Python dictionary?
Instead of PersistentMapping, see the various flavors of BTree, e.g. OOBTree, IOBTree. These do their own conflict resolution and in your scenario that could be a big help. -- Paul Winkler http://www.slinkp.com
Ian Beatty wrote:
However, I don't know how to do this. Is it as simple as using a PersistentMapping where I'd normally use a standard Python dictionary?
Well, yes.
Or shall I wrap each one in a custom class that subclasses Persistent?
That is usually an even better idea. And for big dictionaries, you may want to use the BTree objects for storage.
Or shall I wrap each one in a custom class that subclasses Persistent?
That is usually an even better idea. And for big dictionaries, you may want to use the BTree objects for storage.
So in my containing class, I just have class MyContainer( Persistent ): subObject = None def __init__( self ): self.subObject = BTree() and etc.? That's all there is to it?? Thanks, ..Ian
In article <efc3518404071606004a444b82@mail.gmail.com> you write:
Or shall I wrap each one in a custom class that subclasses Persistent?
That is usually an even better idea. And for big dictionaries, you may want to use the BTree objects for storage.
So in my containing class, I just have
class MyContainer( Persistent ): subObject = None def __init__( self ): self.subObject = BTree()
and etc.? That's all there is to it??
Yes, that's it. You can even store BTree's in BTree's if you fancy :) Florent
-- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com
participants (4)
-
Florent Guillaume -
Ian Beatty -
Lennart Regebro -
Paul Winkler