Forum Discussion
David_Farkas_29
Nimbostratus
Feb 01, 2005Cache persistence on domain name
Under 4.x I've used a very simple cache rule to send requests to a set of caches. However, back in 4.2 PTF6, a 'special' feature was added to allow persistence to a cache based on the level of the ho...
unRuleY_95363
Feb 09, 2005Historic F5 Account
Oh, I forgot to mention that the above rule doesn't handle the concept of hot content being spread across the entire cache.
To do that, the rule would have to track the hit rate which we currently can't do efficiently because we have to use the Tcl clock command (which can have a potential performance impact).
You are welcome to try out the following rule which does track the hit rate and disables persistence so that the hot content is load-balance across the entire set of cache servers.
(I also further customized the rule to be closer to your original 4.x example - using the expression and pools, etc):
when HTTP_REQUEST {
if { [HTTP::host] starts_with "abc" and \
( [HTTP::uri] ends_with "html" or \
[HTTP::uri] ends_with "gif" ) } {
pool cache_servers
set key [crc32 [concat [domain [HTTP::host] 2] [HTTP::uri]]]
set cache_mbr [persist lookup hash $key node]
if { $cache_mbr ne "" } {
Make sure request isn't coming from the cache
if { [IP::addr [IP::remote_addr] equals $cache_mbr] } {
Yup, send the request from the cache to the origin pool
pool origin_server
} else {
set cur_time [clock seconds]
set hit_info [session lookup hash $key]
if { $hit_info ne "" } {
set hit_time [lindex $hit_info 0]
set hit_total [lindex $hit_info 1]
set hit_list [lindex $hit_info 2]
set hot [lindex $hit_info 3]
set hit_count [lindex $hit_list 0]
Calculate current hit rate
set $delta_time [expr $cur_time - $hit_time]
If the amount of elapsed time is > hit period
if {$delta_time > 60} {
Just re-initialize the entire hit period
set hit_info ""
} else {
Shift out the elapsed hits
for {} {$delta_time > 0} {incr delta_time -1} {
set hit_total [expr $hit_total - [lindex $hit_list 0]]
set hit_list [lrange hit_list 1 end]
lappend hit_list 0
}
}
}
if { $hit_info eq "" } {
Initialize hit period with no hits
for {set hot 0} {$hot <= 60} {incr hot} {
lappend hit_list 0
}
set hit_count 0
set hit_total 0
set hot 0
}
Update current hit count
lset hit_list end [incr hit_count]
incr hit_total
if { $hit_total > 100 } {
Above hot threshold
set hot 1
} elseif { $hot and $hit_total < 10 } {
Below cool threshold
set hot 0
}
if { not $hot } {
Use persistence to go to the same cache (with a 3600 secs timeout)
persist hash $key 3600
}
session add hash $key { $cur_time $hit_total $hit_list $hot }
}
} else {
Make sure persistence record is added for this host/uri
persist hash $key 3600
}
} else {
pool origin_pool
}
}
Warning: I have not tested this rule.
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
