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

[RailsClub Moscow 2016] AnyCable

[RailsClub Moscow 2016] AnyCable

ActionCable is one of the most attractive new features in Rails 5. WebSockets out of the box – sounds pretty cool, doesn't it? Or maybe the proper question is "Is it really so good?"

Consider pros: easy configuration, application logic access through channels, JS client that just works.

And what about pros?

In my opinion, there is the only one problem (despite bugs, of course) – Ruby itself, the language that I'm fond of, but I'm not considering it as a technology for writing scalable concurrent applications. At least, not yet.

That's why I'm not going to use ActionCable in production.

Can we find a way out? Can we use the good parts of ActionCable with the power of Erlang/Golang/Whatever-you-like altogether?

My answer is "Yes, we can". And here comes AnyCable.

This presentation demonstrates the proof of concept, shows some benchmarks and shares my thoughts about the future of the idea.

Video [RU]: https://www.youtube.com/watch?v=-k7GQKuBevY
Github: https://github.com/anycable/anycable

52cc8a838bf44a589d2572833b2dd1b9?s=128

Vladimir Dementyev

October 22, 2016
Tweet

Transcript

  1. AnyCable Vladimir Dementyev, Evil Martians

  2. RailsConf 2016

  3. RailsConf 2016

  4. Preface • In my opinion, the idea of ActionCable is

    great; web sockets the Rails way. But I'm pretty sad about implementation • AnyCable is not an alternative; it's an enhancement (or re-design)
  5. Outline • What is ActionCable? • ActionCable: the good parts

    • ActionCable: the bad parts • How does AnyCable eliminate the bad parts without losing the good parts
  6. What is ActionCable?

  7. ActionCable RailsConf 2015 April, 21

  8. ActionCable RailsConf 2015

  9. TwitterCable

  10. TwitterCable

  11. TwitterCable jumping the shark – начало конца или прохождение пика/наивысшей

    точки (популярности)
  12. TutorialCable since 2015

  13. since 2012 TutorialCable since 2015

  14. since 2014 TutorialCable since 2015

  15. CableHype

  16. CableHype

  17. ActionCable in a Nutshell Server Client WebSocket Client WebSocket

  18. ActionCable in a Nutshell Server Client WebSocket Client WebSocket stream

    C Broadcaster stream B stream A stream B
  19. ActionCable in a Nutshell Server Client WebSocket Client WebSocket stream

    C Broadcaster stream B stream A stream B channel X channel Y channel Z
  20. ActionCable Channel

  21. ActionCable: the good parts

  22. ActionCable: Pros • Easy configuration

  23. Opt-In Cable

  24. Opt-In Cable

  25. ActionCable: Pros • Easy configuration • Application logic access through

    channels
  26. ActionCable: Pros • Easy configuration • Application logic access through

    channels • JavaScript client that just works
  27. ActionCable: Pros • Easy configuration • Application logic access through

    channels • JavaScript client that just works
  28. ActionCable: Pros • Easy configuration • Application logic access through

    channels • JavaScript client that just works
  29. ActionCable: the bad parts

  30. MemoryCable

  31. MemoryCable

  32. MemoryCable 20k connections MB 0 375 750 1 125 1

    500 1 875 2 250 2 625 3 000 Go Erlang ActionCable (2x) ActionCable (16x)
  33. PollingCable

  34. PollingCable

  35. ScarySocket

  36. Performance?

  37. Performance?

  38. WebSocket Shootout

  39. WebSocket Shootout Client Server broadcast to all message send message

    back
  40. WebSocket 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 ActionCable Running on AWS EC2 c3.4xlarge (16 vCPU, 30 GiB RAM)
  41. WebSocket Shootout

  42. WayOutCable

  43. LazyCable

  44. PhoenixCable

  45. PhoenixCable

  46. AnyCable

  47. AnyCable

  48. Server Channels Streams Client (Protocol) ActionCable AnyCable

  49. Server Channels Streams Client (Protocol) ActionCable AnyCable

  50. Server Channels Streams Client (Protocol) Separation of Concerns ActionCable AnyCable

  51. Application AnyCable Client WebSocket DB

  52. Application AnyCable Client WebSocket Nginx HTTP DB

  53. Application AnyCable Client WebSocket Nginx HTTP DB ?

  54. gRPC

  55. gRPC = Google RPC

  56. gRPC = Universal RPC Framework

  57. gRPC = protobuf + HTTP/2

  58. AnyCable gRPC

  59. Application WS Client WebSocket DB HTTP/2 RPC

  60. Application WS Client WebSocket DB HTTP/2 RPC Rails App +

    gRPC Server
  61. Application WS Client WebSocket DB HTTP/2 RPC Redis Rails App

    + gRPC Server
  62. HowTo

  63. HowTo

  64. AnyCable Server anycable-go erlycable

  65. HowTo

  66. HowTo # Gemfile gem 'anycable', group: :production

  67. HowTo # Gemfile gem 'anycable', group: :production # generate server

    script rails generate anycable
  68. HowTo # Gemfile gem 'anycable', group: :production # generate server

    script rails generate anycable # run gRPC server ./bin/anycable
  69. HowTo # Gemfile gem 'anycable', group: :production # generate server

    script rails generate anycable # run gRPC server ./bin/anycable # run websocket server anycable-go -addr=0.0.0.0:3334
  70. HowTo # Gemfile gem 'anycable', group: :production # generate server

    script rails generate anycable # run gRPC server ./bin/anycable # run websocket server anycable-go -addr=0.0.0.0:3334 # config/application.rb config.action_cable.url = 'ws://0.0.0.0:3334'
  71. Compatibility Feature Status Connection Identifiers + Connection Request (cookies, params)

    + Disconnect Handling coming soon Subscribe to channels + Parameterized subscriptions + Unsubscribe from channels + Subscription Instance Variables - Performing Channel Actions + Streaming + Custom stream callbacks - Broadcasting +
  72. Compatibility Feature Status Connection Identifiers + Connection Request (cookies, params)

    + Disconnect Handling coming soon Subscribe to channels + Parameterized subscriptions + Unsubscribe from channels + Subscription Instance Variables - Performing Channel Actions + Streaming + Custom stream callbacks - Broadcasting +
  73. ActionCable Channel

  74. WebSocket 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 ActionCable Patch 1 Running on AWS EC2 c3.4xlarge (16 vCPU, 30 GiB RAM)
  75. WhereTo github.com/anycable

  76. DisclaimerCable AnyCable have not been used in production yet…

  77. DisclaimerCable AnyCable have not been used in production yet… …because

    I have not been working with Rails 5 in production at all
  78. MemoryCable 20k connections MB 0 500 1 000 1 500

    2 000 2 500 3 000 3 500 4 000 Go Erlang anycable-go erlycable ActionCable
  79. ActionCable CPU

  80. ActionCable CPU

  81. anycable-go CPU

  82. anycable-go CPU

  83. erlycable CPU

  84. erlycable CPU

  85. WebSocket 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 ActionCable anycable-go erlycable Running on AWS EC2 c3.4xlarge (16 vCPU, 30 GiB RAM)
  86. FutureCable

  87. FutureCable - Shared Socket Server

  88. Shared Server Application A AnyCable Client WebSocket Application B Client

    WebSocket
  89. FutureCable

  90. FutureCable - Shared Socket Server - Transport Support (Fallbacks)

  91. FutureCable - Shared Socket Server - Transport Support (Fallbacks) -

    Enhanced Analytics
  92. FutureCable - Shared Socket Server - Transport Support (Fallbacks) -

    Enhanced Analytics - ActionCable PaaS
  93. cult of martians.com

  94. Let's make ActionCable suck less! Vladimir Dementyev evilmartians.com @palkan @palkan_tula