Make it possible to tune socket buffer sizes

parent d49a451d
......@@ -63,11 +63,14 @@ ranch_init({Ref, Socket, Transport, _} = Opts) ->
case init(Opts) of
{ok, State} ->
ok = ranch:accept_ack(Ref),
ok = Transport:setopts(Socket,
BufSize = application:get_env(?APP, upstream_socket_buffer_size,
?MAX_SOCK_BUF_SIZE),
ok = Transport:setopts(
Socket,
[{active, once},
%% {recbuf, ?MAX_SOCK_BUF_SIZE},
%% {sndbuf, ?MAX_SOCK_BUF_SIZE},
{buffer, ?MAX_SOCK_BUF_SIZE}
{buffer, BufSize}
]),
gen_server:enter_loop(?MODULE, [], State);
error ->
......@@ -361,10 +364,13 @@ handle_upstream_header(DcId, S) ->
-define(SEND_TIMEOUT, 60 * 1000).
connect(Host, Port) ->
BufSize = application:get_env(?APP, downstream_socket_buffer_size,
?MAX_SOCK_BUF_SIZE),
SockOpts = [{active, once},
{packet, raw},
binary,
{mode, binary},
{send_timeout, ?SEND_TIMEOUT},
{buffer, BufSize},
%% {nodelay, true},
{keepalive, true}],
case mtp_metric:rt([?APP, downstream_connect_duration, seconds],
......@@ -372,9 +378,6 @@ connect(Host, Port) ->
gen_tcp:connect(Host, Port, SockOpts, ?CONN_TIMEOUT)
end) of
{ok, Sock} ->
ok = inet:setopts(Sock, [%% {recbuf, ?MAX_SOCK_BUF_SIZE},
%% {sndbuf, ?MAX_SOCK_BUF_SIZE},
{buffer, ?MAX_SOCK_BUF_SIZE}]),
{ok, Sock};
{error, _} = Err ->
Err
......
......@@ -60,6 +60,11 @@
%% module with function `notify/4' exported.
%% See mtp_metric:notify/4 for details
%% {metric_backend, my_metric_backend}
%% User-space recv socket buffer sizes. Set to higher if you have
%% enough RAM
%% {upstream_socket_buffer_size, 51200}, %50kb
%% {downstream_socket_buffer_size, 51200} %50kb
]},
{modules, []},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment