You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/02/05 00:06:23 UTC
[10/50] couch commit: updated refs/heads/import to c3116d7
Use a dict for couch_stats_collector state
This gen_server was falling over in this simple collector. The only real
work it's doing is the keytake function. Most likely a huge list ends up
causing a positive feed back loop as messages pile up. Using a dict
should cut down on the worst case behavior while not being overly harsh
to the opposite work load of very few processes being tracked.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/9ae2380c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/9ae2380c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/9ae2380c
Branch: refs/heads/import
Commit: 9ae2380c928f7a424a85c889358191659cd92165
Parents: 50c195d
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed May 2 16:41:33 2012 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Tue Feb 4 17:03:23 2014 -0600
----------------------------------------------------------------------
src/couch_stats_collector.erl | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/9ae2380c/src/couch_stats_collector.erl
----------------------------------------------------------------------
diff --git a/src/couch_stats_collector.erl b/src/couch_stats_collector.erl
index 0ebca99..99814de 100644
--- a/src/couch_stats_collector.erl
+++ b/src/couch_stats_collector.erl
@@ -92,7 +92,7 @@ track_process_count(Pid, Stat) ->
init(_) ->
ets:new(?HIT_TABLE, [named_table, set, public]),
ets:new(?ABS_TABLE, [named_table, duplicate_bag, public]),
- {ok, []}.
+ {ok, dict:new()}.
terminate(_Reason, _State) ->
ok.
@@ -102,13 +102,15 @@ handle_call(stop, _, State) ->
handle_cast({track_process_count, Pid, Stat}, State) ->
Ref = erlang:monitor(process, Pid),
- {noreply, [{Ref, Stat} | State]}.
+ {noreply, dict:store(Ref, Stat, State)}.
handle_info({'DOWN', Ref, _, _, _}, State) ->
- {value, {Ref, Stat}, NewState} = lists:keytake(Ref, 1, State),
+ Stat = dict:fetch(Ref, State),
ok = couch_stats_collector:decrement(Stat),
- {noreply, NewState}.
+ {noreply, dict:erase(Ref, State)}.
+code_change(_OldVersion, State, _Extra) when is_list(State) ->
+ {ok, dict:from_list(State)};
code_change(_OldVersion, State, _Extra) ->
{ok, State}.