The event management process in erlang. Named Processes or Pids?

I have an event manager that dispatches events to subscribers (eg http_session_created, http_sesssion_destroyed). If a Pid is used instead of a named process, I have to put it in functions to work with the event manager, but if a named process is used, the code will be clearer.

Which option is right?

Thank!

+2


source to share


2 answers


While there is no actual difference in the process, naming the process, registering it, makes it global. You are essentially telling the system that there is a global service here that anyone can use.



From your description, it sounds like you are giving them names to save a little effort to carry them around in your loop. If so, I would put their pids in the record with all the other state data you transfer. This indicates the type of processes much better.

+6


source


If you have a fixed set of "subscription" processes then use the registered names IMO.

If, by contrast, you have a publish / subscribe architecture where subscribers come and go, you need an infrastructure to keep track of those, and from now on it doesn't matter if you use Pid () or names.



One of the disadvantages of using registered names is that you need to keep track of them in the code base to avoid collisions. So it's up to you: personally, I lean towards the named processes because, as you say, it makes the reading of the code clearer. Either way, OTP doesn't care.

+2


source







All Articles