summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2014-03-31 13:21:27 +0100
committerSimon MacMullen <simon@rabbitmq.com>2014-03-31 13:21:27 +0100
commit9ff132150da0b5429958f8ef9e1dbf92f21225fa (patch)
tree05956960a61e6ca66eeb6e8d335e237af6e1fc37
parentf549c91bc489720270d7c12a4f64ecad08ece0ec (diff)
downloadrabbitmq-server-9ff132150da0b5429958f8ef9e1dbf92f21225fa.tar.gz
Explain this formula.
-rw-r--r--src/rabbit_misc.erl13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index 2e87a8f6..58e93a3f 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -1059,6 +1059,19 @@ store_proc_name(TypeProcName) -> put(process_name, TypeProcName).
moving_average(_Time, _HalfLife, Next, undefined) ->
Next;
+%% We want the Weight to decrease as Time goes up (since Weight is the
+%% weight for the current sample, not the new one), so that the moving
+%% average decays at the same speed regardless of how long the time is
+%% between samplings. So we want Weight = math:exp(Something), where
+%% Something turns out to be negative.
+%%
+%% We want to determine Something here in terms of the Time taken
+%% since the last measurement, and a HalfLife. So we want Weight =
+%% math:exp(Time * Constant / HalfLife). What should Constant be? We
+%% want Weight to be 0.5 when Time = HalfLife.
+%%
+%% Plug those numbers in and you get 0.5 = math:exp(Constant). Take
+%% the log of each side and you get math:log(0.5) = Constant.
moving_average(Time, HalfLife, Next, Current) ->
Weight = math:exp(Time * math:log(0.5) / HalfLife),
Next * (1 - Weight) + Current * Weight.