/
advanced.xml
2585 lines (2285 loc) · 127 KB
/
advanced.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?>
<chapter id="user-advanced">
<title>Advanced Concepts</title>
<para>
This chapter discusses some of the more advanced concepts of JGroups with respect to using it and setting it
up correctly.
</para>
<section>
<title>Using multiple channels</title>
<para>
When using a fully virtual synchronous protocol stack, the performance may not be great because of the
larger number of protocols present. For certain applications, however, throughput is more important than
ordering, e.g. for video/audio streams or airplane tracking. In the latter case, it is important that
airplanes are handed over between control domains correctly, but if there are a (small) number of radar
tracking messages (which determine the exact location of the plane) missing, it is not a problem. The first
type of messages do not occur very often (typically a number of messages per hour), whereas the second type of
messages would be sent at a rate of 10-30 messages/second. The same applies for a distributed whiteboard:
messages that represent a video or audio stream have to be delivered as quick as possible, whereas messages
that represent figures drawn on the whiteboard, or new participants joining the whiteboard have to be
delivered according to a certain order.
</para>
<para>
The requirements for such applications can be solved by using two separate channels: one for control messages
such as group membership, floor control etc and the other one for data messages such as video/audio streams
(actually one might consider using one channel for audio and one for video). The control channel might use
virtual synchrony, which is relatively slow, but enforces ordering and retransmission, and the data channel
might use a simple UDP channel, possibly including a fragmentation layer, but no retransmission layer (losing
packets is preferred to costly retransmission).
</para>
</section>
<section id="SharedTransport">
<title>Sharing a transport between multiple channels in a JVM</title>
<para>
A transport protocol (UDP, TCP) has all the resources of a stack: the default thread pool, the OOB thread
pool and the timer thread pool. If we run multiple channels in the same JVM, instead of creating 4
separate stacks with a separate transport each, we can create the transport protocol as a
<emphasis>singleton</emphasis> protocol, shared by all 4 stacks.
</para>
<para>
If those transports happen to be the same (all 4 channels use UDP, for example), then we can share them and
only create 1 instance of UDP. That transport instance is created and started only once; when the first
channel is created, and is deleted when the last channel is closed.
</para>
<para>
If we have 4 channels inside of a JVM (as is the case in an application server such as JBoss), then we
have 12 separate thread pools (3 per transport, 4 transports). Sharing the transport reduces this to 3.
</para>
<para>
Each channel created over a shared transport has to join a different cluster. An exception will be thrown
if a channel sharing a transport tries to connect to a cluster to which another channel over the same
transport is already connected.
</para>
<para>
This is needed to multiplex and de-multiplex messages between the shared transport and the different stacks
running over it; when we have 3 channels (C1 connected to "cluster-1", C2 connected to "cluster-2" and C3
connected to "cluster-3") sending messages over the same shared transport, the cluster name
with which the channel connected is used to multiplex messages over the shared transport: a header with
the cluster name ("cluster-1") is added when C1 sends a message.
</para>
<para>
When a message with a header of "cluster-1" is received by the shared transport, it is used to demultiplex
the message and dispatch it to the right channel (C1 in this example) for processing.
</para>
<para>
How channels can share a single transport is shown in <xref linkend="SharedTransportFig"/>.
</para>
<figure id="SharedTransportFig"><title>A shared transport</title>
<graphic fileref="images/SharedTransport.png" format="PNG" align="center" scale="75" />
</figure>
<para>
Here we see 4 channels which share 2 transports. Note that first 3 channels which share transport
"tp_one" have the same protocols on top of the shared transport. This is <emphasis>not</emphasis>
required; the protocols above "tp_one" could be different for each of the 3 channels as long
as all applications residing on the same shared transport have the same requirements for the transport's
configuration.
</para>
<para>
The "tp_two" transport is used by the application on the right side.
</para>
<para>
Note that the physical address of a shared channel is the same for all connected channels, so all
applications sharing the first transport have physical address 192.168.2.5:35181.
</para>
<para>
To use shared transports, all we need to do is to add a property "singleton_name" to the transport
configuration. All channels with the same singleton name will be shared:
</para>
<programlisting language="XML">
<UDP ...
singleton_name="tp_one" ...
/>
</programlisting>
<para>
All channels using this configuration will now shared transport "tp_one". The channel on the right will
have a different configuration, with singleton_name="tp_two".
</para>
</section>
<section>
<title>Transport protocols</title>
<para>
A <emphasis>transport protocol</emphasis> refers to the protocol at the bottom of the protocol stack which is
responsible for sending messages to and receiving messages from the network. There are a number of transport
protocols in JGroups. They are discussed in the following sections.
</para>
<para>
A typical protocol stack configuration using UDP is:
</para>
<programlisting language="XML">
<config xmlns="urn:org:jgroups"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/JGroups-3.0.xsd">
<UDP
mcast_port="${jgroups.udp.mcast_port:45588}"
tos="8"
ucast_recv_buf_size="20M"
ucast_send_buf_size="640K"
mcast_recv_buf_size="25M"
mcast_send_buf_size="640K"
loopback="true"
discard_incompatible_packets="true"
max_bundle_size="64K"
max_bundle_timeout="30"
ip_ttl="${jgroups.udp.ip_ttl:2}"
enable_bundling="true"
enable_diagnostics="true"
thread_naming_pattern="cl"
timer_type="new"
timer.min_threads="4"
timer.max_threads="10"
timer.keep_alive_time="3000"
timer.queue_max_size="500"
thread_pool.enabled="true"
thread_pool.min_threads="2"
thread_pool.max_threads="8"
thread_pool.keep_alive_time="5000"
thread_pool.queue_enabled="true"
thread_pool.queue_max_size="10000"
thread_pool.rejection_policy="discard"
oob_thread_pool.enabled="true"
oob_thread_pool.min_threads="1"
oob_thread_pool.max_threads="8"
oob_thread_pool.keep_alive_time="5000"
oob_thread_pool.queue_enabled="false"
oob_thread_pool.queue_max_size="100"
oob_thread_pool.rejection_policy="Run"/>
<PING timeout="2000"
num_initial_members="3"/>
<MERGE2 max_interval="30000"
min_interval="10000"/>
<FD_SOCK/>
<FD_ALL/>
<VERIFY_SUSPECT timeout="1500" />
<BARRIER />
<pbcast.NAKACK use_mcast_xmit="true"
retransmit_timeout="300,600,1200"
discard_delivered_msgs="true"/>
<UNICAST timeout="300,600,1200"/>
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
max_bytes="4M"/>
<pbcast.GMS print_local_addr="true" join_timeout="3000"
view_bundling="true"/>
<UFC max_credits="2M"
min_threshold="0.4"/>
<MFC max_credits="2M"
min_threshold="0.4"/>
<FRAG2 frag_size="60K" />
<pbcast.STATE_TRANSFER />
</config>
</programlisting>
<para>
In a nutshell the properties of the protocols are:
</para>
<variablelist>
<varlistentry>
<term>UDP</term>
<listitem>
<para>
This is the transport protocol. It uses IP multicasting to send messages to the entire cluster,
or individual nodes. Other transports include TCP and TUNNEL.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>PING</term>
<listitem>
<para>
This is the discovery protocol. It uses IP multicast (by default) to find initial members.
Once found, the current coordinator can be determined and a unicast JOIN request will be sent
to it in order to join the cluster.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>MERGE2</term>
<listitem>
<para>Will merge sub-clusters back into one cluster, kicks in after a network partition healed.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>FD_SOCK</term>
<listitem>
<para>
Failure detection based on sockets (in a ring form between members). Generates notification
if a member fails
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>FD / FD_ALL</term>
<listitem>
<para>Failure detection based on heartbeat are-you-alive messages. Generates notification
if a member fails</para>
</listitem>
</varlistentry>
<varlistentry>
<term>VERIFY_SUSPECT</term>
<listitem>
<para>Double-checks whether a suspected member is really dead,
otherwise the suspicion generated from protocol below is discarded</para>
</listitem>
</varlistentry>
<varlistentry>
<term>BARRIER</term>
<listitem>
<para>
Needed to transfer state; this will block messages that modify the shared state until a
digest has been taken, then unblocks all threads. <emphasis>Not needed
if no state transfer protocol is present.</emphasis>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>pbcast.NAKACK</term>
<listitem>
<para>Ensures (a) message reliability and (b) FIFO. Message
reliability guarantees that a message will be received. If not,
the receiver(s) will request retransmission. FIFO guarantees that all
messages from sender P will be received in the order P sent them</para>
</listitem>
</varlistentry>
<varlistentry>
<term>UNICAST</term>
<listitem>
<para>Same as NAKACK for unicast messages: messages from sender P
will not be lost (retransmission if necessary) and will be in FIFO
order (conceptually the same as TCP in TCP/IP)</para>
</listitem>
</varlistentry>
<varlistentry>
<term>pbcast.STABLE</term>
<listitem>
<para>Deletes messages that have been seen by all members (distributed message garbage collection)</para>
</listitem>
</varlistentry>
<varlistentry>
<term>pbcast.GMS</term>
<listitem>
<para>Membership protocol. Responsible for joining/leaving members and installing new views.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>UFC</term>
<listitem>
<para>
Unicast Flow Control. Provides flow control between 2 members.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>MFC</term>
<listitem>
<para>
Multicast Flow Control. Provides flow control between a sender and all cluster members.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>FRAG2</term>
<listitem>
<para>Fragments large messages into smaller ones and reassembles
them back at the receiver side. For both multicast and unicast messages</para>
</listitem>
</varlistentry>
<varlistentry>
<term>STATE_TRANSFER</term>
<listitem>
<para>
Ensures that state is correctly transferred from an existing member (usually the coordinator) to a
new member.
</para>
</listitem>
</varlistentry>
</variablelist>
<section id="MessageBundling">
<title>Message bundling</title>
<para>
Message bundling is beneficial when sending many small messages; it queues them until they have accumulated
a certain size, or until a timeout has elapsed. Then, the queued messages are assembled into a larger
message, and that message is then sent. At the receiver, the large message is disassembled and the
smaller messages are sent up the stack.
</para>
<para>
When sending many smaller messages, the ratio between payload and message headers might be small; say we
send a "hello" string: the payload here is 7 bytes, whereas the addresses and headers (depending on the
stack configuration) might be 30 bytes. However, if we bundle (say) 100 messages, then the payload of
the large message is 700 bytes, but the header is still 30 bytes. Thus, we're able to send more
actual data across the wire with one large message than many smaller ones.
</para>
<para>
Message bundling is conceptually similar to TCP's Nagling algorithm.
</para>
<para>
A sample configuration is shown below:
</para>
<programlisting language="XML">
<UDP
enable_bundling="true"
max_bundle_size="64K"
max_bundle_timeout="30"
/>
</programlisting>
<para>
Here, bundling is enabled (the default). The max accumulated size is 64'000 bytes and we wait for
30 ms max. If at time T0, we're sending 10 smaller messages with an accumulated size of 2'000 bytes, but
then send no more messages, then the timeout will kick in after 30 ms and the messages will get packed
into a large message M and M will be sent. If we send 1000 messages of 100 bytes each, then - after
exceeding 64'000 bytes (after ca. 64 messages) - we'll send the large message, and this might have taken
only 3 ms.
</para>
<section id="MessageBundlingAndPerf">
<title>Message bundling and performance</title>
<para>
While message bundling is good when sending many small messages asynchronously, it can be bad when
invoking synchronous RPCs: say we're invoking 10 synchronous (blocking) RPCs across the cluster
with an RpcDispatcher (see <xref linkend="RpcDispatcher"/>), and the payload of the marshalled
arguments of one call is less than 64K.
</para>
<para>
Because the RPC is blocking, we'll wait until the call has returned before invoking the next RPC.
</para>
<para>
For each RPC, the request takes up to 30 ms, and each response will also take up to 30 ms, for a
total of 60 ms <emphasis>per call</emphasis>. So the 10 blocking RPCs would take a total of 600 ms !
</para>
<para>
This is clearly not desirable. However, there's a simple solution: we can use message flags
(see <xref linkend="MessageFlags"/>) to override the default bundling behavior in the transport:
</para>
<programlisting language="Java">
RpcDispatcher disp;
RequestOptions opts=new RequestOptions(ResponseMode.GET_ALL, 5000)
.setFlags(Message.DONT_BUNDLE);
RspList rsp_list=disp.callRemoteMethods(null,
"print",
new Object[]{i},
new Class[]{int.class},
opts);
</programlisting>
<para>
The <methodname>RequestOptions.setFlags(Message.DONT_BUNDLE)</methodname> call tags the message
with the DONT_BUNDLE flag. When the message is to be sent by the transport, it will be sent
immediately, regardless of whether bundling is enabled in the transport.
</para>
<para>
Using the DONT_BUNDLE flag to invoke <methodname>print()</methodname> will take a few milliseconds
for 10 blocking RPCs versus 600 ms without the flag.
</para>
<para>
An alternative to setting the DONT_BUNDLE flag is to use futures to invoke 10 blocking RPCs:
</para>
<programlisting language="Java">
List<Future<RspList>> futures=new ArrayList<Future<RspList>>();
for(int i=0; i < 10; i++) {
Future<RspList> future=disp.callRemoteMethodsWithFuture(...);
futures.add(future);
}
for(Future<RspList> future: futures) {
RspList rsp_list=future.get();
// do something with the response
}
</programlisting>
<para>
Here we use <methodname>callRemoteMethodsWithFuture()</methodname> which (although the call
is blocking!) returns immediately, with a future. After invoking the 10 calls, we then grab the
results by fetching them from the futures.
</para>
<para>
Compared to the few milliseconds above, this will take ca 60 ms (30 for the request and 30 for
the responses), but this is still better than the 600 ms we get when not using the DONT_BUNDLE
flag. Note that, if the accumulated size of the 10 requests exceeds <literal>max_bundle_size</literal>,
the large message would be sent immediately, so this might even be faster than 30 ms for the request.
</para>
</section>
</section>
<section>
<title>UDP</title>
<para>
UDP uses <emphasis>IP multicast</emphasis> for sending messages to all members of a cluster, and
<emphasis>UDP datagrams</emphasis> for unicast messages (sent to a single member). When started, it
opens a unicast and multicast socket: the unicast socket is used to send/receive unicast messages,
while the multicast socket sends/receives multicast messages. The physical address of the channel will
be the address and port number of the <emphasis>unicast</emphasis> socket.
</para>
<section>
<title>Using UDP and plain IP multicasting</title>
<para>
A protocol stack with UDP as transport protocol is typically used with clusters whose members run on
the same host or are distributed across a LAN. Note that before running instances
<emphasis>in different subnets</emphasis>, an admin has to make sure that IP multicast is enabled
across subnets. It is often the case that IP multicast is not enabled across subnets.
Refer to section <xref linkend="ItDoesntWork"/> for running a test program that determines whether
members can reach each other via IP multicast. If this does not work, the protocol stack cannot use
UDP with IP multicast as transport. In this case, the stack has to either use UDP without IP
multicasting, or use a different transport such as TCP.
</para>
</section>
<section id="IpNoMulticast">
<title>Using UDP without IP multicasting</title>
<para>
The protocol stack with UDP and PING as the bottom protocols use IP multicasting by default to
send messages to all members (UDP) and for discovery of the initial members (PING). However, if
multicasting cannot be used, the UDP and PING protocols can be configured to send multiple unicast
messages instead of one multicast message
<footnote>
<para>Although not as efficient (and using more bandwidth), it is sometimes the only possibility
to reach group members.
</para>
</footnote>.
</para>
<para>
To configure UDP to use multiple unicast messages to send a group message instead of using IP
multicasting, the <parameter>ip_mcast</parameter> property has to be set to <literal>false</literal>.
</para>
<para>
If we disable ip_mcast, we now also have to change the discovery protocol (PING). Because PING
requires IP multicasting to be enabled in the transport, we cannot use it. Some of the alternatives
are TCPPING (static list of member addresses), TCPGOSSIP (external lookup service), FILE_PING
(shared directory), BPING (using broadcasts) or JDBC_PING (using a shared database).
</para>
<para>
See <xref linkend="DiscoveryProtocols"/> for details on configuration of different discovery
protocols.
</para>
</section>
</section>
<section>
<title>TCP</title>
<para>
TCP is a replacement for UDP as transport in cases where IP multicast cannot be used.
This may be the case when operating over a WAN, where routers might discard IP multicast packets.
Usually, UDP is used as transport in LANs, while TCP is used for clusters spanning WANs.
</para>
<para>
The properties for a typical stack based on TCP might look like this (edited for brevity):
</para>
<programlisting language="XML">
<TCP bind_port="7800" />
<TCPPING timeout="3000"
initial_hosts="${jgroups.tcpping.initial_hosts:HostA[7800],HostB[7801]}"
port_range="1"
num_initial_members="3"/>
<VERIFY_SUSPECT timeout="1500" />
<pbcast.NAKACK use_mcast_xmit="false"
retransmit_timeout="300,600,1200,2400,4800"
discard_delivered_msgs="true"/>
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
max_bytes="400000"/>
<pbcast.GMS print_local_addr="true" join_timeout="3000"
view_bundling="true"/>
</programlisting>
<variablelist>
<varlistentry>
<term>TCP</term>
<listitem>
<para>The transport protocol, uses TCP (from TCP/IP) to send
unicast and multicast messages. In the latter case, it sends
multiple unicast messages.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>TCPPING</term>
<listitem>
<para>Discovers the initial membership to determine coordinator.
Join request will then be sent to coordinator.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>VERIFY_SUSPECT</term>
<listitem>
<para>Double checks that a suspected member is really dead</para>
</listitem>
</varlistentry>
<varlistentry>
<term>pbcast.NAKACK</term>
<listitem>
<para>Reliable and FIFO message delivery</para>
</listitem>
</varlistentry>
<varlistentry>
<term>pbcast.STABLE</term>
<listitem>
<para>Distributed garbage collection of messages seen by all
members</para>
</listitem>
</varlistentry>
<varlistentry>
<term>pbcast.GMS</term>
<listitem>
<para>Membership services. Takes care of joining and removing
new/old members, emits view changes</para>
</listitem>
</varlistentry>
</variablelist>
<para>
When using TCP, each message to all of the cluster members is sent as multiple unicast messages
(one to each member). Due to the fact that IP multicasting cannot be used to discover the initial
members, another mechanism has to be used to find the initial membership. There are a number of
alternatives (see <xref linkend="DiscoveryProtocols"/> for a discussion of all discovery protocols):
</para>
<itemizedlist>
<listitem>
<para>
TCPPING: uses a list of well-known group members that it solicits for initial membership
</para>
</listitem>
<listitem>
<para>TCPGOSSIP: this requires a GossipRouter (see below), which is an external process, acting
as a lookup service. Cluster members register with under their cluster name, and new members
query the GossipRouter for initial cluster membership information.
</para>
</listitem>
</itemizedlist>
<para>
The next two section illustrate the use of TCP with both TCPPING and TCPGOSSIP.
</para>
<section id="TCPPING">
<title>Using TCP and TCPPING</title>
<para>
A protocol stack using TCP and TCPPING looks like this (other protocols omitted):
</para>
<programlisting language="XML">
<TCP bind_port="7800" /> +
<TCPPING initial_hosts="HostA[7800],HostB[7800]" port_range="2"
timeout="3000" num_initial_members="3" />
</programlisting>
<para>
The concept behind TCPPING is that some selected cluster members assume the role of well-known hosts
from which the initial membership information can be retrieved. In the example,
<parameter>HostA</parameter> and <parameter>HostB</parameter> are designated members that will be
used by TCPPING to lookup the initial membership. The property <parameter>bind_port</parameter>
in <classname>TCP</classname> means that each member should try to assign port 7800 for itself.
If this is not possible it will try the next higher port (<literal>7801</literal>) and so on, until
it finds an unused port.
</para>
<para>
<classname>TCPPING</classname> will try to contact both <parameter>HostA</parameter> and
<parameter>HostB</parameter>, starting at port <literal>7800</literal> and ending at port
<literal>7800 + port_range</literal>, in the above example ports <literal>7800</literal> -
<literal>7802</literal>. Assuming that at least one of <parameter>HostA</parameter> or
<parameter>HostB</parameter> is up, a response will be received. To be absolutely sure to receive
a response, it is recommended to add all the hosts on which members of the cluster will be running
to the configuration.
</para>
</section>
<section id="TCPGOSSIP">
<title>Using TCP and TCPGOSSIP</title>
<para>
<classname>TCPGOSSIP</classname> uses one or more GossipRouters to (1) register itself and (2)
fetch information about already registered cluster members. A configuration looks like this:
</para>
<programlisting language="XML">
<TCP />
<TCPGOSSIP initial_hosts="HostA[5555],HostB[5555]" num_initial_members="3" />
</programlisting>
<para>
The <parameter>initial_hosts</parameter> property is a comma-delimited list of GossipRouters.
In the example there are two GossipRouters on HostA and HostB, at port <literal>5555</literal>.
</para>
<para>
A member always registers with all GossipRouters listed, but fetches information from the first
available GossipRouter. If a GossipRouter cannot be accessed, it will be marked as failed and removed
from the list. A task is then started, which tries to periodically reconnect to the failed process.
On reconnection, the failed GossipRouter is marked as OK, and re-inserted into the list.
</para>
<para>
The advantage of having multiple GossipRouters is that, as long as at least one is running,
new members will always be able to retrieve the initial membership.
</para>
<para>
Note that the GossipRouter should be started before any of the members.
</para>
</section>
</section>
<section id="TUNNEL_Advanced">
<title>TUNNEL</title>
<para>
Firewalls are usually placed at the connection to the internet. They shield local networks from outside
attacks by screening incoming traffic and rejecting connection attempts to host inside the firewalls by
outside machines. Most firewall systems allow hosts inside the firewall to connect to hosts outside it
(outgoing traffic), however, incoming traffic is most often disabled entirely.
</para>
<para>
<emphasis>Tunnels</emphasis> are host protocols which encapsulate other protocols by multiplexing them
at one end and demultiplexing them at the other end. Any protocol can be tunneled by a tunnel protocol.
</para>
<para>
The most restrictive setups of firewalls usually disable <emphasis>all</emphasis> incoming traffic, and
only enable a few selected ports for outgoing traffic. In the solution below, it is
assumed that one TCP port is enabled for outgoing connections to the GossipRouter.
</para>
<para>
JGroups has a mechanism that allows a programmer to tunnel a firewall. The solution involves a
GossipRouter, which has to be outside of the firewall, so other members (possibly also behind firewalls)
can access it.
</para>
<para>
The solution works as follows. A channel inside a firewall has to use protocol TUNNEL instead of UDP or
TCP as transport. The recommended discovery protocol is PING. Here's a configuration:
</para>
<programlisting language="XML">
<TUNNEL gossip_router_hosts="HostA[12001]" />
<PING />
</programlisting>
<para>
<classname>TUNNEL</classname> uses a GossipRouter (outside the firewall) running on HostA at port
<literal>12001</literal> for tunneling. Note that it is not recommended to use TCPGOSSIP for discovery if
TUNNEL is used (use PING instead). TUNNEL accepts one or multiple GossipRouters tor tunneling;
they can be listed as a comma delimited list of host[port] elements specified in property
gossip_router_hosts.
</para>
<para>
<classname>TUNNEL</classname> establishes a TCP connection to the <emphasis>GossipRouter</emphasis>
process (outside the firewall) that accepts messages from members and passes them on to other
members. This connection is initiated by the host inside the firewall and persists as long as the channel
is connected to a group. A GossipRouter will use the <emphasis>same connection</emphasis>
to send incoming messages to the channel that initiated the connection. This is perfectly legal, as TCP
connections are fully duplex. Note that, if GossipRouter tried to establish its own TCP connection to the
channel behind the firewall, it would fail. But it is okay to reuse the existing TCP connection,
established by the channel.
</para>
<para>
Note that <classname>TUNNEL</classname> has to be given the hostname and port of the GossipRouter process.
This example assumes a GossipRouter is running on HostA at port<literal>12001</literal>.
TUNNEL accepts one or multiple router hosts as a comma delimited list of host[port] elements specified in
property gossip_router_hosts.
</para>
<para>
Any time a message has to be sent, TUNNEL forwards the message to GossipRouter, which distributes it to
its destination: if the message's destination field is null (send to all group members), then GossipRouter
looks up the members that belong to that group and forwards the message to all of them via the TCP
connections they established when connecting to GossipRouter. If the destination is a valid member address,
then that member's TCP connection is looked up, and the message is forwarded to it
<footnote>
<para>To do so, GossipRouter maintains a mapping between cluster names and member addresses, and TCP
connections.
</para>
</footnote>
.
</para>
<para>
A GossipRouter is not a single point of failure. In a setup with multiple gossip routers, the routers do
not communicate among themselves, and a single point of failure is avoided by having each channel simply
connect to multiple available routers. In case one or more routers go down, the cluster members are still
able to exchange messages through any of the remaining available router instances, if there are any.
</para>
<para>
For each send invocation, a channel goes through a list of available connections to routers and attempts
to send the message on each connection until it succeeds. If a message can not be sent on any of the
connections, an exception is raised. The default policy for connection selection is random. However, we
provide an plug-in interface for other policies as well.
</para>
<para>
The GossipRouter configuration is static and is not updated for the lifetime of the channel. A list of
available routers has to be provided in the channel's configuration file.
</para>
<para>
To tunnel a firewall using JGroups, the following steps have to be taken:
</para>
<orderedlist>
<listitem>
<para>Check that a TCP port (e.g. 12001) is enabled in the firewall for outgoing traffic</para>
</listitem>
<listitem>
<para>Start the GossipRouter:
<screen>java org.jgroups.stack.GossipRouter -port 12001</screen>
</para>
</listitem>
<listitem>
<para>Configure the TUNNEL protocol layer as instructed above.</para>
</listitem>
<listitem>
<para>Create a channel</para>
</listitem>
</orderedlist>
<para>The general setup is shown in
<xref linkend="TunnelingFig"/>
.
</para>
<figure id="TunnelingFig">
<title>Tunneling a firewall</title>
<mediaobject>
<imageobject>
<imagedata align="center" fileref="images/Tunneling.png"/>
</imageobject>
<textobject>
<phrase>A diagram representing tunneling a firewall.</phrase>
</textobject>
</mediaobject>
</figure>
<para>
First, the GossipRouter process is created on host B. Note that host B should be outside the firewall,
and all channels in the same group should use the same GossipRouter process. When a channel on host A is
created, its <classname>TCPGOSSIP</classname>
protocol will register its address with the GossipRouter and retrieve the initial membership (assume this
is C). Now, a TCP connection with the GossipRouter is established by A; this will persist until A crashes
or voluntarily leaves the group. When A multicasts a message to the cluster, GossipRouter looks up all cluster
members (in this case, A and C) and forwards the message to all members, using their TCP connections. In
the example, A would receive its own copy of the multicast message it sent, and another copy would be sent
to C.
</para>
<para>
This scheme allows for example
<emphasis>Java applets</emphasis>
, which are only allowed to connect back to the host from which they were downloaded, to use JGroups: the
HTTP server would be located on host B and the gossip and GossipRouter daemon would also run on that host.
An applet downloaded to either A or C would be allowed to make a TCP connection to B. Also, applications
behind a firewall would be able to talk to each other, joining a group.
</para>
<para>However, there are several drawbacks: first, having to maintain a TCP connection for the duration of the
connection might use up resources in the host system (e.g. in the GossipRouter), leading to scalability
problems, second, this scheme is inappropriate when only a few channels are located behind firewalls, and
the vast majority can indeed use IP multicast to communicate, and finally, it is not always possible to
enable outgoing traffic on 2 ports in a firewall, e.g. when a user does not 'own' the firewall.
</para>
</section>
</section>
<section id="ConcurrentStack">
<title>The concurrent stack</title>
<para>
The concurrent stack (introduced in 2.5) provides a number of improvements over previous releases,
which has some deficiencies:
<itemizedlist>
<listitem>
Large number of threads: each protocol had by default 2 threads, one for the up and one for the
down queue. They could be disabled per protocol by setting up_thread or down_thread to false.
In the new model, these threads have been removed.
</listitem>
<listitem>
Sequential delivery of messages: JGroups used to have a single queue for incoming messages,
processed by one thread. Therefore, messages from different senders were still processed in
FIFO order. In 2.5 these messages can be processed in parallel.
</listitem>
<listitem>
Out-of-band messages: when an application doesn't care about the ordering properties of a message,
the OOB flag can be set and JGroups will deliver this particular message without regard for any
ordering.
</listitem>
</itemizedlist>
</para>
<section>
<title>Overview</title>
<para>
The architecture of the concurrent stack is shown in <xref linkend="ConcurrentStackFig"/>. The changes
were made entirely inside of the transport protocol (TP, with subclasses UDP, TCP and TCP_NIO). Therefore,
to configure the concurrent stack, the user has to modify the config for (e.g.) UDP in the XML file.
</para>
<para>
<figure id="ConcurrentStackFig"><title>The concurrent stack</title>
<graphic fileref="images/ConcurrentStack.png" format="PNG" align="left" scale="75"/>
</figure>
</para>
<para>
</para>
<para>
The concurrent stack consists of 2 thread pools (java.util.concurrent.Executor): the out-of-band (OOB)
thread pool and the regular thread pool. Packets are received by multicast or unicast receiver threads
(UDP) or a ConnectionTable (TCP, TCP_NIO). Packets marked as OOB (with Message.setFlag(Message.OOB)) are
dispatched to the OOB thread pool, and all other packets are dispatched to the regular thread pool.
</para>
<para>
When a thread pool is disabled, then we use the thread of the caller (e.g. multicast or unicast
receiver threads or the ConnectionTable) to send the message up the stack and into the application.
Otherwise, the packet will be processed by a thread from the thread pool, which sends the message up
the stack. When all current threads are busy, another thread might be created, up to the maximum number
of threads defined. Alternatively, the packet might get queued up until a thread becomes available.
</para>
<para>
The point of using a thread pool is that the receiver threads should only receive the packets and forward
them to the thread pools for processing, because unmarshalling and processing is slower than simply
receiving the message and can benefit from parallelization.
</para>
<section>
<title>Configuration</title>
<para>Note that this is preliminary and names or properties might change</para>
<para>
We are thinking of exposing the thread pools programmatically, meaning that a developer might be able to set both
threads pools programmatically, e.g. using something like TP.setOOBThreadPool(Executor executor).
</para>
<para>
Here's an example of the new configuration:
</para>
<programlisting language="XML">
<UDP
thread_naming_pattern="cl"
thread_pool.enabled="true"
thread_pool.min_threads="1"
thread_pool.max_threads="100"
thread_pool.keep_alive_time="20000"
thread_pool.queue_enabled="false"
thread_pool.queue_max_size="10"
thread_pool.rejection_policy="Run"
oob_thread_pool.enabled="true"
oob_thread_pool.min_threads="1"
oob_thread_pool.max_threads="4"
oob_thread_pool.keep_alive_time="30000"
oob_thread_pool.queue_enabled="true"
oob_thread_pool.queue_max_size="10"
oob_thread_pool.rejection_policy="Run"/>
</programlisting>
<para>
The attributes for the 2 thread pools are prefixed with thread_pool and oob_thread_pool respectively.
</para>
<para>
The attributes are listed below. The roughly correspond to the options of a
java.util.concurrent.ThreadPoolExecutor in JDK 5.
<table>
<title>Attributes of thread pools</title>
<tgroup cols="2">
<colspec align="left" />
<thead>
<row>
<entry align="center">Name</entry>
<entry align="center">Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>thread_naming_pattern</entry>
<entry>Determines how threads are named that are running from thread pools in
concurrent stack. Valid values include any combination of "cl" letters, where
"c" includes the cluster name and "l" includes local address of the channel.
The default is "cl"
</entry>
</row>
<row>
<entry>enabled</entry>
<entry>Whether of not to use a thread pool. If set to false, the caller's thread