diff options
author | Adam Kocoloski <kocolosk@apache.org> | 2009-11-03 17:15:37 +0000 |
---|---|---|
committer | Adam Kocoloski <kocolosk@apache.org> | 2009-11-03 17:15:37 +0000 |
commit | 6943c2f9d7117b7e15090bf7ea86bc18d2bd8a85 (patch) | |
tree | 3bfa50622399310173e3489ae9ef3b37716f4c1e /src/couchdb | |
parent | 5454022f609f88bf67a85d02c39c95c1f3c49a62 (diff) |
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
Diffstat (limited to 'src/couchdb')
-rw-r--r-- | src/couchdb/couch_stats_aggregator.erl | 12 |
1 files changed, 7 insertions, 5 deletions
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}. |