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 2020/08/05 20:04:49 UTC

[couchdb] branch prototype/fdb-layer-ebtree-speedy-tests created (now 47f63fe)

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

rnewson pushed a change to branch prototype/fdb-layer-ebtree-speedy-tests
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at 47f63fe  Speed up ebtree test suite without losing coverage

This branch includes the following new commits:

     new 47f63fe  Speed up ebtree test suite without losing coverage

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: Speed up ebtree test suite without losing coverage

Posted by rn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch prototype/fdb-layer-ebtree-speedy-tests
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 47f63fe753b41ba86dd96ac52f03620d630a01a8
Author: Robert Newson <rn...@apache.org>
AuthorDate: Wed Aug 5 21:04:22 2020 +0100

    Speed up ebtree test suite without losing coverage
---
 src/ebtree/src/ebtree.erl | 59 +++++++++++++++--------------------------------
 1 file changed, 18 insertions(+), 41 deletions(-)

diff --git a/src/ebtree/src/ebtree.erl b/src/ebtree/src/ebtree.erl
index c28693d..4648744 100644
--- a/src/ebtree/src/ebtree.erl
+++ b/src/ebtree/src/ebtree.erl
@@ -1103,7 +1103,7 @@ collate_validation_test() ->
 lookup_test() ->
     Db = erlfdb_util:get_test_db([empty]),
     Tree = open(Db, <<1,2,3>>, 4),
-    Keys = [X || {_, X} <- lists:sort([ {rand:uniform(), N} || N <- lists:seq(1, 100)])],
+    Keys = [X || {_, X} <- lists:sort([ {rand:uniform(), N} || N <- lists:seq(1, 16)])],
     lists:foreach(fun(Key) -> insert(Db, Tree, Key, Key + 1) end, Keys),
     lists:foreach(fun(Key) -> ?assertEqual({Key, Key + 1}, lookup(Db, Tree, Key)) end, Keys),
     ?assertEqual(false, lookup(Db, Tree, 101)).
@@ -1112,7 +1112,7 @@ lookup_test() ->
 delete_test() ->
     Db = erlfdb_util:get_test_db([empty]),
     Tree = open(Db, <<1,2,3>>, 4),
-    Keys = [X || {_, X} <- lists:sort([ {rand:uniform(), N} || N <- lists:seq(1, 100)])],
+    Keys = [X || {_, X} <- lists:sort([ {rand:uniform(), N} || N <- lists:seq(1, 16)])],
     lists:foreach(fun(Key) -> insert(Db, Tree, Key, Key + 1) end, Keys),
     lists:foreach(fun(Key) -> ?assertEqual({Key, Key + 1}, lookup(Db, Tree, Key)) end, Keys),
     lists:foreach(fun(Key) -> delete(Db, Tree, Key) end, Keys),
@@ -1122,12 +1122,12 @@ delete_test() ->
 range_after_delete_test() ->
     Db = erlfdb_util:get_test_db([empty]),
     Tree = open(Db, <<1,2,3>>, 4),
-    Keys = [X || {_, X} <- lists:sort([ {rand:uniform(), N} || N <- lists:seq(1, 100)])],
+    Keys = [X || {_, X} <- lists:sort([ {rand:uniform(), N} || N <- lists:seq(1, 16)])],
     lists:foreach(fun(Key) -> insert(Db, Tree, Key, Key + 1) end, Keys),
     lists:foreach(fun(Key) -> ?assertEqual({Key, Key + 1}, lookup(Db, Tree, Key)) end, Keys),
-    lists:foreach(fun(Key) -> delete(Db, Tree, Key) end, lists:seq(1, 100, 2)),
-    ?assertEqual(50, range(Db, Tree, 1, 100, fun(E, A) -> length(E) + A end, 0)),
-    ?assertEqual(50, reverse_range(Db, Tree, 1, 100, fun(E, A) -> length(E) + A end, 0)).
+    lists:foreach(fun(Key) -> delete(Db, Tree, Key) end, lists:seq(1, 16, 2)),
+    ?assertEqual(8, range(Db, Tree, 1, 16, fun(E, A) -> length(E) + A end, 0)),
+    ?assertEqual(8, reverse_range(Db, Tree, 1, 16, fun(E, A) -> length(E) + A end, 0)).
 
 
 full_reduce_test_() ->
@@ -1147,7 +1147,7 @@ full_reduce_test_() ->
 full_reduce_after_delete_test() ->
     Db = erlfdb_util:get_test_db([empty]),
     Tree = open(Db, <<1,2,3>>, 4, [{reduce_fun, fun reduce_sum/2}]),
-    Max = 100,
+    Max = 16,
     Keys = [X || {_, X} <- lists:sort([ {rand:uniform(), N} || N <- lists:seq(1, Max)])],
     lists:foreach(fun(Key) -> insert(Db, Tree, Key, Key) end, Keys),
     ?assertEqual(round(Max * ((1 + Max) / 2)), full_reduce(Db, Tree)),
@@ -1271,30 +1271,10 @@ custom_collation_test() ->
     ?assertEqual([{2, 2}, {1, 1}], range(Db, Tree, 3, 0, fun(E, A) -> A ++ E end, [])).
 
 
