Merge lp:~david-goetz/swift/log_sleeps into lp:~hudson-openstack/swift/trunk

Proposed by David Goetz
Status: Merged
Approved by: Chuck Thier
Approved revision: 110
Merged at revision: 109
Proposed branch: lp:~david-goetz/swift/log_sleeps
Merge into: lp:~hudson-openstack/swift/trunk
Diff against target: 88 lines (+18/-4)
4 files modified
doc/source/ratelimit.rst (+3/-0)
etc/proxy-server.conf-sample (+2/-1)
swift/common/middleware/ratelimit.py (+7/-0)
test/unit/common/middleware/test_ratelimit.py (+6/-3)
To merge this branch: bzr merge lp:~david-goetz/swift/log_sleeps
Reviewer Review Type Date Requested Status
Chuck Thier (community) Approve
gholt (community) Approve
Review via email: mp+39289@code.launchpad.net

Description of the change

Allow visibility into ratelimit sleeps by logging sleeps that exceed a given config value.

To post a comment you must log in.
Revision history for this message
gholt (gholt) :
review: Approve
Revision history for this message
Chuck Thier (cthier) wrote :

Makes J happy :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'doc/source/ratelimit.rst'
2--- doc/source/ratelimit.rst 2010-10-13 21:30:00 +0000
3+++ doc/source/ratelimit.rst 2010-10-25 16:04:02 +0000
4@@ -27,6 +27,9 @@
5 max_sleep_time_seconds 60 App will immediately return a 498 response
6 if the necessary sleep time ever exceeds
7 the given max_sleep_time_seconds.
8+log_sleep_time_seconds 0 To allow visibility into rate limiting set
9+ this value > 0 and all sleeps greater than
10+ the number will be logged.
11 account_ratelimit 0 If set, will limit all requests to
12 /account_name and PUTs to
13 /account_name/container_name. Number is in
14
15=== modified file 'etc/proxy-server.conf-sample'
16--- etc/proxy-server.conf-sample 2010-10-14 23:47:14 +0000
17+++ etc/proxy-server.conf-sample 2010-10-25 16:04:02 +0000
18@@ -60,7 +60,8 @@
19 # clock accuracy.
20 # clock_accuracy = 1000
21 # max_sleep_time_seconds = 60
22-
23+# log_sleep_time_seconds of 0 means disabled
24+# log_sleep_time_seconds = 0
25 # account_ratelimit of 0 means disabled
26 # account_ratelimit = 0
27
28
29=== modified file 'swift/common/middleware/ratelimit.py'
30--- swift/common/middleware/ratelimit.py 2010-10-20 17:31:50 +0000
31+++ swift/common/middleware/ratelimit.py 2010-10-25 16:04:02 +0000
32@@ -40,6 +40,8 @@
33 self.account_ratelimit = float(conf.get('account_ratelimit', 0))
34 self.max_sleep_time_seconds = float(conf.get('max_sleep_time_seconds',
35 60))
36+ self.log_sleep_time_seconds = float(conf.get('log_sleep_time_seconds',
37+ 0))
38 self.clock_accuracy = int(conf.get('clock_accuracy', 1000))
39 self.ratelimit_whitelist = [acc.strip() for acc in
40 conf.get('account_whitelist', '').split(',')
41@@ -176,6 +178,11 @@
42 obj_name=obj_name):
43 try:
44 need_to_sleep = self._get_sleep_time(key, max_rate)
45+ if self.log_sleep_time_seconds and \
46+ need_to_sleep > self.log_sleep_time_seconds:
47+ self.logger.info("Ratelimit sleep log: %s for %s/%s/%s" % (
48+ need_to_sleep, account_name,
49+ container_name, obj_name))
50 if need_to_sleep > 0:
51 eventlet.sleep(need_to_sleep)
52 except MaxSleepTimeHit, e:
53
54=== modified file 'test/unit/common/middleware/test_ratelimit.py'
55--- test/unit/common/middleware/test_ratelimit.py 2010-10-20 18:05:38 +0000
56+++ test/unit/common/middleware/test_ratelimit.py 2010-10-25 16:04:02 +0000
57@@ -98,9 +98,12 @@
58
59
60 class FakeLogger(object):
61+ # a thread safe logger
62
63 def error(self, msg):
64- # a thread safe logger
65+ pass
66+
67+ def info(self, msg):
68 pass
69
70
71@@ -289,7 +292,7 @@
72 the_498s = [t for t in all_results if t.startswith('Slow down')]
73 self.assertEquals(len(the_498s), 2)
74 time_took = time.time() - begin
75- self.assert_(1.5 <= round(time_took,1) < 1.7, time_took)
76+ self.assert_(1.5 <= round(time_took, 1) < 1.7, time_took)
77
78 def test_ratelimit_max_rate_multiple_acc(self):
79 num_calls = 4
80@@ -326,7 +329,7 @@
81 thread.join()
82 time_took = time.time() - begin
83 # the all 15 threads still take 1.5 secs
84- self.assert_(1.5 <= round(time_took,1) < 1.7)
85+ self.assert_(1.5 <= round(time_took, 1) < 1.7)
86
87 def test_ratelimit_acc_vrs_container(self):
88 conf_dict = {'clock_accuracy': 1000,