migrating_from_1.7.asciidoc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 Prometheus
  14. collector as a separate project as well as a Grafana
  15. dashboard.
  16. Ranch 2.0 is compatible with Erlang/OTP 21.0 onward. Support
  17. for Erlang/OTP 19 and 20 has been removed.
  18. === Features added
  19. * The `num_conns_sup` option has been added. It allows
  20. configuring the number of connection supervisors. It
  21. now defaults to `num_accceptors`. The old behavior can
  22. be obtained by setting this value to 1.
  23. * The `logger` option is no longer experimental. It now
  24. defaults to `logger` instead of `error_logger`.
  25. * UNIX domain sockets are now supported.
  26. * The active N socket option is now supported. It requires
  27. Erlang/OTP 21.3 or above for TLS, however.
  28. * Embedded listeners are now failing in a predictable
  29. manner when `ranch_server` goes down. It is no longer
  30. necessary to embed `ranch_sup` and the recommendation
  31. is now to just start Ranch normally when using embedded
  32. listeners.
  33. === Experimental features added
  34. * The experimental `num_listen_sockets` option has been
  35. added. It allows opening more than one listening socket
  36. per listener. It can only be used alongside the Linux
  37. `SO_REUSEPORT` socket option or equivalent. It allows
  38. working around a bottleneck in the kernel and maximizes
  39. resource usage, leading to increased rates for accepting
  40. new connections.
  41. === Features removed
  42. * The `socket` option was removed. A more viable solution
  43. is to define a custom transport module that returns a fresh
  44. socket when `Transport:listen/1` is called.
  45. === Changed behaviors
  46. * The callback function `Transport:listen/1` and its
  47. implementations in `ranch_tcp` and `ranch_ssl` have changed
  48. to accept a map of transport options instead of only
  49. socket options.
  50. * The callback function `Transport:messages/0` return value
  51. now include the tag used for passive messages.
  52. * The `Socket` argument was removed from `Protocol:start_link/3`.
  53. The socket must now be obtained by calling `ranch:handshake/1,2`.
  54. === Changed functions
  55. * The `NumAcceptors` argument was removed from `ranch:start_listener/5``
  56. and `ranch:child_spec/5` and moved to the transport options.
  57. * Ranch options can no longer be passed along with socket options
  58. as a proplist. The only forms allowed are now the `ranch:opts()`
  59. map or only socket options as-is. Individual transport options
  60. are now validated as well. The `ranch:opts()` map must
  61. be used when socket options also use a map. This applies to the
  62. `ranch:start_listener/5`, `ranch:child_spec/5` and
  63. `ranch:set_transport_options/2` functions.
  64. * The function `ranch:info/1,2` now returns a map containing
  65. each listener's information rather than a list of key/values.
  66. The key `num_acceptors` was removed as it can be found in the
  67. transport options.
  68. * The function `ranch:set_transport_options/2` no longer requires
  69. the listener to be suspended. Which options apply immediately,
  70. on suspend/resume or on restart has been documented. Some work
  71. has also been done to make these option changes more predictable.
  72. === Removed functions
  73. * The function `ranch:accept_ack/1` has been removed in favor
  74. of `ranch:handshake/1,2`.
  75. === Bugs fixed
  76. * Repeatedly calling `ranch:remove_connection/1` from a connection
  77. process would crash the respective connection supervisor. This has
  78. now been fixed.
  79. * When a connection process was failing to start, the socket was
  80. not closed and this lead to leaking sockets. This is now corrected.
  81. === Other changes
  82. * Connection draining has now been documented in the guide
  83. following user feedback and discussions.
  84. * Ranch is now tested against `havoc`, a chaos monkey style
  85. testing tool. Currently includes three scenarios: normal
  86. TCP and TLS listeners and embedded TCP listener. This new
  87. test suite helped uncover a misplaced `monitor/2` call
  88. added during the development of Ranch 2.0.
  89. * The supervisor for acceptors and the parent supervisor for
  90. connection supervisors now have an adaptive restart
  91. intensity limit set to `1 + ceil(math:log2(NumChildren))`
  92. to allow room for errors when they have many children.
  93. * Ranch now uses stricter compiler options. Missing function
  94. specs were added to internal modules.
  95. * Ranch now calls `ssl:handshake/1,2,3` instead of
  96. `ssl:ssl_accept/1,2`.
  97. * The `ranch_ssl:ssl_opt()` type has been updated to conform
  98. with Erlang/OTP 22.0.