This is an automated email from the ASF dual-hosted git repository.

chewbranca pushed a commit to branch chewbranca-ioq-experiments-rebase
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to 
refs/heads/chewbranca-ioq-experiments-rebase by this push:
     new bbe2e20  Add couch_file cache metrics
bbe2e20 is described below

commit bbe2e20a1388e67447f82c2be981de2ed115d11d
Author: Russell Branca <[email protected]>
AuthorDate: Thu Sep 2 11:17:20 2021 -0700

    Add couch_file cache metrics
---
 src/couch/priv/stats_descriptions.cfg | 12 ++++++++++++
 src/couch/src/couch_file.erl          |  3 +++
 2 files changed, 15 insertions(+)

diff --git a/src/couch/priv/stats_descriptions.cfg 
b/src/couch/priv/stats_descriptions.cfg
index 7c8fd94..57ee39f 100644
--- a/src/couch/priv/stats_descriptions.cfg
+++ b/src/couch/priv/stats_descriptions.cfg
@@ -290,6 +290,18 @@
     {type, histogram},
     {desc, <<"duration of validate_doc_update function calls">>}
 ]}.
+{[couchdb, couch_file, cache_misses], [
+    {type, counter},
+    {desc, <<"number of couch_file cache misses">>}
+]}.
+{[couchdb, couch_file, cache_hits], [
+    {type, counter},
+    {desc, <<"number of couch_file cache hits">>}
+]}.
+{[couchdb, couch_file, cache_opens], [
+    {type, counter},
+    {desc, <<"number of new couch_file caches opened">>}
+]}.
 {[pread, exceed_eof], [
     {type, counter},
     {desc, <<"number of the attempts to read beyond end of db file">>}
diff --git a/src/couch/src/couch_file.erl b/src/couch/src/couch_file.erl
index a6eeef5..a3856b9 100644
--- a/src/couch/src/couch_file.erl
+++ b/src/couch/src/couch_file.erl
@@ -192,8 +192,10 @@ pread_binary(Fd, Pos) ->
 pread_iolist(Fd, Pos) ->
     case load_from_cache(Fd, Pos) of
         {ok, IoList, Md5} ->
+            couch_stats:increment_counter([couchdb, couch_file, cache_hits]),
             {ok, verify_md5(Fd, Pos, IoList, Md5)};
         missing ->
+            couch_stats:increment_counter([couchdb, couch_file, cache_misses]),
             case ioq:call(Fd, {pread_iolist, Pos}, erlang:get(io_priority)) of
                 {ok, IoList, Md5} ->
                     {ok, verify_md5(Fd, Pos, IoList, Md5)};
@@ -433,6 +435,7 @@ init({Filepath, Options, ReturnPid, Ref}) ->
     ShouldCache = config:get_boolean("couchdb", "couch_file_cache", true),
     Tab = case ShouldCache of
         true ->
+            couch_stats:increment_counter([couchdb, couch_file, cache_opens]),
             ets:new(?MODULE, [set, protected, {read_concurrency, true}]);
         false ->
             undefined

Reply via email to