You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by "jaydoane (via GitHub)" <gi...@apache.org> on 2023/05/13 20:24:24 UTC

[GitHub] [couchdb] jaydoane commented on a diff in pull request #4601: Add a simple fabric benchmark

jaydoane commented on code in PR #4601:
URL: https://github.com/apache/couchdb/pull/4601#discussion_r1193029754


##########
src/fabric/src/fabric_bench.erl:
##########
@@ -0,0 +1,371 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(fabric_bench).
+
+-export([
+    opts/0,
+    go/0,
+    go/1,
+    doc/2,
+    body/1,
+    delete_old_dbs/0
+]).
+
+-define(VERSION, "1").
+-define(PREFIX, "fabricbenchdb-").
+-define(MAX_DB_AGE_USEC, (60 * 60 * 8 * 1000000)).
+
+opts() ->
+    #{
+        q => default,
+        n => default,
+        % Doc size type: small, medium or large
+        doc_size => medium,
+        % How many total docs to insert using _bulk_docs. These are the
+        % docs used for reads and streaming bechmarks
+        docs => 100000,
+        % Batch size used for _bulk_docs insertion
+        batch_size => 1000,
+        % How many individual doc updates to do
+        individual_docs => 1000
+    }.
+
+go() ->
+    go(#{}).
+
+go(#{} = Opts) ->
+    #{q := Q, n := N} = maps:merge(opts(), Opts),
+    QN = [{q, Q}, {n, N}],
+    DbOpts = [{K, V} || {K, V} <- QN, V =/= default],
+    ok = delete_old_dbs(),
+    Db = db_name(),
+    ok = fabric:create_db(Db, DbOpts),
+    Shards = disable_compaction(Db),
+    try
+        go(Db, Opts)
+    after
+        ok = fabric:delete_db(Db),
+        clear_compaction_settings(Shards)
+    end.
+
+go(Db, #{} = Opts0) when is_binary(Db) ->
+    Opts = maps:merge(opts(), Opts0),
+    #{
+        doc_size := DocSize,
+        docs := BulkDocs,
+        batch_size := BatchSize,
+        individual_docs := IndividualDocs
+    } = Opts,
+
+    log_opts(Opts),
+    log_environment_info(Db),
+
+    io:format("~n *** Inserting ~B docs~n", [BulkDocs]),
+    {T1, {Ok, Accepted}} = run(fun() -> bulk_docs(Db, DocSize, BatchSize, BulkDocs, {0, 0}) end),
+    log("Add ~p docs, ok:~p/accepted:~p", [BulkDocs, Ok, Accepted], T1, BulkDocs),
+
+    % Avoid a lagging internal replicator skewing test results, so wait
+    % for the backlog to clear.
+    wait_for_internal_replicator(),
+
+    {ok, N} = fabric:get_doc_count(Db),
+    case N =/= BulkDocs of
+        true -> throw({unexpected_doc_count, N, BulkDocs});
+        false -> ok
+    end,
+
+    {T2, _} = run(fun() ->
+        rand:seed(default, 0),
+        get_docs(Db, N, N)
+    end),
+    log("Get random doc ~pX", [N], T2, N),
+
+    {T3, N} = run(fun() -> get_all_docs(Db, []) end),
+    log("All docs", [], T3, N),
+
+    {T4, N} = run(fun() -> get_all_docs(Db, [{include_docs, true}]) end),
+    log("All docs w/ include_docs", [], T4, N),
+
+    {T5, N} = run(fun() -> get_changes(Db, []) end),

Review Comment:
   Seeing "Bound variable in pattern: N" from emacs.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org