Ranch 2.0

2020 25 Jun

Ranch 2.0.0 has been released!

In Ranch 1.x, there is only one supervisor per Ranch listener to start and manage connection processes. Under high load (many clients rapidly connecting and/or disconnecting), the message queue of this one supervisor could become congested, leading to declining accept rates or a stalled listener.

Ranch 2.0 introduces the num_conns_sups option (defaulting to the number of acceptors), which allows the message load to be divided between the specified number of connection supervisors. This improves accept concurrency at the same time.

Another bottleneck is a possible congestion of the syn queue of a listening socket. The reason is located within the operating system's TCP/IP implementation, and on Linux the SO_REUSEPORT socket option was introduced to address it. What it boils down to is that you can have more than one socket listening on the same port, causing the sockets to be "load-balanced" when accepting connections.

Ranch 2.0 introduces the num_listen_sockets option, which allows to specify the number of listening sockets a Ranch listener should employ. Whether you can use SO_REUSEPORT at all and how to enable it depends on your operating system, though.

Other changes include proper support for local (Unix Domain) sockets, removing the restriction that a listener be suspended to change its transport options and much needed improvements to embedded listeners.

In addition we have had patches merged to Erlang/OTP to add support for active N to the ssl application (requires Erlang/OTP 21.3 or above) and fix a number of smaller issues we encountered. We have also helped detect and fix a bug in the Windows implementation of active N that greatly reduced its performance in some cases.

To ensure that everything works correctly, new tests have been written, and some existing tests were updated. Ranch is now tested against Stampede, a resilience testing tool that kills random processes and ports in the system; and against Concuerror, a model checking tool for debugging, testing and verifying concurrrent Erlang programs.

Starting from Ranch 2.0 onward, a .appup file is provided and release upgrades are tested and supported. The current plan is to test upgrades from one version to the next.

We are now providing a Prometheus collector as a separate project as well as a Grafana dashboard.

Huge thanks to Jan Uhlig for working on many of the changes and improvements that went into this release.

Ranch 2.0 requires Erlang/OTP 21 or above and is tested and supported on Linux, FreeBSD, macOS and Windows.

A complete list of changes can be found in the migration guide: Migrating from Ranch 1.7 to 2.0.

You can donate to this project via GitHub Sponsors. These funds are used to pay for additional servers for testing. We will soon add two Raspberry Pi 4 in order to have some ARM targets when testing.

As usual, feedback is appreciated, and issues or questions should be sent via Github tickets. Thanks!