Skip to main content
Skip table of contents

Session persistence

When a connection between the application server and a client is established, information about the user and the state of the user interface is placed into a session. While the session is active, this information is stored in memory. However, if the session times out, then the information can be lost. Session persistence allows the storage of the session information for longer periods by writing it to a database or file for later recovery. In this way, if a session does time out, users will remain generally unaware of this fact, and are able to pick up their work from where they left it. Meanwhile, preservation of client state allows users to close the application and later have the application reopen to the screen they were on. Additionally, in the event of a server failure, a persisted session retains information that may otherwise be lost, and the client can continue activities after the point of failure.

For example, consider an advisor working with NexJ CRM, and who is called away from their computer for a discussion with their manager. With session persistence in operation, when the advisor returns, the application will be in the same state as when the advisor left. Without session persistence, when the advisor returns and attempts to use the application, it is possible that the UI will reset as if the advisor had logged on for the first time.

Application servers can also persist sessions in order to help with load balancing for a particular session. If a server node holding session information becomes overloaded, it can persist session information and decide which server node should continue managing the session. Although the application server is able to determine if and how to load balance the sessions, the web server still performs the actual load balancing of the requests.

Information can be persisted to files in a directory or to a session database. File-based persistence is ideal for a single server due to the faster performance provided by the file system and not having to manage connections from multiple nodes.

Session settings

Session settings can be configured in a server or environment file using NexJ Studio.

The following session settings can be configured in the Clustering/Session subtab of the Overview tab when editing a server or environment file:

Session Timeout
The amount of time where an inactive session is considered to be timed out, in minutes. If Persistent Session is disabled, the session information on the server is lost when a timeout occurs. If Persistent Session is enabled, the session information is persisted when a timeout occurs. A value of 0 represents unlimited time, where session information is stored in the server until it is shut down, and no information is persisted. The Session Timeout property overrides any session timeout settings configured on the application server side.

Persistent Session
Enables session persistence. Session information is stored using a file system or a database.

Compressed Persisted Session State
Enables compression of the persisted session state to reduce storage size by approximately five times, at the cost of increased CPU overhead.

Persistence Directory
Shared directory for storing the persisted session state. If using a clustered server, you must configure the directory to be accessible by all nodes. If the directory is left empty, sessions are persisted to the session database. To store sessions in the Session table, you must add a data source connection for the SessionDatabase data source to the connection or environment file and create the SessionDatabase table with the Data Load Tool or the Database Schema Tool.

Persistence Directory Depth
If the Persistence Directory is specified, the session ID is placed into a number of subdirectories. Each
subdirectory is named after 2 characters of the session ID, starting from the beginning of the ID. For example, a
session ID of 18106FCFA235DA286CF27401AD0BCFBB and a depth setting of 2 would store the session ID in
the following directory: \<PersistenceDirectory>\18\10.

Session load balancing algorithm

You can also specify the session load balancing algorithm to use when restoring sessions from the persistence store.

There are three possible values:

preemptive
Default. Indicates that session load balancing is always done when a session is restored from the persistence store.

threshold
Indicates that session load balancing should only occur if the current node is busy, that is, the memory-in-use is above the threshold or CPU is above the threshold.

none
Indicates that no load balancing should be done and the “best” node should be the current node. Request redirection may still occur if an external load balancer redirects a request to another node.

If you want to specify a load balancing algorithm other than preemptive, you need to add the balancing attribute when editing the server or environment file. Add the balancing attribute to the Environment or Server element, using the Source tab in the editor. For example, enter balancing="none" to indicate that no balancing should be done.

Info

Incorrect values will result in a warning message in the system log and the default algorithm preemptive will be used.

The load balancing algorithm controls when the request will be considered for redirection. If the current node happens to be the best available node, then the request will not necessarily be redirected to another node.

Info

To specify the load balancing algorithm at the model level, edit the balancing property in the System.SessionManager.com component. This value will be overridden by the value specified in the environment or server file.

Enabling session persistence to a database

Session persistence is enabled in a server or environment file. You must also create the session database table to store session information.

To enable session persistence to a database:

  1. Open the server or environment file to which you want to enable session persistence. The file opens in the editor window.
  2. In the Overview tab, click the Clustering/Session subtab.
  3. In the Session Timeout field, enter the amount of time to store persisted sessions, in minutes.
  4. Click the Persistent Session checkbox.
  5. Ensure the Persistence Directory field is cleared.
  6. In the connections or environment file, click the Data Source Connections tab.
  7. Add and configure the SessionDatabase data source.
  8. Create the Session table using the SessionDatabase data source, using the Data Load Tool or the Database Schema Tool.
  9. Configure the other session settings as required.

Session information will now be stored in the database when a session timeout occurs.

The amount of time after which the session information is removed from memory (and persisted if session persistence is used) is specified in the server or environment file, defined by the Session Timeout property. The period after which the data is removed from storage is set in NexJ Admin Console, defined by the Persistent Session Timeout property. This property fires off a batch job that cleans up persisted data, and is found in the Session Administration section of the System tab. By default, the Persistent Session Timeout is set to 60 minutes. For more information, see Setting session timeout preferences.

Info

The Persistent Session Timeout property must be set to a larger value than the Session Timeout property to avoid potential race conditions which may lead to unpredictable and unexpected behavior.

Creating a data source connection 
Configuring data source connections 
Recreating databases
Session settings

Enabling session persistence to a file

Session persistence is enabled in a server or environment file.

Before starting this task, create a directory on the file system that will be used to store persisted session information. If a server cluster is used, the directory must be accessible by all nodes in the cluster.

To enable session persistence to a file:

  1. Open the server or environment file to which you want to enable session persistence. The file opens in the editor window.
  2. In the Overview tab, click the Clustering/Session subtab.
  3. In the Session Timeout field, enter the amount of time to store persisted sessions, in minutes.
  4. Click the Persistent Session checkbox.
  5. In the Persistence Directory field, enter the name of the directory that will be used to store persisted session information.
  6. Configure the other session settings as required.

Session information will now be stored in the persistence directory when a session timeout occurs. The session ID is used as the file name.

The amount of time after which the session information is removed from memory (and persisted if session persistence is used) is specified in the server or environment file, defined by the Session Timeout property. The period after which the data is removed from storage is set in NexJ Admin Console, defined by the Persistent Session Timeout property. This property fires off a batch job that cleans up persisted data, and is found in the Session Administration section of the System tab. By default, the Persistent Session Timeout is set to 60 minutes. For more information, see Setting session timeout preferences.

Info

The Persistent Session Timeout property must be set to a larger value than the Session Timeout property to avoid potential race conditions which may lead to unpredictable and unexpected behavior.


Related links

session settings


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.