irule-not-matching-uri-as-expected

I have the following iRule setup which allows me to request a pool based on uri.

when RULE_INIT { set req_count 0 after 60000 -periodic { set req_count 0 } }

when HTTP_REQUEST { if {[HTTP::uri] matches_regex “^/data/main.js\?id=100\&."} { incr ::req_count if { $::req_count > 40000 } { HTTP::respond 503 Retry-After 3 } use pool siteA_http_pool } elseif {[HTTP::uri] matches_regex "^/data/main.js\?id=200\&.”} { use pool siteB_http_pool } elseif {[HTTP::uri] matches_regex “^/data/main.js\?id=300\&.*”} { use pool siteC_http_pool } else { use pool siteD_http_pool } }

rule to siteA_http_pool is enable.expected movement.

but

{[HTTP::uri] matches_regex “^/data/main.js\?id=200\&.*”}use pool siteB_http_pool

&

{[HTTP::uri] matches_regex “^/data/main.js\?id=300\&.*”}use pool siteC_http_pool

are not expected movement. this two rule is invalid, access to siteD_http_pool..

Where is my mistake ?

Is the use of regexp necessary in this case? I was told to avoid regexp whenever possible since they are rather CPU intensive. In this case I think you could just use starts_with instead:

{[HTTP::uri] starts_with “/data/main.js?id=100&”}

Of other notice is that you’re using req_count as a global variable, which is really bad for performance since it will demote the virtual server associated with this iRule to a single CPU core. That whole thing is to limit the number of requests to siteA_http_pool, right? I think there would be more efficient ways to do that. Let me think on that.