Forum Discussion

jethro_106302's avatar
jethro_106302
Icon for Nimbostratus rankNimbostratus
Dec 16, 2008

uri based pool selection and persistence

Hi Folks,

I am rather new to using iRules, and would like some advice for a problem I'm trying to solve.

I want to have an http virtual server, sharing the load on two pools of several members. On the web side, there are two apps working together, 1 under URI /foo and the other under URI /bar. I want to loadbalance requests to /foo on pool A, and requests to /bar on pool B.

Application A (in /foo) expects/sets JSESSIONID cookies , and Application B (in /bar) expects/sets FOOBAZOO cookie. Both Apps send a "Set-Cookie" if there isn't any in the client request, or if the one present is outdated.

As my nodes in my pools aren't able to share any applicative context, I need to make sure a client always gets loadbalanced to the same node once it has an authenticated cookie.

I've been reading the iRules wiki for some time, and had a look at CodeShare as well, from which I borrowed a few lines and ended up with the following iRule :

when HTTP_REQUEST {  
    if { [HTTP::cookie exists "JSESSIONID"] } {  
          persist uie [HTTP::cookie "JSessionID"]  
    }  
    if { [HTTP::cookie exists "FOOBAZOO"] } {  
          persist uie [HTTP::cookie "FOOBAZOO"]  
    }  
    if { [HTTP::uri] starts_with "/foo" } {  
          pool pool_A  
    } elseif { [HTTP::uri] starts_with "/bar" } {  
          pool pool_B  
    } elseif { [HTTP::uri] equals "/" } {  
          HTTP::redirect /foo  
    } else {  
          pool pool_A  
    }  
  }  
    
  when HTTP_RESPONSE {  
     if { [HTTP::cookie exists "JSESSIONID"] } {  
           persist add uie [HTTP::cookie "JSESSIONID"]  
     }  
    if { [HTTP::cookie exists "FOOBAZOO"] } {  
          persist uie [HTTP::cookie "FOOBAZOO"]  
    }  
  }

On the VS side, it is set to standard profile, has "universal" as persistence profile, and pool_A as the default pool.

any feedback, advice would be much appreciated.

tia,

jerome

2 Replies

  • Hi Jerome,

    You could probably move the two cookie checks into the respective tests on the URI. If the cookies are set with a path, they should only be sent by the client in a request which starts with that path.

     
     when HTTP_REQUEST {   
        if { [HTTP::uri] starts_with "/foo" } { 
           if { [HTTP::cookie exists "JSESSIONID"] } {   
              persist uie [HTTP::cookie "JSessionID"]   
           }   
           pool pool_A 
        } elseif { [HTTP::uri] starts_with "/bar" } {   
           if { [HTTP::cookie exists "FOOBAZOO"] } {   
              persist uie [HTTP::cookie "FOOBAZOO"]   
           }   
           pool pool_B   
        } elseif { [HTTP::uri] equals "/" } {   
           HTTP::redirect /foo   
        } else {   
           pool pool_A   
        }   
     }   
      
     when HTTP_RESPONSE {   
        if { [HTTP::cookie exists "JSESSIONID"] } {   
           persist add uie [HTTP::cookie "JSESSIONID"]   
        } 
        if { [HTTP::cookie exists "FOOBAZOO"] } {   
           persist uie [HTTP::cookie "FOOBAZOO"]   
        }   
     } 
     

    Aaron
  • Hey Aaron,

     

     

    thanks for the quick answer, I will do as you suggest, it looks more efficient than what I originally posted.

     

     

    regards,

     

    jerome