• No results found

SET_AND_NON_PRIMITIVE_GET

Important

SET_AND_NON_PRIMITIVE_GET

The default value. Session data is only replicated if an object of a non-primitive type is accessed. This means that the object is not of a well-known Java type such as Integer, Long, or String.

SET

This option assumes that the application will explicitly call setAttributeon the session when the data needs to be replicated. It prevents unnecessary replication and can benefit overall performance, but is inherently unsafe. Regardless of the setting, you can always trigger session replication by calling setAttribute().

<replication- granularity>

Determines the granularity of data that is replicated. It defaults to SESSION, but can be set to AT T RIBUT E instead, to increase performance on sessions where most attributes remain unchanged. The following options rarely need to be changed.

Table 8.2. Less Commonly Changed Options for Session Replication

Option Description

<useJK> Whether to assume that a load balancer such as m od_cluster, m od_jk, or m od_proxy is in use. The default is false. If set to true, the container examines the session ID associated with each request and replaces the jvm Routeportion of the session ID if there is a failover.

<m ax-unreplicated- interval>

The maximum interval (in seconds) to wait after a session before triggering a replication of a session's timestamp, even if it is considered to be unchanged. This ensures that cluster nodes are aware of each session's timestamp and that an unreplicated session will not expire incorrectly during a failover. It also ensures that you can rely on a correct value for calls to method

HttpSession.getLastAccessedT im e()during a failover. By default, no value is specified. This means that the jvm Route configuration of the container determines whether JK failover is being used. A value of 0 causes the timestamp to be replicated whenever the session is accessed. A value of -1 causes the timestamp to be replicated only if other activity during the request triggers a replication. A positive value greater than

HttpSession.getMaxInactiveInterval() is treated as a misconfiguration and converted to 0.

<snapshot-m ode> Specifies when sessions are replicated to other nodes. The default is INST ANTand the other possible value is INT ERVAL.

In INST ANT mode, changes are replicated at the end of a request, by means of the request processing thread. The <snapshot- interval> option is ignored.

In INT ERVAL mode, a background task runs at the interval specified by <snapshot-interval>, and replicates modified sessions.

<snapshot-interval> The interval, in milliseconds, at which modified sessions should be replicated when using INT ERVALfor the value of <snapshot- m ode>.

<session-notification- policy>

The fully-qualified class name of the implementation of interface ClusteredSessionNotificationPolicy which governs whether servlet specification notifications are emitted to any registered HttpSessionListener,

HttpSessionAttributeListener, or HttpSessionBindingListener. Report a bug

8.2. HttpSession Passivation and Activation

8.2.1. About HTTP Session Passivation and Activation

Passivation is the process of controlling memory usage by removing relatively unused sessions from memory while storing them in persistent storage.

Passivation occurs at three different times in a HTTP session's lifetime:

When the container requests the creation of a new session, if the number of currently active session exceeds a configurable limit, the server attempts to passivate some sessions to make room for the new one.

Periodically, at a configured interval, a background task checks to see if sessions should be passivated.

When a web application is deployed and a backup copy of sessions active on other servers is acquired by the newly deploying web application's session manager, sessions may be passivated. A session is passivated if it meets the following conditions:

The session has not been in use for longer than a configurable maximum idle time.

The number of active sessions exceeds a configurable maximum and the session has not been in use for longer than a configurable minimum idle time.

Sessions are always passivated using a Least Recently Used (LRU) algorithm. Report a bug

8.2.2. Configure HttpSession Passivation in Your Application

Overview

HttpSession passivation is configured in your application's WEB_INF/jboss-web.xm l or MET A_INF/jboss-web.xm l file.

Example 8.3. Example jboss-web.xm l File

<!DOCTYPE jboss-web PUBLIC

"-//JBoss//DTD Web Application 5.0//EN"

"http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd"> <jboss-web version="6.0" xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_6_0.xsd"> <max-active-sessions>20</max-active-sessions> <passivation-config>

<use-session-passivation>true</use-session-passivation>

<passivation-min-idle-time>60</passivation-min-idle-time>

<passivation-max-idle-time>600</passivation-max-idle-time>

</passivation-config>

</jboss-web>

Passivation Configuration Elements

<m ax-active-sessions>

The maximum number of active sessions allowed. If the number of sessions managed by the session manager exceeds this value and passivation is enabled, the excess will be passivated based on the configured <passivation-m in-idle-tim e>. Then, if the number of active sessions still exceeds this limit, attempts to create new sessions will fail. The default value of -1 sets no limit on the maximum number of active sessions.

<passivation-config>

This element holds the rest of the passivation configuration parameters, as child elements.

<passivation-config> Child Elements

<use-session-passivation>

Whether or not to use session passivation. The default value is false. <passivation-m in-idle-tim e>

The minimum time, in seconds, that a session must be inactive before the container will consider passivating it in order to reduce the active session count to conform to value defined by max-active-sessions. The default value of -1 disables passivating sessions before

<passivation-m ax-idle-tim e> has elapsed. Neither a value of -1 nor a high value are recommended if <m ax-active-sessions> is set.

<passivation-m ax-idle-tim e>

The maximum time, in seconds, that a session can be inactive before the container attempts to passivate it to save memory. Passivation of such sessions takes place regardless of whether the active session count exceeds <m ax-active-sessions>. This value should be less than the <session-tim eout> setting in the web.xm l. The default value of -1 disables passivation based on maximum inactivity.