This is an automated email from the ASF dual-hosted git repository. vatamane pushed a commit to branch replace-folsom in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 9cf3ce1a492a24be96a29add599291942933e723 Author: Nick Vatamaniuc <[email protected]> AuthorDate: Tue Jul 18 00:53:43 2023 -0400 [fixup|stats_server] rename hist->clean, add comment to clean_msec --- src/couch_stats/src/couch_stats_server.erl | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/couch_stats/src/couch_stats_server.erl b/src/couch_stats/src/couch_stats_server.erl index fed767535..d58a8f061 100644 --- a/src/couch_stats/src/couch_stats_server.erl +++ b/src/couch_stats/src/couch_stats_server.erl @@ -14,7 +14,7 @@ % - Initial metric loading from application stats descriptions. % - Recycling(resetting to 0) stale histogram counters. % - Checking and reloading if stats descriptions change. -% - Checking and reloading if histogram window size config value changes. +% - Checking and reloading if histogram interval config value changes. % -module(couch_stats_server). @@ -38,7 +38,7 @@ -record(st, { hist_interval, histograms, - hist_tref, + clean_tref, reload_tref }). @@ -51,7 +51,7 @@ start_link() -> init([]) -> St = #st{ hist_interval = config:get("stats", "interval"), - hist_tref = erlang:send_after(hist_msec(), self(), clean), + clean_tref = erlang:send_after(clean_msec(), self(), clean), reload_tref = erlang:send_after(reload_msec(), self(), reload) }, {_, Stats} = try_reload(St), @@ -73,8 +73,8 @@ handle_info(Msg, #st{} = St) -> {stop, {unknown_info, Msg}, St}. do_clean(#st{} = St) -> - timer:cancel(St#st.hist_tref), - HistTRef = erlang:send_after(hist_msec(), self(), clean), + timer:cancel(St#st.clean_tref), + HistTRef = erlang:send_after(clean_msec(), self(), clean), NowSec = erlang:monotonic_time(second), BufferSec = couch_stats_util:histogram_safety_buffer_size_sec(), IntervalSec = couch_stats_util:histogram_interval_sec(), @@ -95,19 +95,19 @@ do_clean(#st{} = St) -> end, St#st.histograms ), - St#st{hist_tref = HistTRef}. + St#st{clean_tref = HistTRef}. do_reload(#st{} = St) -> timer:cancel(St#st.reload_tref), RTRef = erlang:send_after(reload_msec(), self(), reload), case try_reload(St) of {true, NewStats} -> - timer:cancel(St#st.hist_tref), + timer:cancel(St#st.clean_tref), Histograms = couch_stats_util:histograms(NewStats), - HTRef = erlang:send_after(hist_msec(), self(), clean), + HTRef = erlang:send_after(clean_msec(), self(), clean), St#st{ histograms = Histograms, - hist_tref = HTRef, + clean_tref = HTRef, reload_tref = RTRef, hist_interval = config:get("stats", "interval") }; @@ -141,7 +141,11 @@ interval_changed(#st{hist_interval = OldInterval}) -> reload_msec() -> 1000 * ?RELOAD_INTERVAL_SEC. -hist_msec() -> +clean_msec() -> + % We want to wake up more often than our interval so we decide to wake + % about twice as often. If the interval is 10 seconds, we'd wake up every 5 + % seconds and clean the most stale 10 seconds. It's a bit wasteful but it's + % a safety feature to ensure we don't miss anything. (couch_stats_util:histogram_interval_sec() * 1000) div 2. -ifdef(TEST).
