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

Comparing AnyEvent-MP/MP/Intro.pod (file contents):
Revision 1.25 by root, Sat Aug 29 15:36:06 2009 UTC vs.
Revision 1.26 by root, Sat Aug 29 16:08:03 2009 UTC

221themselves in the appropriate group, and your web frontends can start to 221themselves in the appropriate group, and your web frontends can start to
222find some database backend. 222find some database backend.
223 223
224=head3 C<initialise_node> And The Network 224=head3 C<initialise_node> And The Network
225 225
226Now, lets have a look at the next new thing, the C<initialise_node>: 226Now, let's have a look at the new function, C<initialise_node>:
227 227
228 initialise_node "eg_simple_receiver"; 228 initialise_node "eg_simple_receiver";
229 229
230Before we are able to send messages to other nodes we have to initialise 230Before we are able to send messages to other nodes we have to initialise
231ourself to become a "distributed node". Initialising a node means naming
232the node, optionally binding some TCP listeners so that other nodes can
233contact it and connecting to a predefined set of seed addresses so the
234node can discover the existing network - and the existing network can
235discover the node!
236
231ourself. The first argument, the string C<"eg_simple_receiver">, is called the 237The first argument, the string C<"eg_simple_receiver">, is the so-called
232I<profile> of this node. A profile holds some information about the application 238I<profile> to use: A profile holds some information about the application
233that is going to be a node in an L<AnyEvent::MP> network. 239that is going to be a node in an L<AnyEvent::MP> network. Customarily you
240don't specify a profile name at all: in this case, AnyEvent::MP will use
241the POSIX nodename.
234 242
235Most importantly the profile allows you to set the I<node id> that your 243The profile allows you to set the I<node ID> that your application will
236application will use. You can also set I<binds> in the profile, meaning that 244use (the node ID defaults to the profile name if not specified). You can
237you can define TCP ports that the application will listen on for incoming 245also set I<binds> in the profile, meaning that you can define TCP ports
238connections from other nodes of the network. 246that the application will listen on for incoming connections from other
247nodes of the network.
239 248
240Next you can configure I<seeds> in profile. A I<seed> is just a TCP endpoint 249You should also configure I<seeds> in the profile: A I<seed> is just a
241which tells the application where to find other nodes of it's network. To 250TCP address of some other node in the network. To explain this a bit
242explain this a bit more detailed we have to look at the topology of an 251more detailed we have to look at the topology of an L<AnyEvent::MP>
243L<AnyEvent::MP> network. The topology is called a I<fully connected mesh>, here 252network. The topology is called a I<fully connected mesh>, here an example
244an example with 4 nodes: 253with 4 nodes:
245 254
246 N1--N2 255 N1--N2
247 | \/ | 256 | \/ |
248 | /\ | 257 | /\ |
249 N3--N4 258 N3--N4
253 N1--N2 262 N1--N2
254 | \/ | N5 263 | \/ | N5
255 | /\ | 264 | /\ |
256 N3--N4 265 N3--N4
257 266
258The new node needs to know the I<binds> of all of those 4 already connected 267The new node needs to know the I<binds> of all nodes already
259nodes. And exactly this is what the I<seeds> are for. Now lets assume that 268connected. Exactly this is what the I<seeds> are for: Let's assume that
260the new node C<N5> has as I<seed> the TCP endpoint of the node C<N2>. 269the new node (C<N5>) uses the TCP address of the node C<N2> as seed. This
261It then connects to C<N2>: 270cuases it to connect to C<N2>:
262 271
263 N1--N2____ 272 N1--N2____
264 | \/ | N5 273 | \/ | N5
265 | /\ | 274 | /\ |
266 N3--N4 275 N3--N4
267 276
268C<N2> then tells C<N5> the I<binds> of the other nodes it is connected to, 277C<N2> then tells C<N5> about the I<binds> of the other nodes it is
269and C<N5> builds up the rest of the connections: 278connected to, and C<N5> creates the rest of the connections:
270 279
271 /--------\ 280 /--------\
272 N1--N2____| 281 N1--N2____|
273 | \/ | N5 282 | \/ | N5
274 | /\ | /| 283 | /\ | /|
275 N3--N4--- | 284 N3--N4--- |
276 \________/ 285 \________/
277 286
278Finished. C<N5> is now happily connected to the rest of the network. 287All done: C<N5> is now happily connected to the rest of the network.
279 288
280=head3 Setting Up The Profiles 289=head3 Setting Up The Profiles
281 290
282Ok, so much to the profile. Now lets setup the C<eg_simple_receiver> I<profile> 291Ok, so much to the profile. Now let's setup the C<eg_simple_receiver>
283for later. For the receiver we just give the receiver a I<bind>: 292I<profile> for later use. For the receiver we just give the receiver a
293I<bind>:
284 294
285 aemp profile eg_simple_receiver setbinds localhost:12266 295 aemp profile eg_simple_receiver setbinds localhost:12266
286 296
297We use C<localhost> in the example, but in the real world, you usually
298want to use the "real" IP address of your node, so hosts can connect to
299it. Of course, you can specify many binds, and it is also perfectly useful
300to run multiple nodes on the same host. Just keep in mind that other nodes
301will try to I<connect> to those addresses, and this better succeeds if you
302want your network to be in good working conditions.
303
287And while we are at it, just setup the I<profile> for the sender in the second 304While we are at it, we setup the I<profile> for the sender in the
288part of this example too. We will call the sender I<profile> 305second part of this example, too. We will call the sender I<profile>
289C<eg_simple_sender>. For the sender we will just setup a I<seed> to the 306C<eg_simple_sender>. For the sender we set up a I<seed> pointing to the
290receiver: 307receiver:
291 308
292 aemp profile eg_simple_sender setseeds localhost:12266 309 aemp profile eg_simple_sender setseeds localhost:12266
293 aemp profile eg_simple_sender setbinds 310 aemp profile eg_simple_sender setbinds
294 311
295You might wonder why we setup I<binds> to be empty here. Well, there can be 312You might wonder why we setup I<binds> to be empty here: actually, the the
296exceptions to the I<fully> in the I<fully connected mesh> in L<AnyEvent::MP>. 313I<fully> in the I<fully connected mesh> is not the complete truth: If you
297If you don't configure a I<bind> for a node's profile it won't bind itself 314don't configure any I<binds> for a node profile it will parse and try to
298somewhere. These kinds of I<nodes> will not be able to send messages to other 315resolve the node ID to find addresses to bind to. In this case we pretend
299I<nodes> that also didn't I<bind> them self to some TCP address. For this 316that we do not want this and epxlicitly specify an empty binds list, so
317the node will not actually listen on any TCP ports.
318
319Nodes without listeners will not be able to send messages to other nodes
320without listeners, but they can still talk to all other nodes. For this
300example, as well as some cases in the real world, we can live with this 321example, as well as in many cases in the real world, we can live with this
301limitation. 322restriction, and this makes it easier to avoid DNS (assuming your setup is
323broken, eliminating one potential problem :).
302 324
303=head3 Registering The Receiver 325=head3 Registering The Receiver
304 326
305Ok, where were we. We now discussed the basic purpose of L<AnyEvent::MP::Global> 327Ok, where were we. We now discussed the basic purpose of L<AnyEvent::MP::Global>
306and initialise_node with it's relations to profiles. We also setup our profiles 328and initialise_node with it's relations to profiles. We also setup our profiles

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines