Make multiplexed downstream socket buffer size tunable

parent 0af1923c
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
-define(APP, mtproto_proxy). -define(APP, mtproto_proxy).
-define(CONN_TIMEOUT, 10000). -define(CONN_TIMEOUT, 10000).
-define(SEND_TIMEOUT, 15000). -define(SEND_TIMEOUT, 15000).
-define(MAX_SOCK_BUF_SIZE, 1024 * 300). % Decrease if CPU is cheaper than RAM -define(MAX_SOCK_BUF_SIZE, 1024 * 500). % Decrease if CPU is cheaper than RAM
-type handle() :: pid(). -type handle() :: pid().
-type upstream_opts() :: #{addr := mtp_config:netloc(), % IP/Port of TG client -type upstream_opts() :: #{addr := mtp_config:netloc(), % IP/Port of TG client
...@@ -262,17 +262,17 @@ connect(DcId, S) -> ...@@ -262,17 +262,17 @@ connect(DcId, S) ->
end. end.
tcp_connect(Host, Port) -> tcp_connect(Host, Port) ->
BufSize = application:get_env(?APP, downstream_socket_buffer_size,
?MAX_SOCK_BUF_SIZE),
SockOpts = [{active, once}, SockOpts = [{active, once},
{packet, raw}, {packet, raw},
binary, {mode, binary},
{buffer, BufSize},
{send_timeout, ?SEND_TIMEOUT}, {send_timeout, ?SEND_TIMEOUT},
%% {nodelay, true}, %% {nodelay, true},
{keepalive, true}], {keepalive, true}],
case gen_tcp:connect(Host, Port, SockOpts, ?CONN_TIMEOUT) of case gen_tcp:connect(Host, Port, SockOpts, ?CONN_TIMEOUT) of
{ok, Sock} -> {ok, Sock} ->
ok = inet:setopts(Sock, [%% {recbuf, ?MAX_SOCK_BUF_SIZE},
%% {sndbuf, ?MAX_SOCK_BUF_SIZE},
{buffer, ?MAX_SOCK_BUF_SIZE}]),
{ok, Sock}; {ok, Sock};
{error, _} = Err -> {error, _} = Err ->
Err Err
......
{application, mtproto_proxy, {application, mtproto_proxy,
[{description, "An OTP application"}, [{description, "An OTP application"},
{vsn, "0.4.0"}, {vsn, "0.4.1-mux"},
{registered, []}, {registered, []},
{mod, { mtproto_proxy_app, []}}, {mod, { mtproto_proxy_app, []}},
{applications, {applications,
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
%% User-space recv socket buffer sizes. Set to higher if you have %% User-space recv socket buffer sizes. Set to higher if you have
%% enough RAM %% enough RAM
%% {upstream_socket_buffer_size, 51200}, %50kb %% {upstream_socket_buffer_size, 51200}, %50kb
%% {downstream_socket_buffer_size, 51200} %50kb %% {downstream_socket_buffer_size, 512000} %500kb
]}, ]},
{modules, []}, {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