[Wroc_Love.rb 2018] Cables! Cables! Cables!

[Wroc_Love.rb 2018] Cables! Cables! Cables!

52cc8a838bf44a589d2572833b2dd1b9?s=128

Vlad Dem

March 17, 2018
Tweet

Transcript

  1. CABLES! CABLES! CABLES! Vladimir Dementyev

  2. Vladimir Dementyev

  3. ! Moscow # Wrocław

  4. @palkan @palkan_tula

  5. None
  6. EVIL MARTIANS

  7. EVIL MARTIANS

  8. None
  9. WHY I’M HERE

  10. THE TALK Action Cable pros & cons The tale of

    Action Cable Alternative cables for Rails and non-Rails
  11. CABLES Tools for building real-time applications Intro

  12. REAL-TIME Messaging (i.e. chats) Notifications Live updates Online games Other

  13. RUBY CABLES *based on https://www.ruby-toolbox.com/categories/HTTP_Pub_Sub

  14. RUBY CABLES

  15. © https://twitter.com/erneestoc/status/974485805770072064

  16. THE RED RUBY PILL?

  17. Part 1 RailsConf 2015 ACTION CABLE

  18. IN A NUTSHELL Server Client WebSocket Client WebSocket

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

    Broadcaster stream B stream A stream B
  20. IN A NUTSHELL Server Client WebSocket Client WebSocket stream C

    Broadcaster stream B stream A stream B channel X channel Y channel Z
  21. PROS & CONS

  22. CABLE PROS Zero-configuration

  23. CABLE PROS Zero-configuration Channels framework

  24. CHANNELS class AnswersChannel < ApplicationCable ::Channel def subscribed reject_subscription unless

    current_user.admin? end def follow(params) stream_from "questions/ #{params['id']}" end end
  25. CABLE PROS Zero-configuration Channels framework JS client that just works

  26. CABLE CONS

  27. CABLE CONS Lack of transport fallbacks

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

  29. CABLE CONS Lack of transport fallbacks Memory usage

  30. MEMORY 20k idle connections MB 0 200 400 600 800

    1 000 1 200 1 400 1 600 Go Erlang Action Cable (8x)
  31. CABLE PROS Lack of transport fallbacks Memory usage Real-time performance

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

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

  34. SHOOTOUT Broadcast RTT 0,0s 0,8s 1,6s 2,4s 3,2s 4,0s 4,8s

    5,6s 6,4s 7,2s 8,0s Number of connections 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 Go Erlang Action Cable (8x) Action Cable (2x) See https://github.com/anycable/anycable/tree/master/benchmarks
  35. None
  36. Action Cable Low Latency Crowded Channels CABLE THEOREM

  37. CABLE CONS Lack of transport fallbacks Memory usage Real-time performance

    CPU usage
  38. CPU

  39. CPU

  40. WHAT ABOUT REAL LIFE? I WANT TO BELIEVE IN BENCHMARKS

  41. Part 2 THE TALE OF ACTION CABLE © http://www.equipe.com

  42. None
  43. None
  44. –Jon Stenqvist, CEO, Equipe “We've used all kind of push

    solutions over the years, the latest is faye, pusher, actioncable and X.”
  45. EQUIPE “With Action Cable, we could easily have 20+ 1GB

    dynos running during the weekends, with every growing memory”
  46. EQUIPE “After switching to X, we have 4 512MB dynos,

    very stable at ~200MB memory usage”
  47. EQUIPE ActionCable: 20+ 2X (1GB) dynos X: 4 X (0.5GB)

    dynos
  48. EQUIPE ActionCable: 20+ 2X (1GB) dynos X: 4 X (0.5GB)

    dynos $1000 $100
  49. None
  50. X = AnyCable

  51. Part 3 ANYCABLE

  52. ANYCABLE

  53. Client (protocol) Channels Streams Server ACTION CABLE

  54. Client (protocol) Channels Streams Server ACTION CABLE

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

  56. ACTION CABLE Client (protocol) Channels Streams Server ANYCABLE

  57. gRPC https://grpc.io

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

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

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

  61. ANYCABLE Go WS

  62. None
  63. ANYCABLE SERVERS anycable-go erlycable

  64. CPU anycable-go erlycable action_cable

  65. CPU anycable-go erlycable action_cable

  66. SHOOTOUT Broadcast RTT 0,0s 0,8s 1,6s 2,4s 3,2s 4,0s 4,8s

    5,6s 6,4s 7,2s 8,0s Number of connections 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 anycable-go erlycable Action Cable (8x) See https://github.com/anycable/anycable/tree/master/benchmarks
  67. PLUG-N-PLAY gem 'anycable-rails', group: :production rails generate anycable config.action_cable.url =

    ‘ws: //example.com:3334' ./bin/anycable # => Run RPC server brew install anycable/anycable/anycable-go anycable-go -p 3334 # => Run WebSocket server
  68. 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 + Remote Disconnect wip (planned for 0.6.0) Custom stream callbacks - Broadcasting +
  69. COMPATIBILITY https://medium.com/@leshchuk/from-action-to-any-1e8d863dd4cf

  70. MORE FEATURES

  71. MORE FEATURES Zero-disconnect deployment

  72. DISCONNECT Client Re-connect & Re-subscribe Client Disconnected ActionCable ActionCable

  73. DISCONNECT WebSocket Server Client Connected Client Connected App App RPC

    RPC
  74. DISCONNECT WebSocket Server App App gRPC App App App App

    Envoy Proxy * https://www.envoyproxy.io
  75. MORE FEATURES Zero-disconnect deployment Metrics & Stats

  76. METRICS

  77. http://anycable.io

  78. http://anycable.io

  79. github.com/anycable @any_cable ANYCABLE

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

  81. NON-RAILS

  82. github.com/palkan/litecable LITE CABLE

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

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

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

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

  87. PLEZI CABLE

  88. PLEZI Iodine–fast concurrent web server for real-time Ruby applications Rack-compatible

    CPU efficient Less memory than Puma/Passenger Stable?
  89. plezi.io github.com/boazsegev/iodine PLEZI

  90. Outro RUBY OR NOT © RailsClub Moscow

  91. RUBY OR NOT WebSockets in Ruby are possible…

  92. RUBY OR NOT WebSockets in Ruby are possible… …but more

    efficient with the help of other languages
  93. ActionCable is usable… RUBY OR NOT

  94. ActionCable is usable… …and fixable/replaceable if necessary RUBY OR NOT

  95. DZIĘKUJĘ! Vladimir Dementyev anycable.io evilmartians.com @palkan @palkan_tula