ninenines / gun

HTTP/1.1, HTTP/2, Websocket client (and more) for Erlang/OTP.
ISC License
891 stars 232 forks source link

Opening a connection is slow #235

Closed x0id closed 3 years ago

x0id commented 3 years ago

Testing gun with simple get request I noticed its relatively slow. The test code: https://gist.github.com/x0id/7c395c5916493ace9b380eb029a6060b Result showing inets httpc:request/1 is twice as fast. The result is stable and is not changed if I force the gun to pick http/1.1. I guess the time-consuming part is setting up a secure connection. Is there any way to optimize the library?

protocol: http2
status: 200
headers: [{<<"date">>,<<"Wed, 29 Jul 2020 00:18:42 GMT">>},
          {<<"content-type">>,<<"application/json; charset=utf-8">>},
          {<<"content-length">>,<<"15">>},
          {<<"server">>,<<"Kestrel">>}]
<<"{\"Status\":\"UP\"}">>
query took 286003 microseconds

inets httpc test...
{ok,{{"HTTP/1.1",200,"OK"},
     [{"connection","keep-alive"},
      {"date","Wed, 29 Jul 2020 00:18:42 GMT"},
      {"server","Kestrel"},
      {"content-length","15"},
      {"content-type","application/json; charset=utf-8"}],
     "{\"Status\":\"UP\"}"}}
query took 139283 microseconds
x0id commented 3 years ago

Actually, I found this issue in 1.3.2 hexpm version. The master branch looks perfect in that matter. Looking forward to 2.0.0 release.