第7章 Web アプリケーションのクラスター化
7.1. セッションレプリケーション
7.1.1. セッションレプリケーション
7.1.2. [en-US] About the Web Session Cache
standalone-ha.xml
profile, or the managed domain profiles ha
or full-ha
. The most commonly configured elements are the cache mode and the number of cache owners for a distributed cache.
The cache mode can either be REPL
(the default) or DIST
.
- REPL
- The
REPL
mode replicates the entire cache to every other node in the cluster. This is the safest option, but introduces more overhead. - DIST
- The
DIST
mode is similar to the buddy mode provided in previous implementations. It reduces overhead by distributing the cache to the number of nodes specified in theowners
parameter. This number of owners defaults to2
.
The owners
parameter controls how many cluster nodes hold replicated copies of the session. The default is 2
.
7.1.3. [en-US] Configure the Web Session Cache
REPL
. If you wish to use DIST
mode, run the following two commands in the Management CLI. If you use a different profile, change the profile name in the commands. If you use a standalone server, remove the /profile=ha
portion of the commands.
手順7.1 Configure the Web Session Cache
Change the default cache mode to
DIST
./profile=ha/subsystem=infinispan/cache-container=web/:write-attribute(name=default-cache,value=dist)
Set the number of owners for a distributed cache.
The following command sets5
owners. The default is2
./profile=ha/subsystem=infinispan/cache-container=web/distributed-cache=dist/:write-attribute(name=owners,value=5)
Change the default cache mode back to
REPL
./profile=ha/subsystem=infinispan/cache-container=web/:write-attribute(name=default-cache,value=repl)
Restart the Server
After changing the web cache mode, you must restart the server.
Your server is configured for session replication. To use session replication in your own applications, refer to the following topic: 「アプリケーションにおけるセッションレプリケーションの有効化」.
7.1.4. アプリケーションにおけるセッションレプリケーションの有効化
Enterprise Application Platform の高可用性 (HA) 機能を利用するには、アプリケーションが配布可能になるよう設定する必要があります。ここでは配布可能にする手順を説明した後、使用可能な高度な設定オプションの一部について解説します。
手順7.2 タスク
要件: アプリケーションが配布可能であることを示します。
アプリケーションが配布可能になっていないとセッションが配布されません。アプリケーションのweb.xml
記述子ファイルの<web-app>
タグ内に<distributable />
要素を追加します。例は次の通りです。例7.1 配布可能なアプリケーションの最低限の設定
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <distributable/> </web-app>
希望する場合はデフォルトのレプリケーション動作を変更します。
セッションレプリケーションに影響する値を変更したい場合は、<jboss-web>
要素の子要素である<replication-config>
要素内で値を上書きします。デフォルトを上書きしたい場合のみ指定の要素が含まれるようにします。以下の例に、全デフォルト設定の一覧と、最も一般的に変更されるオプションを説明する表を示します。例7.2 デフォルトの
<replication-config>
値<jboss-web> <replication-config> <cache-name>custom-session-cache</cache-name> <replication-trigger>SET</replication-trigger> <replication-granularity>ATTRIBUTE</replication-granularity> <replication-field-batch-mode>true</replication-field-batch-mode> <use-jk>false</use-jk> <max-unreplicated-interval>30</max-unreplicated-interval> <snapshot-mode>INSTANT</snapshot-mode> <snapshot-interval>1000</snapshot-interval> <session-notification-policy>com.example.CustomSessionNotificationPolicy</session-notification-policy> </replication-config> </jboss-web>
表7.1 セッションレプリケーションの一般的なオプション
オプション
|
詳細
|
---|---|
<replication-trigger>
|
クラスター全体でセッションデータのレプリケーションが引き起こされるのはどのような状態であるか制御します。セッション属性として保存された可変オブジェクトがセッションからアクセスされた後、メソッド
setAttribute() が直接呼び出されない限り、オブジェクトが変更されレプリケーションが必要であるかをコンテナは明確に認識できないため、このオプションは必須となります。
設定に関係なく、
setAttribute() を呼び出すと常にセッションレプリケーションが引き起こされます。
|
<replication-granularity>
|
レプリケートされるデータの細かさを決定します。デフォルトは
SESSION ですが、ATTRIBUTE を設定すると、ほとんどの属性は変更されずにセッションのパフォーマンスを向上することができます。
|
表7.2 セッションレプリケーションの変更が稀なオプション
オプション
|
詳細
|
---|---|
<useJK>
| mod_cluster や mod_jk 、mod_proxy などのロードバランサーの使用を前提とするか指定します。デフォルトは false です。 true に設定すると、各要求に関連付けられているセッション ID がコンテナによって確認され、フェイルオーバーが発生するとセッション ID の jvmRoute の部分が置き換えられます。
|
<max-unreplicated-interval>
|
セッションのタイムスタンプのレプリケーションがトリガーされるまで、セッション後に待機する最大間隔 (秒単位) になります。変更がないと判断された場合でも適用されます。これにより、各セッションのタイムスタンプがクラスターノードによって認識されるようにし、フェイルオーバー中にレプリケートされなかったセッションが誤って期限切れにならないようにします。また、フェイルオーバー中に
HttpSession.getLastAccessedTime() への呼び出しに対する正しい値を信頼できるようにします。
デフォルトでは値は指定されません。値が指定されないと、コンテナの
jvmRoute 設定が JK フェイルオーバーが使用されているかを判断します。 0 を設定すると、セッションがアクセスされるたびにタイムスタンプがレプリケートされます。-1 を設定すると、要求中の他のアクティビティがレプリケーションをトリガーした場合のみタイムスタンプがレプリケートされます。 HttpSession.getMaxInactiveInterval() よりも大きい正の値を設定すると設定ミスとして扱われ、0 に変換されます。
|
<snapshot-mode>
|
セッションが他のノードへレプリケートされるタイミングを指定します。デフォルトは
INSTANT で、INTERVAL を使用することも可能です。
INSTANT モードでは要求処理スレッドが使用され、変更は要求の最後にレプリケートされます。<snapshot-interval> オプションは無視されます。
INTERVAL モードでは、バックグラウンドタスクは <snapshot-interval> によって指定される間隔で実行され、変更されたセッションがレプリケートされます。
|
<snapshot-interval>
| INTERVAL が <snapshot-mode> の値として使用された時に、変更されたセッションがレプリケートされる間隔 (ミリ秒単位) になります。
|
<session-notification-policy>
|
インターフェース
ClusteredSessionNotificationPolicy の実装の完全修飾クラス名です。登録された HttpSessionListener 、HttpSessionAttributeListener 、 HttpSessionBindingListener へサーブレット仕様の通知が発信されたかどうかを管理します。
|