aboutsummaryrefslogtreecommitdiffstats
path: root/src/ranch_conns_sup.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-11-26 14:22:10 +0100
committerLoïc Hoguin <[email protected]>2013-11-26 14:22:10 +0100
commit99242f3342f24f447e487aee6cbf909fcfce9fdb (patch)
tree7174e2ca193efee7a9d8b48959566b44aa56c642 /src/ranch_conns_sup.erl
parent95bb778f57f55e02bd7fe6f86dfbb4f0a94d6ade (diff)
downloadranch-99242f3342f24f447e487aee6cbf909fcfce9fdb.tar.gz
ranch-99242f3342f24f447e487aee6cbf909fcfce9fdb.tar.bz2
ranch-99242f3342f24f447e487aee6cbf909fcfce9fdb.zip
Add accept_ack on all transports and ack_timeout transport option
Doing this in the connection process allows us to free acceptors to start accepting more connections quicker, especially under load.
Diffstat (limited to 'src/ranch_conns_sup.erl')
-rw-r--r--src/ranch_conns_sup.erl26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/ranch_conns_sup.erl b/src/ranch_conns_sup.erl
index 245a5e0..f920919 100644
--- a/src/ranch_conns_sup.erl
+++ b/src/ranch_conns_sup.erl
@@ -20,12 +20,12 @@
-module(ranch_conns_sup).
%% API.
--export([start_link/4]).
+-export([start_link/5]).
-export([start_protocol/2]).
-export([active_connections/1]).
%% Supervisor internals.
--export([init/5]).
+-export([init/6]).
-export([system_continue/3]).
-export([system_terminate/4]).
-export([system_code_change/4]).
@@ -39,15 +39,17 @@
transport = undefined :: module(),
protocol = undefined :: module(),
opts :: any(),
- max_conns = undefined :: non_neg_integer() | infinity
+ ack_timeout :: timeout(),
+ max_conns = undefined :: ranch:max_conns()
}).
%% API.
--spec start_link(ranch:ref(), conn_type(), module(), module()) -> {ok, pid()}.
-start_link(Ref, ConnType, Transport, Protocol) ->
+-spec start_link(ranch:ref(), conn_type(), module(), timeout(), module())
+ -> {ok, pid()}.
+start_link(Ref, ConnType, Transport, AckTimeout, Protocol) ->
proc_lib:start_link(?MODULE, init,
- [self(), Ref, ConnType, Transport, Protocol]).
+ [self(), Ref, ConnType, Transport, AckTimeout, Protocol]).
%% We can safely assume we are on the same node as the supervisor.
%%
@@ -92,8 +94,9 @@ active_connections(SupPid) ->
%% Supervisor internals.
--spec init(pid(), ranch:ref(), conn_type(), module(), module()) -> no_return().
-init(Parent, Ref, ConnType, Transport, Protocol) ->
+-spec init(pid(), ranch:ref(), conn_type(), module(), timeout(), module())
+ -> no_return().
+init(Parent, Ref, ConnType, Transport, AckTimeout, Protocol) ->
process_flag(trap_exit, true),
ok = ranch_server:set_connections_sup(Ref, self()),
MaxConns = ranch_server:get_max_connections(Ref),
@@ -101,17 +104,18 @@ init(Parent, Ref, ConnType, Transport, Protocol) ->
ok = proc_lib:init_ack(Parent, {ok, self()}),
loop(#state{parent=Parent, ref=Ref, conn_type=ConnType,
transport=Transport, protocol=Protocol, opts=Opts,
- max_conns=MaxConns}, 0, 0, []).
+ ack_timeout=AckTimeout, max_conns=MaxConns}, 0, 0, []).
loop(State=#state{parent=Parent, ref=Ref, conn_type=ConnType,
transport=Transport, protocol=Protocol, opts=Opts,
- max_conns=MaxConns}, CurConns, NbChildren, Sleepers) ->
+ ack_timeout=AckTimeout, max_conns=MaxConns},
+ CurConns, NbChildren, Sleepers) ->
receive
{?MODULE, start_protocol, To, Socket} ->
case Protocol:start_link(Ref, Socket, Transport, Opts) of
{ok, Pid} ->
Transport:controlling_process(Socket, Pid),
- Pid ! {shoot, Ref},
+ Pid ! {shoot, Ref, Transport, Socket, AckTimeout},
put(Pid, true),
CurConns2 = CurConns + 1,
if CurConns2 < MaxConns ->