<p dir="ltr">An observation: Your receive code looks dodgy - you receive only the first chunk of data, not everything up till tcp_closed / ssl_closed.<br>
That is probably not what you want.</p>
<p dir="ltr">Besides that: is the time linear in the data size? Try measuring eg for 100MB and 200MB.<br>
(I suspect with the code you presented it would give the same durations independent of data size.)</p>
<p dir="ltr">/Erik</p>
<div class="gmail_quote">Den 11/02/2015 12.39 skrev "SeanD" <<a href="mailto:seand-erlang@seand.me.uk">seand-erlang@seand.me.uk</a>>:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>We are experiencing a bottleneck in our application that has the option of using SSL. Conducting some generic tests, I am seeing that SSL can be upto 20,000 times slower when processing large amounts of data and was wondering if anyone else has seen the same behaviour or can tell me that I'm doing something really silly?</div><div><br></div><div>Transferring a 200MB binary between 2 nodes on the same machine using gen_tcp is taking between 100 and 200 microseconds, whilst transferring the same binary using ssl usually takes around 3 seconds! I'm currently using R16B01, but can happily move to a later version if this is required.</div><div><br></div><div>Is there any way to speed this up or any alternative SSL implementations that call out to openssl natively that could be used instead? Any insights would be very welcome.</div><div><br></div><div>Thanks,</div><div>Sean</div><div><br></div><div>P.S. The code I'm using is enclosed below:</div><div><br></div><div><div>-module(network_performance).</div><div><br></div><div>-export([client/0,ssl_client/0,server/1,ssl_server/1]).</div><div><br></div><div>client() -></div><div> SomeHostInNet = "localhost", % to make it runnable on one machine</div><div> {ok, Sock} = gen_tcp:connect(SomeHostInNet, 5678,</div><div> [binary, {packet, 0}, {active, once}]),</div><div> Before = erlang:now(),</div><div> ok = do_client_recv(Sock),</div><div> After = erlang:now(),</div><div> ok = gen_tcp:close(Sock),</div><div> io:format("Time taken: ~p microsecs~n",[total_microsecs(After) - total_microsecs(Before)]).</div><div><br></div><div>server(Data) -></div><div> {ok, LSock} = gen_tcp:listen(5678, [binary, {packet, raw}, {active, once},{reuseaddr,true}]),</div><div> {ok, Sock} = gen_tcp:accept(LSock),</div><div> gen_tcp:send(Sock, Data),</div><div> gen_tcp:close(Sock).</div><div><br></div><div>ssl_client() -></div><div> SomeHostInNet = "localhost", % to make it runnable on one machine</div><div> ssl:start(),</div><div> {ok, Sock} = ssl:connect(SomeHostInNet, 5679,</div><div> [binary, {packet, 0}, {active, once}]),</div><div> ok = ssl:ssl_accept(Sock),</div><div> Before = erlang:now(),</div><div> ok = do_client_recv(Sock),</div><div> After = erlang:now(),</div><div> ok = ssl:close(Sock),</div><div> io:format("Time taken: ~p microsecs~n",[total_microsecs(After) - total_microsecs(Before)]).</div><div><br></div><div>ssl_server(Data) -></div><div> ssl:start(),</div><div> {ok, LSock} = ssl:listen(5679, [binary, {packet, raw},</div><div> {active, once},{reuseaddr,true},{certfile,"test.pem"},{keyfile,"test.key"}]),</div><div> {ok, Sock} = ssl:transport_accept(LSock),</div><div> ok = ssl:ssl_accept(Sock),</div><div> ssl:send(Sock, Data),</div><div> ssl:close(Sock).</div><div><br></div><div>total_microsecs({MegaSecs,Secs,MicroSecs}) -></div><div> (MegaSecs*1000000 + Secs)*1000000 + MicroSecs.</div><div><br></div><div>do_client_recv(Socket) -></div><div> receive</div><div> {tcp, Socket, _Data} -></div><div> ok;</div><div> {ssl, Socket, _Data} -></div><div> ok;</div><div> {tcp_closed, Socket} -></div><div> io:format("Socket closed~n",[]);</div><div> {tcp_error, Socket, Reason} -></div><div> io:format("Error: ~p~n",[Reason])</div><div> after 20000 -></div><div> io:format("Receive timed out~n",[])</div><div> end.</div></div><div><br></div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div>