Supporting a greater number of concurrent sessions in Ehcache

When you are using Ehcache as the cache manager in some Unica Interact environments, a high number of concurrent sessions may cause the Unica Interact runtime to exceed its available memory, causing a system slowdown or out-of-memory error. An out-of-memory situation is more likely if you have increased the maxEntriesInCache configuration parameter (Unica Interact > cacheManagement > Caches > InteractCache > maxEntriesInCache) to a number higher than the default setting, although it can occur even with the default setting of a maximum of 100,000 sessions. To avoid this issue, you can reduce the maxEntriesInCache value, or you can follow the instructions here to modify the system memory cache to roll the cached memory over to disk storage. This modification allows many more concurrent sessions than would otherwise be possible.

To prevent the Unica Interact runtime from exceeding the available memory in the Java virtual machine (JVM) memory heap, you can modify the memory caching mechanism to use disk storage for caching the data that exceeds the available memory.

System administrators can adjust the amount of memory available to the deployment systems via the following JVM parameters:

-Xms####m -Xmx####m -XX:MaxPermSize=256m

Where the characters #### should be 2048 or higher (depending on their system load.) Note that a 64-bit application server and JVM are usually necessary for values greater than 2048.

Unica Interact uses an open source distributed caching system called Ehcache for caching data. By default, Unica Interact uses the settings specified by the Unica Platform to manage the Ehcache caching. However, you can override those settings for Unica Interact by creating your own Ehcache configuration file that is automatically loaded whenever Unica Interact starts up.

To load a custom Ehcache configuration file on startup, the following must be true:

  • Your JVM must include the parameter interact.ehcache.config property, as in the following example:

    -Dinteract.ehcache.config=/temp/abc.xml

    You can set a JVM property for your web application server in the startup command script (Oracle WebLogic) or Admin Console (IBM® WebSphere®). The information in /temp/abc.xml is the actual path to the XML file containing the Ehcache configuration you want to load at startup.

  • A configuration file containing valid Ehcache configuration settings in XML format must exist at the location specified by the JVM property.

    If you do not set this property, or if you set this property and there is no configuration file at the specified location, Unica Interact uses its default cache configuration.

If both conditions are true, the Ehcache configuration file is loaded on startup, and its settings override any default Unica Interact configuration parameters for caching session data.

The following example shows a sample configuration file (in XML format) that you might use to customize Ehcache:

<config
      xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
      xmlns='http://www.ehcache.org/v3'
      xmlns:eh='http://www.ehcache.org/v3'
      xmlns:jsr107='http://www.ehcache.org/v3/jsr107'>
   <service>
      <jsr107:defaults enable-statistics="true" enable-management="true"/>
   </service>

   <persistence directory="${ehcache.disk.store.dir}"/>

   <cache alias="InteractCache">
      <key-type>java.lang.String</key-type>
      <value-type>com.unicacorp.interact.session.InteractSession</value-type>
      <expiry>
         <tti unit="seconds">300</tti>
      </expiry>
      <listeners>
         <listener>
            <class>com.unicacorp.interact.cache.ehcache.EHCacheEventListener</class>
            <event-firing-mode>ASYNCHRONOUS</event-firing-mode>
            <event-ordering-mode>UNORDERED</event-ordering-mode>
            <events-to-fire-on>CREATED</events-to-fire-on>
            <events-to-fire-on>UPDATED</events-to-fire-on>
            <events-to-fire-on>EXPIRED</events-to-fire-on>
            <events-to-fire-on>REMOVED</events-to-fire-on>
            <events-to-fire-on>EVICTED</events-to-fire-on>
         </listener>
      </listeners>
      <resources>
         <heap unit="entries">10000</heap>
         <!--<offheap unit="MB">100</offheap>-->
         <disk persistent="true" unit="GB">1</disk>
      </resources>
   </cache>
   <cache alias="PatternStateCache">
      <key-type>com.unicacorp.interact.treatment.optimization.IAudienceID</key-type>
      <value-type>com.unicacorp.interact.eventhandler.eventpatterns.state.PatternStatesForAudience</value-type>
      <expiry>
         <tti unit="seconds">600</tti>
      </expiry>
      <loader-writer>
         <class>com.unicacorp.interact.cache.ehcache.loaderwriter.InteractCacheLoaderWriterAdapter</class>
         <write-behind>
            <batching batch-size="100" coalesce="true">
               <max-write-delay unit="seconds">5</max-write-delay>
            </batching>
         </write-behind>
      </loader-writer>
      <listeners>
         <listener>
            <class>com.unicacorp.interact.cache.ehcache.EHCacheEventListener</class>
            <event-firing-mode>ASYNCHRONOUS</event-firing-mode>
            <event-ordering-mode>UNORDERED</event-ordering-mode>
            <events-to-fire-on>CREATED</events-to-fire-on>
            <events-to-fire-on>UPDATED</events-to-fire-on>
            <events-to-fire-on>EXPIRED</events-to-fire-on>
            <events-to-fire-on>REMOVED</events-to-fire-on>
            <events-to-fire-on>EVICTED</events-to-fire-on>
         </listener>
      </listeners>
      <resources>
         <heap unit="entries">10000</heap>
         <!--<offheap unit="MB">100</offheap>-->
         <disk persistent="true" unit="GB">1</disk>
      </resources>
   </cache>
</config>

If you saved this file as /HCL/Unica Interact/conf/Ehcache.xml, you would then set the JVM property for the web application as in the following example:

-Dinteract.ehcache.config=/HCL/Unica Interact/conf/Ehcache.xml

For a complete list of the options available for modifying the Ehcache software, see http://www.ehcache.org/documentation/