Permalink
Browse files

Add support for testing java client clusters.

  • Loading branch information...
1 parent cf9ec73 commit c5388764caf43afa3b1ea7d19cb180c2bab8d969 @kellymclaughlin kellymclaughlin committed Aug 3, 2011
Showing with 44 additions and 17 deletions.
  1. +15 −6 examples/riakc_java.config
  2. +1 −1 rebar.config
  3. +16 −9 src/basho_bench_driver_riakc_java.erl
  4. +12 −1 src/basho_bench_java_client.erl
View
@@ -12,14 +12,23 @@
{value_generator, {fixed_bin, 10000}}.
+%% The options for transport are pb, http,
+%% pbcluster, or httpcluster
+{riakc_java_transport, pbcluster}.
+
%% 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 interface that Java client should call
-
-{riakc_java_nodes, [{'java@127.0.0.1', {127,0,0,1}, 8087}]}.
+%% {node(), [{inet:ip4_address(), inet:port_number()}]}
+%% Where host is the Jinterface node and
+%% each ip and port tuple form the address of the
+%% Riak interface that Java client could call.
+%% If the transport type is pb or http, the basho_bench
+%% driver will select one of the provided {ip, port}
+%% tuples to communicate with. If the transport type is
+%% pbcluster or httpcluster then the provided {ip, port}
+%% tuples will be used to form a java client cluster.
+
+{riakc_java_nodes, {'java@127.0.0.1', [{{192,168,1,101}, 8087}]}}.
@russelldb

russelldb Aug 4, 2011

Contributor

Can we still provide a list of Java mailbox host nodes (Jinterface nodes) to run against?

@kellymclaughlin

kellymclaughlin Aug 5, 2011

Contributor

Yeah, so use a list of mailbox host nodes that can each have a list of cluster clients? I think that's good.

%% The transport you want the java client to use
%% ether pb (for protocol buffers) or http.
View
@@ -8,4 +8,4 @@
{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"}.
+{escript_emu_args, "%%! -name bb@127.0.0.1 -setcookie MYCOOKIE\n"}.
@russelldb

russelldb Aug 4, 2011

Contributor

Should this should still be commented out by default?

@kellymclaughlin

kellymclaughlin Aug 5, 2011

Contributor

Yes indeed.

@@ -38,8 +38,8 @@
%% ====================================================================
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.
+ {TargetNode, ClientNodes} = basho_bench_config:get(riakc_java_nodes, {'java@127.0.0.1', [{{127,0,0,1}, 8087}]}),
+ %% riakc_java_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),
@@ -50,8 +50,6 @@ new(Id) ->
Transport = basho_bench_config:get(riakc_java_transport, pb),
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
@@ -62,8 +60,18 @@ new(Id) ->
_ ->
ok
end,
-
- case basho_bench_java_client:new(TargetNode, Ip, Port, PBBuffer, Transport) of
+ if Transport =:= pbcluster orelse Transport =:= httpcluster ->
+ Result = basho_bench_java_client:new(TargetNode, ClientNodes, PBBuffer, Transport),
+ FailureMsg = "Failed to connect java jinterface node ~p to cluster nodes ~p: ~p\n",
+ FailureArgs = [TargetNode, ClientNodes];
+ true ->
+ %% Choose the node using our ID as a modulus
+ {Ip, Port} = lists:nth((Id rem length(ClientNodes)+1), ClientNodes),
+ Result = basho_bench_java_client:new(TargetNode, Ip, Port, PBBuffer, Transport),
+ FailureMsg = "Failed to connect java jinterface node ~p on ip ~p to ~p port ~p: ~p\n",
+ FailureArgs = [TargetNode, Ip, Port]
+ end,
+ case Result of
{ok, Pid} ->
{ok, #state { pid = Pid,
bucket = Bucket,
@@ -72,9 +80,8 @@ new(Id) ->
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])
+ {error, Reason} ->
+ ?FAIL_MSG(FailureMsg, FailureArgs ++ Reason)
end.
run(get, KeyGen, _ValueGen, State) ->
@@ -21,7 +21,7 @@
%% -------------------------------------------------------------------
-module(basho_bench_java_client).
--export([new/5, get/4, put/6, create_update/7, update/7, delete/4]).
+-export([new/4, new/5, 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, Transport) ->
@@ -34,6 +34,17 @@ new(Node, Ip, Port, PBBuffer, Transport) ->
link(Pid),
{ok, Pid}.
+%%% Ask the java node to create a new process, and link to it
+new(Node, ClientNodes, PBBuffer, Transport) ->
+ erlang:send({factory, Node}, {self(), {ClientNodes, PBBuffer, Transport}}),
+
+ 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

0 comments on commit c538876

Please sign in to comment.