Permalink
Browse files

Update perf tests to support active mode

  • Loading branch information...
1 parent 788092e commit 01395027704ba4d0461a0eb0ddae68312cb17197 @evax evax committed Mar 28, 2011
Showing with 126 additions and 18 deletions.
  1. +50 −3 perf/erlzmq_perf.erl
  2. +2 −7 perf/local_lat.erl
  3. +14 −0 perf/local_lat_active.erl
  4. +31 −0 perf/local_thr_active.erl
  5. +5 −8 perf/remote_lat.erl
  6. +24 −0 perf/remote_lat_active.erl
View
53 perf/erlzmq_perf.erl
@@ -1,15 +1,62 @@
-module(erlzmq_perf).
--export([recv_loop/2, send_loop/3]).
+-export([local_lat_loop/3, local_lat_loop/4,
+ remote_lat_loop/3, remote_lat_loop/4,
+ recv_loop/2, recv_loop/3, send_loop/3]).
+local_lat_loop(N, S, M) ->
+ local_lat_loop(N, S, M, passive).
-recv_loop(0, _) ->
+local_lat_loop(0, _, _, _) ->
ok;
+local_lat_loop(N, S, M, active) ->
+ ok = receive
+ {zmq, S, M} ->
+ ok
+ end,
+ ok = erlzmq:send(S, M),
+ local_lat_loop(N-1, S, M, active);
+local_lat_loop(N, S, M, passive) ->
+ {ok, M} = erlzmq:recv(S),
+ ok = erlzmq:send(S, M),
+ local_lat_loop(N-1, S, M, passive).
+
+remote_lat_loop(N, S, M) ->
+ remote_lat_loop(N, S, M, passive).
+
+remote_lat_loop(0, _, _, _) ->
+ ok;
+remote_lat_loop(N, S, M, active) ->
+ ok = erlzmq:send(S, M),
+ ok = receive
+ {zmq, S, M} ->
+ ok
+ end,
+ remote_lat_loop(N-1, S, M, active);
+
+remote_lat_loop(N, S, M, passive) ->
+ ok = erlzmq:send(S, M),
+ {ok, M} = erlzmq:recv(S),
+ remote_lat_loop(N-1, S, M, passive).
+
recv_loop(N, S) ->
+ recv_loop(N, S, passive).
+
+recv_loop(0, _, _) ->
+ ok;
+recv_loop(N, S, passive) ->
erlzmq:recv(S),
- recv_loop(N-1, S).
+ recv_loop(N-1, S, passive);
+recv_loop(N, S, active) ->
+ receive
+ {zmq, S, _Msg} ->
+ ok
+ end,
+ recv_loop(N-1, S, active).
send_loop(0, _, _) ->
ok;
send_loop(N, S, M) ->
erlzmq:send(S, M),
send_loop(N-1, S, M).
+
+
View
9 perf/local_lat.erl
@@ -1,5 +1,5 @@
#! /usr/bin/env escript
-%%! -smp enable -pa ebin
+%%! -smp enable -pa ebin -pa perf
main([BindTo,MessageSizeStr,RoundtripCountStr]) ->
{MessageSize, _} = string:to_integer(MessageSizeStr),
@@ -8,12 +8,7 @@ main([BindTo,MessageSizeStr,RoundtripCountStr]) ->
{ok, Socket} = erlzmq:socket(Context, [rep, {active, false}]),
ok = erlzmq:bind(Socket, BindTo),
Msg = list_to_binary(lists:duplicate(MessageSize, 0)),
- Do = fun() ->
- {ok, RMsg} = erlzmq:brecv(Socket),
- RMsg = Msg,
- erlzmq:send(Socket, Msg)
- end,
- [ Do() || _I <- lists:seq(1,RoundtripCount) ],
+ ok = erlzmq_perf:local_lat_loop(RoundtripCount, Socket, Msg),
erlzmq:close(Socket),
erlzmq:term(Context).
View
14 perf/local_lat_active.erl
@@ -0,0 +1,14 @@
+#! /usr/bin/env escript
+%%! -smp enable -pa ebin -pa perf
+
+main([BindTo,MessageSizeStr,RoundtripCountStr]) ->
+ {MessageSize, _} = string:to_integer(MessageSizeStr),
+ {RoundtripCount, _} = string:to_integer(RoundtripCountStr),
+ {ok, Context} = erlzmq:context(),
+ {ok, Socket} = erlzmq:socket(Context, [rep, {active, true}]),
+ ok = erlzmq:bind(Socket, BindTo),
+ Msg = list_to_binary(lists:duplicate(MessageSize, 0)),
+ ok = erlzmq_perf:local_lat_loop(RoundtripCount, Socket, Msg, active),
+ erlzmq:close(Socket),
+ erlzmq:term(Context).
+
View
31 perf/local_thr_active.erl
@@ -0,0 +1,31 @@
+#! /usr/bin/env escript
+%%! -smp enable -pa ebin -pa perf
+%-mode(compile).
+
+main([BindTo,MessageSizeStr,MessageCountStr]) ->
+ {MessageSize, _} = string:to_integer(MessageSizeStr),
+ {MessageCount, _} = string:to_integer(MessageCountStr),
+ {ok, Context} = erlzmq:context(),
+ {ok, Socket} = erlzmq:socket(Context, [sub, {active, true}]),
+ ok = erlzmq:setsockopt(Socket,subscribe, <<>>),
+ ok = erlzmq:bind(Socket, BindTo),
+ receive
+ _ ->
+ ok
+ end,
+ Start = now(),
+ erlzmq_perf:recv_loop(MessageCount-1, Socket, active),
+ Elapsed = timer:now_diff(now(), Start),
+
+ Throughput = MessageCount / Elapsed * 1000000,
+ Megabits = Throughput * MessageSize * 8 / 1000000,
+
+ io:format("message size: ~p [B]~n"
+ "message count: ~p~n"
+ "mean throughput: ~p [msg/s]~n"
+ "mean throughput: ~p [Mb/s]~n",
+ [MessageSize, MessageCount, Throughput, Megabits]),
+
+ erlzmq:close(Socket),
+ erlzmq:term(Context).
+
View
13 perf/remote_lat.erl
@@ -1,5 +1,5 @@
#! /usr/bin/env escript
-%%! -smp enable -pa ebin
+%%! -smp enable -pa ebin -pa perf
main([ConnectTo,MessageSizeStr,RoundtripCountStr]) ->
{MessageSize, _} = string:to_integer(MessageSizeStr),
@@ -8,14 +8,10 @@ main([ConnectTo,MessageSizeStr,RoundtripCountStr]) ->
{ok, Socket} = erlzmq:socket(Context, [req, {active, false}]),
ok = erlzmq:connect(Socket, ConnectTo),
Msg = list_to_binary(lists:duplicate(MessageSize, 0)),
- Do = fun() ->
- erlzmq:send(Socket, Msg),
- {ok, Msg} = erlzmq:brecv(Socket)
- end,
- {Elapsed, _} = timer:tc(fun () ->
- [ Do() || _I <- lists:seq(1,RoundtripCount) ]
- end,[]),
+ Start = now(),
+ erlzmq_perf:remote_lat_loop(RoundtripCount, Socket, Msg),
+ Elapsed = timer:now_diff(now(), Start),
Latency = Elapsed / (RoundtripCount * 2),
@@ -25,3 +21,4 @@ main([ConnectTo,MessageSizeStr,RoundtripCountStr]) ->
[MessageSize, RoundtripCount, Latency]),
erlzmq:close(Socket),
erlzmq:term(Context).
+
View
24 perf/remote_lat_active.erl
@@ -0,0 +1,24 @@
+#! /usr/bin/env escript
+%%! -smp enable -pa ebin -pa perf
+
+main([ConnectTo,MessageSizeStr,RoundtripCountStr]) ->
+ {MessageSize, _} = string:to_integer(MessageSizeStr),
+ {RoundtripCount, _} = string:to_integer(RoundtripCountStr),
+ {ok, Context} = erlzmq:context(),
+ {ok, Socket} = erlzmq:socket(Context, [req, {active, true}]),
+ ok = erlzmq:connect(Socket, ConnectTo),
+ Msg = list_to_binary(lists:duplicate(MessageSize, 0)),
+
+ Start = now(),
+ erlzmq_perf:remote_lat_loop(RoundtripCount, Socket, Msg, active),
+ Elapsed = timer:now_diff(now(), Start),
+
+ Latency = Elapsed / (RoundtripCount * 2),
+
+ io:format("message size: ~p [B]~n"
+ "roundtrip count: ~p~n"
+ "average latency: ~p [us]~n",
+ [MessageSize, RoundtripCount, Latency]),
+ erlzmq:close(Socket),
+ erlzmq:term(Context).
+

0 comments on commit 0139502

Please sign in to comment.