[Zope3-dev] randid()
Jeremy Hylton
jeremy@zope.com
Sat, 23 Mar 2002 13:35:38 -0500
>>>>> "JF" == Jim Fulton <jim@zope.com> writes:
JF> Jeremy Hylton wrote:
>>
JF> ...
>> Is there any reason we can't replace its use in ObjectHub with a
>> simple persistence counter?
JF> What is a simple persistence counter? I can't know whether the
JF> current approach should be changed without knowing more about
JF> your proposal.
JF> How does a persistence counter work? Is it simply a counter
JF> implemented as a persistent object? If so, then it would become
JF> a hot spot, which would be bad.
I think we've talked offline about persistent counters before. One
relatively simple approaches is to use manage a collection of counters
selected via threadid. The amount of contention is limited by
selecting a range of ids for a thread id and then consuming the ids in
that range one-at-a-time. Most conflicts are easily resolved;
occasionally conflicts would occur when two threads need to get new
ranges of ids.
But if randid() really just returns a random number, and the caller is
responsible for guaranteeing uniqueness, then this seems like the
simplest approach:
random.randrange(1, 2**30)
This is much simpler than the current randid() function, which has
three default arguments, two calls to random functions, and a
multiply. My question about randid() started because that code seemed
to be doing a lot of work for reasons that weren't very clear.
Jeremy