Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[RubyConf Malaysia 2017] AnyCable

[RubyConf Malaysia 2017] AnyCable

52cc8a838bf44a589d2572833b2dd1b9?s=128

Vladimir Dementyev

October 12, 2017
Tweet

Transcript

  1. ANYCABLE Vladimir Dementyev

  2. Vladimir Dementyev

  3. Vladimir Dementyev

  4. Vladimir Dementyev John

  5. ! Moscow # Cyberjaya

  6. @palkan @palkan_tula

  7. Rubyist Rails Commiter Ruby Commiter

  8. Rubyist Rails Commiter mRuby Commiter

  9. None
  10. EVIL MARTIANS

  11. Let’s Go!

  12. ANYCABLE

  13. Part 1 RailsConf 2015 ACTION CABLE

  14. ACTION CABLE RailsConf 2015

  15. IN A NUTSHELL Server Client WebSocket Client WebSocket stream C

    Broadcaster stream B stream A stream B channel X channel Y channel Z
  16. CHANNELS class AnswersChannel < ApplicationCable ::Channel def subscribed reject_subscription unless

    current_user.admin? end def follow(params) stream_from "questions/ #{params['id']}" end end
  17. CABLE HYPE

  18. CABLE HYPE

  19. PROS & CONS

  20. CABLE PROS Easy configuration

  21. CABLE PROS Easy configuration Channels framework

  22. CABLE PROS Easy configuration Channels framework JS client that just

    works
  23. CABLE CONS

  24. CABLE CONS Lack of transport fallbacks

  25. WEBSOCKETS http://caniuse.com/#search=websockets

  26. CABLE CONS Lack of transport fallbacks Memory usage

  27. MEMORY 20k idle connections MB 0 375 750 1 125

    1 500 1 875 2 250 2 625 3 000 Go Erlang Action Cable (2x) Action Cable (16x)
  28. CABLE PROS Lack of transport fallbacks Memory usage Performance

  29. SHOOTOUT https://hashrocket.com/blog/posts/websocket-shootout

  30. SHOOTOUT Client Server broadcast to all message send message back

  31. SHOOTOUT Broadcast RTT 0s 1s 2s 3s 4s 5s 6s

    7s 8s 9s 10s Number of connections 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 Go Erlang Action Cable (2x) Action Cable (16x) Running on AWS EC2 c3.4xlarge (16 vCPU, 30 GiB RAM)
  32. None
  33. Action Cable Low Latency Crowded Channels CABLE THEOREM

  34. CABLE CONS Lack of transport fallbacks Memory usage Performance CPU

    usage
  35. CPU

  36. IS THERE A WAY OUT?

  37. LAZY WAY

  38. Part 2 ANYCABLE

  39. Client (protocol) Channels Streams Server ACTION CABLE

  40. Client (protocol) Channels Streams Server ACTION CABLE

  41. ACTION CABLE Client (protocol) Channels Streams Server ?

  42. INITIAL IDEA ?

  43. gRPC https://grpc.io

  44. gRPC = Google RPC https://grpc.io

  45. gRPC = universal RPC framework https://grpc.io

  46. gRPC = HTTP/2 + protobuf https://grpc.io

  47. https://grpc.io

  48. Erlang? https://grpc.io OOPS!

  49. ANYCABLE Go WS

  50. None
  51. ANYCABLE SERVERS anycable-go erlycable

  52. 20k idle connections MB 0 500 1 000 1 500

    2 000 2 500 3 000 3 500 4 000 anycable-go erlycable Action Cable (16x) MEMORY
  53. ANYCABLE-GO

  54. ERLYCABLE

  55. ACTION CABLE

  56. SHOOTOUT Broadcast RTT 0s 1s 2s 3s 4s 5s 6s

    7s 8s 9s 10s Number of connections 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 anycable-go erlycable Action Cable (2x) Action Cable (16x) Running on AWS EC2 c3.4xlarge (16 vCPU, 30 GiB RAM)
  57. None
  58. HOW TO gem 'anycable-rails', group: :production rails generate anycable ./bin/anycable

    # => Run RPC server brew install anycable/anycable/anycable-go anycable-go -addr=0.0.0.0:3334 config.action_cable.url = 'ws: //0.0.0.0:3334'
  59. COMPATIBILITY Feature Status Connection Identifiers + Connection Request (cookies, params)

    + Disconnect Handling + Subscribe to channels + Parameterized subscriptions + Unsubscribe from channels + Subscription Instance Variables - Performing Channel Actions + Streaming + Custom stream callbacks - Broadcasting +
  60. http://anycable.io

  61. github.com/anycable @any_cable ANYCABLE

  62. Part 3 BEYOND RAILS © Призрачная Колыма

  63. NON-RAILS

  64. Rails-free Action Cable No deps (even ActiveSupport) Compatible with AnyCable

    Compatible with Action Cable JS LITE CABLE
  65. module Chat class Channel < LiteCable ::Channel ::Base identifier :chat

    def subscribed stream_from "chat_ #{chat_id}" end end end LITE CABLE
  66. run Rack ::Builder.new do map '/cable' do use LiteCable ::Server

    ::Middleware, connection_class: Chat ::Connection run proc { |_| [200, {}, ['']] } end end LITE CABLE
  67. HANAMI CABLE http://gabrielmalakias.com.br/ruby/hanami/iot/2017/05/26/websockets-connecting-litecable-to-hanami.html

  68. github.com/palkan/litecable LITE CABLE

  69. Part 4 FUTURE

  70. CABLE CONS Lack of transport fallbacks Memory & CPU usage

    Performance Consistency
  71. CABLE CONS Lack of transport fallbacks Memory & CPU usage

    Performance Consistency
  72. CONSISTENCY

  73. HISTORY STREAM class ChatChannel < ApplicationCable ::Channel def subscribed stream_from

    "chat_ #{id}", history: { time: 5.minutes } end end class ChatChannel < ApplicationCable ::Channel def subscribed stream_from "chat_ #{chat_id}", history: { size: 100 } end end
  74. MORE FEATURES Disconnect-less deployment

  75. DISCONNECT WebSocket Server Client WebSocket Client WebSocket App App RPC

    RPC
  76. MORE FEATURES Disconnect-less deployment Data compression (MsgPack?) Better instrumentation (WIP)

    Sharing WebSocket server between applications
  77. THANK YOU! anycable.io evilmartians.com @palkan @palkan_tula Vladimir Dementyev