Turn TCP_NODELAY on for client requests by default (#134)

This commit is contained in:
Andrew Mayorov 2020-05-13 14:24:52 +03:00 committed by GitHub
parent 8543878a55
commit b6ec9887fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,16 @@
-type transport_options() :: map().
-export_type([transport_options/0]).
-define(DEFAULT_TRANSPORT_OPTIONS, #{
connect_options => [
% Turn TCP_NODELAY on.
% We expect that Nagle's algorithm would not be very helpful for typical
% Woody RPC workloads, negatively impacting perceived latency. So it's
% better to turn it off.
{nodelay, true}
]
}).
-type woody_transport() :: #{
url := woody:url(),
woody_state := woody_state:st(),
@ -111,9 +121,10 @@ send(Url, Body, Options, ResOpts, WoodyState) ->
case woody_resolver:resolve_url(Url, WoodyState, ResOpts) of
{ok, {OldUrl, NewUrl}} ->
Headers = add_host_header(OldUrl, make_woody_headers(Context)),
Timeouts = maps:to_list(set_timeouts(Options, Context)),
Options1 = set_defaults(Options),
Options2 = set_timeouts(Options1, Context),
HeaderList = maps:to_list(Headers),
Result = hackney:request(post, NewUrl, HeaderList, Body, Timeouts),
Result = hackney:request(post, NewUrl, HeaderList, Body, maps:to_list(Options2)),
transform_request_results(Result);
{error, Reason} ->
{error, {resolve_failed, Reason}}
@ -127,6 +138,9 @@ transform_request_results({ok, Code, Headers}) ->
transform_request_results(Any) ->
Any.
set_defaults(Options) ->
maps:merge(?DEFAULT_TRANSPORT_OPTIONS, Options).
set_timeouts(Options, Context) ->
case woody_context:get_deadline(Context) of
undefined ->