[ZODB-Dev] ZODB idioms

Jeremy Hylton jeremy@zope.com
Mon, 24 Jun 2002 10:33:55 -0400


>>>>> "CD" == Casey Duncan <casey@zope.com> writes:

  CD> Storing this many objects in a BTree should be fine, they will
  CD> rebalance themselves AFAIK. Insertion of more random ids might
  CD> tend to be faster though as the BTree grows since rebalancing
  CD> will happen much less often.  How big an affect that would have
  CD> I am not sure. You might want to do some timing experiments with
  CD> large BTrees.

BTrees do not rebalance themselves.  I suspect that the use of random
ids in Zope is to avoid balancing problems by random insertions.  In
the case of sequential ids, each BTree bucket will be half full.  When
the bucket reaches its limit, it will be split into two buckets of
equal size (call them left and right).  Since the ids are sequential
the left bucket will never grow and all the new ids will be put in the
right bucket.

  CD> Random ids might be even better, but for hundreds of thousands
  CD> of objects, you should reseed the random number generator
  CD> periodically, or it may repeat itself (assuming your app is that
  CD> stable ;^).

The period of Python's random number generator is slightly more than
6.9 * 10 ** 12.  (http://www.python.org/doc/current/lib/module-random.html)
I think reseeding will do more harm than good.

Jeremy