これは、なにをしたくて書いたもの?
最近のInfinispan Serverでクラスタを構成しようとして、ちょっと変化に気づいたので。
Infinispan Serverは10.0.0.Finalから新しいサーバーモジュールになっているのですが、この時にデフォルトのJGroups Stackが
UDPからTCPに変わっていたようです。
Blog: Infinispan 10.0.0.Final - Infinispan
環境
今回の環境は、こちら。
$ java --version openjdk 11.0.5 2019-10-15 OpenJDK Runtime Environment 18.9 (build 11.0.5+10) OpenJDK 64-Bit Server VM 18.9 (build 11.0.5+10, mixed mode)
Infinispan Serverは、10.1.0.Finalを使用します。
Cache ContainerのTransport Stackを見る
Infinispan Serverに含まれている設定ファイルの一覧は、こちら。
$ ls -l server/conf total 24 -rw-r--r-- 1 xxxxx xxxxx 569 Dec 23 07:55 groups.properties -rw-r--r-- 1 xxxxx xxxxx 2209 Dec 23 07:55 infinispan-local.xml -rw-r--r-- 1 xxxxx xxxxx 2731 Dec 23 07:55 infinispan-xsite.xml -rw-r--r-- 1 xxxxx xxxxx 2196 Dec 23 07:55 infinispan.xml -rw-r--r-- 1 xxxxx xxxxx 2425 Dec 23 07:55 logging.properties -rw-r--r-- 1 xxxxx xxxxx 802 Dec 23 07:55 users.properties
「server/conf/infinispan.xml」の中に記載されている、「cache-container」を見てみます。
<cache-container name="default" statistics="true"> <transport cluster="${infinispan.cluster.name}" stack="${infinispan.cluster.stack:tcp}"/> </cache-container>
特に指定がなければ、TCP Stackを使うように設定してありますね。
Infinispan Serverに含まれる設定ファイルは、こちら。
「infinispan.xml」は、こちらですね。
で、ここで指定されているTCP Stackとは、こちらのファイルのことになります。
その他のJGroups Stackについては、こちらのディレクトリを参照してください。
https://github.com/infinispan/infinispan/tree/10.1.0.Final/core/src/main/resources/default-configs
ドキュメントでの説明は、こちら。
Infinispan Server 10.0.0.Final以前(要は9.x以前で、WildFlyベースのサーバーの頃)は、デフォルトのJGroups StackはUDPでした。
こんな感じですね。
<stacks default="${jboss.default.jgroups.stack:udp}">
ちなみに、こんな感じでEmbedded ModeでAPIを使い、デフォルト設定のクラスタを組もうとするとUDPが使われます。
GlobalConfiguration globalConfiguration = GlobalConfigurationBuilder.defaultClusteredBuilder().build();
EmbeddedCacheManager manager = new DefaultCacheManager(globalConfiguration);
このあたりは、互換性の関係でしょうか?
TCP or UDP
さて、どうしてInfinispan Server 10.0.0.Finalから、デフォルトのJGroups StackがTCPになったのかはわかりませんが…。
デフォルトのStackがTCPになっているissue、Pull Requestは、見つけましたけどね…。
[ISPN-10450] ServerNG: improve the initial experience - Red Hat Issue Tracker
デフォルトのUDPとTCPの違いについては、ドキュメントを参照しましょう。
Uses UDP for transport and UDP multicast for discovery. Suitable for larger clusters (over 100 nodes) or if you are using replicated caches or invalidation mode. Minimises the number of open sockets.
Uses TCP for transport and UDP multicast for discovery. Suitable for smaller clusters (under 100 nodes) only if you are using distributed caches because TCP is more efficient than UDP as a point-to-point protocol.
UDPでもTCPでも、Node Discoveryにはマルチキャストを使います。
UDPは、100 Nodeより大きなクラスタ、またはReplicated CacheやInvalidation Modeに向くようです。
TCPは、100 Node以下の小さいクラスタでDistributed Cacheを使っている時に適します。
だそうで。
使い分けはわかるのですが、新しいサーバーモジュールでどうしてこうしたのかは、どこかに書いてあると(とても個人的にですが)
嬉しかったかなぁと思います。
デフォルトのTCP Stackでクラスタを組む
一応。
デフォルトでは、MPINGのbind_addrが127.0.0.1となっているため、他のホスト上のNodeとクラスタを組むことができません。
<MPING bind_addr="${jgroups.tcp.address:127.0.0.1}" mcast_addr="${jgroups.mcast_addr:228.6.7.8}" mcast_port="${jgroups.mcast_port:46655}" num_discovery_runs="3" ip_ttl="${jgroups.udp.ip_ttl:2}" />
これを変更するには、ドキュメントにもあるように「jgroups.tcp.address」システムプロパティに、バインドするIPアドレスを指定します。
-Djgroups.tcp.address=[バインドするIPアドレス]
Tuning JGroups Stacks with System Properties
こんな感じですね。
$ curl -O -L https://downloads.jboss.org/infinispan/10.1.0.Final/infinispan-server-10.1.0.Final.zip $ unzip infinispan-server-10.1.0.Final.zip $ cd infinispan-server-10.1.0.Final $ bin/server.sh -Djgroups.tcp.address=[バインドするIPアドレス]
オマケですが、クラスタに関係なく、デフォルトではInfinispan Serverは他のホストからアクセスすることもできません。
Hot Rodなどで使用されるIPアドレスも、デフォルトで127.0.0.1が使われるからです。バインドするアドレスを変更するには、
ドキュメントの以下を参照しましょう。
Changing the Default Bind Address for Infinispan Servers
「-b」オプションまたは「infinispan.bind.address」システムプロパティを使って、バインドするIPアドレスを指定します。