Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/osiris_replica.erl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@

-define(DEFAULT_ONE_TIME_TOKEN_TIMEOUT, 30000).
-define(TOKEN_SIZE, 32).
-define(DEF_REC_BUF, 408300 * 5).
%% Size of the Erlang inet driver's read buffer (userspace).
-define(DEF_BUFFER, 408300 * 10).

%%%===================================================================
%%% API functions
Expand Down Expand Up @@ -779,8 +780,7 @@ setopts(ssl, Socket, Options) ->
ssl:setopts(Socket, Options).

listener_opts(tcp) ->
RcvBuf = application:get_env(osiris, replica_recbuf, ?DEF_REC_BUF),
Buffer = application:get_env(osiris, replica_buffer, RcvBuf * 2),
Buffer = application:get_env(osiris, replica_buffer, ?DEF_BUFFER),
KeepAlive = application:get_env(osiris, replica_keepalive, false),
ReuseAddr = application:get_env(osiris, replica_reuseaddr, true),
Linger = application:get_env(osiris, replica_linger, true),
Expand All @@ -795,10 +795,13 @@ listener_opts(tcp) ->
{backlog, 0},
{packet, raw},
{active, false},
{buffer, Buffer},
{recbuf, RcvBuf},
{keepalive, KeepAlive}
];
]
%% `recbuf' is applied before `buffer': on older OTP releases setting
%% recbuf raises the driver buffer to match, so `buffer' must come last
%% to stay authoritative.
++ osiris_util:optional_socket_opt(recbuf, replica_recbuf)
++ [{buffer, Buffer}];
listener_opts(ssl) ->
Opts = listener_opts(tcp),
SslOptions = application:get_env(osiris, replication_server_ssl_options, []),
Expand Down
6 changes: 2 additions & 4 deletions src/osiris_replica_reader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

-include("osiris.hrl").

-define(DEF_SND_BUF, 146988 * 10).
%% replica reader, spawned remotely by replica process, connects back to
%% configured host/port, reads entries from master and uses file:sendfile to
%% replicate read records
Expand Down Expand Up @@ -386,15 +385,14 @@ close(ssl, Socket) ->
ssl:close(Socket).

connect_options() ->
SndBuf = application:get_env(osiris, replica_sndbuf, ?DEF_SND_BUF),
KeepAlive = application:get_env(osiris, replica_keepalive, false),
IPAddrFamily = osiris_util:get_replica_listener_inet_address_family(),
[binary,
IPAddrFamily,
{packet, 0},
{nodelay, true},
{sndbuf, SndBuf},
{keepalive, KeepAlive}].
{keepalive, KeepAlive}]
++ osiris_util:optional_socket_opt(sndbuf, replica_sndbuf).

setopts(tcp, Sock, Opts) ->
inet:setopts(Sock, Opts);
Expand Down
10 changes: 10 additions & 0 deletions src/osiris_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
get_replication_configuration_from_tls_dist/1,
get_replication_configuration_from_tls_dist/2,
get_replica_listener_inet_address_family/0,
optional_socket_opt/2,
partition_parallel/3,
normalise_name/1,
get_reader_context/1,
Expand Down Expand Up @@ -248,6 +249,15 @@ get_replica_listener_inet_address_family() ->
_ -> inet
end.

-spec optional_socket_opt(atom(), atom()) -> [{atom(), pos_integer()}].
optional_socket_opt(Opt, Key) ->
case application:get_env(osiris, Key) of
{ok, Value} when is_integer(Value) andalso Value > 0 ->
[{Opt, Value}];
_ ->
[]
end.

inet_tls_enabled([]) ->
false;
inet_tls_enabled([{proto_dist, ["inet_tls"]} | _]) ->
Expand Down
Loading