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

[RubyConf Malaysia 2017] AnyCable

[RubyConf Malaysia 2017] AnyCable

Vladimir Dementyev

October 12, 2017
Tweet

More Decks by Vladimir Dementyev

Other Decks in Programming

Transcript

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

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

    current_user.admin? end def follow(params) stream_from "questions/ #{params['id']}" end end
  3. 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)
  4. 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)
  5. CPU

  6. 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
  7. 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)
  8. 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'
  9. 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 +
  10. module Chat class Channel < LiteCable ::Channel ::Base identifier :chat

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

    ::Middleware, connection_class: Chat ::Connection run proc { |_| [200, {}, ['']] } end end LITE CABLE
  12. 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