Forum Discussion
Ger_Hackett_323
Aug 25, 2011Nimbostratus
Limit number of resource intensive pages being served
Hi All,
I have a website that contains a mixture of static and dynamic pages. Some of the dynamic pages are very resource intensive and can be indentify by examining the URI.
I would like to limit the number of these resource intensive pages that can be served at any one time. Does the rule below look like it might do the trick? It looks too simple to be true. Having reviewed other examples, they tend to decrement the counter when the connection is closed, when the CLIENT_CLOSED event fires. I have chosen to decrement the counter when the HTTP_RESPONSE event is fired because at that stage all of the hard work of generating the response should have been completed.
rule limit_specific_pages {
when RULE_INIT {
set ::requests_in_progress 0
set ::max_pages 20
}
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/abc" } {
This is a resource intensive page, so check now many
currently are in progress before we serve it
set was_resource_intensive 1
incr ::requests_in_progress
if { $::requests_in_progress >= $::max_pages } {
There are too many resource intensive pages being served at the moment
so send the user to the too busy page
HTTP::redirect "http://mydomain.com/too.busy"
return
} else {
We are under the limit, so just serve the page
pool A
}
} else {
This is just a request for a regular page
set was_resource_intensive 0
pool A
}
}
when HTTP_RESPONSE {
Now that the page has been processed, if it was a resource intensive one
decrement the counter
if { $was_resource_intensive }
{ incr ::requests_in_progress -1 }
}
}
- HamishCirrocumulus
- Ger_Hackett_323NimbostratusHi Hamish,
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