简体   繁体   中英

Load balancing a tomcat application running on two wars

My application (deployed in tomcat) got two wars, a client (say A) and a server (say B). Both of them are deployed in same jvm, and they commnicate via web service. Now in order to make the application scalable, I want this to be clustered and deployed in multiple nodes. Following is the load balancer configuration in apache server.

<Proxy balancer://mycluster stickysession=JSESSIONID>
BalancerMember ajp://127.0.0.1:8009 min=10 max=100 route=jvm1 loadfactor=1
BalancerMember ajp://127.0.0.1:8019 min=20 max=200 route=jvm2 loadfactor=1
</Proxy>

ProxyPass /A balancer://mycluster/A
ProxyPass /B balancer://mycluster/B

In my client application, server url is provided like below

server.url=http://localhost/B/myservice/

My intention is that any request reaching web app A on a node should get processed in web app B on same node. But with the current configuration,its not giving intended result. Request processed in web app A on jvm1 goes to web app B on jvm2 and vice versa. Please let me know what I'm missing here and how could I get rid of the problem

The behaviour you observe seems reasonable: You send a request to your Apache load balancer, and it gets routed to one of the nodes. If I understand your scenario right, you want to force the request (initiated by your web app) to be routed to the correct node. I can think of two ways to achieve this:

  1. I suppose the initial request reaching web app A comes from a user owning a session. If you have configured sticky sessions in Tomcat, you might reuse the user's session cookie and send it along with your web service request. This way, the load balancer will decide that the request be routed to the same node as the original request which brought you the cookie. Yet it might not be feasible to access the cookie from where you call your web service.
  2. It is not quite the load balancer's job to process your internal requests. So why use it at all? You might add a regular HTTP connector to both your Tomcat configurations and use them instead for web service requests. Thus you could circumvent load balancing, which in this case only adds unnecessary latency and overhead to your communications. Downside is: you'd probably need to hard-code the IPs to call.

BTW: Your configuration looks as if both nodes and the load balancer run on a single machine. Sure about that?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM