AnyEvent-MP
view release on metacpan or search on metacpan
print "*$_=$family->{$_}\n" for @$c;
print "-$_=$family->{$_}\n" for @$d;
};
AnyEvent::MP vs. Distributed Erlang
AnyEvent::MP got lots of its ideas from distributed Erlang (Erlang node
== aemp node, Erlang process == aemp port), so many of the documents and
programming techniques employed by Erlang apply to AnyEvent::MP. Here is
a sample:
http://www.erlang.se/doc/programming_rules.shtml
http://erlang.org/doc/getting_started/part_frame.html # chapters 3 and 4
http://erlang.org/download/erlang-book-part1.pdf # chapters 5 and 6
http://erlang.org/download/armstrong_thesis_2003.pdf # chapters 4 and 5
Despite the similarities, there are also some important differences:
* Node IDs are arbitrary strings in AEMP.
Erlang relies on special naming and DNS to work everywhere in the
same way. AEMP relies on each node somehow knowing its own
address(es) (e.g. by configuration or DNS), and possibly the
addresses of some seed nodes, but will otherwise discover other
nodes (and their IDs) itself.
* Erlang has a "remote ports are like local ports" philosophy, AEMP
uses "local ports are like remote ports".
The failure modes for local ports are quite different (runtime
errors only) then for remote ports - when a local port dies, you
*know* it dies, when a connection to another node dies, you know
nothing about the other port.
Erlang pretends remote ports are as reliable as local ports, even
when they are not.
AEMP encourages a "treat remote ports differently" philosophy, with
local ports being the special case/exception, where transport errors
cannot occur.
* Erlang uses processes and a mailbox, AEMP does not queue.
Erlang uses processes that selectively receive messages out of
order, and therefore needs a queue. AEMP is event based, queuing
messages would serve no useful purpose. For the same reason the
pattern-matching abilities of AnyEvent::MP are more limited, as
there is little need to be able to filter messages without dequeuing
them.
This is not a philosophical difference, but simply stems from
AnyEvent::MP being event-based, while Erlang is process-based.
You can have a look at Coro::MP for a more Erlang-like process model
on top of AEMP and Coro threads.
* Erlang sends are synchronous, AEMP sends are asynchronous.
Sending messages in Erlang is synchronous and blocks the process
until a connection has been established and the message sent (and so
does not need a queue that can overflow). AEMP sends return
immediately, connection establishment is handled in the background.
* Erlang suffers from silent message loss, AEMP does not.
Erlang implements few guarantees on messages delivery - messages can
get lost without any of the processes realising it (i.e. you send
messages a, b, and c, and the other side only receives messages a
and c).
AEMP guarantees (modulo hardware errors) correct ordering, and the
guarantee that after one message is lost, all following ones sent to
the same port are lost as well, until monitoring raises an error, so
there are no silent "holes" in the message sequence.
If you want your software to be very reliable, you have to cope with
corrupted and even out-of-order messages in both Erlang and AEMP.
AEMP simply tries to work better in common error cases, such as when
a network link goes down.
* Erlang can send messages to the wrong port, AEMP does not.
In Erlang it is quite likely that a node that restarts reuses an
Erlang process ID known to other nodes for a completely different
process, causing messages destined for that process to end up in an
unrelated process.
AEMP does not reuse port IDs, so old messages or old port IDs
floating around in the network will not be sent to an unrelated
port.
* Erlang uses unprotected connections, AEMP uses secure authentication
and can use TLS.
AEMP can use a proven protocol - TLS - to protect connections and
securely authenticate nodes.
* The AEMP protocol is optimised for both text-based and binary
communications.
The AEMP protocol, unlike the Erlang protocol, supports both
programming language independent text-only protocols (good for
debugging), and binary, language-specific serialisers (e.g.
Storable). By default, unless TLS is used, the protocol is actually
completely text-based.
It has also been carefully designed to be implementable in other
languages with a minimum of work while gracefully degrading
functionality to make the protocol simple.
* AEMP has more flexible monitoring options than Erlang.
In Erlang, you can chose to receive *all* exit signals as messages
or *none*, there is no in-between, so monitoring single Erlang
processes is difficult to implement.
Monitoring in AEMP is more flexible than in Erlang, as one can
choose between automatic kill, exit message or callback on a
per-port basis.
* Erlang tries to hide remote/local connections, AEMP does not.
( run in 0.471 second using v1.01-cache-2.11-cpan-f56aa216473 )