AnyEvent-MP

 view release on metacpan or  search on metacpan

MP.pm  view on Meta::CPAN

In addition to discovering the network, seed nodes are also used to
maintain the network - all nodes using the same seed node are part of the
same network. If a network is split into multiple subnets because e.g. the
network link between the parts goes down, then using the same seed nodes
for all nodes ensures that eventually the subnets get merged again.

Seed nodes are expected to be long-running, and at least one seed node
should always be available. They should also be relatively responsive - a
seed node that blocks for long periods will slow down everybody else.

For small networks, it's best if every node uses the same set of seed
nodes. For large networks, it can be useful to specify "regional" seed
nodes for most nodes in an area, and use all seed nodes as seed nodes for
each other. What's important is that all seed nodes connections form a
complete graph, so that the network cannot split into separate subnets
forever.

Seed nodes are represented by seed IDs.

=item seed IDs - C<host:port>

MP.pm  view on Meta::CPAN

   db_set $family => $port => $value

Except that the port is monitored and automatically removed from the
database family when it is kil'ed.

If C<$value> is missing, C<undef> is used. If C<$port> is missing, then
C<$SELF> is used.

This function is most useful to register a port in some port group (which
is just another name for a database family), and have it removed when the
port is gone. This works best when the port is a local port.

=cut

sub db_reg($$;$) {
   my $family = shift;
   my $port = @_ ? shift : $SELF;

   my $clr = sub { db_del $family => $port };
   mon $port, $clr;

MP/Intro.pod  view on Meta::CPAN

name with a random suffix to make it unique, but for this example we want
the node to have a bit more personality, and name it C<eg_receiver> with a
random suffix.

Why the random suffix? Node IDs need to be unique within the network and
appending a random suffix is the easiest way to do that.

The second parameter, C<binds>, specifies a list of C<address:port> pairs
to bind TCP listeners on. The special "address" of C<*> means to bind on
every local IP address (this might not work on every OS, so explicit IP
addresses are best).

The reason to bind on a TCP port is not just that other nodes can connect
to us: if no binds are specified, the node will still bind on a dynamic
port on all local addresses - but in this case we won't know the port, and
cannot tell other nodes to connect to it as seed node.

Now, a I<seed> is simply the TCP address of some other node in the
network, often the same string as used for the C<binds> parameter of the
other node. The need for seeds is easy to explain: I<somehow> the nodes
of an aemp network have to find each other, and often this means over the

MP/Intro.pod  view on Meta::CPAN

it, it could be crashed, but also still running without knowing we lost
the connection).

So another way to view monitors is: "notify me when some of my messages
couldn't be delivered". AEMP has a guarantee about message delivery to a
port:  After starting a monitor, any message sent to a port will either
be delivered, or, when it is lost, any further messages will also be lost
until the monitoring action is invoked. After that, further messages
I<might> get delivered again.

This doesn't sound like a very big guarantee, but it is kind of the best
you can get while staying sane: Specifically, it means that there will be
no "holes" in the message sequence: all messages sent are delivered in
order, without any of them missing in between, and when some were lost,
you I<will> be notified of that, so you can take recovery action.

And, obviously, the guarantee only works in the presence of
correctly-working hardware, and no relevant bugs inside AEMP itself.

=head3 Supervising

MP/Kernel.pm  view on Meta::CPAN

      $port = "0" if $port eq "*";

      if ($host eq "*") {
         $cv->begin;

         my $get_addr = sub {
            my @addr;

            require Net::Interface;

            # Net::Interface hangs on some systems, so hope for the best
            local $SIG{ALRM} = 'DEFAULT';
            alarm 2;

            for my $if (Net::Interface->interfaces) {
               # we statically lower-prioritise ipv6 here, TODO :()
               for $_ ($if->address (Net::Interface::AF_INET ())) {
                  next if /^\x7f/; # skip localhost etc.
                  push @addr, $_;
               }
               for ($if->address (Net::Interface::AF_INET6 ())) {

README  view on Meta::CPAN

        of the same network. If a network is split into multiple subnets
        because e.g. the network link between the parts goes down, then
        using the same seed nodes for all nodes ensures that eventually the
        subnets get merged again.

        Seed nodes are expected to be long-running, and at least one seed
        node should always be available. They should also be relatively
        responsive - a seed node that blocks for long periods will slow down
        everybody else.

        For small networks, it's best if every node uses the same set of
        seed nodes. For large networks, it can be useful to specify
        "regional" seed nodes for most nodes in an area, and use all seed
        nodes as seed nodes for each other. What's important is that all
        seed nodes connections form a complete graph, so that the network
        cannot split into separate subnets forever.

        Seed nodes are represented by seed IDs.

    seed IDs - "host:port"
        Seed IDs are transport endpoint(s) (usually a hostname/IP address

README  view on Meta::CPAN

           db_set $family => $port => $value

        Except that the port is monitored and automatically removed from the
        database family when it is kil'ed.

        If $value is missing, "undef" is used. If $port is missing, then
        $SELF is used.

        This function is most useful to register a port in some port group
        (which is just another name for a database family), and have it
        removed when the port is gone. This works best when the port is a
        local port.

    db_family $family => $cb->(\%familyhash)
        Queries the named database $family and call the callback with the
        family represented as a hash. You can keep and freely modify the
        hash.

    db_keys $family => $cb->(\@keys)
        Same as "db_family", except it only queries the family *subkeys* and
        passes them as array reference to the callback.



( run in 0.528 second using v1.01-cache-2.11-cpan-4e96b696675 )