PID recycling

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

PID recycling

Zoltan Peter Toth
Hi,

I saw that Erlang PID-s, beside their visible part, have an invisible part, incarnation counter.
It appears to be cycled between the values 1->2->3. (Look at the last byte of the binaries below.)

erl -sname a
Erlang (BEAM) emulator version 5.6.1 [source] [async-threads:0] [kernel-poll:false]

Eshell V5.6.1  (abort with ^G)
(a@mwlx081)1> term_to_binary(self()).
<<131,103,100,0,9,97,64,109,119,108,120,48,56,49,0,0,0,37,
  0,0,0,0,2>>

erl -sname a
Erlang (BEAM) emulator version 5.6.1 [source] [async-threads:0] [kernel-poll:false]

Eshell V5.6.1  (abort with ^G)
(a@mwlx081)1> term_to_binary(self()).
<<131,103,100,0,9,97,64,109,119,108,120,48,56,49,0,0,0,37,
  0,0,0,0,3>>

(a@mwlx081)3> binary_to_term( <<131,103,100,0,9,97,64,109,119,108,120,48,56,49,0,0,0,37,0,0,0,0,2>> ).
<0.37.0>
(a@mwlx081)4> binary_to_term( <<131,103,100,0,9,97,64,109,119,108,120,48,56,49,0,0,0,37,0,0,0,0,1>> ).
<0.37.0>
(a@mwlx081)5> binary_to_term( <<131,103,100,0,9,97,64,109,119,108,120,48,56,49,0,0,0,37,0,0,0,0,1>> ) == self().
false
(a@mwlx081)6> binary_to_term( <<131,103,100,0,9,97,64,109,119,108,120,48,56,49,0,0,0,37,0,0,0,0,2>> ) == self().
false
(a@mwlx081)7> binary_to_term( <<131,103,100,0,9,97,64,109,119,108,120,48,56,49,0,0,0,37,0,0,0,0,3>> ) == self().
true
(a@mwlx081)8> binary_to_term( <<131,103,100,0,9,97,64,109,119,108,120,48,56,49,0,0,0,37,0,0,0,0,2>> ) ! ok.    

=ERROR REPORT==== 3-Sep-2008::15:04:42 ===
Discarding message ok from <0.37.0> to <0.37.0> in an old incarnation (2) of this node (3)

ok

Question: how is the last used incarnation stored and when are values recycled ? (on Linux)
Is there any way to change the cycling range ?
Just for my curiosity :)

Br,
    Zoltan


_______________________________________________
erlang-questions mailing list
[hidden email]
http://www.erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: PID recycling

Raimo Niskanen-2
Firstly. Please do not send HTML code to this list.
It is very hard to read for some (at least me).

On Fri, Sep 05, 2008 at 02:08:22PM +0200, Zoltan Peter Toth wrote:
:
> Question: how is the last used incarnation stored and when are values recycled
> ? (on Linux)
> Is there any way to change the cycling range ?
> Just for my curiosity :)
>
> Br,
>     Zoltan

The incarnation aka "Creation" is stored in EPMD, the Erlang
Port Mapper Daemon, that is external to all nodes.
It cycles 1,2,3 then round to 1 again. You can not change it.
It is platform independent. An undistributed node has creation 0.
Creation 0 is also used for dirty tricks having the meaning
of the current creation.

We have had plans to change it from 2 bits to 32 but it would
hit hard on erl_interface and applications using it.


--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB
_______________________________________________
erlang-questions mailing list
[hidden email]
http://www.erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: : PID recycling

Raimo Niskanen-2
On Mon, Sep 08, 2008 at 01:59:56PM +0200, Zoltan Peter Toth wrote:
> Hi Raimo !
>
> Thanks. So if a node completely restarts, i.e. epmd as well, then the
> cycling is lost,
> i.e. after 0 there will be 0 again after the reboot, right ?

Well, 1, since nodes with names use creation 1..3,
but you are right.

>
> (Regarding HMTL, I think you could try Seamonkey or Thunderbird, they
> have no difficulties
> displaying HMTL mail.)

There _are_ reasons I prefer not to use a graphical mail client.
Furthermore I strongly believe mail should remain non-graphical.

>
> Br,
>    Zoltan
>
> Raimo Niskanen wrote:
> >Firstly. Please do not send HTML code to this list.
> >It is very hard to read for some (at least me).
> >
> >On Fri, Sep 05, 2008 at 02:08:22PM +0200, Zoltan Peter Toth wrote:
> >:
> >  
> >>Question: how is the last used incarnation stored and when are values
> >>recycled
> >>? (on Linux)
> >>Is there any way to change the cycling range ?
> >>Just for my curiosity :)
> >>
> >>Br,
> >>    Zoltan
> >>    
> >
> >The incarnation aka "Creation" is stored in EPMD, the Erlang
> >Port Mapper Daemon, that is external to all nodes.
> >It cycles 1,2,3 then round to 1 again. You can not change it.
> >It is platform independent. An undistributed node has creation 0.
> >Creation 0 is also used for dirty tricks having the meaning
> >of the current creation.
> >
> >We have had plans to change it from 2 bits to 32 but it would
> >hit hard on erl_interface and applications using it.
> >
> >
> >  

--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB
_______________________________________________
erlang-questions mailing list
[hidden email]
http://www.erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: : : PID recycling

Raimo Niskanen-2
On Tue, Sep 09, 2008 at 10:38:54AM +0200, Zoltan Peter Toth wrote:

> Hi,
>
> What about the case when we have a number of erlang nodes on different
> hosts ?
> Will the epmd-s on the other hosts maintain the incarnation counter for
> a restarted host ?
>
> It seems to me that even if one host is restarted (or beam and epmd
> killed on it), the
> incarnation counter continues as if the local epmd was running. So I
> assume that
> those are the other epmd-s that keep track of that counter.
> (... or I just overlooked something ? )

Well, yes.

The incarnation counter aka creation is kept in the local epmd.
Any erlang node only registers with the local epmd. When you
look up a node on a remote host you ask the remote epmd.
Epmd is mostly a local register on a host to map from node
to TCP/IP port number, and it also keeps the creation counter
(for the local nodes).

For a new node (also when epmd is new) the initial creation
is "randomized" in the interval 1..3 as current time in
seconds modulo 3 plus 1.

epmd_srv.c:1093:
          node->creation = (current_time(g) % 3) + 1; /* "random" 1-3 */


>
> Br,
>    Zoltan
>
> Raimo Niskanen wrote:
> >On Mon, Sep 08, 2008 at 01:59:56PM +0200, Zoltan Peter Toth wrote:
> >  
> >>Hi Raimo !
> >>
> >>Thanks. So if a node completely restarts, i.e. epmd as well, then the
> >>cycling is lost,
> >>i.e. after 0 there will be 0 again after the reboot, right ?
> >>    
> >
> >Well, 1, since nodes with names use creation 1..3,
> >but you are right.
> >
> >  

--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB
_______________________________________________
erlang-questions mailing list
[hidden email]
http://www.erlang.org/mailman/listinfo/erlang-questions