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

Discussion in 'Apache' started by Tingel Christian, May 6, 2009.

  1. #1
    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 http://localhost:31038 route=goodboy
    BalancerMember http://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
     
    Tingel Christian, May 6, 2009 IP