Matthias Hryniszak
Matthias Hryniszak

Reputation: 3162

Configuration of Apache and Tomcat for load balancing

I'm trying to setup Apache as a load balancer for 2 Tomcat instances with session affinity.

The goal is to have the session stick to one server but to have next session (when it's changed by the backend server) to go to the next available server (let's say using round-robin algorithm for easier implementation). When using the "jvmRoute" in Tomcat and an equivalent "route" in Apache the actual value that does the routing is the route name which does not change and all requests are routed always to the same backend server for a single client.

I found out so far that there's an chicken/egg problem when using just the JSESSIONID cookie. Let's consider the following setup:

2 Tomcat servers listening on ports 8009 and 8010 (AJP13) 1 Apache server with the following configuration

<Proxy balancer://hello-cluster>
    BalancerMember ajp://127.0.0.1:8009/hello
    BalancerMember ajp://127.0.0.1:8010/hello
</Proxy>

ProxyPass /hello balancer://hello-cluster stickysession=JSESSIONID

And here's the scenario:

  1. The first request has no cookie so Apache selects the next available server in the load balancer to handle the request.
  2. The backend Tomcat server sets JSESSIONID but does not note the actual value being returned.
  3. The next request comes in, Apache notes that there's no backend server noted for the given JSESSIONID so it selects the next available, which in this case the other one as served the first request
  4. Tomcat notices that the value of JSESSIONID is invalid so it creates a new one.
  5. Apache does not take a note that the JSESSIONID has changed to pin it down to that backend server.
  6. Back to pt. 3

Is there a way to convince Apache to note the value returned by Tomcat?

Upvotes: 2

Views: 4079

Answers (1)

Sergio
Sergio

Reputation: 21

maybe if you try with tomcat session replication. I found this interesting post:

. You could try too with redis:

Let me know your experience please.

Upvotes: 2

Related Questions