Forum Discussion

Robert_47833's avatar
Robert_47833
Icon for Altostratus rankAltostratus
Jun 26, 2012

one difficult question in irule with repect to ratio hits or "virtual pools"?

hello,dear irule

 

 

there is a irule ,with many pools and uri match on it,

 

 

 

such as

 

 

 

if { [HTTP::uri] starts_with "/test1"} {

 

pool CJJ-SLX1

 

return

 

}

 

if {[HTTP::uri] starts_with "/test2"}{

 

pool CJJ-SLX2

 

return

 

}

 

if {[URI::query [HTTP::uri]] starts_with "test3"} {

 

pool CJJ-SLX3

 

return

 

}

 

 

 

the requirement is:

 

 

 

we plan to create create another pools ,same blades as old pools:

 

 

 

CJJ-SLX1-test

 

CJJ-SLX2-test

 

CJJ-SLX3-test

 

 

rule:

 

 

------------------------------------

 

if it is a new request(without cookie) and match "/test1",it should go to CJJ-SLX1 and CJJ-SLX1-test per ratio(10% or something else)

 

 

if it is an old request(with cookie) and match "/test1",it should go to CJJ-SLX1-test

 

-------------------------------------------

 

 

 

 

not all pool should follow this rule,it is better there is some switch or config we can control which pools should follow this rule

 

 

 

 

 

How to change irule or anything else in bigip to meet this requirement?

 

 

thanks in advance

 

 

not an easy question

 

 

 

  • Hi Robbie,

     

     

    You can use a session cookie to track whether a request should go to a specific pool. You can set the cookie in HTTP_RESPONSE using 'HTTP::cookie insert $cookie_name value $cookie_value path / domain $domain'. You can check for the cookie in HTTP_REQUEST using [HTTP::cookie value $cookie_name].

     

     

    If you want to "randomly" send x% of requests without a cookie to a specific pool, you can use rand(). The third example in this codeshare entry shows how to implement what you've described.

     

     

    Example 3 - Send 90% of requests to poolA, 5% to poolB and 5% to poolC. Use a session cookie to persist clients to the same pool over their HTTP session

     

    https://devcentral.f5.com/wiki/iRules.ratio_load_balancing_using_rand_function.ashx

     

     

    If you want to prevent users from manually specifying the pool they go to, you could encrypt the cookie using a custom HTTP profile and the cookie to encryption option.

     

     

    Aaron
  • hi,Aaron

     

    thanks for your answer

     

    1:I also want to know whether I can store this ratio in a datagroup,then other team can update this ratio in GUI

     

    from 0% to 100%

     

    in the ends,I wanna 100% traffic to the new pool ,while 0% to old pool ,can we achieve this?

     

  • 1:I also want to know whether I can store this ratio in a datagroup,then other team can update this ratio in GUI

     

    from 0% to 100%

     

    in the ends,I wanna 100% traffic to the new pool ,while 0% to old pool ,can we achieve this?i do not think there is any problem in reading ratio from data group/class.

     

     

    class wiki

     

    https://devcentral.f5.com/wiki/irules.class.ashx
  • The result is always strictly greater than 0.0 and strictly less than 1.0.rand

     

    http://www2.tcl.tk/1549
  • it means it is impossible to reach 0 or 1.0,right?i think so.