I'm not sure what you mean by building in some logic to handle the fact that every request is evaluated by the rule.
I have the following rule below that I'm testing. It looks for an existing cookie and if it exists then it's sent to the named pool which is extracted from the value field in the cookie.
If no cookie is found then it is assumed to be a new session so it distributes between three pools based on the value returned by the random number generator.
Is it a problem that every request is evaluated by this iRule? When you say I will need to build in logic to handle that what do you mean? Do you mean just make the iRule as efficient as possible? (which I have tried to do)
Thanks.
===================================================
when HTTP_REQUEST {
if { [HTTP::cookie exists "stick2"]} {
existing cookie found so not a new session. Send to correct pool based on cookie value
pool [HTTP::cookie "stick2"]
}
else {
no existing cookie (new session). Distribute between 3 pools using random number (1-100)
set rndnum [expr { int(100 * rand()) }]
if { $rndnum > 9 } {
pool www1
approx. 90% to pool www1
}
elseif { $rndnum >=5 } {
pool www2
approx 5% to pool www2
}
else {
pool www3
remaining 5% to pool www3
}
}
}
Is this iRule inefficient in terms of looking at all requests? How can it be made more efficient?