4
votes

I am using apache http and the mod_jk for load balancing. While using sticky sessions if one of the tomcat instances dies the request is successfully redirected to the other node. If for some reason the applications dies but the tomcat is alive then the requests keep going to node which has the dead application. Any ideas how to resolve this?

Below you can fine me worker.properties file.

worker.list=myworker

worker.myworker1.port=8009
worker.myworker1.host=host1
worker.myworker1.type=ajp13
worker.myworker1.lbfactor=1

worker.myworker2.port=8009
worker.myworker2.host=host2
worker.myworker2.type=ajp13
worker.myworker2.lbfactor=1

worker.myworker.type=lb
worker.myworker.balance_workers=myworker1,myworker2
worker.myworker.sticky_session=True

Thanks!

2

2 Answers

2
votes

Generally it gives 404 error when application is not available while tomcat is still running. I think there is a worker directive for this to handle and is fail_on_status and you could use this for 404 error and there may be no need of including 503 error code with this directive which probably means tomcat is stopped and it's the work of mod_jk to failover to other working node. Try the below workers.properties(a line appended to each worker) also for other error codes separated by comma.

worker.list=myworker

worker.myworker1.port=8009
worker.myworker1.host=host1
worker.myworker1.type=ajp13
worker.myworker1.lbfactor=1
#worker.myworker1.fail_on_status=-404,503
worker.myworker1.fail_on_status=-404

worker.myworker2.port=8009
worker.myworker2.host=host2
worker.myworker2.type=ajp13
worker.myworker2.lbfactor=1
#worker.myworker2.fail_on_status=-404,503
worker.myworker2.fail_on_status=-404

worker.myworker.type=lb
worker.myworker.balance_workers=myworker1,myworker2
worker.myworker.sticky_session=True
worker.myworker.sticky_session_force=True
1
votes

mod_jk isn't able to ping a heartbeat URL to decide node health.

One solution is to use an external script which will do that for you and if the application is not alive it should restart the tomcat instance.