今度は、ちゃんと設定ファイルを用意して、クラスタ構成を取ってみようと思います。
以下、Infinispanのインストールディレクトリを「$ISPN_HOME」と表記します。あと、ここで出てくる設定ファイルは、すべて自分で追加したものです。
$ISPN_HOME/etc/infinispan-clustered.xml
<?xml version="1.0" encoding="UTF-8"?> <infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:infinispan:config:5.2 http://www.infinispan.org/schemas/infinispan-config-5.2.xsd" xmlns="urn:infinispan:config:5.2"> <global> <transport clusterName="hotrod-cluster"> <properties> <property name="configurationFile" value="jgroups-udp.xml" /> </properties> </transport> <globalJmxStatistics enabled="true" jmxDomain="org.infinispan" cacheManagerName="DefaultCacheManager" /> </global> <default> <jmxStatistics enabled="true" /> <clustering mode="distribution"> <hash numOwners="2" /> <sync /> </clustering> </default> </infinispan>
クラスタのモードは、分散です。
続いて、JGroupsの設定ファイル。
$ISPN_HOME/etc/jgroups-udp.xml
<?xml version="1.0" encoding="UTF-8"?> <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.2.xsd"> <UDP mcast_addr="${jgroups.udp.mcast_addr:228.11.11.11}" mcast_port="${jgroups.udp.mcast_port:45688}" tos="8" ucast_recv_buf_size="130000" ucast_send_buf_size="100000" mcast_recv_buf_size="130000" mcast_send_buf_size="100000" loopback="true" max_bundle_size="64000" max_bundle_timeout="30" ip_ttl="${jgroups.udp.ip_ttl:2}" enable_bundling="true" enable_unicast_bundling="true" enable_diagnostics="true" diagnostics_addr="${jboss.jgroups.diagnostics_addr:224.0.0.75}" diagnostics_port="${jboss.jgroups.diagnostics_port:7500}" thread_naming_pattern="hr-cl" 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="1000" thread_pool.rejection_policy="discard" oob_thread_pool.enabled="true" oob_thread_pool.min_threads="2" oob_thread_pool.max_threads="8" oob_thread_pool.keep_alive_time="1000" oob_thread_pool.queue_enabled="false" oob_thread_pool.rejection_policy="discard" /> <PING timeout="3000" num_initial_members="2" /> <!-- <FD timeout="3000" max_tries="5" /> --> <FD_ALL interval="3000" timeout="10000" /> <FD_SOCK /> <VERIFY_SUSPECT timeout="1500" /> <UNICAST2 /> <pbcast.NAKACK2 use_mcast_xmit="false" xmit_interval="1000" discard_delivered_msgs="true" /> <pbcast.GMS print_local_addr="true" join_timeout="3000" leave_timeout="3000" merge_timeout="3000" max_bundling_time="200" view_bundling="true" /> <UFC max_credits="500000" min_threshold="0.20" /> <MFC max_credits="500000" min_threshold="0.20" /> <MERGE3 max_interval="30000" min_interval="10000" /> <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000" max_bytes="400000" /> <FRAG2 frag_size="60000" /> </config>
バッファのサイズは、Linuxのカーネルパラメータのチューニングをしていないので、絞りまくってます。それにしても、まだ自信ないなぁ…。
それでは、Infinispanを2つ起動してみます。カレントディレクトリは、$ISPN_HOMEとします。
# ひとつ目 $ bin/startServer.sh -r memcached -p 11211 -c etc/infinispan-clustered.xml # ふたつ目 $ bin/startServer.sh -r memcached -p 11212 -c etc/infinispan-clustered.xml
今度は、Hot RodではなくtelnetでMemcachedプロトコルで試してみることにしました。
サーバが起動したところで、telnetで接続。
$ telnet localhost 11211 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. set key1 0 0 6 value1 STORED set key2 0 0 6 value2 STORED get key1 VALUE key1 0 6 value1 END get key2 VALUE key2 0 6 value2 END quit Connection closed by foreign host.
とりあえず、ひとつ目のサーバに接続して2つほどエントリを登録してみました。
続いて、ふたつ目のサーバに繋いで確認。
$ telnet localhost 11212 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. get key1 VALUE key1 0 6 value1 END get key2 VALUE key2 0 6 value2 END quit Connection closed by foreign host.
ちゃんと、値が取れることが確認できます。
ついでにもう1回繋いで、エントリをひとつ追加。
$ telnet localhost 11212 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. set key3 0 0 6 value3 STORED quit Connection closed by foreign host.
ここで、今度は3つ目のサーバを起動してみます。
$ bin/startServer.sh -r memcached -p 11213 -c etc/infinispan-clustered.xml
telnetで確認。
$ telnet localhost 11213 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. get key1 VALUE key1 0 6 value1 END get key2 VALUE key2 0 6 value2 END get key3 VALUE key3 0 6 value3 END quit Connection closed by foreign host.
全部の値が見えます。これ、すごいですね。
各サーバのローカルのキャッシュがどうなってるのか、ちょっと気になるところですね。JMXを使って少し遊んでみました。
まずは、1度全部のサーバを落として、再度2台起動。
$ bin/startServer.sh -r memcached -p 11211 -c etc/infinispan-clustered.xml $ bin/startServer.sh -r memcached -p 11212 -c etc/infinispan-clustered.xml
Key/Valueペアを3つ放り込みます。
$ telnet localhost 11211 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. set key1 0 0 6 value1 STORED set key2 0 0 6 value2 STORED set key3 0 0 6 value3 STORED quit Connection closed by foreign host.
JConsoleで覗いてみます。
今回の設定だと、「org.infinispan/Cache/memcachedCache(dist_sync)/DefaultCacheManager/Statistics」のnumberOfEntriesが持っているエントリの数のようです。ここでは、両方のサーバにエントリが3つあることになっています。
では、3つ目を起動。
$ bin/startServer.sh -r memcached -p 11213 -c etc/infinispan-clustered.xml
とりあえず、JConsoleで見てみます。
なんか、ひとつエントリがあることになってますね。
telnetで各エントリにアクセスしても、特に統計情報には変化なし。
$ telnet localhost 11213 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. get key1 VALUE key1 0 6 value1 END get key2 VALUE key2 0 6 value2 END get key3 VALUE key3 0 6 value3 END quit Connection closed by foreign host.
もちろん、キャッシュのヒット率とかは変わりますけど。
では、ここで2つ目のサーバを落としてみます。そして、3つ目のサーバの様子を見ると…
なんか、numberOfEntriesが3になっていますが…。
3つ目のサーバにもデータが入ったっぽくて、最終的にひとつ目のサーバも落としても3つ目のサーバだけで今まで入れたデータを見ることができました。
Key/Valueペアは3つしか入れてないわけですけど、それでもすごいですね…。