Slide 1

Slide 1 text

ANYCABLE Vladimir Dementyev

Slide 2

Slide 2 text

Vladimir Dementyev

Slide 3

Slide 3 text

Vladimir Dementyev

Slide 4

Slide 4 text

Vladimir Dementyev John

Slide 5

Slide 5 text

! Moscow # Cyberjaya

Slide 6

Slide 6 text

@palkan @palkan_tula

Slide 7

Slide 7 text

Rubyist Rails Commiter Ruby Commiter

Slide 8

Slide 8 text

Rubyist Rails Commiter mRuby Commiter

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

EVIL MARTIANS

Slide 11

Slide 11 text

Let’s Go!

Slide 12

Slide 12 text

ANYCABLE

Slide 13

Slide 13 text

Part 1 RailsConf 2015 ACTION CABLE

Slide 14

Slide 14 text

ACTION CABLE RailsConf 2015

Slide 15

Slide 15 text

IN A NUTSHELL Server Client WebSocket Client WebSocket stream C Broadcaster stream B stream A stream B channel X channel Y channel Z

Slide 16

Slide 16 text

CHANNELS class AnswersChannel < ApplicationCable ::Channel def subscribed reject_subscription unless current_user.admin? end def follow(params) stream_from "questions/ #{params['id']}" end end

Slide 17

Slide 17 text

CABLE HYPE

Slide 18

Slide 18 text

CABLE HYPE

Slide 19

Slide 19 text

PROS & CONS

Slide 20

Slide 20 text

CABLE PROS Easy configuration

Slide 21

Slide 21 text

CABLE PROS Easy configuration Channels framework

Slide 22

Slide 22 text

CABLE PROS Easy configuration Channels framework JS client that just works

Slide 23

Slide 23 text

CABLE CONS

Slide 24

Slide 24 text

CABLE CONS Lack of transport fallbacks

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

CABLE CONS Lack of transport fallbacks Memory usage

Slide 27

Slide 27 text

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)

Slide 28

Slide 28 text

CABLE PROS Lack of transport fallbacks Memory usage Performance

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

SHOOTOUT Client Server broadcast to all message send message back

Slide 31

Slide 31 text

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)

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Action Cable Low Latency Crowded Channels CABLE THEOREM

Slide 34

Slide 34 text

CABLE CONS Lack of transport fallbacks Memory usage Performance CPU usage

Slide 35

Slide 35 text

CPU

Slide 36

Slide 36 text

IS THERE A WAY OUT?

Slide 37

Slide 37 text

LAZY WAY

Slide 38

Slide 38 text

Part 2 ANYCABLE

Slide 39

Slide 39 text

Client (protocol) Channels Streams Server ACTION CABLE

Slide 40

Slide 40 text

Client (protocol) Channels Streams Server ACTION CABLE

Slide 41

Slide 41 text

ACTION CABLE Client (protocol) Channels Streams Server ?

Slide 42

Slide 42 text

INITIAL IDEA ?

Slide 43

Slide 43 text

gRPC https://grpc.io

Slide 44

Slide 44 text

gRPC = Google RPC https://grpc.io

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

https://grpc.io

Slide 48

Slide 48 text

Erlang? https://grpc.io OOPS!

Slide 49

Slide 49 text

ANYCABLE Go WS

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

ANYCABLE SERVERS anycable-go erlycable

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

ANYCABLE-GO

Slide 54

Slide 54 text

ERLYCABLE

Slide 55

Slide 55 text

ACTION CABLE

Slide 56

Slide 56 text

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)

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

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'

Slide 59

Slide 59 text

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 +

Slide 60

Slide 60 text

http://anycable.io

Slide 61

Slide 61 text

github.com/anycable @any_cable ANYCABLE

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

NON-RAILS

Slide 64

Slide 64 text

Rails-free Action Cable No deps (even ActiveSupport) Compatible with AnyCable Compatible with Action Cable JS LITE CABLE

Slide 65

Slide 65 text

module Chat class Channel < LiteCable ::Channel ::Base identifier :chat def subscribed stream_from "chat_ #{chat_id}" end end end LITE CABLE

Slide 66

Slide 66 text

run Rack ::Builder.new do map '/cable' do use LiteCable ::Server ::Middleware, connection_class: Chat ::Connection run proc { |_| [200, {}, ['']] } end end LITE CABLE

Slide 67

Slide 67 text

HANAMI CABLE http://gabrielmalakias.com.br/ruby/hanami/iot/2017/05/26/websockets-connecting-litecable-to-hanami.html

Slide 68

Slide 68 text

github.com/palkan/litecable LITE CABLE

Slide 69

Slide 69 text

Part 4 FUTURE

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

CONSISTENCY

Slide 73

Slide 73 text

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

Slide 74

Slide 74 text

MORE FEATURES Disconnect-less deployment

Slide 75

Slide 75 text

DISCONNECT WebSocket Server Client WebSocket Client WebSocket App App RPC RPC

Slide 76

Slide 76 text

MORE FEATURES Disconnect-less deployment Data compression (MsgPack?) Better instrumentation (WIP) Sharing WebSocket server between applications

Slide 77

Slide 77 text

THANK YOU! anycable.io evilmartians.com @palkan @palkan_tula Vladimir Dementyev