From 6943c2f9d7117b7e15090bf7ea86bc18d2bd8a85 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Tue, 3 Nov 2009 17:15:37 +0000 Subject: eliminate new process flood after OS wakes from sleep. COUCHDB-539 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@832477 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_stats_aggregator.erl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/couchdb') diff --git a/src/couchdb/couch_stats_aggregator.erl b/src/couchdb/couch_stats_aggregator.erl index 3292e5f0..2f5c6d13 100644 --- a/src/couchdb/couch_stats_aggregator.erl +++ b/src/couchdb/couch_stats_aggregator.erl @@ -86,7 +86,7 @@ get_json(Key, Time) -> to_json_term(?MODULE:get(Key, Time)). collect_sample() -> - gen_server:call(?MODULE, collect_sample). + gen_server:call(?MODULE, collect_sample, infinity). init(StatDescsFileName) -> @@ -115,13 +115,15 @@ init(StatDescsFileName) -> Rate = list_to_integer(couch_config:get("stats", "rate", "1000")), % TODO: Add timer_start to kernel start options. - timer:apply_interval(Rate, ?MODULE, collect_sample, []). + {ok, TRef} = timer:apply_after(Rate, ?MODULE, collect_sample, []), + {ok, {TRef, Rate}}. -terminate(_Reason, TRef) -> +terminate(_Reason, {TRef, _Rate}) -> timer:cancel(TRef), ok. -handle_call(collect_sample, _, State) -> +handle_call(collect_sample, _, {_TRef, SampleInterval}) -> + {ok, TRef} = timer:apply_after(SampleInterval, ?MODULE, collect_sample, []), % Gather new stats values to add. Incs = lists:map(fun({Key, Value}) -> {Key, {incremental, Value}} @@ -151,7 +153,7 @@ handle_call(collect_sample, _, State) -> end, ets:insert(?MODULE, {{Key, Rate}, NewAgg}) end, ets:tab2list(?MODULE)), - {reply, ok, State}. + {reply, ok, {TRef, SampleInterval}}. handle_cast(stop, State) -> {stop, normal, State}. -- cgit v1.2.3