diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2014-03-31 13:21:27 +0100 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2014-03-31 13:21:27 +0100 |
| commit | b795aeb8dd38c59cdcf225f05a9b7dbd4eb4d76d (patch) | |
| tree | 05956960a61e6ca66eeb6e8d335e237af6e1fc37 | |
| parent | 2f7757f491c04cbc69034ed6ebf85dd88200e4c4 (diff) | |
| download | rabbitmq-server-git-b795aeb8dd38c59cdcf225f05a9b7dbd4eb4d76d.tar.gz | |
Explain this formula.
| -rw-r--r-- | src/rabbit_misc.erl | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 2e87a8f6e1..58e93a3f9e 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. |
