Number of Executions IRule
Hello community,
We are using an IRule to throttle traffic from our client. We would think the number of requests per second on the VIP would equal the number of times the Irule gets executed per second, however we are seeing a decrepancies in these values. We are using Solarwinds to get the number of Executions per second and the number of Requests Per second. We have found that these values are not equal(however they do trend in the same direction). The number of executions is always lower then the number of requests by about 200.
Can anyone explain why these two values would differ? We would expect them to be exactly the same and I am concerned it is not executing for all requests.
Below is the IRule we are using to throttle. We are using ltmRuleEventStatTotalExecutions and ltmVirtualServStatTotRequests to compute the requestsper Second and Executions per second.
Thank you!
when RULE_INIT {
set static::win_size 1000
set static::qps_hwm 1800
set static::no_bid_file "/Common/RTB_no_bid_response"
set static::window_count 10
set static::debug 1
array set ::time_windows {}
set ::req_counter 0
set ::sample_rate 100
set ::last_time [clock clicks -milliseconds]
}
when HTTP_REQUEST {
set ::req_counter [incr ::req_counter]
if { $::req_counter == $static::win_size } {
set timestamp [clock clicks -milliseconds]
set difference [expr {$timestamp - $::last_time}]
set current_qps [expr {double($static::win_size) / double($difference)}]
if {[info exists ::time_windows($static::window_count)]} {
for {set i 0} {$i < $static::window_count} {incr i} {
set tmp [lindex [array get ::time_windows [expr {$i + 1}]] 1]
set ::time_windows($i) $tmp
}
set ::time_windows($static::window_count) $current_qps
} else {
set ::time_windows([array size ::time_windows]) $current_qps
}
set total 0
foreach index [array names ::time_windows] {
set total [expr {$total + $::time_windows($index)}]
}
set avg_qps [expr {double($total) / [array size ::time_windows]}]
set avg_qps [expr {$avg_qps * 1000}]
if { $avg_qps < $static::qps_hwm } {
set ::sample_rate 100
} else {
set ::sample_rate [expr {100 * [expr {double($static::qps_hwm) / double($avg_qps)}]}]
}
set ::req_counter 0
set ::last_time $timestamp
if { $static::debug == 1 } {
log -noname local0. "Current avg qps: ${avg_qps}"
log -noname local0. "Current sample rate: ${::sample_rate}"
}
}
set random_number [expr {rand() * 100}]
if { $random_number >= $::sample_rate } {
HTTP::respond 200 content [ifile get $static::no_bid_file] Cache-Control "no-cache,no-store,must-revalidate" Pragma "no-cache" Expires "Fri, 01 Jan 1990 00:00:00 GMT"
return
}
}