Commit 0b1c3a8f authored by neverlord's avatar neverlord

distributed benchmark

parent 0c3537cb
...@@ -76,23 +76,23 @@ inline option<int> _2i(std::string const& str) ...@@ -76,23 +76,23 @@ inline option<int> _2i(std::string const& str)
void usage() void usage()
{ {
cout << "Running in server mode:" << endl cout << "Running in server mode:" << endl
<< " --mode=server " << endl << " mode=server " << endl
<< " --port=NUM publishes an actor at port NUM" << endl << " --port=NUM publishes an actor at port NUM" << endl
<< " -p NUM alias for --port=NUM" << endl << " -p NUM alias for --port=NUM" << endl
<< endl << endl
<< endl << endl
<< "Running the benchmark:" << 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 << " 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 << endl
<< " example: --mode=benchmark 192.168.9.1:1234 " << " example: mode=benchmark 192.168.9.1:1234 "
"192.168.9.2:1234 " "192.168.9.2:1234 "
"--num_pings=100" << endl "--num_pings=100" << endl
<< endl << endl
<< endl << endl
<< "Shutdown servers:" << 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
<< endl << endl
<< "Miscellaneous:" << endl << "Miscellaneous:" << endl
...@@ -467,16 +467,16 @@ int main(int argc, char** argv) ...@@ -467,16 +467,16 @@ int main(int argc, char** argv)
{ {
usage(); usage();
}, },
on("--mode=server") >> [=]() on("mode=server") >> [=]()
{ {
server_mode(first + 1, last); server_mode(first + 1, last);
}, },
on("--mode=benchmark") >> [=]() on("mode=benchmark") >> [=]()
{ {
client_mode(first + 1, last); client_mode(first + 1, last);
await_all_others_done(); await_all_others_done();
}, },
on("--mode=shutdown") >> [=]() on("mode=shutdown") >> [=]()
{ {
shutdown_mode(first + 1, last); shutdown_mode(first + 1, last);
}, },
......
...@@ -5,7 +5,7 @@ ping_loop(Parent, Pong) -> ...@@ -5,7 +5,7 @@ ping_loop(Parent, Pong) ->
receive receive
{pong, 0} -> Parent ! done; {pong, 0} -> Parent ! done;
{pong, X} -> {pong, X} ->
Pong ! {self(), ping, X - 1}, Pong ! {ping, self(), X - 1},
ping_loop(Parent, Pong); ping_loop(Parent, Pong);
{kickoff, Value} -> {kickoff, Value} ->
Pong ! {ping, self(), Value}, Pong ! {ping, self(), Value},
...@@ -14,7 +14,7 @@ ping_loop(Parent, Pong) -> ...@@ -14,7 +14,7 @@ ping_loop(Parent, Pong) ->
server_loop(Pongs) -> server_loop(Pongs) ->
receive receive
{ping, Pid, Value} -> Pid ! {pong, Value}; {ping, Pid, Value} -> Pid ! {pong, Value}, server_loop(Pongs);
{add_pong, Pid, Node} -> {add_pong, Pid, Node} ->
case lists:any(fun({N, _}) -> N == Node end, Pongs) of case lists:any(fun({N, _}) -> N == Node end, Pongs) of
true -> true ->
...@@ -41,17 +41,17 @@ server_mode() -> ...@@ -41,17 +41,17 @@ server_mode() ->
add_pong_fun(_, _, []) -> true; add_pong_fun(_, _, []) -> true;
add_pong_fun(Pong, Node, [Node|T]) -> add_pong_fun(Pong, Node, T); add_pong_fun(Pong, Node, [Node|T]) -> add_pong_fun(Pong, Node, T);
add_pong_fun(Pong, Node, [H|T]) -> add_pong_fun(Pong, Node, [H|T]) ->
Pong ! {add_pong, H}, Pong ! {add_pong, self(), H},
receive receive
{ok} -> add_pong_fun(Pong, Node, T); {ok} -> add_pong_fun(Pong, Node, T);
{error, Reason} -> error(Reason) {error, Reason} -> error(Reason)
after 10000 -> error(timeout)
end. end.
% receive a {done} message for each node % receive a {done} message for each node
client_mode([], [], [], _) -> true; client_mode([], [], [], _) -> true;
client_mode([], [], [_|T], NumPings) -> client_mode([], [], [_|T], NumPings) ->
receive {done} -> receive done ->
client_mode([], [], T, NumPings) client_mode([], [], T, NumPings)
end; end;
...@@ -65,29 +65,28 @@ client_mode(Pongs, [H|T], Nodes, NumPings) -> ...@@ -65,29 +65,28 @@ client_mode(Pongs, [H|T], Nodes, NumPings) ->
{badrpc, Reason} -> {badrpc, Reason} ->
io:format("cannot connect to ~s~n", [atom_to_list(H)]), io:format("cannot connect to ~s~n", [atom_to_list(H)]),
error(Reason); error(Reason);
undefined ->
io:format("no 'pong' defined on node ~s~n", [atom_to_list(H)]);
P -> P ->
add_pong_fun(P, H, Nodes), add_pong_fun(P, H, Nodes),
client_mode(Pongs ++ [P], T, Nodes, NumPings) client_mode(Pongs ++ [P], T, Nodes, NumPings)
end. end.
run([], undefined, ['mode=server']) -> server_mode();
run(_, undefined, []) -> error("NumPings is undefined"); run(_, undefined, []) -> error("NumPings is undefined");
run(Hosts, _, []) when length(Hosts) < 2 -> error("less than two nodes specified"); run(Hosts, _, []) when length(Hosts) < 2 -> error("less than two nodes specified");
run(Hosts, NumPings, []) -> client_mode([], Hosts, Hosts, NumPings); run(Hosts, NumPings, []) -> client_mode([], Hosts, Hosts, NumPings);
run(Hosts, NumPings, [H|T]) -> run(Hosts, NumPings, [H|T]) ->
Arg = atom_to_list(H), Arg = atom_to_list(H),
SetNumPings = lists:prefix("num_pings=", Arg), case lists:prefix("num_pings=", Arg) of
if true when NumPings /= undefined -> error("NumPings already set");
SetNumPings == true andalso NumPings /= undefined -> true -> run(Hosts, list_to_integer(lists:sublist(Arg, 11, length(Arg))), T);
error("NumPings already set"); false -> run(Hosts ++ [H], NumPings, T)
SetNumPings == true ->
run(Hosts, list_to_integer(lists:sublist(Arg, 11, length(Arg))), T);
true ->
run(Hosts ++ [H], NumPings, T)
end. end.
start(X) -> 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 #!/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