[erlang-questions] How to do counters?
Wed Jul 1 03:40:04 CEST 2009
On Jun 30, 2009, at 1:35 PM, Jarrod Roberson wrote:
> On Mon, Jun 29, 2009 at 7:46 PM, Richard O'Keefe <>
>> As a general rule, don't register a process unless there is
>> a REALLY good reason to do so.
> Is the reason not to register processes performance related
> or is it a "best practices" thing?
It's the fact that the process registry is *global*.
At startup, length(registered()) is currently 16.
But that's only the processes that are _initially_
registered, not all that Erlang/OTP _might_ already
register for itself. There's at least another 20.
So it's not just that each possible registered name
counts as a global variable, it's that you don't know
which of them may be needed by the current release of
the system and which of them might be needed in a future
If you have a strong reason to register a process, and
there _can_ be good reasons, try some convention like
(name @ your initials) or something like that;
OTP doesn't seem to use atoms with @ signs as registered names.
> And if it is performance related,
> how would someone know if they have a
> REALLY good reason to register the process?
You have a REALLY good reason to register a process
when there is something you need to do that cannot be
done any other way. In particular, when process A needs
to talk to process B and process A didn't create process
B and nobody else has told process A which process B is
(the pid hasn't been sent in a message). In this case
registering B under a name that's known to both parties
will do the trick.
Another situation is where the thing you want to talk
to is a "role" rather than an actor, as in "I want to
talk to whoever is in charge of alarm reporting right
now". A role might be filled by a succession of actors
because the actors die, or because work is redistributed
for load balancing, or for debugging reasons, ...
A project might well run its own registry. That's just
a process that keeps a mapping from names (or other
descriptions) to pids. But the processes in that project
have to find _that_ registry. Using *one* registered name
in the project, for the project's own registry, makes sense.
More information about the erlang-questions