using apache as load balancer (with his own cookie)

Yesterday with the help of my friend Alex Koltun we had a task to configure apache as a load balancer, we had two nodes that listen on port 80 10.161.205.66, 10.161.205.175.

we started with trivial configuration of mod_proxy_balancer that have the two nodes declaration and setting of a cookie to be used as the key for the route algorithm (soon to understand we were partially mistaken)

<Proxy balancer://mycluster>
BalancerMember http://10.161.205.66:80 route=node1
BalancerMember http://10.161.205.175:80 route=node2
</Proxy>

ProxyPass / balancer://mycluster/ stickysession=MYCOOKIE
ProxyPassReverse / balancer://mycluster/ stickysession=MYCOOKIE

<Location /balancer-manager>
SetHandler balancer-manager

Order Deny,Allow
Allow from all
</Location>

We tried browsing but that didn't work!!! after searching for some 30 minutes and multiple retries we found the solution that apparently apache except the sticky session cookie to be in a special format that actually tells it which node to choose (it doesn't have auto associating for that), the format of the value should end with .{route name}

This enables you to set on the node you are working the cookie , but we didn't want to change each node and rather have apache do it (because it already did the job of balancing so simply persist it)

The solution was simply adding header manipulation (with mod_headers):

Header add Set-Cookie "MYCOOKIE=SOMEVALUE.%{BALANCER_WORKER_ROUTE}e; path=/;" env=BALANCER_ROUTE_CHANGED

This actually set the cookie using the selected root only if root chosen and used is changed

pretty slick ha ?

Solution was based on this forum answer

The basic assumption that apache uses the cookie as the key to an internal map of key and route was mistaken although for some reason this was the trivial assumption, because we try to do thing so complex while the solution is so simple. still i would except that this would be found on the first page of mod_proxy_balancer

Enjoy and i guess this should save you at least 1 hour of “balancing”

Full httpd.conf file here

<Update 26-Jan-2010 19:41>

I add ProxyPassReverse also to make sure the redirects are also replaced wit correct value

</Update>

using apache as load balancer (with his own cookie) using apache as load balancer (with his own cookie) Reviewed by Ran Davidovitz on 8:34 PM Rating: 5

No comments:

Powered by Blogger.