The Apache mod_jk module is a plug-in that handles communication between Tomcat and the HP-UX Apache-based Web server.
Figure 3-3 illustrates load balancing with mod_jk . The mod_jk module load balances between several application servers. In most cases, the web server handles the static data and distributes dynamic content to the application servers.
Figure 3-3 Load Balancing With mod_jk
(http://docs.hp.com/en/5992-5286/ch03s02.html )
When configuring mod_jk load balancing, you can do the following:
-
Ensure that requests are not routed to a server that is not responding.
-
Set up round-robin, or weighted round-robin to route requests to a server.
-
Route all requests from the same session to the same server (sticky session).
(办法1)
sticky session 就是要保证隶属同一个会话的所有http请求被固定分发到同一个tomcat (route all requests from the same session to the same server)。 可以猜测或许tomcat的AJP connector 会将session相关信息(sessionid和服务器端保留的状态信息)告诉mod_jk,以便mod_jk在收到新的http请求时,能够判断出该请求是否隶属前面的某个session,以决定是否固定路由到曾今的tomcat。 但是还有个问题,如果此时这个被固定路由的tomcat宕了,mod_jk别无选择,不得不将请求分发到另外的tomat,但是问题是该tomcat却不具有session信息。那mod_jk是不是需要将自己从先前tomcat冗余来的session信息复制到新的tomcat上呢?似乎不是这么回事?(下图)
(办法2)
各个tomcat放弃局部于本tomcat的session,改用分布式session容器,session容器以一个单独的服务存在,状态信息集中保存在该session服务器上,各个tomcat通过特定的客户端访问session服务器,以使sesssion服务器的信息为所有tomcat共享。具体实现可以采用memcache或干脆简单点写到DB中去。