[ZODB-Dev] create unique container keys
Jim Fulton
jim at zope.com
Thu Apr 2 11:39:47 EDT 2009
On Apr 2, 2009, at 4:19 AM, Adam GROSZER wrote:
> Hello,
>
> What's a good practice to create unique container keys for a heavily
> loaded application? (I mean lots of writes to the same container)
> Obviously having a counter on the container and incrementing and using
> that for key gives write conflicts.
>
> What do the experts use?
Assuming that ordering of the keys isn't important, my favorite
strategy is to:
- use integer keys, which saves memory and makes lookup faster if you
use an IOBTree.
- assign keys sequentially with random starting points, using a _v_
variable to keep track of the index. The idea is that instances in
separate threads/processes use different random starting points, to
avoid conflicts, but assign keys sequentially to update the btree
efficiently.
See for example _generateId in:
http://svn.zope.org/zope.intid/trunk/src/zope/intid/__init__.py?rev=95793&view=auto
Jim
--
Jim Fulton
Zope Corporation
More information about the ZODB-Dev
mailing list