ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/MP.pm
(Generate patch)

Comparing AnyEvent-MP/MP.pm (file contents):
Revision 1.22 by root, Tue Aug 4 18:33:30 2009 UTC vs.
Revision 1.28 by root, Tue Aug 4 22:16:54 2009 UTC

30This module (-family) implements a simple message passing framework. 30This module (-family) implements a simple message passing framework.
31 31
32Despite its simplicity, you can securely message other processes running 32Despite its simplicity, you can securely message other processes running
33on the same or other hosts. 33on the same or other hosts.
34 34
35For an introduction to this module family, see the L<AnyEvent::MP::Intro>
36manual page.
37
35At the moment, this module family is severly brokena nd underdocumented, 38At the moment, this module family is severly broken and underdocumented,
36so do not use. This was uploaded mainly to reserve the CPAN namespace - 39so do not use. This was uploaded mainly to reserve the CPAN namespace -
37stay tuned! 40stay tuned! The basic API should be finished, however.
38 41
39=head1 CONCEPTS 42=head1 CONCEPTS
40 43
41=over 4 44=over 4
42 45
85 88
86use AE (); 89use AE ();
87 90
88use base "Exporter"; 91use base "Exporter";
89 92
90our $VERSION = '0.02'; 93our $VERSION = '0.1';
91our @EXPORT = qw( 94our @EXPORT = qw(
92 NODE $NODE *SELF node_of _any_ 95 NODE $NODE *SELF node_of _any_
93 become_slave become_public 96 become_slave become_public
94 snd rcv mon kil reg psub 97 snd rcv mon kil reg psub
95 port 98 port
241sub mon_guard { 244sub mon_guard {
242 my ($port, @refs) = @_; 245 my ($port, @refs) = @_;
243 246
244 mon $port, sub { 0 && @refs } 247 mon $port, sub { 0 && @refs }
245} 248}
249
250=item lnk $port1, $port2
251
252Link two ports. This is simply a shorthand for:
253
254 mon $port1, $port2;
255 mon $port2, $port1;
256
257It means that if either one is killed abnormally, the other one gets
258killed as well.
246 259
247=item $local_port = port 260=item $local_port = port
248 261
249Create a new local port object that supports message matching. 262Create a new local port object that supports message matching.
250 263
495 snd $NODE, time => $myport, timereply => 1, 2; 508 snd $NODE, time => $myport, timereply => 1, 2;
496 # => snd $myport, timereply => 1, 2, <time> 509 # => snd $myport, timereply => 1, 2, <time>
497 510
498=back 511=back
499 512
513=head1 AnyEvent::MP vs. Distributed Erlang
514
515AnyEvent::MP got lots of its ideas from distributed erlang (erlang node
516== aemp node, erlang process == aemp port), so many of the documents and
517programming techniques employed by erlang apply to AnyEvent::MP. Here is a
518sample:
519
520 http://www.erlang.se/doc/programming_rules.shtml
521 http://erlang.org/doc/getting_started/part_frame.html # chapters 3 and 4
522 http://erlang.org/download/erlang-book-part1.pdf # chapters 5 and 6
523 http://erlang.org/download/armstrong_thesis_2003.pdf # chapters 4 and 5
524
525Despite the similarities, there are also some important differences:
526
527=over 4
528
529=item * Node references contain the recipe on how to contact them.
530
531Erlang relies on special naming and DNS to work everywhere in the
532same way. AEMP relies on each node knowing it's own address(es), with
533convenience functionality.
534
535This means that AEMP requires a less tightly controlled environment at the
536cost of longer node references and a slightly higher management overhead.
537
538=item * Erlang uses processes and a mailbox, AEMP does not queue.
539
540Erlang uses processes that selctively receive messages, and therefore
541needs a queue. AEMP is event based, queuing messages would serve no useful
542purpose.
543
544(But see L<Coro::MP> for a more erlang-like process model on top of AEMP).
545
546=item * Erlang sends are synchronous, AEMP sends are asynchronous.
547
548Sending messages in erlang is synchronous and blocks the process. AEMP
549sends are immediate, connection establishment is handled in the
550background.
551
552=item * Erlang can silently lose messages, AEMP cannot.
553
554Erlang makes few guarantees on messages delivery - messages can get lost
555without any of the processes realising it (i.e. you send messages a, b,
556and c, and the other side only receives messages a and c).
557
558AEMP guarantees correct ordering, and the guarantee that there are no
559holes in the message sequence.
560
561=item * In erlang, processes can be declared dead and later be found to be
562alive.
563
564In erlang it can happen that a monitored process is declared dead and
565linked processes get killed, but later it turns out that the process is
566still alive - and can receive messages.
567
568In AEMP, when port monitoring detects a port as dead, then that port will
569eventually be killed - it cannot happen that a node detects a port as dead
570and then later sends messages to it, finding it is still alive.
571
572=item * Erlang can send messages to the wrong port, AEMP does not.
573
574In erlang it is quite possible that a node that restarts reuses a process
575ID known to other nodes for a completely different process, causing
576messages destined for that process to end up in an unrelated process.
577
578AEMP never reuses port IDs, so old messages or old port IDs floating
579around in the network will not be sent to an unrelated port.
580
581=item * Erlang uses unprotected connections, AEMP uses secure
582authentication and can use TLS.
583
584AEMP can use a proven protocol - SSL/TLS - to protect connections and
585securely authenticate nodes.
586
587=item * The AEMP protocol is optimised for both text-based and binary
588communications.
589
590The AEMP protocol, unlike the erlang protocol, supports both
591language-independent text-only protocols (good for debugging) and binary,
592language-specific serialisers (e.g. Storable).
593
594It has also been carefully designed to be implementable in other languages
595with a minimum of work while gracefully degrading fucntionality to make the
596protocol simple.
597
598=back
599
500=head1 SEE ALSO 600=head1 SEE ALSO
501 601
502L<AnyEvent>. 602L<AnyEvent>.
503 603
504=head1 AUTHOR 604=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines