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 host name (see below). I was wonder if this 'feature' was carried forward in 9.x or is there a iRule that will accomplish the same thing.
Here is how the feature works:
b internal set cache_uses_host_domain = 0 (default) - makes cache rules use the URI
b internal set cache_uses_host_domain = 1 - makes cache rule use 1st level TLD. (i.e. .com, .net, .org, etc.)
b internal set cache_uses_host_domain = 2 - makes cache rule use 2nd level domain (i.e. merck.com, yahoo.com, hotmail.com, etc.)
b internal set cache_uses_host_domain = 3 - makes cache rule use 3rd level domain (i.e. www.merck.com , ftp.yahoo.com
, www.slashdot.org ,etc.)
- unRuleY_95363Historic F5 AccountWe have not yet implemented the 4.x cache rule command in 9.0. This is currently planned for the release in late spring.
- David_Farkas_29
Nimbostratus
So is this why I get an error when I attempt to use the cache rule, even the example that is the manual?when HTTP_REQUEST { if { [HTTP::host] starts_with "abc" } { cache { [HTTP::uri] ends_with "html" or [HTTP::uri] ends_with "gif" } { origin_pool origin_server cache_pool cache_servers hot_pool cache_servers hot_threshold 100 cool_threshold 10 hit_period 60 content_hash_size 1024 } else { pool host named_servers } } }
- unRuleY_95363Historic F5 AccountYes, I must apologize for that.
- David_Farkas_29
Nimbostratus
Here is the current cache rule I am using in the 4.x:cache (not (http_host == "xxxx")) { origin_pool Caches cache_pool Caches }
when HTTP_REQUEST { if { [HTTP::host] != "xxxx"} { pool cache_pool persist universal [domain [HTTP::host] 2] 86400 } else { pool cache_pool persist universal [domain [HTTP::host] 2] 86400 } }
- David_Farkas_29
Nimbostratus
Just check ing to see if there was a possibility of getting a TCL equivalent written for this functionality? - unRuleY_95363Historic F5 AccountThe following is an approximation of the logic used by the cache rule command. However, it does not remap uri's to a new cache member when a cache member goes down. In this rule, that is instead handled at the time a request for the uri comes in. I don't foresee this really being an issue though.
when HTTP_REQUEST { if { } { pool cache_pool 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_pool return } } Make sure persistence record is added for this host/uri persist hash $key } else { pool origin_pool } }
- unRuleY_95363Historic F5 AccountOh, I forgot to mention that the above rule doesn't handle the concept of hot content being spread across the entire cache.
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 } }
- David_Farkas_29
Nimbostratus
First of all I would like to THANK YOU for getting this iRule together. However, I have a few questions about the hash and the persistence. - unRuleY_95363Historic F5 AccountYes, the default persist time is 180 seconds, however, if you notice in the second rule I actually set this to an hour. Yes, it does have the potential to create a lot of persist records, but they are fairly small and the system can support millions of them with no effect on performance.
- David_Farkas_29
Nimbostratus
I used the following rule and it works great with HTTP requests. However, it breaks HTTPS requests.when HTTP_REQUEST { if { [HTTP::host] != "xxxxx" } { pool Caches set key [crc32 [domain [HTTP::host] 2]] Make sure persistence record is added for this domain persist hash $key } else { pool Caches } }
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