Skip to content

Commit 1a4ea77

Browse files
committed
Add initial sketch of src/basho_bench_driver_kv_backend.erl
1 parent 8bd7027 commit 1a4ea77

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

Diff for: examples/kv_backend.config

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{mode, max}.
2+
3+
{duration, 5}.
4+
{report_interval, 1}.
5+
6+
{concurrent, 16}.
7+
8+
{driver, basho_bench_driver_kv_backend}.
9+
{code_paths, [
10+
"/Users/fritchie/b/src/riak_kv/ebin",
11+
"/Users/fritchie/b/src/riak_core/ebin"
12+
]}.
13+
14+
{key_generator, {int_to_bin, {uniform_int, 5000}}}.
15+
{disable_sequential_int_progress_report, true}.
16+
{value_generator, {fixed_bin, 102480}}.
17+
18+
%{be_disable_uses_r_object, true}.
19+
%{be_backend_mod, riak_kv_yessir_backend}.
20+
%{be_config, [
21+
% {yessir_aae_mode_encoding, constant_binary},
22+
% {yessir_default_size, 102480} % coordinate with value_generator!
23+
% ]}.
24+
25+
{be_backend_mod, riak_kv_memory_backend}.
26+
{be_config, [ ]}.
27+
28+
%% Our ops: 75% of 'absolutely_nothing'
29+
%% 15% of 'do_something'
30+
%% 10% of 'do_something_else'
31+
%{operations, [{get, 15}, {put, 15}]}.
32+
{operations, [{put, 15}]}.

Diff for: src/basho_bench_driver_kv_backend.erl

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
%% -------------------------------------------------------------------
2+
%%
3+
%% basho_bench: Benchmarking Suite
4+
%%
5+
%% Copyright (c) 2009-2010 Basho Techonologies
6+
%%
7+
%% This file is provided to you under the Apache License,
8+
%% Version 2.0 (the "License"); you may not use this file
9+
%% except in compliance with the License. You may obtain
10+
%% a copy of the License at
11+
%%
12+
%% http://www.apache.org/licenses/LICENSE-2.0
13+
%%
14+
%% Unless required by applicable law or agreed to in writing,
15+
%% software distributed under the License is distributed on an
16+
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
%% KIND, either express or implied. See the License for the
18+
%% specific language governing permissions and limitations
19+
%% under the License.
20+
%%
21+
%% -------------------------------------------------------------------
22+
-module(basho_bench_driver_kv_backend).
23+
24+
-export([new/1,
25+
run/4]).
26+
27+
-include("basho_bench.hrl").
28+
29+
-record(state, {
30+
backend :: atom(),
31+
bucket :: binary(),
32+
uses_r_object :: boolean(),
33+
be_state :: term()
34+
}).
35+
36+
%% ====================================================================
37+
%% API
38+
%% ====================================================================
39+
40+
%% @doc new
41+
%%
42+
%% Config items:
43+
%% - be_backend_mod :: atom()
44+
%% - be_disable_uses_r_object :: boolean()
45+
%% - be_config :: proplist(), passed to start/2
46+
47+
new(_Id) ->
48+
Backend = basho_bench_config:get(be_backend_mod, riak_kv_yessir_backend),
49+
io:format("DBG ~p\n", [Backend]),
50+
Bucket = <<"Oh, shouldn't matter much">>,
51+
{ok, Caps} = Backend:capabilities(x),
52+
UsesRObj = proplists:get_value(uses_r_object, Caps, false),
53+
RObjDisabled = basho_bench_config:get(be_disable_uses_r_object, false),
54+
Use = UsesRObj andalso not RObjDisabled,
55+
{ok, BE} = Backend:start(0, basho_bench_config:get(be_config, [])),
56+
57+
{ok, #state{backend=Backend, bucket=Bucket, uses_r_object=Use,
58+
be_state=BE}}.
59+
60+
run(get, KeyGen, _ValueGen,
61+
#state{backend=Backend, bucket=Bucket, uses_r_object=RObjP,
62+
be_state=BE} = State) ->
63+
Key = KeyGen(),
64+
if RObjP ->
65+
{_ok_err, _, NewBE} = Backend:get_object(Bucket, Key, false, BE),
66+
{ok, State#state{be_state = NewBE}};
67+
true ->
68+
{_ok_err, _, NewBE} = Backend:get(Bucket, Key, BE),
69+
{ok, State#state{be_state = NewBE}}
70+
end;
71+
run(put, KeyGen, ValueGen,
72+
#state{backend=Backend, bucket=Bucket, be_state=BE} = State) ->
73+
Key = KeyGen(),
74+
Val = ValueGen(),
75+
{ok, NewBE} = Backend:put(Bucket, Key, [], Val, BE),
76+
{ok, State#state{be_state = NewBE}};
77+
run(do_something_else, KeyGen, ValueGen, State) ->
78+
_Key = KeyGen(),
79+
ValueGen(),
80+
{ok, State};
81+
run(an_error, KeyGen, _ValueGen, State) ->
82+
_Key = KeyGen(),
83+
{error, went_wrong, State};
84+
run(another_error, KeyGen, _ValueGen, State) ->
85+
_Key = KeyGen(),
86+
{error, {bad, things, happened}, State}.
87+

0 commit comments

Comments
 (0)