max_conns() = non_neg_integer() | infinity
ranch - Socket acceptor pool
The module ranch
provides functions for starting and manipulating Ranch listeners.
Start/stop:
Suspend/resume:
Connections:
Options:
Introspection:
max_conns() = non_neg_integer() | infinity
Maximum number of connections allowed per connection supervisor.
This is a soft limit. The actual number of connections might be slightly above the limit due to concurrency when accepting new connections. Some connections may also be removed from this count explicitly by the user code.
opts() = any() | transport_opts(any())
Transport or socket options.
ref() = any()
Unique name used to refer to a listener.
transport_opts(SocketOpts) = #{ alarms => #{ term() => #{ type := num_connections, threshold := non_neg_integer(), callback := fun((ref(), term(), pid(), [pid()]) -> any()), cooldown => non_neg_integer() } }, connection_type => worker | supervisor, handshake_timeout => timeout(), max_connections => max_conns(), logger => module(), num_acceptors => pos_integer(), num_conns_sups => pos_integer(), post_listen_callback => fun((term()) -> ok | {error, term()}), shutdown => timeout() | brutal_kill, socket_opts => SocketOpts }
Transport options.
The transport options are a combination of Ranch-specific options and transport-specific socket options.
None of the options are required.
Alarms to call a function when the number of connections tracked by one connection supervisor reaches or exceeds a defined threshold.
The map keys are the alarm names, which can be any term
. The associated values are the respective alarm options, again in a map with the following keys:
Must be set to num_connections
.
Threshold value, which must be a non_neg_integer
. When the number of connections tracked by a single connection supervisor reaches or exceeds this value, The alarm will trigger and call the function defined in the callback
key (see below).
The alarm function, which takes the listener name, the alarm name, the pid of the connection supervisor and a list of the pids of all connection processes under that supervisor as arguments. The return value is ignored.
The minimum time after which the alarm can be triggered again, in milliseconds.
Type of process that will handle the connection.
Maximum allowed time for the ranch:handshake/1,2
call to finish.
The module that will be used to write log messages.
Maximum number of active connections per connection supervisor. Soft limit. Use infinity
to disable the limit entirely.
Number of processes that accept connections.
Number of processes that supervise connection processes. If not specified, defaults to be equal to num_acceptors
.
A function which will be called after a listen socket has been successfully created, with the socket as argument. It can be used to perform any necessary setup steps on the socket.
If the callback function returns ok
, the listener will start accepting connections on the socket. If it returns {error, Reason}
, the listener will fail to start.
Maximum allowed time for children to stop on listener shutdown.
Socket options to be used by Transport:listen/1
. Please refer to the documentation of the transport module you are using for more details.
post_listen_callback
transport option was added.
transport_opts(SocketOpts)
was added.
ranch:accept_ack/1
was removed in favor of ranch:handshake(3).
max_connections
is now per connection supervisor.
num_conns_sup
option was added.
socket
option was removed.
logger
option is no longer experimental. It now defaults to logger
instead of error_logger
.
opt()
type was removed.
logger
option was added.
opt()
type was deprecated in favor of the new opts()
type.
Donate to Loïc Hoguin because his work on Cowboy, Ranch, Gun and Erlang.mk is fantastic:
Recurring payment options are also available via GitHub Sponsors. These funds are used to cover the recurring expenses like food, dedicated servers or domain names.