From 662d94a531178af005f06b0bfb4a8660b0fa023f Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 11 Jan 2013 10:31:00 -0500 Subject: Ignore tracking of requests when MaxConn = infinity There is no need to contact the server and track requests unless being asked to do so by the user. It's going to be faster and more efficient to not track anything when being told tracking doesn't matter. Whenever the max connections is set to infinity, the connections counting key is not created, or is deleted if it existed already. When using a numeric value, the connection count is created or maintained if it existed already. Moreover, trying to reduce a listener's counter while the max connection number is set to `infinity` will return 0 and avoid all counting operations as they are meaningless. --- test/acceptor_SUITE.erl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl index f5db464..8827ec8 100644 --- a/test/acceptor_SUITE.erl +++ b/test/acceptor_SUITE.erl @@ -40,6 +40,7 @@ -export([tcp_max_connections/1]). -export([tcp_max_connections_and_beyond/1]). -export([tcp_set_max_connections/1]). +-export([tcp_infinity_max_connections/1]). -export([tcp_upgrade/1]). %% supervisor. @@ -58,6 +59,7 @@ groups() -> tcp_active_echo, tcp_echo, tcp_max_connections, + tcp_infinity_max_connections, tcp_max_connections_and_beyond, tcp_set_max_connections, tcp_upgrade @@ -275,6 +277,25 @@ tcp_set_max_connections(_) -> 10 = receive_loop(connected, 1000), 20 = ranch:get_max_connections(tcp_set_max_connections). +tcp_infinity_max_connections(_) -> + {ok, _} = ranch:start_listener(tcp_infinity_max_connections, 1, + ranch_tcp, [{port, 0}, {max_connections, 10}], + notify_and_wait_protocol, [{msg, connected}, {pid, self()}]), + Port = ranch:get_port(tcp_infinity_max_connections), + %% @todo We'll probably want a more direct interface to count_connections. + ListenerPid = ranch_server:lookup_listener(tcp_infinity_max_connections), + ok = connect_loop(Port, 20, 0), + 10 = ranch_server:count_connections(ListenerPid), + 10 = receive_loop(connected, 1000), + 10 = ranch:get_max_connections(tcp_infinity_max_connections), + ranch:set_max_connections(tcp_infinity_max_connections, infinity), + 0 = ranch_server:count_connections(ListenerPid), + infinity = ranch:get_max_connections(tcp_infinity_max_connections), + ranch:set_max_connections(tcp_infinity_max_connections, 10), + 0 = ranch_server:count_connections(ListenerPid), + 10 = receive_loop(connected, 1000), + 10 = ranch_server:count_connections(ListenerPid). % count could be off + tcp_upgrade(_) -> receive after 20000 -> ok end, {ok, _} = ranch:start_listener(tcp_upgrade, 1, -- cgit v1.2.3