Make BucketedTimeSeries::rate() more accurate
authorAdam Simpkins <simpkins@fb.com>
Wed, 17 Apr 2013 01:32:23 +0000 (18:32 -0700)
committerSara Golemon <sgolemon@fb.com>
Mon, 20 May 2013 18:01:26 +0000 (11:01 -0700)
commite9bf39f0e3d57672e03d01a788f097c76405362e
tree454d7eb9632b777e7be5eab6c0482ce26f14e0dd
parent4b9cc255b07960d87abe202ab898ad5bb5eba7ca
Make BucketedTimeSeries::rate() more accurate

Summary:
Make rate() and countRate() more accurate when queried for a specific
time range.

Previously these functions divided the estimated sum/count by the entire
time range specified.  This underestimated the rate if we don't actually
have data for the entire time period.  (Since the sum computed only
takes into account the time range for which we have data.)

For example, if the timeseries duration was 60 seconds, but only 30
seconds of data had been entered so far, rate(now - 60, now) would
underestimate the rate by half, since there was only 30 seconds worth of
data available.  The no-argument version of rate() did work correctly in
that case.

Test Plan:
Added a new unit test for this behavior.

Also fixed the existing rate test code, which had the same bug and
expected the underestimated rate.

Reviewed By: delong.j@fb.com

FB internal diff: D778114
folly/stats/BucketedTimeSeries-defs.h
folly/stats/BucketedTimeSeries.h
folly/test/TimeseriesTest.cpp