… | |
… | |
251 | have a few database backends, a few web front-ends and some processing |
251 | have a few database backends, a few web front-ends and some processing |
252 | distributed over a number of hosts: all of these would simply register |
252 | distributed over a number of hosts: all of these would simply register |
253 | themselves in the appropriate group, and your web front-ends can start to |
253 | themselves in the appropriate group, and your web front-ends can start to |
254 | find some database backend. |
254 | find some database backend. |
255 | |
255 | |
256 | =head3 C<configure> and the Network |
256 | =head3 C<configure> and Joining and Maintaining the Network |
257 | |
257 | |
258 | Now, let's have a look at the new function, C<configure>: |
258 | Now, let's have a look at the new function, C<configure>: |
259 | |
259 | |
260 | configure nodeid => "eg_receiver", binds => ["*:4040"]; |
260 | configure nodeid => "eg_receiver", binds => ["*:4040"]; |
261 | |
261 | |
… | |
… | |
277 | any string - if you don't care, you can specify a node ID of C<anon/> |
277 | any string - if you don't care, you can specify a node ID of C<anon/> |
278 | which will then be replaced by a random node name. |
278 | which will then be replaced by a random node name. |
279 | |
279 | |
280 | The second parameter, C<binds>, specifies a list of C<address:port> pairs |
280 | The second parameter, C<binds>, specifies a list of C<address:port> pairs |
281 | to bind TCP listeners on. The special "address" of C<*> means to bind on |
281 | to bind TCP listeners on. The special "address" of C<*> means to bind on |
282 | every local IP address. |
282 | every local IP address (this might not work on every OS, so it should not |
|
|
283 | be used unless you know it works). |
283 | |
284 | |
284 | The reason to bind on a TCP port is not just that other nodes can connect |
285 | The reason to bind on a TCP port is not just that other nodes can connect |
285 | to us: if no binds are specified, the node will still bind on a dynamic |
286 | to us: if no binds are specified, the node will still bind on a dynamic |
286 | port on all local addresses - but in this case we won't know the port, and |
287 | port on all local addresses - but in this case we won't know the port, and |
287 | cannot tell other nodes to connect to it as seed node. |
288 | cannot tell other nodes to connect to it as seed node. |
… | |
… | |
323 | N3--N4--- | |
324 | N3--N4--- | |
324 | \________/ |
325 | \________/ |
325 | |
326 | |
326 | All done: C<N5> is now happily connected to the rest of the network. |
327 | All done: C<N5> is now happily connected to the rest of the network. |
327 | |
328 | |
328 | Of course, this process takes time, during which the node is already |
329 | Apart form the obvious function - joining the network - seed nodes fulfill |
|
|
330 | another very important function: the connections created by connecting |
|
|
331 | to seed nodes are used to keep the network together - by trying to keep |
|
|
332 | connections to all seed nodes active, the network ensures that it will not |
|
|
333 | split into multiple networks without connection to each other. |
|
|
334 | |
|
|
335 | This means that the graph created by all seed node connections must span |
|
|
336 | the whole network, in some way. |
|
|
337 | |
|
|
338 | There are many ways of doing this - the most simple is probably to use |
|
|
339 | a single set of one or more seednodes as seednodes for all nodes in the |
|
|
340 | network - this creates a "hub" of seednodes that connect to each other, |
|
|
341 | and "leaf" nodes that connect to the nodes in the hub, keeping everything |
|
|
342 | together. |
|
|
343 | |
|
|
344 | The process of joining a network takes time, during which the node is |
329 | running. This also means it takes time until the node is fully connected, |
345 | already running. This also means it takes time until the node is fully |
330 | and global groups and other information is available. The best way to deal |
346 | connected, and global groups and other information is available. The best |
331 | with this is to either retry regularly until you found the resource you |
347 | way to deal with this is to either retry regularly until you found the |
332 | were looking for, or to only start services on demand after a node has |
348 | resource you were looking for, or to only start services on demand after a |
333 | become available. |
349 | node has become available. |
334 | |
350 | |
335 | =head3 Registering the Receiver |
351 | =head3 Registering the Receiver |
336 | |
352 | |
337 | Coming back to our example, we have now introduced the basic purpose of |
353 | Coming back to our example, we have now introduced the basic purpose of |
338 | L<AnyEvent::MP::Global> and C<configure> and its use of profiles. We |
354 | L<AnyEvent::MP::Global> and C<configure> and its use of profiles. We |