-intense_lookup_test_() ->
-    [
-        {timeout, 1000, fun() -> lookup_test_fun(1000, 20) end},
-        {timeout, 1000, fun() -> lookup_test_fun(1000, 50) end},
-        {timeout, 1000, fun() -> lookup_test_fun(1000, 500) end}
-    ].
-
-
-lookup_test_fun(Max, Order) ->
-    Db = erlfdb_util:get_test_db([empty]),
-    Keys = [X || {_, X} <- lists:sort([ {rand:uniform(), N} || N <- lists:seq(1, Max, 2)])],
-    T0 = erlang:monotonic_time(),
-    Tree = lists:foldl(fun(Key, T) -> insert(Db, T, Key, Key + 1) end, open(Db, <<1,2,3>>, Order), Keys),
-    T1 = erlang:monotonic_time(),
-    lists:foreach(fun(Key) -> ?assertEqual({Key, Key + 1}, lookup(Db, Tree, Key)) end, Keys),
-    T2 = erlang:monotonic_time(),
-    ?debugFmt("~B order. ~B iterations. insert rate: ~.2f/s, lookup rate: ~.2f/s",
-        [Order, Max, 1000 * (Max / msec(T1 - T0)), 1000 * (Max / msec(T2 - T1))]).
-
-
 range_test_() ->
     {timeout, 1000, fun() ->
         Db = erlfdb_util:get_test_db([empty]),
-        Max = 1000,
+        Max = 100,
         Keys = [X || {_, X} <- lists:sort([ {rand:uniform(), N} || N <- lists:seq(1, Max)])],
         Tree = lists:foldl(fun(Key, T) -> insert(Db, T, Key, Key + 1) end, open(Db, <<1,2,3>>, 10), Keys),
         lists:foreach(
@@ -1303,33 +1283,33 @@ range_test_() ->
                 ?assertEqual([{K, K + 1} || K <- lists:seq(StartKey, EndKey)],
                     range(Db, Tree, StartKey, EndKey, fun(E, A) -> A ++ E end, [])
                 ) end,
-        lists:seq(1, 1000))
+        lists:seq(1, 100))
     end}.
 
 
 reverse_range_test_() ->
     {timeout, 1000, fun() ->
         Db = erlfdb_util:get_test_db([empty]),
-        Max = 1000,
+        Max = 100,
         Keys = [X || {_, X} <- lists:sort([ {rand:uniform(), N} || N <- lists:seq(1, Max)])],
-        Tree = lists:foldl(fun(Key, T) -> insert(Db, T, Key, Key + 1) end, open(Db, <<1,2,3>>, 10), Keys),
+        Tree = lists:foldl(fun(Key, T) -> insert(Db, T, Key, Key + 1) end, open(Db, <<1,2,3>>, 8), Keys),
         lists:foreach(
             fun(_) ->
                 [StartKey, EndKey] = lists:sort([rand:uniform(Max), rand:uniform(Max)]),
                 ?assertEqual([{K, K + 1} || K <- lists:seq(EndKey, StartKey, -1)],
                     reverse_range(Db, Tree, StartKey, EndKey, fun(E, A) -> A ++ E end, [])
                 ) end,
-        lists:seq(1, 1000))
+        lists:seq(1, 100))
     end}.
 
 
 custom_collation_range_test_() ->
     {timeout, 1000, fun() ->
         Db = erlfdb_util:get_test_db([empty]),
-        Max = 1000,
+        Max = 100,
         Keys = [X || {_, X} <- lists:sort([ {rand:uniform(), N} || N <- lists:seq(1, Max)])],
         CollateFun = fun(A, B) -> collate_raw(B, A) end,
-        Tree = open(Db, <<1,2,3>>, 10, [{collate_fun, CollateFun}]),
+        Tree = open(Db, <<1,2,3>>, 6, [{collate_fun, CollateFun}]),
         lists:foldl(fun(Key, T) -> insert(Db, T, Key, Key + 1) end, Tree, Keys),
         lists:foreach(
             fun(_) ->
@@ -1343,17 +1323,17 @@ custom_collation_range_test_() ->
                 ?assertEqual([{K, K + 1} || K <- Seq],
                     range(Db, Tree, StartKey, EndKey, fun(E, A) -> A ++ E end, [])
                 ) end,
-        lists:seq(1, 1000))
+        lists:seq(1, 100))
     end}.
 
 
 custom_collation_reverse_range_test_() ->
     {timeout, 1000, fun() ->
         Db = erlfdb_util:get_test_db([empty]),
-        Max = 1000,
+        Max = 100,
         Keys = [X || {_, X} <- lists:sort([ {rand:uniform(), N} || N <- lists:seq(1, Max)])],
         CollateFun = fun(A, B) -> collate_raw(B, A) end,
-        Tree = open(Db, <<1,2,3>>, 10, [{collate_fun, CollateFun}]),
+        Tree = open(Db, <<1,2,3>>, 6, [{collate_fun, CollateFun}]),
         lists:foldl(fun(Key, T) -> insert(Db, T, Key, Key + 1) end, Tree, Keys),
         lists:foreach(
             fun(_) ->
@@ -1367,11 +1347,8 @@ custom_collation_reverse_range_test_() ->
                 ?assertEqual([{K, K + 1} || K <- lists:reverse(Seq)],
                     reverse_range(Db, Tree, StartKey, EndKey, fun(E, A) -> A ++ E end, [])
                 ) end,
-        lists:seq(1, 1000))
+        lists:seq(1, 100))
     end}.
 
 
-msec(Native) ->
-    erlang:max(1, erlang:convert_time_unit(Native, native, millisecond)).
-
 -endif.