mirror of
https://github.com/valitydev/woody_erlang.git
synced 2024-11-06 02:15:19 +00:00
Turn TCP_NODELAY on for client requests by default (#134)
This commit is contained in:
parent
8543878a55
commit
b6ec9887fb
@ -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 ->
|
||||
|
Loading…
Reference in New Issue
Block a user