Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

A driver that uses the riak-java-client via a remote Jinterface node #8

Merged
merged 1 commit into from

2 participants

@russelldb
Owner

A bench driver that calls out to the riak-java-client

@dizzyd

Also, please squash these commits.

@russelldb
Owner

Updated as per comments and squashed to one commit

@russelldb
Owner

Simplified and added documentation to example config .

@russelldb russelldb Add driver for the riak-java-client
Requires that the java bench driver application is installed
and running also. See the README for that application for
details of how to use.

Added the new rebar as using Jinterface to bridge to Java
so basho_bench app must start in distributed mode, new rebar allows
emu_script_args to set -name and -setcookie.
c66d3e4
@russelldb
Owner

Updated copyright dates and fixed IP typo in config example

@dizzyd

+1. Merge at will. :)

@russelldb russelldb merged commit 13abff5 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 23, 2011
  1. @russelldb

    Add driver for the riak-java-client

    russelldb authored
    Requires that the java bench driver application is installed
    and running also. See the README for that application for
    details of how to use.
    
    Added the new rebar as using Jinterface to bridge to Java
    so basho_bench app must start in distributed mode, new rebar allows
    emu_script_args to set -name and -setcookie.
This page is out of date. Refresh to see the latest.
View
2  ebin/basho_bench.app
@@ -14,6 +14,8 @@
basho_bench_driver_bitcask,
basho_bench_driver_hibari,
basho_bench_driver_null,
+ basho_bench_driver_riakc_java,
+ basho_bench_java_client,
basho_bench_log,
basho_bench_keygen,
basho_bench_stats,
View
29 examples/riakc_java.config
@@ -0,0 +1,29 @@
+{test_dir, "java_tests"}.
+
+{mode, max}.
+
+{duration, 1}.
+
+{concurrent, 3}.
+
+{driver, basho_bench_driver_riakc_java}.
+
+{code_paths, ["deps/stats"]}.
+
+{key_generator, {int_to_bin, {uniform_int, 10000}}}.
+
+{value_generator, {fixed_bin, 10000}}.
+
+%% The list of remote Java client nodes you want to bench.
+%% Each entry is a tupple of the format
+%% {node(), inet:ip4_address(), inet:port_number()}
+%% Were host is the Jinterface node and
+%% ip and port form the address of the
+%% Riak PB interface that Java client should call
+
+{riakc_java_nodes, [{'java@127.0.0.1', {127,0,0,1}, 8087}]}.
+
+{riakc_java_replies, 1}.
+
+{operations, [{get, 1}, {update, 1}]}.
+
View
BIN  rebar
Binary file not shown
View
3  rebar.config
@@ -6,3 +6,6 @@
]}.
{escript_incl_apps, [stats, ibrowse, riakc, protobuffs]}.
+
+%% Uncomment to use the Java client bench driver
+%% {escript_emu_args, "%%! -name bb@127.0.0.1 -setcookie YOUR_ERLANG_COOKIE\n"}.
View
142 src/basho_bench_driver_riakc_java.erl
@@ -0,0 +1,142 @@
+%% -------------------------------------------------------------------
+%%
+%% basho_bench_driver_riakc_java: Driver for riak java client
+%%
+%% Copyright (c) 2011 Basho Techonologies
+%%
+%% This file is provided to you 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(basho_bench_driver_riakc_java).
+
+-export([new/1,
+ run/4]).
+
+-include("basho_bench.hrl").
+
+-record(state, { pid,
+ bucket,
+ r,
+ w,
+ dw,
+ rw}).
+
+%% ====================================================================
+%% API
+%% ====================================================================
+
+new(Id) ->
+ Nodes = basho_bench_config:get(riakc_java_nodes, [[{'java@127.0.0.1',{127,0,0,1}, 8087}]]),
+ %% riakc_pb_replies sets defaults for R, W, DW and RW.
+ %% Each can be overridden separately
+ Replies = basho_bench_config:get(riakc_java_replies, 2),
+ R = basho_bench_config:get(riakc_java_r, Replies),
+ W = basho_bench_config:get(riakc_java_w, Replies),
+ DW = basho_bench_config:get(riakc_java_dw, Replies),
+ RW = basho_bench_config:get(riakc_java_rw, Replies),
+ Bucket = basho_bench_config:get(riakc_java_bucket, <<"test">>),
+ PBBuffer = basho_bench_config:get(riakc_java_pbc_buffer, 16),
+
+ %% Choose the node using our ID as a modulus
+ {TargetNode, Ip, Port} = lists:nth((Id rem length(Nodes)+1), Nodes),
+ ?INFO("Using target node ~p for worker ~p\n", [TargetNode, Id]),
+
+ %% Check that we can at least talk to the jinterface riak java client node
+ case net_adm:ping(TargetNode) of
+ pang ->
+ ?FAIL_MSG("~s requires that you run a java client jinterface node.\n",
+ [?MODULE]);
+ _ ->
+ ok
+ end,
+
+ case basho_bench_java_client:new(TargetNode, Ip, Port, PBBuffer) of
+ {ok, Pid} ->
+ {ok, #state { pid = Pid,
+ bucket = Bucket,
+ r = R,
+ w = W,
+ dw = DW,
+ rw = RW
+ }};
+ {error, Reason2} ->
+ ?FAIL_MSG("Failed to connect java jinterface node ~p on ip ~p to ~p port ~p: ~p\n",
+ [TargetNode, Ip, Port, Reason2])
+ end.
+
+run(get, KeyGen, _ValueGen, State) ->
+ Key = KeyGen(),
+ case basho_bench_java_client:get(State#state.pid, State#state.bucket, Key, State#state.r) of
+ {ok, _} ->
+ {ok, State};
+ {error, Reason} ->
+ {error, Reason, State}
+ end;
+run(get_existing, KeyGen, _ValueGen, State) ->
+ Key = KeyGen(),
+ case basho_bench_java_client:get(State#state.pid, State#state.bucket, Key, State#state.r) of
+ {ok, found} ->
+ {ok, State};
+ {ok, notfound} ->
+ {error, {not_found, Key}, State};
+ {error, Reason} ->
+ {error, Reason, State}
+ end;
+run(put, KeyGen, ValueGen, State) ->
+ Key = KeyGen(),
+ Value =ValueGen(),
+ case basho_bench_java_client:put(State#state.pid, State#state.bucket, Key, Value, State#state.w, State#state.dw) of
+ ok ->
+ {ok, State};
+ {error, Reason} ->
+ {error, Reason, State}
+ end;
+run(update, KeyGen, ValueGen, State) ->
+ Key = KeyGen(),
+ Value = ValueGen(),
+ case basho_bench_java_client:create_update(State#state.pid, State#state.bucket,
+ Key, Value, State#state.r, State#state.w, State#state.dw) of
+
+ ok ->
+ {ok, State};
+ {error, Reason} ->
+ {error, Reason, State}
+ end;
+run(update_existing, KeyGen, ValueGen, State) ->
+ Key = KeyGen(),
+ Value = ValueGen(),
+ case basho_bench_java_client:update(State#state.pid, State#state.bucket,
+ Key, Value, State#state.r, State#state.w, State#state.dw) of
+ ok ->
+ {ok, State};
+ {error, notfound} ->
+ {error, {not_found, Key}, State};
+ {error, Reason} ->
+ {error, Reason, State}
+ end;
+run(delete, KeyGen, _ValueGen, State) ->
+ %% Pass on rw
+ case basho_bench_java_client:delete(State#state.pid, State#state.bucket, KeyGen(), State#state.rw) of
+ ok ->
+ {ok, State};
+ {error, Reason} ->
+ {error, Reason, State}
+ end.
+
+
+%% ====================================================================
+%% Internal functions
+%% ====================================================================
+
View
81 src/basho_bench_java_client.erl
@@ -0,0 +1,81 @@
+%% -------------------------------------------------------------------
+%%
+%% basho_bench_java_client: Local API to remote Java client
+%%
+%% Copyright (c) 2011 Basho Techonologies
+%%
+%% This file is provided to you 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(basho_bench_java_client).
+
+-export([new/4, get/4, put/6, create_update/7, update/7, delete/4]).
+
+%%% Ask the java node to create a new process, and link to it
+new(Node, Ip, Port, PBBuffer) ->
+ erlang:send({factory, Node}, {self(), {Ip, Port, PBBuffer}}),
+
+ receive
+ Pid when is_pid(Pid) ->
+ ok
+ end,
+ link(Pid),
+ {ok, Pid}.
+
+get(Pid, Bucket, Key, R) ->
+ Pid ! {self(), {get, [{bucket, Bucket}, {key, Key}, {r, R}]}},
+ receive
+ {Pid, Res} ->
+ ok
+ end,
+ Res.
+
+put(Pid, Bucket, Key, Value, W, DW) ->
+ Pid ! {self(), {put, [{bucket, Bucket}, {key, Key}, {value, Value}, {w, W}, {dw, DW}]}},
+
+ receive
+ {Pid, Res} ->
+ ok
+ end,
+ Res.
+
+create_update(Pid, Bucket, Key, Value, R, W, DW) ->
+ Pid ! {self(), {create_update, [{bucket, Bucket}, {key, Key}, {value, Value},
+ {r, R}, {w, W}, {dw, DW}]}},
+
+ receive
+ {Pid, Res} ->
+ ok
+ end,
+ Res.
+
+update(Pid, Bucket, Key, Value, R, W, DW) ->
+ Pid ! {self(), {update, [{bucket, Bucket}, {key, Key}, {value, Value},
+ {r, R}, {w, W}, {dw, DW}]}},
+
+ receive
+ {Pid, Res} ->
+ ok
+ end,
+ Res.
+
+delete(Pid, Bucket, Key, RW) ->
+ Pid ! {self(), {delete, [{bucket, Bucket}, {key, Key}, {r, RW}]}}, %%HACK to reuse GetArgs on java side, change
+ receive
+ {Pid, Res} ->
+ ok
+ end,
+ Res.
+
Something went wrong with that request. Please try again.