From e09e2b2aa2c72b021311787afbff37f206dde012 Mon Sep 17 00:00:00 2001 From: Kresten Krab Thorup Date: Thu, 5 Jan 2012 22:28:39 +0800 Subject: [PATCH] Add basho_bench script/driver --- rebar.config | 3 +- src/basho_bench_driver_fractal_btree.erl | 75 ++++++++++++++++++++++++ src/fractal_btree_bbench.config | 26 ++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 src/basho_bench_driver_fractal_btree.erl create mode 100644 src/fractal_btree_bbench.config diff --git a/rebar.config b/rebar.config index 5ff7129..4936f36 100644 --- a/rebar.config +++ b/rebar.config @@ -3,5 +3,6 @@ {deps, [ {plain_fsm, "1.1.*", {git, "git://github.com/uwiger/plain_fsm", {branch, "master"}}}, - {ebloom, "1.0.*", {git, "git://github.com/basho/ebloom.git", {branch, "master"}}} + {ebloom, "1.0.*", {git, "git://github.com/basho/ebloom.git", {branch, "master"}}}, + {basho_bench, ".*", {git, "git://github.com/basho/basho_bench.git", {branch, "master"}}} ]}. diff --git a/src/basho_bench_driver_fractal_btree.erl b/src/basho_bench_driver_fractal_btree.erl new file mode 100644 index 0000000..34db63c --- /dev/null +++ b/src/basho_bench_driver_fractal_btree.erl @@ -0,0 +1,75 @@ +-module(basho_bench_driver_fractal_btree). + +-record(state, { tree, + filename, + flags, + sync_interval, + last_sync }). + +-export([new/1, + run/4]). + +-include_lib("basho_bench/include/basho_bench.hrl"). + + +%% ==================================================================== +%% API +%% ==================================================================== + +new(_Id) -> + %% Make sure bitcask is available + case code:which(fractal_btree) of + non_existing -> + ?FAIL_MSG("~s requires fractal_btree to be available on code path.\n", + [?MODULE]); + _ -> + ok + end, + + %% Get the target directory + Dir = basho_bench_config:get(fractal_btree_dir, "."), + Filename = filename:join(Dir, "test.frac"), + + %% Look for sync interval config + case basho_bench_config:get(fractal_btree_sync_interval, infinity) of + Value when is_integer(Value) -> + SyncInterval = Value; + infinity -> + SyncInterval = infinity + end, + + %% Get any bitcask flags + case fractal_btree:open(Filename) of + {error, Reason} -> + ?FAIL_MSG("Failed to open fractal btree in ~s: ~p\n", [Filename, Reason]); + {ok, FBTree} -> + {ok, #state { tree = FBTree, + filename = Filename, + sync_interval = SyncInterval, + last_sync = os:timestamp() }} + end. + +run(get, KeyGen, _ValueGen, State) -> + case fractal_btree:lookup(State#state.tree, KeyGen()) of + {ok, _Value} -> + {ok, State}; + notfound -> + {ok, State}; + {error, Reason} -> + {error, Reason} + end; +run(put, KeyGen, ValueGen, State) -> + case fractal_btree:put(State#state.tree, KeyGen(), ValueGen()) of + ok -> + {ok, State}; + {error, Reason} -> + {error, Reason} + end; +run(delete, KeyGen, _ValueGen, State) -> + case fractal_btree:delete(State#state.tree, KeyGen()) of + ok -> + {ok, State}; + {error, Reason} -> + {error, Reason} + end. + diff --git a/src/fractal_btree_bbench.config b/src/fractal_btree_bbench.config new file mode 100644 index 0000000..3399ee8 --- /dev/null +++ b/src/fractal_btree_bbench.config @@ -0,0 +1,26 @@ + +{mode, max}. + +{duration, 1}. + +{concurrent, 1}. + +{driver, basho_bench_driver_fractal_btree}. + +{key_generator, {int_to_bin,{uniform_int, 5000000}}}. + +{value_generator, {fixed_bin, 10000}}. + +{operations, [{get, 1}, {put, 1}]}. + +%% the second element in the list below (e.g., "../../public/bitcask") must point to +%% the relevant directory of a fractal_btree installation +{code_paths, ["deps/stats", + "/Users/krab/Projects/fractal_btree/ebin", + "/Users/krab/Projects/fractal_btree/deps/plain_fsm/ebin", + "/Users/krab/Projects/fractal_btree/deps/ebloom/ebin" + ]}. + +{bitcask_dir, "/tmp/fractal_btree.bench"}. + +{bitcask_flags, [o_sync]}.