From d59eef5c737d0b08eb8c16c5316300e863bc935c Mon Sep 17 00:00:00 2001 From: juhlig Date: Wed, 8 May 2019 15:05:27 +0200 Subject: Add the num_conns_sups option This new option allows configuring the number of connection supervisors. The old behavior can be obtained by setting this value to 1. A value larger than num_acceptors will result in some connection supervisors not being used as the acceptors currently only use one connection supervisor. --- src/ranch_conns_sup.erl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/ranch_conns_sup.erl') diff --git a/src/ranch_conns_sup.erl b/src/ranch_conns_sup.erl index 0ff12c6..171565e 100644 --- a/src/ranch_conns_sup.erl +++ b/src/ranch_conns_sup.erl @@ -34,7 +34,6 @@ -record(state, { parent = undefined :: pid(), ref :: ranch:ref(), - acceptor_id :: non_neg_integer(), conn_type :: conn_type(), shutdown :: shutdown(), transport = undefined :: module(), @@ -47,10 +46,10 @@ %% API. --spec start_link(ranch:ref(), non_neg_integer(), module(), module()) -> {ok, pid()}. -start_link(Ref, AcceptorId, Transport, Protocol) -> +-spec start_link(ranch:ref(), pos_integer(), module(), module()) -> {ok, pid()}. +start_link(Ref, Id, Transport, Protocol) -> proc_lib:start_link(?MODULE, init, - [self(), Ref, AcceptorId, Transport, Protocol]). + [self(), Ref, Id, Transport, Protocol]). %% We can safely assume we are on the same node as the supervisor. %% @@ -100,10 +99,10 @@ active_connections(SupPid) -> %% Supervisor internals. --spec init(pid(), ranch:ref(), non_neg_integer(), module(), module()) -> no_return(). -init(Parent, Ref, AcceptorId, Transport, Protocol) -> +-spec init(pid(), ranch:ref(), pos_integer(), module(), module()) -> no_return(). +init(Parent, Ref, Id, Transport, Protocol) -> process_flag(trap_exit, true), - ok = ranch_server:set_connections_sup(Ref, AcceptorId, self()), + ok = ranch_server:set_connections_sup(Ref, Id, self()), MaxConns = ranch_server:get_max_connections(Ref), TransOpts = ranch_server:get_transport_options(Ref), ConnType = maps:get(connection_type, TransOpts, worker), @@ -112,7 +111,7 @@ init(Parent, Ref, AcceptorId, Transport, Protocol) -> Logger = maps:get(logger, TransOpts, error_logger), ProtoOpts = ranch_server:get_protocol_options(Ref), ok = proc_lib:init_ack(Parent, {ok, self()}), - loop(#state{parent=Parent, ref=Ref, acceptor_id=AcceptorId, conn_type=ConnType, + loop(#state{parent=Parent, ref=Ref, conn_type=ConnType, shutdown=Shutdown, transport=Transport, protocol=Protocol, opts=ProtoOpts, handshake_timeout=HandshakeTimeout, max_conns=MaxConns, logger=Logger}, 0, 0, []). -- cgit v1.2.3