couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [11/14] couch-stats commit: updated refs/heads/master to bb24add
Date Wed, 20 Aug 2014 13:09:19 GMT
Store tracked processes in ets rather than dict


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/commit/7c44fe48
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/tree/7c44fe48
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/diff/7c44fe48

Branch: refs/heads/master
Commit: 7c44fe4816e3e3db711c35d7cfa02a76ea9e2aa6
Parents: 30fd32c
Author: Benjamin Anderson <b@banjiewen.net>
Authored: Wed Feb 12 09:52:50 2014 -0800
Committer: Robert Newson <rnewson@apache.org>
Committed: Tue Aug 19 14:48:31 2014 +0100

----------------------------------------------------------------------
 src/couch_stats_process_tracker.erl | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/blob/7c44fe48/src/couch_stats_process_tracker.erl
----------------------------------------------------------------------
diff --git a/src/couch_stats_process_tracker.erl b/src/couch_stats_process_tracker.erl
index 825142b..3d25d03 100644
--- a/src/couch_stats_process_tracker.erl
+++ b/src/couch_stats_process_tracker.erl
@@ -17,7 +17,7 @@
 ]).
 
 -record(st, {
-    tracked
+
 }).
 
 -spec track(any()) -> ok.
@@ -32,24 +32,34 @@ start_link() ->
     gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
 
 init([]) ->
-    {ok, #st{tracked = dict:new()}}.
+    ets:new(?MODULE, [named_table]),
+    {ok, #st{}}.
 
 handle_call(Msg, _From, State) ->
     twig:log(notice, "~p received unknown call ~p", [?MODULE, Msg]),
     {noreply, State}.
 
-handle_cast({track, Pid, Name}, #st{tracked=Tracked}=State) ->
+handle_cast({track, Pid, Name}, State) ->
     couch_stats:increment_counter(Name),
     Ref = erlang:monitor(process, Pid),
-    {noreply, State#st{tracked=dict:store(Ref, Name, Tracked)}};
+    ets:insert(?MODULE, {Ref, Name}),
+    {noreply, State};
 handle_cast(Msg, State) ->
     twig:log(notice, "~p received unknown cast ~p", [?MODULE, Msg]),
     {noreply, State}.
 
-handle_info({'DOWN', Ref, _, _, _}, #st{tracked=Tracked}=State) ->
-    Name = dict:fetch(Ref, Tracked),
-    couch_stats:decrement_counter(Name),
-    {noreply, State#st{tracked=dict:erase(Ref, Tracked)}};
+handle_info({'DOWN', Ref, _, _, _}=Msg, State) ->
+    case ets:lookup(?MODULE, Ref) of
+        [] ->
+            twig:log(
+                notice,
+                "~p received unknown exit; message was ~p", [?MODULE, Msg]
+            );
+        [{Ref, Name}] ->
+            couch_stats:decrement_counter(Name),
+            ets:delete(?MODULE, Ref)
+    end,
+    {noreply, State};
 handle_info(Msg, State) ->
     twig:log(notice, "~p received unknown message ~p", [?MODULE, Msg]),
     {noreply, State}.


Mime
View raw message