diff options
| -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. |
