Forum Discussion
Robert_47833
Altostratus
Jul 20, 2011will rand() cause performance issue
rand()
one question about rand
will rand cause performance issue?How to test it?
Can u give me an example
We want to put rand() in production
14 Replies
- hoolio
Cirrostratus
You can use timing to check the load that rand() adds. Try one test run of a batch of requests with rand and then one without.
http://devcentral.f5.com/wiki/iRules.timing.ashx
and:
http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/123/iRules-Optimization-101--05--Evaluating-iRule-Performance.aspx
Aaron - Robert_47833
Altostratus
here is the stats for irule which use rand
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule srwd29cjjmain show all
RULE srwd29cjjmain
+-> HTTP_REQUEST 3553 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 465171, 1446128)
+-> HTTP_RESPONSE 157 total 0 fail 0 abort
| Cycles (min, avg, max) = (0, 0, 0)
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule srwd29cjjmain show all
RULE srwd29cjjmain
+-> HTTP_REQUEST 3560 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 466582, 1446128)
+-> HTTP_RESPONSE 165 total 0 fail 0 abort
| Cycles (min, avg, max) = (0, 0, 0)
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule srwd29cjjmain show all
RULE srwd29cjjmain
+-> HTTP_REQUEST 3560 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 466582, 1446128)
+-> HTTP_RESPONSE 165 total 0 fail 0 abort
| Cycles (min, avg, max) = (0, 0, 0)
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule srwd29cjjmain show all
RULE srwd29cjjmain
+-> HTTP_REQUEST 3561 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 466582, 1446128)
+-> HTTP_RESPONSE 165 total 0 fail 0 abort
| Cycles (min, avg, max) = (0, 0, 0)
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule srwd29cjjmain show all
RULE srwd29cjjmain
+-> HTTP_REQUEST 3561 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 466582, 1446128)
+-> HTTP_RESPONSE 166 total 0 fail 0 abort
| Cycles (min, avg, max) = (0, 0, 0)
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule srwd29cjjmain show all
RULE srwd29cjjmain
+-> HTTP_REQUEST 3561 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 466582, 1446128)
+-> HTTP_RESPONSE 166 total 0 fail 0 abort
| Cycles (min, avg, max) = (0, 0, 0)
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule srwd29cjjmain show all
RULE srwd29cjjmain
+-> HTTP_REQUEST 3561 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 466582, 1446128)
+-> HTTP_RESPONSE 166 total 0 fail 0 abort
| Cycles (min, avg, max) = (0, 0, 0)
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule srwd29cjjmain show all
RULE srwd29cjjmain
+-> HTTP_REQUEST 3563 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 466582, 1446128)
+-> HTTP_RESPONSE 168 total 0 fail 0 abort
this is for irule which didn't use rand
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule SRWD29-Main-rb1112 show all
RULE SRWD29-Main-rb1112
+-> HTTP_REQUEST 14 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 350114, 378678)
+-> HTTP_RESPONSE 14 total 0 fail 0 abort
| Cycles (min, avg, max) = (0, 0, 0)
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule SRWD29-Main-rb1112 show all
RULE SRWD29-Main-rb1112
+-> HTTP_REQUEST 14 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 350114, 378678)
+-> HTTP_RESPONSE 14 total 0 fail 0 abort
| Cycles (min, avg, max) = (0, 0, 0)
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule SRWD29-Main-rb1112 show all
RULE SRWD29-Main-rb1112
+-> HTTP_REQUEST 14 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 350114, 378678)
+-> HTTP_RESPONSE 14 total 0 fail 0 abort
| Cycles (min, avg, max) = (0, 0, 0)
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule SRWD29-Main-rb1112 show all
RULE SRWD29-Main-rb1112
+-> HTTP_REQUEST 15 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 350114, 378678)
+-> HTTP_RESPONSE 15 total 0 fail 0 abort
| Cycles (min, avg, max) = (0, 0, 0)
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule SRWD29-Main-rb1112 show all
RULE SRWD29-Main-rb1112
+-> HTTP_REQUEST 15 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 350114, 378678)
+-> HTTP_RESPONSE 15 total 0 fail 0 abort
| Cycles (min, avg, max) = (0, 0, 0)
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule SRWD29-Main-rb1112 show all
RULE SRWD29-Main-rb1112
+-> HTTP_REQUEST 15 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 350114, 378678)
+-> HTTP_RESPONSE 15 total 0 fail 0 abort
| Cycles (min, avg, max) = (0, 0, 0)
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule SRWD29-Main-rb1112 show all
RULE SRWD29-Main-rb1112
+-> HTTP_REQUEST 16 total 0 fail 0 abort
| | Cycles (min, avg, max) = (0, 350114, 378678)
+-> HTTP_RESPONSE 16 total 0 fail 0 abort
| Cycles (min, avg, max) = (0, 0, 0)
[jucao@srwd00lba001:/S1-green-P:Active] ~ b rule SRWD29-Main-rb1112 show all
RULE SRWD29-Main-rb1112
It seems rand will cost more time,how to resolve it? - Ryan_Paras_7933
Nimbostratus
What is it your rule is trying to accomplish? You can imitate randomness with a number of mathematical functions, but trying to do so may prove foolish if what you are trying to accomplish is best served by optimized rand() function in the first place. - Robert_47833
Altostratus
Hi,Ryan
what I am trying to achieve is:
I have two pool cjj1 and cjj2
20% request to cjj1 while 80% request to cjj2
in one session,the 20% user will still persist hit pool cjj1
when HTTP_RESPONSE {
HTTP::header replace StubHubBlade [LB::server name]
if { $stubhubA_cookie == 1 }{
HTTP::cookie insert name stubhubA_cookie value 1 path "/"
}
if { $stubhubB_cookie == 1 }{
HTTP::cookie insert name stubhubB_cookie value 1 path "/"
}
when HTTP_REQUEST timing on {
if {[class match $uri starts_with gen3abURLs_SRWD29]} {
if {[HTTP::cookie value stubhubA_cookie] == 1}{
pool cjj1
return
}
if {[HTTP::cookie value stubhubB_cookie] == 1}{
pool cjj2
return
}
if { rand() <0.2 } {
pool cjj1
set stubhubA_cookie 1
return
}
else {
pool cjj2
set stubhubB_cookie 1
return
}
1:do we have other method to achieve this?
2:if not,how to optimize this rand()? - Ryan_Paras_7933
Nimbostratus
Can you please explain what you are doing in the HTTP_RESPONSE section?
Why would a single pool with weighted load balancing and persistence not work for you? - Robert_47833
Altostratus
ok,u mean put all members in 2 pools in one pool ,like cjjall
and then insert a cookie to persistence?
can u give me an example? - Robert_47833
Altostratus
Hi,Ryan
can u give me an example of this?
1:how to insert a cookie to it and persistence according to this cooike,we suppose the cookie name is bigip_cookie(send to the same backend server)
2:how to achieve this if we use bladeserver as the cookie name - Ryan_Paras_7933
Nimbostratus
Do you need to have the bladeserver cookie for a reason?
Can you not accomplish what you are looking to do by creating a single pool with "Load Balancing Method" set to "Ratio (Member)" and then setting the vip to use "Default Persistence Profile" "cookie"? No iRule needed? - Robert_47833
Altostratus
Hi,Ryan
the VS is used by lots of pools ,so I can't set the "Default Persistence Profile" " - Ryan_Paras_7933
Nimbostratus
I still do not understand why you cannot use single pool with "Load Balancing Method" set to "Ratio (Member)" and then setting the vip to use "Default Persistence Profile" "cookie"...
Regardless, I don't think you are going to beat rand() for way you are trying to use it.
To note, your times really didn't jump up that much in the example times you provided. Your average time without rand was 350114 and your average time with rand was 466582. It is worth noting, your sample sizes for the comparisons were quite different - potentially skewing these statistics While you sampled 3561 requests with rand, you only sampled 16 times without rand.
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