You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/08/01 11:10:19 UTC

[23/35] git commit: Add a event count metrics

Add a event count metrics


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

Branch: refs/heads/windsor-merge
Commit: a8b378b9967b56c3e8473931d00adf691d18b863
Parents: 7d5c7e1
Author: Paul J. Davis <pa...@gmail.com>
Authored: Fri Apr 26 13:50:14 2013 -0500
Committer: Robert Newson <rn...@apache.org>
Committed: Wed Jul 30 17:42:31 2014 +0100

----------------------------------------------------------------------
 src/couch_event_dist.erl | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-event/blob/a8b378b9/src/couch_event_dist.erl
----------------------------------------------------------------------
diff --git a/src/couch_event_dist.erl b/src/couch_event_dist.erl
index 7f99a2d..95aaf65 100644
--- a/src/couch_event_dist.erl
+++ b/src/couch_event_dist.erl
@@ -54,10 +54,10 @@ handle_call(Msg, From, St) ->
 
 
 handle_cast({DbName, Event}, #st{batch_size=BS}=St) when is_binary(DbName) ->
-    P1 = #client{dbname=DbName, _='_'},
-    notify_clients(ets:select(?REGISTRY_TABLE, P1, BS), DbName, Event),
-    P2 = #client{dbname=all_dbs, _='_'},
-    notify_clients(ets:select(?REGISTRY_TABLE, P2, BS), DbName, Event),
+    margaret_counter:increment([couch_event, events_received]),
+    T1 = notify_clients(#client{dbname=DbName, _='_'}, BS, DbName, Event),
+    T2 = notify_clients(#client{dbname=all_dbs, _='_'}, BS, DbName, Event),
+    margaret_counter:increment([couch_event, events_delivered], T1 + T2),
     {noreply, St};
 
 handle_cast(Msg, St) ->
@@ -74,10 +74,15 @@ code_change(_OldVsn, St, _Extra) ->
     {ok, St}.
 
 
-notify_clients('$end_of_table', _DbName, _Event) ->
-    ok;
-notify_clients({Clients, Cont}, DbName, Event) ->
+notify_clients(Pattern, BatchSize, DbName, Event) ->
+    MSpec = [{Pattern, [], ['$_']}],
+    do_notify(ets:select(?REGISTRY_TABLE, MSpec, BatchSize), DbName, Event, 0).
+
+
+do_notify('$end_of_table', _DbName, _Event, Total) ->
+    Total;
+do_notify({Clients, Cont}, DbName, Event, Total) ->
     lists:foreach(fun(#client{pid=Pid}) ->
         Pid ! {'$couch_event', DbName, Event}
     end, Clients),
-    notify_clients(ets:select(Cont), DbName, Event).
+    do_notify(ets:select(Cont), DbName, Event, Total + length(Clients)).