diff --git a/include/httpc_bench.hrl b/include/httpc_bench.hrl index 7ce82a1..b8ebac7 100644 --- a/include/httpc_bench.hrl +++ b/include/httpc_bench.hrl @@ -5,5 +5,5 @@ -define(PIPELINING, 1024). -define(PATH, <<"/">>). -define(PORT, 8080). --define(TIMEOUT, 12000). +-define(TIMEOUT, 300_000). -define(URL, <<"http://127.0.0.1:8080/">>). diff --git a/rebar.config b/rebar.config index 7fe1d07..3e12efb 100644 --- a/rebar.config +++ b/rebar.config @@ -7,7 +7,8 @@ {git, "https://github.com/benoitc/hackney.git", {tag, "1.17.4"}}}, % {ibrowse, ".*", % {git, "https://github.com/cmullaparthi/ibrowse.git", {tag, "v4.4.0"}}}, - {ehttpc, ".*", {git, "https://github.com/emqx/ehttpc", {tag, "0.1.11"}}}, + % {ehttpc, ".*", {git, "https://github.com/emqx/ehttpc", {tag, "0.1.15"}}}, + {ehttpc, ".*", {git, "https://github.com/emqx/ehttpc", {branch, "0404-refactor-collect-gen-calls-to-queue"}}}, {timing, ".*", {git, "https://github.com/lpgauth/timing.git", {branch, "master"}}} ]}. diff --git a/rebar.lock b/rebar.lock deleted file mode 100644 index 2610f14..0000000 --- a/rebar.lock +++ /dev/null @@ -1,68 +0,0 @@ -{"1.1.0", -[{<<"bear">>, - {git,"https://github.com/boundary/bear.git", - {ref,"119234548783af19b8ec75c879c5062676b92571"}}, - 1}, - {<<"buoy">>, - {git,"https://github.com/lpgauth/buoy.git", - {ref,"7c49e2d5ec6b35625004fb8842342ee28641e864"}}, - 0}, - {<<"certifi">>,{pkg,<<"certifi">>,<<"0.7.0">>},1}, - {<<"cowlib">>,{pkg,<<"cowlib">>,<<"1.0.0">>},1}, - {<<"dispcount">>, - {git,"https://github.com/ferd/dispcount.git", - {ref,"f466aecdb8ea2dda0996af08c3f2683dae612aed"}}, - 1}, - {<<"dlhttpc">>, - {git,"https://github.com/lpgauth/dlhttpc.git", - {ref,"ca9664358f3d7e63b58cda48545a57c44189a16b"}}, - 0}, - {<<"edown">>, - {git,"https://github.com/uwiger/edown.git", - {ref,"b7c8eb0ac1859f8fce11cbfe3526f5ec83194776"}}, - 2}, - {<<"fqc">>, - {git,"https://github.com/project-fifo/fqc.git", - {ref,"ad62f8121414ed026a6a9f564b1856191ab7d1fc"}}, - 2}, - {<<"gproc">>,{pkg,<<"gproc">>,<<"0.5.0">>},1}, - {<<"granderl">>,{pkg,<<"granderl">>,<<"0.1.5">>},2}, - {<<"hackney">>, - {git,"https://github.com/benoitc/hackney.git", - {ref,"b3814c981cb600211f0b1b0e133c4dbffc8299bc"}}, - 0}, - {<<"hdr_histogram">>, - {git,"https://github.com/HdrHistogram/hdr_histogram_erl.git", - {ref,"46a4f86f3a9b72181859c2a30c8039c5d486248b"}}, - 1}, - {<<"ibrowse">>, - {git,"https://github.com/cmullaparthi/ibrowse.git", - {ref,"7529807170cf3c8f6a8c5c95526e670420ff591b"}}, - 0}, - {<<"idna">>,{pkg,<<"idna">>,<<"1.2.0">>},1}, - {<<"katipo">>, - {git,"https://github.com/puzza007/katipo.git", - {ref,"40660e346d29fec133087ff64e87552b0de19da1"}}, - 0}, - {<<"metal">>,{pkg,<<"metal">>,<<"0.1.0">>},2}, - {<<"metrics">>,{pkg,<<"metrics">>,<<"1.1.0">>},1}, - {<<"mimerl">>,{pkg,<<"mimerl">>,<<"1.0.2">>},1}, - {<<"shackle">>,{pkg,<<"shackle">>,<<"0.5.0">>},1}, - {<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.1">>},1}, - {<<"timing">>, - {git,"https://github.com/lpgauth/timing.git", - {ref,"8a3c0320692fe48a266b29854e4e27b99f6a7a95"}}, - 0}]}. -[ -{pkg_hash,[ - {<<"certifi">>, <<"861A57F3808F7EB0C2D1802AFEAAE0FA5DE813B0DF0979153CBAFCD853ABABAF">>}, - {<<"cowlib">>, <<"397D890D669E56D486B0B5329973AD1A07012412BC110D34A737698DD6941741">>}, - {<<"gproc">>, <<"2DF2D886F8F8A7B81A4B04AA17972B5965BBC5BF0100EA6D8E8AC6A0E7389AFE">>}, - {<<"granderl">>, <<"F20077A68BD80B8D8783BD15A052813C6483771DEC1A5B837D307CBE92F14122">>}, - {<<"idna">>, <<"AC62EE99DA068F43C50DC69ACF700E03A62A348360126260E87F2B54ECED86B2">>}, - {<<"metal">>, <<"168E0AB553E3B8144547E353085CEDAA43C8769E0B7E43C0146C99C2C33507AC">>}, - {<<"metrics">>, <<"41450DFFBA18B1206BF44FA1AD4E29324D1E561617C2DAF4EF32E3CE50DF08F3">>}, - {<<"mimerl">>, <<"993F9B0E084083405ED8252B99460C4F0563E41729AB42D9074FD5E52439BE88">>}, - {<<"shackle">>, <<"1C90E21A8181D4750BDEBF203F6A7412659A4C04947591FBE71797B89BEC9600">>}, - {<<"ssl_verify_fun">>, <<"28A4D65B7F59893BC2C7DE786DEC1E1555BD742D336043FE644AE956C3497FBE">>}]} -]. diff --git a/src/httpc_bench.erl b/src/httpc_bench.erl index c67547b..819e530 100644 --- a/src/httpc_bench.erl +++ b/src/httpc_bench.erl @@ -5,33 +5,40 @@ run/0 ]). --define(N, 2048000). +-define(N, 10240). -define(CLIENTS, [ - httpc_bench_buoy, - httpc_bench_ehttpc, - httpc_bench_hackney, - httpc_bench_httpc + % httpc_bench_buoy, + httpc_bench_ehttpc + % httpc_bench_hackney, + % httpc_bench_httpc ]). -% -define(CONCURENCIES, [32, 64, 128, 512, 2048, 4096]). -% -define(POOL_SIZES, [8, 16, 32, 64, 128, 256]). - -define(CONCURENCIES, [10240]). --define(POOL_SIZES, [1024]). +-define(POOL_SIZES, [1]). + +% -define(CONCURENCIES, [20480]). +% -define(POOL_SIZES, [16]). + +% -define(CONCURENCIES, [10240]). +% -define(POOL_SIZES, [1024]). %% public run() -> error_logger:tty(false), io:format("Running benchmark...~n~n" ++ - "Client PoolSize Concurency Requests/s Error %~n" ++ - [$= || _ <- lists:seq(1, 49)] ++ "~n", []), + "Client PoolSize Concurency Requests/s Error % Success Totol Time(s)~n" ++ + [$= || _ <- lists:seq(1, 71)] ++ "~n", []), + case lists:any(fun(C) -> ?N < C end, ?CONCURENCIES) of + true -> error(bad_iteration); + false -> ok + end, run_client(?CLIENTS, ?POOL_SIZES, ?CONCURENCIES, ?N). %% private lookup(Key, List) -> case lists:keyfind(Key, 1, List) of - false -> undefined; + false -> error({bad_lookup_key, Key}); {_, Value} -> Value end. @@ -66,7 +73,7 @@ run_concurency(Client, PoolSize, [Concurency | T], N) -> ]), Qps = lookup(success, Results) / (lookup(total_time, Results) / 1000000), Errors = lookup(errors, Results) / lookup(iterations, Results) * 100, - io:format("~-8s ~7B ~11B ~11B ~8.1f~n", - [Client2, PoolSize, Concurency, trunc(Qps), Errors]), + io:format("~-8s ~7B ~11B ~11B ~8.1f ~8B ~12.2f~n", + [Client2, PoolSize, Concurency, trunc(Qps), Errors, lookup(success, Results), (lookup(total_time, Results) / 1000000)]), Client:stop(), run_concurency(Client, PoolSize, T, N). diff --git a/src/httpc_bench_ehttpc.erl b/src/httpc_bench_ehttpc.erl index cd9b6b0..4a25b53 100644 --- a/src/httpc_bench_ehttpc.erl +++ b/src/httpc_bench_ehttpc.erl @@ -22,11 +22,11 @@ start(PoolSize) -> application:ensure_all_started(ehttpc), PoolOpts = [{host, "127.0.0.1"}, {port, 8080}, - {enable_pipelining, true}, + {enable_pipelining, false}, {pool_size, PoolSize}, {pool_type, random}, {connect_timeout, 5000}, - {retry, 5}, + {retry, 0}, {retry_timeout, 1000} ], {ok, _} = ehttpc_sup:start_pool(httpc_bench, PoolOpts). diff --git a/src/httpc_bench_server.erl b/src/httpc_bench_server.erl index 8c79fdc..b13311c 100644 --- a/src/httpc_bench_server.erl +++ b/src/httpc_bench_server.erl @@ -13,10 +13,11 @@ start() -> case get(?MODULE) of undefined -> - io:format("Server started...~n", []), + Sleep = sleep(), + io:format("HTTP Server started on port ~p, sleep=~p...~n", [?PORT, Sleep]), {ok, LSocket} = listen(), put(?MODULE, LSocket), - spawn(fun () -> accept(LSocket) end), + spawn(fun () -> accept(LSocket, Sleep) end), ok; _LSocket -> {error, already_started} @@ -33,15 +34,26 @@ stop() -> end. %% private -accept(LSocket) -> +accept(LSocket, Sleep) -> case gen_tcp:accept(LSocket) of {ok, Socket} -> - spawn(fun() -> loop(Socket, <<>>) end), - accept(LSocket); + spawn_link( + fun() -> + io:format(user, "started one server process ~p, sleep=~p\n", [Socket, Sleep]), + loop(Socket, Sleep, <<>>) + end), + accept(LSocket, Sleep); {error, _Reason} -> ok end. +sleep() -> + case os:getenv("SLEEP_PER_REQ") of + false -> 10; + "" -> 10; + N -> list_to_integer(N) + end. + count_requests([<<>>], N) -> {N, <<>>}; count_requests([Buffer], N) -> @@ -61,10 +73,13 @@ listen() -> end), receive {ok, LSocket} -> - {ok, LSocket} + {ok, LSocket}; + Other -> + io:format(user, "unexpected listen result: ~p\n", [Other]), + exit(kill) end. -loop(Socket, Buffer) -> +loop(Socket, Sleep, Buffer) -> case gen_tcp:recv(Socket, 0) of {ok, Data} -> Split = binary:split(<>, @@ -76,12 +91,16 @@ loop(Socket, Buffer) -> "Date: Tue, 07 Mar 2017 01:10:09 GMT\r\n", "Content-Length: 12\r\n\r\n", "httpc_bench!">> || _ <- lists:seq(1, N)], - case gen_tcp:send(Socket, Responses) of - ok -> - loop(Socket, Buffer2); - {error, _Reason} -> - ok - end; - {error, _Reason} -> - ok + lists:foreach( + fun(R) -> + case gen_tcp:send(Socket, R) of + ok -> ok; + {error, _} -> exit(normal) + end, + timer:sleep(Sleep) + end, Responses), + loop(Socket, Sleep, Buffer2); + {error, Reason} -> + io:format(user, "stopped one server process ~p: ~0p\n", [Socket, Reason]), + exit(normal) end.