Debian Codegraph @

doc/src/guide/migrating_from_1.7.asciidoc

raw
1 [appendix]
2 == Migrating from Ranch 1.7+ to Ranch 2.0
3
4 Ranch 2.0 adds support for multiple connection supervisors.
5
6 Ranch 1.x had a bottleneck because it used only a single
7 connection supervisor. This was more evident when many
8 connections were dropped at once as the supervisor couldn't
9 keep up and failed to accept new connections while cleaning
10 up the old ones. Ranch 2.0 behaves much better in this scenario
11 by default. Multiple connection supervisors also helps with
12 concurrently accepting new connections.
13
14 Ranch 2.0 also adds experimental support for opening more
15 than one listening socket on a single port.
16
17 Starting with Ranch 2.0 we are also providing a
18 https://github.com/juhlig/prometheus_ranch[Prometheus collector]
19 as a separate project as well as a
20 https://github.com/juhlig/prometheus_ranch/blob/master/dashboards/ranch-dashboard.json[Grafana dashboard].
21
22 Ranch 2.0 is compatible with Erlang/OTP 21.0 onward. Support
23 for Erlang/OTP 19 and 20 has been removed.
24
25 === Features added
26
27 * Ranch now comes with a `ranch.appup` file necessary for
28 performing release upgrades. A test suite has been added
29 to confirm release upgrades work from one tag to the next.
30 Numerous fixes were made that will also improve error recovery.
31 Release upgrades will only be supported from Ranch 2.0
32 onward.
33
34 * The `num_conns_sups` option has been added. It allows
35 configuring the number of connection supervisors. It
36 now defaults to `num_accceptors`. The old behavior can
37 be obtained by setting this value to 1.
38
39 * The `logger` option is no longer experimental. It now
40 defaults to `logger` instead of `error_logger`.
41
42 * UNIX domain sockets are now supported.
43
44 * The active N socket option is now supported. It requires
45 Erlang/OTP 21.3 or above for TLS, however.
46
47 * Embedded listeners are now failing in a predictable
48 manner when `ranch_server` goes down. It is no longer
49 necessary to embed `ranch_sup` and the recommendation
50 is now to just start Ranch normally when using embedded
51 listeners.
52
53 * Two steps handshake is now supported. This allows
54 obtaining TLS extensions and updating options before
55 resuming the handshake. The handshake can also be
56 canceled.
57
58 === Experimental features added
59
60 * The experimental `num_listen_sockets` option has been
61 added. It allows opening more than one listening socket
62 per listener. It can only be used alongside the Linux
63 `SO_REUSEPORT` socket option or equivalent. It allows
64 working around a bottleneck in the kernel and maximizes
65 resource usage, leading to increased rates for accepting
66 new connections.
67
68 === Features removed
69
70 * The `socket` option was removed. A more viable solution
71 is to define a custom transport module that returns a fresh
72 socket when `Transport:listen/1` is called.
73
74 === Changed behaviors
75
76 * The callback function `Transport:listen/1` and its
77 implementations in `ranch_tcp` and `ranch_ssl` have changed
78 to accept a map of transport options instead of only
79 socket options.
80
81 * The callback function `Transport:messages/0` return value
82 now includes the tag used for passive messages.
83
84 * The `Socket` argument was removed from `Protocol:start_link/3`.
85 The socket must now be obtained by calling `ranch:handshake/1,2`.
86
87 === Added functions
88
89 * The functions `ranch:handshake_continue/1,2` and
90 `ranch:handshake_cancel/1` can be used to perform
91 a two steps handshake. These functions may not be
92 supported by all transports.
93
94 === Changed functions
95
96 * The `NumAcceptors` argument was removed from `ranch:start_listener/5`
97 and `ranch:child_spec/5` and moved to the transport options.
98
99 * Ranch options can no longer be passed along with socket options
100 as a proplist. The only forms allowed are now the `ranch:opts()`
101 map or only socket options as-is. Individual transport options
102 are now validated as well. The `ranch:opts()` map must
103 be used when socket options also use a map. This applies to the
104 `ranch:start_listener/5`, `ranch:child_spec/5` and
105 `ranch:set_transport_options/2` functions.
106
107 * The function `ranch:info/1,2` now returns a map containing
108 each listener's information rather than a list of key/values.
109 The key `num_acceptors` was removed as it can be found in the
110 transport options.
111
112 * The function `ranch:set_transport_options/2` no longer requires
113 the listener to be suspended. Which options apply immediately,
114 on suspend/resume or on restart has been documented. Some work
115 has also been done to make these option changes more predictable.
116
117 === Removed functions
118
119 * The function `ranch:accept_ack/1` has been removed in favor
120 of `ranch:handshake/1,2`.
121
122 === Bugs fixed
123
124 * Calling `ranch:remove_connection/1` will now resume a sleeping
125 acceptor process when applicable.
126
127 * Repeatedly calling `ranch:remove_connection/1` from a connection
128 process would crash the respective connection supervisor. This has
129 now been fixed.
130
131 * When a connection process was failing to start, the socket was
132 not closed and this lead to leaking sockets. This is now corrected.
133
134 === Other changes
135
136 * Connection draining has now been documented in the guide
137 following user feedback and discussions.
138
139 * Ranch is now tested against https://concuerror.com/[Concuerror],
140 a model checking tool for debugging, testing and verifying
141 concurrent Erlang programs. Two tests have been added in this
142 release and more will follow in the future.
143
144 * Ranch is now tested against `stampede`, a chaos monkey style
145 testing tool. Currently includes three scenarios: normal
146 TCP and TLS listeners and embedded TCP listener. This new
147 test suite helped uncover a misplaced `monitor/2` call
148 added during the development of Ranch 2.0 (we were using a
149 similar tool, `havoc`, at the time of finding that issue).
150
151 * The supervisor for acceptors and the parent supervisor for
152 connection supervisors now have an adaptive restart
153 intensity limit set to `1 + ceil(math:log2(NumChildren))`
154 to allow room for errors when they have many children.
155
156 * Ranch now uses stricter compiler options. Missing function
157 specs were added to internal modules.
158
159 * Ranch now calls `ssl:handshake/1,2,3` instead of
160 `ssl:ssl_accept/1,2`.
161
162 * The `ranch_ssl:ssl_opt()` type has been updated to conform
163 with Erlang/OTP 23.0.