limit PUT, DELETE, POSTs to /a/c and /a/c/o

This commit is contained in:
David Goetz
2011-07-12 08:15:15 -07:00
parent e3ff894fab
commit 01307fd46f
2 changed files with 9 additions and 10 deletions

View File

@@ -35,20 +35,17 @@ rate_buffer_seconds 5 Number of seconds the rate counter can
faster than listed rate). A larger number faster than listed rate). A larger number
will result in larger spikes in rate but will result in larger spikes in rate but
better average accuracy. better average accuracy.
account_ratelimit 0 If set, will limit all requests to account_ratelimit 0 If set, will limit PUT, DELETE, and POST
/account_name and PUTs to requests to /account_name/container_name.
/account_name/container_name. Number is in Number is in requests per second.
requests per second
account_whitelist '' Comma separated lists of account names that account_whitelist '' Comma separated lists of account names that
will not be rate limited. will not be rate limited.
account_blacklist '' Comma separated lists of account names that account_blacklist '' Comma separated lists of account names that
will not be allowed. Returns a 497 response. will not be allowed. Returns a 497 response.
container_ratelimit_size '' When set with container_limit_x = r: container_ratelimit_size '' When set with container_limit_x = r:
for containers of size x, limit requests for containers of size x, limit requests
per second to r. Will limit GET and HEAD per second to r. Will limit PUT, DELETE,
requests to /account_name/container_name and POST requests to /a/c/o.
and PUTs and DELETEs to
/account_name/container_name/object_name
======================== ========= =========================================== ======================== ========= ===========================================
The container rate limits are linearly interpolated from the values given. A The container rate limits are linearly interpolated from the values given. A

View File

@@ -105,15 +105,17 @@ class RateLimitMiddleware(object):
:param obj_name: object name from path :param obj_name: object name from path
""" """
keys = [] keys = []
limit_req_types = ['PUT', 'DELETE', 'POST']
# COPYs are not limited
if self.account_ratelimit and \ if self.account_ratelimit and \
account_name and container_name and not obj_name and \ account_name and container_name and not obj_name and \
req_method in ('PUT', 'DELETE', 'POST'): req_method in limit_req_types:
# account_ratelimit PUTs/DELETEs to acc_name/cont_name # account_ratelimit PUTs/DELETEs to acc_name/cont_name
keys.append(("ratelimit/%s" % account_name, keys.append(("ratelimit/%s" % account_name,
self.account_ratelimit)) self.account_ratelimit))
if account_name and container_name and obj_name and \ if account_name and container_name and obj_name and \
req_method in ('PUT', 'DELETE', 'POST', 'COPY'): req_method in limit_req_types:
# container_ratelimit PUTs/DELETEs to acc_name/cont_name/obj_name # container_ratelimit PUTs/DELETEs to acc_name/cont_name/obj_name
container_size = None container_size = None
memcache_key = get_container_memcache_key(account_name, memcache_key = get_container_memcache_key(account_name,