Linking to/from a gen_server?
Mon Mar 3 01:15:38 CET 2003
Is there any limitation imposed by erts on the number of processes
another process (my gen_server) can monitor at once? Or is it just
the limitation on number of actively running processes within the
I'm only interested in this gen_server monitoring a large number
(around 4-5k) of local processes so that if they crash or terminate
unexpectedly the ets dictionary is cleaned up so future lookups for
that process won't find it.
Essentially its my own form of register/2 for local processes, but
register/2 is too limited for me, I need to use more than just an
atom to associate a process to my data.
I had forgotten about the monitor/2 call, thanks for the pointer. :)
Lennart ?hman <> wrote:
> your concerns are valid. However...:
> 1) In the early beginning of BOS (OTP ancestor) we choose to use
> a time-out *only* in gen_server:call. One reason was what you
> described. But the other was that internal handling of links
> (the structure it was stored in) was not built for having a
> lot of links and at the same time manage them frequently.
> 2) Nowdays there is another mechanism - erlang:monitor which
> monitors the existance of "things". Today the only "thing"
> which can be monitored is another process.
> Monitoring has two significant differences to links.
> (i) Monitoring is *not* bi-directional.
> (ii) Monitoring results in as many DOWN-messages as monitoing
> has be been called. Very good for writing library code
> for instance.
> Today, to my knowledge, all OTP gen-code has been rewritten in
> "modern style" using monitoring instead.
> Hence you may very well implement your solution as have your gen-server
> monitor the client PID, and be responsive (in handle_info) to
> DOWN-messages from such PIDs.
> Shawn Pearce wrote:
> >Ok, so I'm trying to use OTP stuff as much as I can right now, as I
> >haven't really learned it all yet. :)
> >I'm trying to setup a way to have a client process send a gen_server
> >a message, where the gen_server stuffs a term and the client's pid
> >into an ets table managed by the gen_server. I want the gen_server
> >to link to the client process so it can remove the term and client
> >pid when the client process exits.
> >But it occured to me, gen_server:call/2 links to the gen_server
> >process, sends the message, and waits for the response with a
> >timeout. It then unlinks from the gen_server. This means the
> >gen_server can't link to the client process during its handle_call/3
> >callback, as the unlink will be done by the client after the call
> >I could use gen_server:cast/2, but i do need a response to be sent
> >back to the client so it knows the operation was successful.
> >Ideas from the OTP experts?
> Lennart Ohman phone : +46-8-587 623 27
> Sjoland & Thyselius Telecom AB cellular: +46-70-552 6735
> Sehlstedtsgatan 6 fax : +46-8-667 8230
> SE-115 28 STOCKHOLM, SWEDEN email :
You will gain money by a fattening action.
More information about the erlang-questions