migrating_from_1.7.asciidoc 6.1 KB

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