Forum Discussion
Bala_02_152654
Nimbostratus
Aug 20, 2014irule for load balancing to particular pool member based on maximum number of http requests
I have a virtual server 192.168.1.1 and pool members are 10.10.10.1 and 10.10.10.2 The both pool members are basically serving a streaming media content. It listens on either http or any streaming me...
nitass
Employee
Aug 21, 2014i do mathematics (divide and remainder) to select pool member based on number of requests. this is just an example and you may have to revise to suit your environment. please be noted that this logic won't be accurate if some of the pool member is down.
e.g.
config
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
ltm virtual bar {
destination 172.28.24.10:80
ip-protocol tcp
mask 255.255.255.255
pool foo
profiles {
http { }
tcp { }
}
rules {
qux
}
source 0.0.0.0/0
source-address-translation {
type automap
}
vs-index 69
}
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo
ltm pool foo {
members {
200.200.200.101:80 {
address 200.200.200.101
}
200.200.200.111:80 {
address 200.200.200.111
}
}
}
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
ltm rule qux {
when RULE_INIT {
set static::multiply 10
set static::pool "foo"
set static::command "members $static::pool"
set static::number [eval $static::command]
}
when CLIENT_ACCEPTED {
set lb_fails 0
}
when HTTP_REQUEST {
set c [table incr counter]
set m1 [expr { ( $c - 1 ) / $static::multiply }]
set m2 [expr { $m1 % $static::number }]
pool [LB::server pool] member [lindex [lindex [members -list [LB::server pool]] $m2] 0]
}
when HTTP_RESPONSE {
log local0. "c=$c server=[IP::server_addr]"
}
when LB_FAILED {
if { $lb_fails < [active_members [LB::server pool]] } {
LB::mode rr
LB::reselect pool [LB::server pool]
} else {
incr lb_fails
}
}
}
test (generating 21 http requests)
[root@ve11a:Active:In Sync] config tail -f /var/log/ltm
Aug 20 22:35:17 ve11a info tmm1[29362]: Rule /Common/qux : c=1 server=200.200.200.111
Aug 20 22:35:17 ve11a info tmm[29362]: Rule /Common/qux : c=2 server=200.200.200.111
Aug 20 22:35:17 ve11a info tmm1[29362]: Rule /Common/qux : c=3 server=200.200.200.111
Aug 20 22:35:17 ve11a info tmm[29362]: Rule /Common/qux : c=4 server=200.200.200.111
Aug 20 22:35:17 ve11a info tmm1[29362]: Rule /Common/qux : c=5 server=200.200.200.111
Aug 20 22:35:17 ve11a info tmm[29362]: Rule /Common/qux : c=6 server=200.200.200.111
Aug 20 22:35:17 ve11a info tmm1[29362]: Rule /Common/qux : c=7 server=200.200.200.111
Aug 20 22:35:17 ve11a info tmm[29362]: Rule /Common/qux : c=8 server=200.200.200.111
Aug 20 22:35:17 ve11a info tmm1[29362]: Rule /Common/qux : c=9 server=200.200.200.111
Aug 20 22:35:17 ve11a info tmm[29362]: Rule /Common/qux : c=10 server=200.200.200.111
Aug 20 22:35:18 ve11a info tmm1[29362]: Rule /Common/qux : c=11 server=200.200.200.101
Aug 20 22:35:18 ve11a info tmm[29362]: Rule /Common/qux : c=12 server=200.200.200.101
Aug 20 22:35:18 ve11a info tmm1[29362]: Rule /Common/qux : c=13 server=200.200.200.101
Aug 20 22:35:18 ve11a info tmm[29362]: Rule /Common/qux : c=14 server=200.200.200.101
Aug 20 22:35:18 ve11a info tmm1[29362]: Rule /Common/qux : c=15 server=200.200.200.101
Aug 20 22:35:18 ve11a info tmm[29362]: Rule /Common/qux : c=16 server=200.200.200.101
Aug 20 22:35:18 ve11a info tmm1[29362]: Rule /Common/qux : c=17 server=200.200.200.101
Aug 20 22:35:18 ve11a info tmm[29362]: Rule /Common/qux : c=18 server=200.200.200.101
Aug 20 22:35:18 ve11a info tmm1[29362]: Rule /Common/qux : c=19 server=200.200.200.101
Aug 20 22:35:18 ve11a info tmm[29362]: Rule /Common/qux : c=20 server=200.200.200.101
Aug 20 22:35:18 ve11a info tmm1[29362]: Rule /Common/qux : c=21 server=200.200.200.111
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