Re: Sinister variable caching problem with rand()

Michael Ludwig <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <20100516132311.GB5264@wladimir>
André Warnier schrieb am 16.05.2010 um 13:40:31 (+0200):

> One alternative is to use some strictly incremental
> counter, shared between multiple processes running on
> potentially multiple systems or CPUs.  This requires a
> common place to store the counter, which survives a system
> restart, and it requires some lock-read-increment-unlock
> mechanism.  I don't know any really fast and efficient way
> of doing this.  I am interested however if anyone knows
> one.

In an SQL server, you'd use a SEQUENCE:

  SELECT NEXT VALUE FOR MY_BLA_SEQ FROM <...>

Read about Redis recently, like Memcache, just "semi-persistent".
You can store and increment an integer there. Or in any other
key-value store.

I think the locking required for incrementing an integer, if
necessary at all, is negligible.

But I agree that in practice for most scenarios, your solution
will work just fine ;-)
-- 
Michael Ludwig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.