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.50 by root, Fri Aug 14 14:01:05 2009 UTC vs.
Revision 1.52 by root, Fri Aug 14 15:13:20 2009 UTC

25 snd @msg_with_first_element_being_a_port; 25 snd @msg_with_first_element_being_a_port;
26 26
27 # creating/using ports, the simple way 27 # creating/using ports, the simple way
28 my $somple_port = port { my @msg = @_; 0 }; 28 my $somple_port = port { my @msg = @_; 0 };
29 29
30 # creating/using ports, type matching 30 # creating/using ports, tagged message matching
31 my $port = port; 31 my $port = port;
32 rcv $port, ping => sub { snd $_[0], "pong"; 0 }; 32 rcv $port, ping => sub { snd $_[0], "pong"; 0 };
33 rcv $port, pong => sub { warn "pong received\n"; 0 }; 33 rcv $port, pong => sub { warn "pong received\n"; 0 };
34 34
35 # create a port on another node 35 # create a port on another node
143 kil $SELF, die => $msg; 143 kil $SELF, die => $msg;
144} 144}
145 145
146=item $thisnode = NODE / $NODE 146=item $thisnode = NODE / $NODE
147 147
148The C<NODE> function returns, and the C<$NODE> variable contains 148The C<NODE> function returns, and the C<$NODE> variable contains the
149the noderef of the local node. The value is initialised by a call 149noderef of the local node. The value is initialised by a call to
150to C<become_public> or C<become_slave>, after which all local port 150C<initialise_node>.
151identifiers become invalid.
152 151
153=item $noderef = node_of $port 152=item $noderef = node_of $port
154 153
155Extracts and returns the noderef from a portid or a noderef. 154Extracts and returns the noderef from a port ID or a noderef.
156 155
157=item initialise_node $noderef, $seednode, $seednode... 156=item initialise_node $noderef, $seednode, $seednode...
158 157
159=item initialise_node "slave/", $master, $master... 158=item initialise_node "slave/", $master, $master...
160 159
279=item snd $port, type => @data 278=item snd $port, type => @data
280 279
281=item snd $port, @msg 280=item snd $port, @msg
282 281
283Send the given message to the given port ID, which can identify either 282Send the given message to the given port ID, which can identify either
284a local or a remote port, and can be either a string or soemthignt hat 283a local or a remote port, and must be a port ID.
285stringifies a sa port ID (such as a port object :).
286 284
287While the message can be about anything, it is highly recommended to use a 285While the message can be about anything, it is highly recommended to use a
288string as first element (a portid, or some word that indicates a request 286string as first element (a port ID, or some word that indicates a request
289type etc.). 287type etc.).
290 288
291The message data effectively becomes read-only after a call to this 289The message data effectively becomes read-only after a call to this
292function: modifying any argument is not allowed and can cause many 290function: modifying any argument is not allowed and can cause many
293problems. 291problems.
738convenience functionality. 736convenience functionality.
739 737
740This means that AEMP requires a less tightly controlled environment at the 738This means that AEMP requires a less tightly controlled environment at the
741cost of longer node references and a slightly higher management overhead. 739cost of longer node references and a slightly higher management overhead.
742 740
741=item Erlang has a "remote ports are like local ports" philosophy, AEMP
742uses "local ports are like remote ports".
743
744The failure modes for local ports are quite different (runtime errors
745only) then for remote ports - when a local port dies, you I<know> it dies,
746when a connection to another node dies, you know nothing about the other
747port.
748
749Erlang pretends remote ports are as reliable as local ports, even when
750they are not.
751
752AEMP encourages a "treat remote ports differently" philosophy, with local
753ports being the special case/exception, where transport errors cannot
754occur.
755
743=item * Erlang uses processes and a mailbox, AEMP does not queue. 756=item * Erlang uses processes and a mailbox, AEMP does not queue.
744 757
745Erlang uses processes that selctively receive messages, and therefore 758Erlang uses processes that selectively receive messages, and therefore
746needs a queue. AEMP is event based, queuing messages would serve no useful 759needs a queue. AEMP is event based, queuing messages would serve no
747purpose. 760useful purpose. For the same reason the pattern-matching abilities of
761AnyEvent::MP are more limited, as there is little need to be able to
762filter messages without dequeing them.
748 763
749(But see L<Coro::MP> for a more Erlang-like process model on top of AEMP). 764(But see L<Coro::MP> for a more Erlang-like process model on top of AEMP).
750 765
751=item * Erlang sends are synchronous, AEMP sends are asynchronous. 766=item * Erlang sends are synchronous, AEMP sends are asynchronous.
752 767
753Sending messages in Erlang is synchronous and blocks the process. AEMP 768Sending messages in Erlang is synchronous and blocks the process (and
754sends are immediate, connection establishment is handled in the 769so does not need a queue that can overflow). AEMP sends are immediate,
755background. 770connection establishment is handled in the background.
756 771
757=item * Erlang can silently lose messages, AEMP cannot. 772=item * Erlang suffers from silent message loss, AEMP does not.
758 773
759Erlang makes few guarantees on messages delivery - messages can get lost 774Erlang makes few guarantees on messages delivery - messages can get lost
760without any of the processes realising it (i.e. you send messages a, b, 775without any of the processes realising it (i.e. you send messages a, b,
761and c, and the other side only receives messages a and c). 776and c, and the other side only receives messages a and c).
762 777
774eventually be killed - it cannot happen that a node detects a port as dead 789eventually be killed - it cannot happen that a node detects a port as dead
775and then later sends messages to it, finding it is still alive. 790and then later sends messages to it, finding it is still alive.
776 791
777=item * Erlang can send messages to the wrong port, AEMP does not. 792=item * Erlang can send messages to the wrong port, AEMP does not.
778 793
779In Erlang it is quite possible that a node that restarts reuses a process 794In Erlang it is quite likely that a node that restarts reuses a process ID
780ID known to other nodes for a completely different process, causing 795known to other nodes for a completely different process, causing messages
781messages destined for that process to end up in an unrelated process. 796destined for that process to end up in an unrelated process.
782 797
783AEMP never reuses port IDs, so old messages or old port IDs floating 798AEMP never reuses port IDs, so old messages or old port IDs floating
784around in the network will not be sent to an unrelated port. 799around in the network will not be sent to an unrelated port.
785 800
786=item * Erlang uses unprotected connections, AEMP uses secure 801=item * Erlang uses unprotected connections, AEMP uses secure

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines