Apache Ignite Integrations

The Apache Ignite Integrations Developer Hub

Welcome to the Apache Ignite Integrations developer hub. You'll find comprehensive guides and documentation to help you start working with Apache Ignite Integrations as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

Web Session Clustering

Cache all your web sessions in a fault-tolerant distributed cache.

Overview

Ignite In-Memory Data Fabric is capable of caching web sessions of all Java Servlet containers that follow Java Servlet 3.0 Specification, including Apache Tomcat, Eclipse Jetty, Oracle WebLogic, and others.

Web sessions caching becomes useful when running a cluster of app servers. When running a web application in a servlet container, you may face performance and scalability problems. A single app server is usually not able to handle large volumes of traffic by itself. A common solution is to scale your web application across multiple clustered instances:

In the architecture shown above, High Availability Proxy (Load Balancer) distributes requests between multiple Application Server instances (App Server 1, App Server 2, ...), reducing the load on each instance and providing service availability if any of the instances fails. The problem here is web session availability. A web session keeps an intermediate logical state between requests by using cookies, and is normally bound to a particular application instance. Generally this is handled using sticky connections, ensuring that requests from the same user are handled by the same app server instance. However, if that instance fails, the session is lost, and the user will have to create it anew, loosing all the current unsaved state:

A solution here is to use Ignite In-Memory Data Fabric web sessions cache - a distributed cache that maintains a copy of each created session, sharing them between all instances. If any of your application instances fails, Ignite will automatically restore the sessions, owned by the failed instance, from the distributed cache regardless of which app server the next request will be forwarded to. Moreover, with web session caching sticky connections become less important as the session is available on any app server the web request may be routed to.

In this chapter we give a brief architecture overview of Ignite's web session caching functionality and instructions on how to configure your web application to enable web sessions caching.

Architecture

To set up a distributed web sessions cache with Ignite, you normally configure your web application to start a Ignite node (embedded mode). When multiple application server instances are started, all Ignite nodes connect with each-other forming a distributed cache.

Note that not every Ignite caching node has to be running inside of application server. You can also start additional, standalone Ignite nodes and add them to the topology as well.

Replication Strategies

There are several replication strategies you can use when storing sessions in Ignite In-Memory Data Fabric. The replication strategy is defined by the backing cache settings. In this section we briefly cover most common configurations.

Fully Replicated Cache

This strategy stores copies of all sessions on each Ignite node, providing maximum availability. However with this approach you can only cache as many web sessions as can fit in memory on a single server. Additionally, the performance may suffer as every change of web session state now must be replicated to all other cluster nodes.

To enable fully replicated strategy, set cacheMode of your backing cache to REPLICATED:

<bean class="org.apache.ignite.configuration.CacheConfiguration">
    <!-- Cache mode. -->
    <property name="cacheMode" value="REPLICATED"/>
    ...
</bean>

Partitioned Cache with Backups

In partitioned mode, web sessions are split into partitions and every node is responsible for caching only partitions assigned to that node. With this approach, the more nodes you have, the more data can be cached. New nodes can always be added on the fly to add more memory.

With Partitioned mode, redundancy is addressed by configuring number of backups for every web session being cached.

To enable partitioned strategy, set cacheMode of your backing cache to PARTITIONED, and set the number of backups with backups property of CacheConfiguration:

<bean class="org.apache.ignite.configuration.CacheConfiguration">
    <!-- Cache mode. -->
    <property name="cacheMode" value="PARTITIONED"/>
    <property name="backups" value="1"/>
</bean>

See Cache Distribution Models for more information on different replication strategies available in Ignite.

Expiration and Eviction

Stale sessions are cleaned up from cache automatically when they expire. However, if there are a lot of long-living sessions created, you may want to save memory by evicting dispensable sessions from cache when cache reaches a certain limit. This can be done by setting up cache eviction policy and specifying the maximum number of sessions to be stored in cache. For example, to enable automatic eviction with LRU algorithm and a limit of 10000 sessions, you will need to use the following cache configuration:

<bean class="org.apache.ignite.configuration.CacheConfiguration">
    <!-- Cache name. -->
    <property name="name" value="session-cache"/>
 
    <!-- Set up LRU eviction policy with 10000 sessions limit. -->
    <property name="evictionPolicy">
        <bean class="org.apache.ignite.cache.eviction.lru.LruEvictionPolicy">
           <property name="maxSize" value="10000"/>
        </bean>
    </property>
    ...
</bean>

For more information about various eviction policies, see Eviction Policies section.

Configuration

To enable web session caching in your application with Ignite, you need to:

1. Add Ignite JARs - Download Ignite and add the following jars to your application’s classpath (WEB_INF/libs folder):

  • ignite.jar
  • ignite-web.jar
  • ignite-log4j.jar
  • ignite-spring.jar

Or, if you have a Maven based project, add the following to your application's pom.xml.

<dependency>
      <groupId>org.apache.ignite</groupId>
      <artifactId>ignite-core</artifactId>
      <version> ${ignite.version}</version>
</dependency>

<dependency>
    <groupId>org.apache.ignite</groupId>
    <artifactId>ignite-web</artifactId>
    <version> ${ignite.version}</version>
</dependency>

<dependency>
    <groupId>org.apache.ignite</groupId>
    <artifactId>ignite-log4j</artifactId>
    <version>${ignite.version}</version>
</dependency>

<dependency>
    <groupId>org.apache.ignite</groupId>
    <artifactId>ignite-spring</artifactId>
    <version>${ignite.version}</version>
</dependency>

Make sure to replace ${ignite.version} with actual Ignite version.

2. Configure Cache Mode - Configure Ignite cache in either PARTITIONED or REPLICATED mode (See examples above).

3. Update web.xml - Declare a context listener and web session filter in web.xml:

...

<listener>
   <listener-class>org.apache.ignite.startup.servlet.ServletContextListenerStartup</listener-class>
</listener>

<filter>
   <filter-name>IgniteWebSessionsFilter</filter-name>
   <filter-class>org.apache.ignite.cache.websession.WebSessionFilter</filter-class>
</filter>

<!-- You can also specify a custom URL pattern. -->
<filter-mapping>
   <filter-name>IgniteWebSessionsFilter</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Specify Ignite configuration (relative to META-INF folder or Ignite_HOME). -->
<context-param>
   <param-name>IgniteConfigurationFilePath</param-name>
   <param-value>config/default-config.xml </param-value>
</context-param>

<!-- Specify the name of Ignite cache for web sessions. -->
<context-param>
   <param-name>IgniteWebSessionsCacheName</param-name>
   <param-value>partitioned</param-value>
</context-param>

...

On application start, the listener will start a Ignite node within your application, which will connect to other nodes in the network, forming a distributed cache.

4. Set Eviction Policy (Optional) - Set eviction policy for stale web sessions data lying in cache (See example above).

Configuration Parameters

ServletContextListenerStartup has the following configuration parameters:

Parameter Name
Description
Default

IgniteConfigurationFilePath

Path to Ignite configuration file (relative to META_INF folder or IGNITE_HOME).

/config/default-config.xml

WebSessionFilter has the following configuration parameters:

Parameter Name
Description
Default

IgniteWebSessionsGridName

Grid name for a started Ignite node. Should refer to grid in configuration file (if a grid name is specified in configuration).

null

IgniteWebSessionsCacheName

Name of Ignite cache to use for web sessions caching.

null

IgniteWebSessionsMaximumRetriesOnFail

Valid only for ATOMIC caches. Specifies number of retries in case of primary node failures.

3

Supported Containers

Ignite has been officially tested with following servlet containers:

  • Apache Tomcat 7
  • Eclipse Jetty 9
  • Apache Tomcat 6
  • Oracle WebLogic >= 10.3.4

Web Session Clustering

Cache all your web sessions in a fault-tolerant distributed cache.