Last active
August 29, 2015 14:01
-
-
Save hsiboy/2cc253ff9d814e715ed1 to your computer and use it in GitHub Desktop.
Zeus Traffic Manager - Dynamic rate shaping for slow applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# implement the following policy: | |
# if transactions complete within 50 ms, do not attempt to shape traffic. | |
# if transactions take more than 50 ms, assume that we are in danger of overload and Rate-limit traffic to 100 requests per second, and if requests exceed that rate limit, send back a '204 No Content' message rather then queuing them. | |
# Once transaction time comes down to less than 50ms, remove the rate limit. | |
# Create a rate shaping class named "Searchlimit" with a max_rate_per_second: 100 | |
# Create a Service Level Monitoring class named SearchTimer with a response_time of 500 ms. | |
# We're only concerned with requests for search. | |
$url = http.getPath(); | |
if($url != "/search.aspx") break; | |
# Time this request using the Service Level Monitoring class | |
connection.setServiceLevelClass("SearchTimer"); | |
# Test if any of the recent requests fell outside the desired SLM threshold | |
if(slm.conforming("SearchTimer") < 100) { | |
if( rate.getBacklog("SearchLimit") > 0) { | |
# To minimize response time, send a 204 No Content response if the | |
# request exceeds the configured rate of 100/second. | |
# You could also use http.redirect() to a more pleasant 'sorry' page. | |
http.sendResponse(204, "No Content", "Cache-control: no-cache"); | |
} else { | |
# Shape the traffic to 100/second | |
rate.use("SearchLimit"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment