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

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

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

Vladimir Dementyev

March 17, 2018
Tweet

More Decks by Vladimir Dementyev

Other Decks in Programming

Transcript

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

    Action Cable Alternative cables for Rails and non-Rails
  2. IN A NUTSHELL Server Client WebSocket Client WebSocket stream C

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

    current_user.admin? end def follow(params) stream_from "questions/ #{params['id']}" end end
  4. MEMORY 20k idle connections MB 0 200 400 600 800

    1 000 1 200 1 400 1 600 Go Erlang Action Cable (8x)
  5. 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
  6. CPU

  7. CPU

  8. –Jon Stenqvist, CEO, Equipe “We've used all kind of push

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

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

    very stable at ~200MB memory usage”
  11. 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
  12. 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
  13. 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 +
  14. DISCONNECT WebSocket Server App App gRPC App App App App

    Envoy Proxy * https://www.envoyproxy.io
  15. module Chat class Channel < LiteCable ::Channel ::Base identifier :chat

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

    ::Middleware, connection_class: Chat ::Connection run proc { |_| [200, {}, ['']] } end end LITE CABLE
  17. RUBY OR NOT WebSockets in Ruby are possible… …but more

    efficient with the help of other languages