Forum Moderators: phranque

Message Too Old, No Replies

How to implement session-sticked load balance with Apache and embedded

         

Tingel Christian

7:08 am on May 7, 2009 (gmt 0)

10+ Year Member



Hello everyone!

I have been puzzled by a complex jetty and apache related problem for quit a long time...

I am now using jetty 6.1.11 as an embedded web container, and I am planning to use an Apache(2.2.2/2.2.10) as front end and jetty as back end (and some other web application not based on jetty will also be used as back ends as well.), apache-jetty is 1-N and apache-other is 1-1. For some reason, I am not going to use the jetty-web.xml to implement the load balance.So I coded my source something like this:

String workerName = getWorkerNameFromConfigFile();
Server server = new Server();
SessionIdManager sessionIdManager = new HashSessionIdManager();
sessionIdManager.setWorkerName(workerName);
server.setSessionIdManager(sessionIdManager);

(In this way, I have already got the JSESSIONID in correct form like JSESSIONID=abcdefghijklmnopqrstuvwxyz.beautifulgirl by both just visiting the back end directly and with the apache mod_proxy_balancer functionality)

and then, I configured httpd.conf in the following way:

<Proxy balancer://my_cluster>
BalancerMember [localhost:31038...] route=goodboy
BalancerMember [localhost:21038...] route=beautifulgirl
</Proxy>
<VirtualHost *:8081>
ServerName localhost
ProxyPass /balancer !
ProxyPass /status !
ProxyPass / balancer://my_cluster/ stickysession=JSESSIONID lbmethod=byrequests nofailover=On
ProxyPassReverse / balancer://my_cluster/
ProxyPreserveHost on
</VirtualHost>

now, when I start the jetty based container and apache, the load balance is implemented, but the session is NOT sticked with the browser.When I request for an html resource which includes some other js or gif files, all requests are proxied to the nodes averagely while what is expected is that all requests should be proxied to one node

Could someone please tell me why the solution goes this way?

Thank you very much!

Best Regards
Tingel Christian T. Sun
Edit/Delete Message

jdMorgan

2:36 pm on May 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This question is rather specialized to the load balancer, and we don't get a lot of jetty questions here. So you may have better luck in a jetty-related forum. I don't know anything about it, myself.

However, in general, the key question here is whether the jsessionID in the HTTP request has any meaning to the load balancer. If not, then it cannot "know" to send the request to the initially-assigned back-end server, and you must find a way to implement this "sticky" functionality.

The proxy through-put function of mod_rewrite may come in handy here, because mod_rewrite can examine HTTP request headers and cookies, and base the selected proxy through-put 'target' on those variables.

Again, I have no experience with your described set-up, so the above response may in fact be useless... :)

Jim

Tingel Christian

7:32 am on May 8, 2009 (gmt 0)

10+ Year Member



Hello Jim~

Thank you very much.

I have tried the way you mentioned and it works well when I was using "GET" method really.

But I've got another problem which is that...

I need to match data existing in POSTDATA and now on my way resolving it~~~

Do you have any idea about that?

Thanks!

jdMorgan

1:54 pm on May 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To validate POST data, you'll have to feed the requests to a script which can examine it.

You can use mod_rewrite's RewriteMap function to call this script during the URL-to-filename translation API phase, so that the content-handler is not invoked until the result is known. The RewriteMap can then supply a new URL-path (for example a proxy-path to your back-end, or an error page).

Once the content-handler phase is invoked, it's too late to redirect or rewrite the request, except by using scripted redirects or "includes." So RewriteMap may be the best solution here.

Jim

Caterham

3:47 pm on May 9, 2009 (gmt 0)

10+ Year Member



A RewriteMap program can't validate POST data since it can't access the request record. The information has to be passed via the map lookup call to the map and since you can't access the request body via mod_rewrite, you can't pass the body to the script via STDIN.

Using a self-written apache module (e.g. in c, perl via mod_perl, python via mod_python) to access the request record within the internal request processing would be the smoothest solution.

Actually; internal redirects are called by a content handler and not within a module's hook in ap_process_request_internal.