Merge lp:~lucio.torre/txstatsd/fix-exp-overflow into lp:txstatsd

Proposed by Lucio Torre
Status: Merged
Approved by: Sidnei da Silva
Approved revision: 76
Merged at revision: 75
Proposed branch: lp:~lucio.torre/txstatsd/fix-exp-overflow
Merge into: lp:txstatsd
Diff against target: 50 lines (+20/-5)
2 files modified
txstatsd/stats/exponentiallydecayingsample.py (+5/-5)
txstatsd/tests/stats/test_exponentiallydecayingsample.py (+15/-0)
To merge this branch: bzr merge lp:~lucio.torre/txstatsd/fix-exp-overflow
Reviewer Review Type Date Requested Status
Sidnei da Silva Approve
Review via email: mp+96448@code.launchpad.net

Commit message

fix exp overflow

Description of the change

we now rescale before processing the metric, to make sure the scale difference between the last scale an now is smaller than RESCALE THRESHOLD.

To post a comment you must log in.
76. By Lucio Torre

fix overflow

Revision history for this message
Sidnei da Silva (sidnei) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'txstatsd/stats/exponentiallydecayingsample.py'
2--- txstatsd/stats/exponentiallydecayingsample.py 2012-01-30 20:36:02 +0000
3+++ txstatsd/stats/exponentiallydecayingsample.py 2012-03-07 20:30:23 +0000
4@@ -60,6 +60,11 @@
5 @param timestamp: The epoch timestamp of *value* in seconds.
6 """
7
8+ now = self._wall_time()
9+ next = self.next_scale_time
10+ if now >= next:
11+ self.rescale(now, next)
12+
13 if timestamp is None:
14 timestamp = self.tick()
15
16@@ -75,11 +80,6 @@
17 bisect.insort(self._values, (priority, value))
18 self._values = self._values[1:]
19
20- now = self._wall_time()
21- next = self.next_scale_time
22- if now >= next:
23- self.rescale(now, next)
24-
25 def get_values(self):
26 return [v for (k, v) in self._values]
27
28
29=== modified file 'txstatsd/tests/stats/test_exponentiallydecayingsample.py'
30--- txstatsd/tests/stats/test_exponentiallydecayingsample.py 2012-02-07 21:11:42 +0000
31+++ txstatsd/tests/stats/test_exponentiallydecayingsample.py 2012-03-07 20:30:23 +0000
32@@ -67,3 +67,18 @@
33 'Should have 100 elements')
34 test_ewma_sample_load.skip = "takes too long to run"
35
36+ def test_ewma_overflow(self):
37+ """Long pauses on metric input should not overflow weight."""
38+ _time = [10000]
39+
40+ def wtime():
41+ return _time[0]
42+
43+ sample = ExponentiallyDecayingSample(100, 0.99, wall_time=wtime)
44+ for i in xrange(100):
45+ sample.update(random.normalvariate(0, 10))
46+ _time[0] += 10000
47+
48+ self.assertEqual(sample.size(), 100)
49+ self.assertEqual(len(sample.get_values()), 100,
50+ 'Should have 100 elements')

Subscribers

People subscribed via source and target branches