[erlang-questions] Singleton Process

Scott Lystig Fritchie <>
Thu Feb 5 07:58:35 CET 2009


Edward Stow <> wrote:

eb> However, I would like to know if this is how you would produce a
eb> counter object that returns an incrementally increasing value.

Edward, a suggestion.  Assuming there's no need for the counter to grow
by exactly 1 each time, and that skipping some values is OK, then
... why bother updating the "next_id.dat" file each time?  Why not
update it very Nth time, e.g. every 100 or 7000 times?  If the process
crashes, it'll restart and start handing out values based on
"next_id.dat" anyway.

If you think disk/network/Mnesia/Amazon S3/whatever is going to be too
slow, then at some interval before you reach N, spawn a proc to update
it asynchronously.  (Bonus: allow only one of them at a time, to avoid
icky race conditions.)

-Scott



More information about the erlang-questions mailing list