Commit 0b1c3a8f authored by neverlord's avatar neverlord

distributed benchmark

parent 0c3537cb
......@@ -76,23 +76,23 @@ inline option<int> _2i(std::string const& str)
void usage()
{
cout << "Running in server mode:" << endl
<< " --mode=server " << endl
<< " mode=server " << endl
<< " --port=NUM publishes an actor at port NUM" << endl
<< " -p NUM alias for --port=NUM" << endl
<< endl
<< endl
<< "Running the benchmark:" << endl
<< " --mode=benchmark run the benchmark, connect to any number"<< endl
<< " mode=benchmark run the benchmark, connect to any number"<< endl
<< " of given servers, use HOST:PORT syntax" << endl
<< " --num_pings=NUM run benchmark with NUM messages per node"<< endl
<< " num_pings=NUM run benchmark with NUM messages per node"<< endl
<< endl
<< " example: --mode=benchmark 192.168.9.1:1234 "
<< " example: mode=benchmark 192.168.9.1:1234 "
"192.168.9.2:1234 "
"--num_pings=100" << endl
<< endl
<< endl
<< "Shutdown servers:" << endl
<< " --mode=shutdown shuts down any number of given servers" << endl
<< " mode=shutdown shuts down any number of given servers" << endl
<< endl
<< endl
<< "Miscellaneous:" << endl
......@@ -467,16 +467,16 @@ int main(int argc, char** argv)
{
usage();
},
on("--mode=server") >> [=]()
on("mode=server") >> [=]()
{
server_mode(first + 1, last);
},
on("--mode=benchmark") >> [=]()
on("mode=benchmark") >> [=]()
{
client_mode(first + 1, last);
await_all_others_done();
},
on("--mode=shutdown") >> [=]()
on("mode=shutdown") >> [=]()
{
shutdown_mode(first + 1, last);
},
......
......@@ -5,7 +5,7 @@ ping_loop(Parent, Pong) ->
receive
{pong, 0} -> Parent ! done;
{pong, X} ->
Pong ! {self(), ping, X - 1},
Pong ! {ping, self(), X - 1},
ping_loop(Parent, Pong);
{kickoff, Value} ->
Pong ! {ping, self(), Value},
......@@ -14,7 +14,7 @@ ping_loop(Parent, Pong) ->
server_loop(Pongs) ->
receive
{ping, Pid, Value} -> Pid ! {pong, Value};
{ping, Pid, Value} -> Pid ! {pong, Value}, server_loop(Pongs);
{add_pong, Pid, Node} ->
case lists:any(fun({N, _}) -> N == Node end, Pongs) of
true ->
......@@ -41,17 +41,17 @@ server_mode() ->
add_pong_fun(_, _, []) -> true;
add_pong_fun(Pong, Node, [Node|T]) -> add_pong_fun(Pong, Node, T);
add_pong_fun(Pong, Node, [H|T]) ->
Pong ! {add_pong, H},
Pong ! {add_pong, self(), H},
receive
{ok} -> add_pong_fun(Pong, Node, T);
{error, Reason} -> error(Reason)
after 10000 -> error(timeout)
end.
% receive a {done} message for each node
client_mode([], [], [], _) -> true;
client_mode([], [], [_|T], NumPings) ->
receive {done} ->
receive done ->
client_mode([], [], T, NumPings)
end;
......@@ -65,29 +65,28 @@ client_mode(Pongs, [H|T], Nodes, NumPings) ->
{badrpc, Reason} ->
io:format("cannot connect to ~s~n", [atom_to_list(H)]),
error(Reason);
undefined ->
io:format("no 'pong' defined on node ~s~n", [atom_to_list(H)]);
P ->
add_pong_fun(P, H, Nodes),
client_mode(Pongs ++ [P], T, Nodes, NumPings)
end.
run([], undefined, ['mode=server']) -> server_mode();
run(_, undefined, []) -> error("NumPings is undefined");
run(Hosts, _, []) when length(Hosts) < 2 -> error("less than two nodes specified");
run(Hosts, NumPings, []) -> client_mode([], Hosts, Hosts, NumPings);
run(Hosts, NumPings, [H|T]) ->
Arg = atom_to_list(H),
SetNumPings = lists:prefix("num_pings=", Arg),
if
SetNumPings == true andalso NumPings /= undefined ->
error("NumPings already set");
SetNumPings == true ->
run(Hosts, list_to_integer(lists:sublist(Arg, 11, length(Arg))), T);
true ->
run(Hosts ++ [H], NumPings, T)
case lists:prefix("num_pings=", Arg) of
true when NumPings /= undefined -> error("NumPings already set");
true -> run(Hosts, list_to_integer(lists:sublist(Arg, 11, length(Arg))), T);
false -> run(Hosts ++ [H], NumPings, T)
end.
start(X) ->
run([], undefined, X).
case X of
['mode=server'|[]] -> server_mode();
['mode=server'|_] -> io:format("too much arguments~n", []);
['mode=benchmark'|T] -> run([], undefined, T);
_ -> io:format("invalid arguments~n", [])
end.
#!/bin/bash
echo "erl -noshell -noinput +P 20000000 -s $@ -s init stop" | ./exec.sh
echo "erl -noshell -noinput +P 20000000 -sname benchmark -s $@ -s init stop" | ./exec.sh
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment