What is the sticky session boolean for?
I would like to implement stateless Tomcat servers with a Couchbase memcached cluster. As I read the memcached-session-manager documentation I come to the following assumptions:
- A session is only retrieved from memcached if the session is not already on the Tomcat server
- If sticky sessions on the load balancer are used, then there is ONLY a performance hit when a Tomcat server crashes because the request will be served by another Tomcat server that must retrieve the session from memcached.
I see the following example:
Example for non-sticky sessions with couchbase + kryo
To connect to a membase bucket "bucket1" the configuration would look like this:
<Context>
...
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="http://host1.yourdomain.com:8091/pools"
username="bucket1"
password="topsecret"
memcachedProtocol="binary"
sticky="false"
sessionBackupAsync="false"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>
But I don't understand why there is a boolean "sticky". Isn't this only something you turn on or off on the load balancer?
So if I use sticky sessions on the load balancer, do I have to set this sticky boolean to true or false in the example above. Or are both valid choices?
Your 2 assumptions are correct for sticky=true. For sticky=false, the session exists in tomcat only for the current request, afterwards it will be removed from the local sessions map. This is done because request1 could hit tomcat1, request2 tomcat2 and request3 tomcat1 again. For request3 tomcat1 must load the session from memcached again because otherwise the session would be stale.
If you configure your loadbalancer for sticky sessions I'd recommend to set sticky=true for msm, because this is more efficient.
Okay, thanks! So if I understand you correctly, the sticky variable must correspond with your load balancer. If sticky sessions are enabled on the load balancer, the sticky variable must be true. If sticky sessions are disabled on the load balancer, the sticky variable must be false.
Correct.
If sticky sessions are enabled on the load balancer, the sticky variable must be true.
To confirm my understanding, If sticky sessions are enabled on the load balancer(e.g ip-hash in nginx), in msm setting, both sticky=true and sticky=false should work, though sticky=true is more efficient
Exactly.
everyone in this thread deserves a 🍺 - this should be in the docs.