Forum Discussion
Ido_Katz_38061
Nimbostratus
Jun 22, 2010IRule Creation help
Hi Guys,
our marketing ask to to check if there is a possbility to create an IRule that said that 2% of the traffic that coming to specific virtual server will go a specfic pool.
For example:
I got a virtual server with the IP address of 1.1.1.1 which have a default pool named x.
I need a rule that say that once he got a traffic so 2% of the traffic will go to some other pool which is not the default pool of the virtual server.
Is it possible?
Thanks
Ido
15 Replies
- L4L7_53191
Nimbostratus
I'm sure that some other folks will have ideas here too, but this particular issue is a little hard to solve directly. After all, how much of your traffic is 2%? You won't really know what 2% was until your day is done and you're counting requests in your server logs. But you can approximate it using something like below.
**Note: This uses the (totally great) table command, which requires 10.1 or higher. Also, this rule is an example only and it may not work for your requirements. That said, it will send 2% of HTTP requests to a specific place.when HTTP_REQUEST { set requestNum [table incr "mkt_count" ] if { $requestNum >= 99 }{ table set "mkt_count" 0 } if { $requestNum == 1 or $requestNum == 2 } { log local0. "Got a 2% request. Counter is at $requestNum" pool marketing-pool } else { log local0. "Got a normal request. Counter is at $requestNum " pool default-pool } }
Give this a whirl in your test environment and see if it will work for you. Obviously, change your pool names to match. Also, if any of the smart folks out there have ideas to bulletproof this approach please chime in! This is a very cool use case.
HTH,
-Matt - The_Bhattman
Nimbostratus
Hi Ido,
incidentally you can find information about the table command here
http://devcentral.f5.com/wiki/default.aspx/iRules/table.html
I hope this helps
Bhattman - Ido_Katz_38061
Nimbostratus
Thanks a lot, I will try it on our test env.
Ido - Kevin_Davies_40
Nacreous
when HTTP_REQUEST { if { rand() > 0.02 } { pool default-pool } else { pool marketing-pool } }
Regards
Kevin - Martin_Williams
Nimbostratus
Hi Guys,
I have a similar requirement from my marketing team but they would like to send 90% of traffice to a default pool and then 5% to pool x and 5% to pool y . Is this achievable?
Thanks,
Martin - Colin_Walker_12Historic F5 AccountSure, you could use effectively the same logic as above just move some numbers around. Send anything that's 1-5 to poolA, 6-10 to poolB, and the rest to the main pool.
Colin - Colin_Walker_12Historic F5 AccountIf you have any issues or questions, feel free to ask and I'm happy to help with the code.
Colin - Martin_Williams
Nimbostratus
Hi Colin,
How could I set the range from 1-5 for example using $requestNum or is there something I could do using the rand command above?
Thanks,
Martin - hoolio
Cirrostratus
Hi Martin,
I think this is what Colin was suggesting:when HTTP_REQUEST { Save a random number between 0 and 1 set rand [expr { rand() }] if { $rand < .90 } { pool poolA } elseif { $rand < .95 }{ pool poolB } else { pool poolC } }
Aaron - Martin_Williams
Nimbostratus
Thanks Aaron this seems to work well. How could I prove (to marketing) that the pools are being load balanced as requested. Do I need to create a stats profile?
Thanks,
Martin
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
