%%% Author: Badlop %%% Published: 2/October/2007 %%% License: GPLv2 -module(multicast_test). -export([ normal/4, trusted/4, untrusted/4, testn/2, testt/2, testu/2 ]). normal(ServerT, A, B, Inc) -> Nums = lists:seq(A, B, Inc), Res = [{X, timer:tc(?MODULE, testn, [ServerT, X])} || X <- Nums], print_results(Res). trusted(ServerT, A, B, Inc) -> Nums = lists:seq(A, B, Inc), Res = [{X, timer:tc(?MODULE, testt, [ServerT, X])} || X <- Nums], print_results(Res). untrusted(ServerT, A, B, Inc) -> Nums = lists:seq(A, B, Inc), Res = [{X, timer:tc(?MODULE, testu, [ServerT, X])} || X <- Nums], print_results(Res). build_destinations(ServerT, N) -> case ServerT of single -> [ jlib:make_jid("test_"++integer_to_list(Num), "localhost", []) || Num <- lists:seq(0, N) ]; multiple -> [ jlib:make_jid("test_"++integer_to_list(Num), integer_to_list(Num)++".localhost", []) || Num <- lists:seq(0, N) ] end. print_results(Res) -> Format = fun(X, T) -> [XS] = io_lib:format("~p", [X]), [TS] = io_lib:format("~p", [T]), [DS] = io_lib:format("~.2f", [T/X]), {XS, TS, DS} end, Res2 = [Format(X, T) || {X, {T, ok}} <- Res], io:format(" # Exec Time Time per destination~n"), io:format(" Destinations (microseconds) (microseconds)~n"), [io:format(" ~12s~14s~23s~n", [X, T, D]) || {X, T, D} <- Res2], ok. testn(ServerT, X) -> Destinations = build_destinations(ServerT, X), FromJID = {jid,"test_171", "localhost", "stressingser", "test_171", "localhost", "stressingser"}, Packet = {xmlelement,"message",[{"xml:lang","es"}], [{xmlelement,"body",[],[{xmlcdata,"Hello, world!"}]}]}, [ejabberd_router:route(FromJID, To, Packet) || To <- Destinations], ok. testt(ServerT, X) -> Destinations = build_destinations(ServerT, X), LServiceS = "multicast.localhost", LServerS = "localhost", FromJID = {jid,"test_171", "localhost", "stressingser", "test_171", "localhost", "stressingser"}, Packet = {xmlelement,"message",[{"xml:lang","es"}], [{xmlelement,"body",[],[{xmlcdata,"Hello, world!"}]}]}, mod_multicast:route_trusted(LServiceS, LServerS, FromJID, Destinations, Packet), ok. testu(ServerT, X) -> Destinations = build_destinations(ServerT, X), LServiceS = "multicast.localhost", LServerS = "localhost", Access = all, SLimits = {service_limits,{limits,{default,1000},{default,1000}}, {limits,{default,2000},{default,2000}}}, From = {jid,"test_171", "localhost", "stressingser", "test_171", "localhost", "stressingser"}, F = fun(To) -> ToS = jlib:jid_to_string(To), {xmlelement, "address", [{"type","to"}, {"jid",ToS}, {"desc","Bob Tomtomtom"} ], []} end, Addresses = [ F(To) || To <- Destinations ], Packet = {xmlelement, "message", [{"to","multicast.localhost"},{"xml:lang","en"}], [{xmlelement,"body",[],[{xmlcdata,"Hello, world!"}]}, {xmlelement, "addresses", [{"xmlns","http://jabber.org/protocol/address"}], Addresses}]}, mod_multicast:route_untrusted(LServiceS, LServerS, Access, SLimits, From, Destinations, Packet), ok.