adding rate limit sleep log

This commit is contained in:
David Goetz
2010-10-22 11:43:39 -07:00
parent f494fc37a6
commit 4bfedf86a4
3 changed files with 12 additions and 1 deletions

View File

@@ -27,6 +27,9 @@ clock_accuracy 1000 Represents how accurate the proxy servers'
max_sleep_time_seconds 60 App will immediately return a 498 response max_sleep_time_seconds 60 App will immediately return a 498 response
if the necessary sleep time ever exceeds if the necessary sleep time ever exceeds
the given max_sleep_time_seconds. the given max_sleep_time_seconds.
log_sleep_time_seconds 0 To allow visibility into rate limiting set
this value > 0 and all sleeps greater than
the number will be logged.
account_ratelimit 0 If set, will limit all requests to account_ratelimit 0 If set, will limit all requests to
/account_name and PUTs to /account_name and PUTs to
/account_name/container_name. Number is in /account_name/container_name. Number is in

View File

@@ -60,7 +60,8 @@ use = egg:swift#ratelimit
# clock accuracy. # clock accuracy.
# clock_accuracy = 1000 # clock_accuracy = 1000
# max_sleep_time_seconds = 60 # max_sleep_time_seconds = 60
# log_sleep_time_seconds of 0 means disabled
# log_sleep_time_seconds = 0
# account_ratelimit of 0 means disabled # account_ratelimit of 0 means disabled
# account_ratelimit = 0 # account_ratelimit = 0

View File

@@ -40,6 +40,8 @@ class RateLimitMiddleware(object):
self.account_ratelimit = float(conf.get('account_ratelimit', 0)) self.account_ratelimit = float(conf.get('account_ratelimit', 0))
self.max_sleep_time_seconds = float(conf.get('max_sleep_time_seconds', self.max_sleep_time_seconds = float(conf.get('max_sleep_time_seconds',
60)) 60))
self.log_sleep_time_seconds = float(conf.get('log_sleep_time_seconds',
0))
self.clock_accuracy = int(conf.get('clock_accuracy', 1000)) self.clock_accuracy = int(conf.get('clock_accuracy', 1000))
self.ratelimit_whitelist = [acc.strip() for acc in self.ratelimit_whitelist = [acc.strip() for acc in
conf.get('account_whitelist', '').split(',') conf.get('account_whitelist', '').split(',')
@@ -176,6 +178,11 @@ class RateLimitMiddleware(object):
obj_name=obj_name): obj_name=obj_name):
try: try:
need_to_sleep = self._get_sleep_time(key, max_rate) need_to_sleep = self._get_sleep_time(key, max_rate)
if self.log_sleep_time_seconds and \
need_to_sleep > self.log_sleep_time_seconds:
self.logger.info("Ratelimit sleep log: %s for %s/%s/%s" % (
need_to_sleep, account_name,
container_name, obj_name))
if need_to_sleep > 0: if need_to_sleep > 0:
eventlet.sleep(need_to_sleep) eventlet.sleep(need_to_sleep)
except MaxSleepTimeHit, e: except MaxSleepTimeHit, e: