Using tomcat in round robin mode

假如想象 提交于 2019-12-05 14:28:21

Basically you have two choices:

1) Replicate your sessions so they become reachable by any Tomcat node. Solutions: Tomcat Cluster, memcached-session-manager, possibly others.

2) Use a load balancer and implement sticky sessions. First requests will be routed randomly on a round robin basis, but subsequent requests will stick to the same server. Solutions: mod_proxy, hardware traffic managers.

The disadvantage of the first option is that session replication is costly, not very reliable and often requires Serializable-only data to be put in session.

The disadvantage of the second approach is that if you shut down your Tomcat for maintenance, the users will be forced to log in again.

You are incorrectly assuming that "for every request a new session would be created". The new session will be created only if not created before on that same server, or if it was created but already expired.

We usually used Tomcat behind an Apache web server with mod_jk for load balancing the requests across the Tomcat instances.

With sticky sessions a user will only get a session upon the first request and will afterwards always be directed to the Tomcat from where his session originates. So there is no need to replicate sessions across all Tomcats and the requests will be distributed across the Tomcats, too.

Of course, this does not ensure some kind of round-robin which you asked for.

A session will only be created once your code requests the session so if your application doesn't require the session then just simply dont access it. Checkout the section on getSession() in HttpServletRequest

http://download.oracle.com/javaee/5/api/javax/servlet/http/HttpServletRequest.html#getSession(boolean)

I'm not sure if there is a way to replicate the session across different tomcat instances however if you require some user state without session then you can use cookies instead.

EDIT: If you do need to replicate the session you could probably start by reading this tomcat document. http://tomcat.apache.org/tomcat-5.5-doc/cluster-howto.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!