aboutsummaryrefslogtreecommitdiffstats
path: root/src/ranch_server.erl
diff options
context:
space:
mode:
authorjuhlig <[email protected]>2019-05-08 15:05:27 +0200
committerLoïc Hoguin <[email protected]>2019-05-08 16:38:47 +0200
commitd59eef5c737d0b08eb8c16c5316300e863bc935c (patch)
treebe6ab3327717f847677484edf027af9e21266045 /src/ranch_server.erl
parentaa64151149e947145728a1f1339c689f1100720e (diff)
downloadranch-d59eef5c737d0b08eb8c16c5316300e863bc935c.tar.gz
ranch-d59eef5c737d0b08eb8c16c5316300e863bc935c.tar.bz2
ranch-d59eef5c737d0b08eb8c16c5316300e863bc935c.zip
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.
Diffstat (limited to 'src/ranch_server.erl')
-rw-r--r--src/ranch_server.erl33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/ranch_server.erl b/src/ranch_server.erl
index 9116217..b77b935 100644
--- a/src/ranch_server.erl
+++ b/src/ranch_server.erl
@@ -88,22 +88,25 @@ cleanup_connections_sups(Ref) ->
ok.
-spec set_connections_sup(ranch:ref(), non_neg_integer(), pid()) -> ok.
-set_connections_sup(Ref, AcceptorId, Pid) ->
- gen_server:call(?MODULE, {set_connections_sup, Ref, AcceptorId, Pid}).
+set_connections_sup(Ref, Id, Pid) ->
+ gen_server:call(?MODULE, {set_connections_sup, Ref, Id, Pid}).
--spec get_connections_sup(ranch:ref(), non_neg_integer()) -> pid().
-get_connections_sup(Ref, AcceptorId) ->
- ets:lookup_element(?TAB, {conns_sup, Ref, AcceptorId}, 2).
+-spec get_connections_sup(ranch:ref(), pos_integer()) -> pid().
+get_connections_sup(Ref, Id) ->
+ ConnsSups = get_connections_sups(Ref),
+ NConnsSups = length(ConnsSups),
+ {_, Pid} = lists:keyfind((Id rem NConnsSups) + 1, 1, ConnsSups),
+ Pid.
--spec get_connections_sups(ranch:ref()) -> [{non_neg_integer(), pid()}].
+-spec get_connections_sups(ranch:ref()) -> [{pos_integer(), pid()}].
get_connections_sups(Ref) ->
- [{AcceptorId, Pid} ||
- [AcceptorId, Pid] <- ets:match(?TAB, {{conns_sup, Ref, '$1'}, '$2'})].
+ [{Id, Pid} ||
+ [Id, Pid] <- ets:match(?TAB, {{conns_sup, Ref, '$1'}, '$2'})].
--spec get_connections_sups() -> [{ranch:ref(), non_neg_integer(), pid()}].
+-spec get_connections_sups() -> [{ranch:ref(), pos_integer(), pid()}].
get_connections_sups() ->
- [{Ref, AcceptorId, Pid} ||
- [Ref, AcceptorId, Pid] <- ets:match(?TAB, {{conns_sup, '$1', '$2'}, '$3'})].
+ [{Ref, Id, Pid} ||
+ [Ref, Id, Pid] <- ets:match(?TAB, {{conns_sup, '$1', '$2'}, '$3'})].
-spec set_listener_sup(ranch:ref(), pid()) -> ok.
set_listener_sup(Ref, Pid) ->
@@ -165,8 +168,8 @@ count_connections(Ref) ->
%% gen_server.
init([]) ->
- ConnMonitors = [{{erlang:monitor(process, Pid), Pid}, {conns_sup, Ref, AcceptorId}} ||
- [Ref, AcceptorId, Pid] <- ets:match(?TAB, {{conns_sup, '$1', '$2'}, '$3'})],
+ ConnMonitors = [{{erlang:monitor(process, Pid), Pid}, {conns_sup, Ref, Id}} ||
+ [Ref, Id, Pid] <- ets:match(?TAB, {{conns_sup, '$1', '$2'}, '$3'})],
ListenerMonitors = [{{erlang:monitor(process, Pid), Pid}, {listener_sup, Ref}} ||
[Ref, Pid] <- ets:match(?TAB, {{listener_sup, '$1'}, '$2'})],
{ok, #state{monitors=ConnMonitors++ListenerMonitors}}.
@@ -177,8 +180,8 @@ handle_call({set_new_listener_opts, Ref, MaxConns, TransOpts, ProtoOpts, StartAr
ets:insert_new(?TAB, {{proto_opts, Ref}, ProtoOpts}),
ets:insert_new(?TAB, {{listener_start_args, Ref}, StartArgs}),
{reply, ok, State};
-handle_call({set_connections_sup, Ref, AcceptorId, Pid}, _, State0) ->
- State = set_monitored_process({conns_sup, Ref, AcceptorId}, Pid, State0),
+handle_call({set_connections_sup, Ref, Id, Pid}, _, State0) ->
+ State = set_monitored_process({conns_sup, Ref, Id}, Pid, State0),
{reply, ok, State};
handle_call({set_listener_sup, Ref, Pid}, _, State0) ->
State = set_monitored_process({listener_sup, Ref}, Pid, State0),