after
2 TopicsThrottle incoming requests per minute
Hi Guys! Trying to write an iRule that throttles incoming requests but I can't get this very simple example to work. Basically my problem seems to be that the global connections variable never is being reset. Also, I'm not sure if I have to use a global variable in this case. The limit should only affect one particular VIP and the iRule is only used at this VIP. Throttle number of requests per minute when RULE_INIT { array set connections { } after 60000 -periodic { array set ::connections { } } } when HTTP_REQUEST { if { [info exists ::connections([IP::client_addr])] } { if { [incr ::connections([IP::client_addr])] > 10 } { HTTP::respond 200 content "You have passed the request threshold of 10/minute." set blocked 1 } } else { set ::connections([IP::client_addr]) 1 HTTP::respond 200 content "OK" } } Thankful for any advice! Kind regards, Patrik387Views0likes4CommentsCan an "after" job be referenced from a different context?
This is related to a previously un-answered question: https://devcentral.f5.com/questions/periodic-summary-logging-with-table-and-after. I'm trying to accomplish roughly the same thing, but I'm looking for a more specific answer. I'm trying to count the number of times a certain kind of request has been processed, then dump those counts every X seconds. Is it possible to reference an "after" ID that was registered in a different thread of execution? The docs don't explicitly state one way or the other: after info [ …] * Returns information about currently scheduled scripts, or about a specific . * Returns active timer ID(s) ( ...) for the current executing context (i.e., client, server). * If called without supplying or multiple s supplied, return value is TCL list. When I pass a after ID to "after info " that was registered in a different thread (The ID was saved to/retrieved from a session table), I get something like: TCL error: MY_IRULE - Invalid after ID: afterbf8f674 My code looks something like this: set count [ table incr "count_$tbl" ] set after_id [after info [table lookup -subtable ${static::prefix} -notouch count_monitor]] if { [ info exists after_id ]} { do nothing, don't log right now } else { set after_id [after 10000 { log local4.notice "prefix=${static::prefix} -- count=${count}" table delete "count_$tbl" }] table set -subtable ${static::prefix} count_monitor ${after_id} 120000 } When I run that code, it fails on the second line, trying to reference the "after info" by ID. If I log "[after info] by itself, it returns nothing. After some playing around, it appears that after IDs can't be referenced outside of the original context. Is there a way that they can be registered in such a way as to be able to access them from a different context? If not, is there a different (v10-compatible) way that I could achieve some sort of asynchronous "dumping and clearing" of session table data?334Views0likes2Comments