Skip to content

Commit 474ead5

Browse files
committed
Merge branch 'rdb-counters'
Conflicts: src/basho_bench_driver_2i.erl
2 parents 191c407 + 9bbfdf0 commit 474ead5

4 files changed

Lines changed: 70 additions & 5 deletions

File tree

examples/counters.config

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{mode, max}.
2+
3+
{duration, 5}.
4+
5+
{concurrent, 1}.
6+
7+
{driver, basho_bench_driver_riakc_pb}.
8+
9+
{key_generator, {int_to_bin, {uniform_int, 10000}}}.
10+
11+
{value_generator, {uniform_int, 50}}.
12+
13+
{riakc_pb_ips, [{127,0,0,1}]}.
14+
15+
{riakc_pb_replies, 2}.
16+
17+
{operations, [{counter_incr, 100}, {counter_val, 1}]}.
18+
19+
%% Use {auto_reconnect, false} to get "old" behavior (prior to April 2013).
20+
%% See deps/riakc/src/riakc_pb_socket.erl for all valid socket options.
21+
{pb_connect_options, [{auto_reconnect, true}]}.
22+
23+
%% Overrides for the PB client's default 60 second timeout, on a
24+
%% per-type-of-operation basis. All timeout units are specified in
25+
%% milliseconds. The pb_timeout_general config item provides a
26+
%% default timeout if the read/write/listkeys/mapreduce timeout is not
27+
%% specified.
28+
29+
{pb_timeout_general, 30000}.
30+
{pb_timeout_read, 5000}.
31+
{pb_timeout_write, 5000}.
32+
{pb_timeout_listkeys, 50000}.
33+
%% The general timeout will be used because this specific item is commented:
34+
%% {pb_timeout_mapreduce, 50000}.

src/basho_bench_driver_2i.erl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,6 @@ to_list(B) when is_binary(B) ->
359359
to_list(I) when is_integer(I) ->
360360
integer_to_list(I).
361361

362-
choose(N, L) ->
363-
lists:nth((N rem length(L) + 1), L).
364-
365362
json_get(Url, State) ->
366363
Response = ibrowse:send_req(lists:flatten(Url), [], get,
367364
[], [], State#state.pb_timeout),

src/basho_bench_driver_riakc_pb.erl

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
-record(state, { pid,
3232
bucket,
3333
r,
34+
pr,
3435
w,
3536
dw,
37+
pw,
3638
rw,
3739
keylist_length,
3840
preloaded_keys,
@@ -75,6 +77,8 @@ new(Id) ->
7577
W = basho_bench_config:get(riakc_pb_w, Replies),
7678
DW = basho_bench_config:get(riakc_pb_dw, Replies),
7779
RW = basho_bench_config:get(riakc_pb_rw, Replies),
80+
PW = basho_bench_config:get(riakc_pb_pw, Replies),
81+
PR = basho_bench_config:get(riakc_pb_pr, Replies),
7882
Bucket = basho_bench_config:get(riakc_pb_bucket, <<"test">>),
7983
KeylistLength = basho_bench_config:get(riakc_pb_keylist_length, 1000),
8084
PreloadedKeys = basho_bench_config:get(
@@ -90,9 +94,11 @@ new(Id) ->
9094
{ok, #state { pid = Pid,
9195
bucket = Bucket,
9296
r = R,
97+
pr = PR,
9398
w = W,
9499
dw = DW,
95100
rw = RW,
101+
pw = PW,
96102
keylist_length = KeylistLength,
97103
preloaded_keys = PreloadedKeys,
98104
timeout_general = get_timeout_general(),
@@ -234,8 +240,32 @@ run(mr_keylist_erlang, KeyGen, _ValueGen, State) ->
234240
mapred(State, Keylist, ?ERLANG_MR);
235241
run(mr_keylist_js, KeyGen, _ValueGen, State) ->
236242
Keylist = make_keylist(State#state.bucket, KeyGen,
237-
State#state.keylist_length),
238-
mapred(State, Keylist, ?JS_MR).
243+
State#state.keylist_length),
244+
mapred(State, Keylist, ?JS_MR);
245+
run(counter_incr, KeyGen, ValueGen, State) ->
246+
Amt = ValueGen(),
247+
Key = KeyGen(),
248+
case riakc_pb_socket:counter_incr(State#state.pid, State#state.bucket, Key, Amt,
249+
[{w, State#state.w},
250+
{dw, State#state.dw},
251+
{pw, State#state.pw}]) of
252+
ok ->
253+
{ok, State};
254+
{error, Reason} ->
255+
{error, Reason, State}
256+
end;
257+
run(counter_val, KeyGen, _ValueGen, State) ->
258+
Key = KeyGen(),
259+
case riakc_pb_socket:counter_val(State#state.pid, State#state.bucket, Key,
260+
[{r, State#state.r}, {pr, State#state.pr}]) of
261+
{ok, _N} ->
262+
{ok, State};
263+
{error, notfound} ->
264+
{ok, State};
265+
{error, Reason} ->
266+
{error, Reason, State}
267+
end.
268+
239269

240270
%% ====================================================================
241271
%% Internal functions

src/basho_bench_valgen.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ new({function, Module, Function, Args}, Id) ->
5252
_Error ->
5353
?FAIL_MSG("Could not find valgen function: ~p:~p\n", [Module, Function])
5454
end;
55+
new({uniform_int, MaxVal}, _Id) ->
56+
fun() -> random:uniform(MaxVal) end;
57+
new({uniform_int, MinVal, MaxVal}, _Id) ->
58+
fun() -> random:uniform(MinVal, MaxVal) end;
5559
new(Other, _Id) ->
5660
?FAIL_MSG("Unsupported value generator requested: ~p\n", [Other]).
5761

0 commit comments

Comments
 (0)