IAmYourFaja
IAmYourFaja

Reputation: 56912

How to cluster a Grails 2.3.6 app's session with embedded Tomcat?

I'm deploying my Grails (2.3.6) app with the Grails Standalone App Runner plugin, like so:

grails -Dgrails.env=prod build-standalone myapp.jar --tomcat

Then, my CI build places myapp.jar onto my app server, say, myapp01.

I now want to cluster app sessions when myapp is running on multiple nodes. So if myapp gets deployed to myapp01, myapp02 and myapp03, and one of those instances starts a new session with a user, I want all 3 to be aware of the same session. This is obviously so I can put all the nodes behind a load balanced URL (http://myapp.example.com, etc.) and it doesn't matter what node you get routed to: all nodes share the same sessions.

I googled "grails session clustering" and see a bunch of articles that seem to require terracotta, but I also heard that Grails has built-in session clustering facilities. But any searches I do come back empty-handed.

So I ask: How can I achieve this kind of session clustering with an embedded Tomcat?

Upvotes: 0

Views: 1827

Answers (3)

Ryan
Ryan

Reputation: 11

You could achieve this by using the tomcat build-in functionality. Tomcat instance node could replicate session from others, then all the session get shared between nodes. You can do this in at least three ways:

  1. Session Replication by using Muilcast between instance nodes.
  2. Session Replication just between primary and secondary node backup.
  3. Session Replication between Static Memberships, this one is useful when the multicast cannot be enabled or supported such as in AWS EC2 Env.

Reference:

http://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html http://khaidoan.wikidot.com/tomcat-cluster-session-replication

Upvotes: 0

Germán Sancho
Germán Sancho

Reputation: 111

Besides the seesion-cookie plugin that @injecteer proposed, there are several other plugins allowing to keep sessions in a shared storage (DB, mongodb, redis, memcached) that can be accessed by any of your tomcat instances. Take a look at these:

Upvotes: 2

injecteer
injecteer

Reputation: 20699

I never heard of something like this out-of-box. I would give 2 options a try:

  1. Use a session-cookie plugin, with which you decouple your clients from storing the sessions in tomcat
  2. Use or implement persistent sessions, which are stored in some sort of DB and are not bound to any tomcat instance.

Upvotes: 1

Related Questions