Forum Discussion
Re-balance requests from a single client
I think I figured it out. I wrote and iRule and tried it on a virtual server having a default pool with two members. The load balancing method was predictive.
The result seems to be what you want. There was no interruptions to the requests and the server was changed as planned.
when RULE_INIT {
set static::lifetime 60
set static::requestlimit 5
set static::debug 1
}
when CLIENT_ACCEPTED {
log local0. "New connection"
}
when HTTP_REQUEST {
if { [HTTP::header "User-Agent"] contains "Mozilla" } {
Add a table entry with a lifetime in seconds of the value of $lifetime.
table add [IP::client_addr] 1 indefinite $static::lifetime
Check if the limit has been reached
if { [table incr [IP::client_addr]] > $static::requestlimit } {
Delete the table entry to restart the timeout
table delete [IP::client_addr]
if { $static::debug } { log local0. "Before select [LB::server addr]" }
Disconnect the server session
LB::detach
Force a new load balancing decision based on the current load
eval [LB::select]
if { $static::debug } { log local0. "After select [LB::server addr]" }
} else {
if { $static::debug } { log local0. "Connections still ok" }
}
}
}
Added some debug options for testing it, but you can remove them (and the whole CLIENT_ACCEPTED event.
To test it I wrote a powershell script that sends a request every 3 seconds and echoes the result. Since it's only using one session (can be verified by the fact that CLIENT_ACCEPTED logging only is triggered once) it could be used to simulate the calls made by your service.
Create a web client object
$wc = New-Object System.Net.WebClient
while(0 -lt 1){
Add headers
$wc.Headers.Add("User-Agent", "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0;)")
"Sending a request"
$result = $wc.DownloadString("https://www.mysite.com")
Echo request result
$result
Wait for 3 seconds before sending the next one
sleep 3
}
Hope it works for you!
/Patrik
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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