Skip to content

ConfigureElastiCache

Daniel Serodio edited this page Jun 4, 2013 · 6 revisions

Configure MSM for using Amazon AWS ElastiCache

ElastiCache is a Amazon Cloud service that provides a managed pool of Memcached servers. You can use these just like normal memcached servers but there is a feature which makes it easier. ElastiCache provides "AutoDiscover" which allows you to just use one DNS for the entire pool and not need to manage changing configurations as you add or subtract memcached servers from the pool.

To use ElastiCache with MSM:

Or use the pre-built JAR file AmazonElastiCacheClusterClient-no-version.jar

AmazonElastiCacheClusterClient should be used instead of spymemcached (file spymemcached-2.7.3.jar) to properly support Amazon ElastiCache Auto Discovery, and is placed in the tomcat/lib directory.

  • Configure your tomcat to use a single memcached node with no prefixes.

An example of context.xml:

<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
     memcachedNodes="pool.lkxx3b2.cfg.use1.cache.amazonaws.com:11211"
     requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
     transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
     sessionBackupAsync="true"
     sticky="true"
     copyCollectionsForSerialization="false"
/>

This has been tested with Sticky sessions (load balancer sticky) and async backup.

It should work with non sticky sessions as well but has not yet been tested

You can make sure that the code is detecting the proper nodes by examining the catalina.out file which will show the discovery in process and all the nodes it detects. Adding or removing nodes is automatically detected.

If you are using Elastic Load Balancer (ELB) you can use either the ELB Cookie stickiness or the App Cookie stickiness policy. If using the App stickiness policy use the cookie JSESSIONID. Note that this doesn't work with other ways of configuring MSM because those add a suffix to the cookie like "-n1". Using the ElastiCache pool without a prefix defined for memcachedNodes allows the server to use the cookie JSESSIONID without any suffixes.

Clone this wiki locally