[ZODB-Dev] Unique Object ID

Casey Duncan casey at zope.com
Mon Jun 9 17:26:36 EDT 2003


On Monday 09 June 2003 04:11 pm, Christian Reis wrote:
> On Wed, Jun 04, 2003 at 11:32:37PM -0400, Casey Duncan wrote:
> > Actually Catalog uses a combination of random and sequencial ids. That way 
if 
> > many objects are added at once, they tend to cluster in the BTree data 
> > structure minimizing the number of nodes and buckets that need to be 
touched. 
> > Have a look at the catalogObject method of Catalog.py in the Zope head.
> 
> So something like time.time() + random would cluster better in our case?

I never suggested using time, ZCatalog does something like this:

uid = self._v_nextuid
while uid is None or self.stuff.has_key(uid):
    uid = randint(-2000000000, 2000000000)
self._v_nextuid = uid + 1
return uid
    
_v_nextuid defaults to None using a class attribute. For a single thread, this 
will tend to cluster uids sequencially so they don't touch as many buckets.  
Since _v_ attrs are thread specific, each thread willbe working from a 
different base uid.

I think using time might be problematic on certain *ahem* platforms, since its 
granularity can vary quite a bit. This method does not depend on the 
vagarities of the system clock and insulates threads from one another quite 
effectively.

-Casey



More information about the ZODB-Dev mailing list