Slide 1

Slide 1 text

CABLES! CABLES! CABLES! Vladimir Dementyev

Slide 2

Slide 2 text

Vladimir Dementyev

Slide 3

Slide 3 text

! Moscow # Wrocław

Slide 4

Slide 4 text

@palkan @palkan_tula

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

EVIL MARTIANS

Slide 7

Slide 7 text

EVIL MARTIANS

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

WHY I’M HERE

Slide 10

Slide 10 text

THE TALK Action Cable pros & cons The tale of Action Cable Alternative cables for Rails and non-Rails

Slide 11

Slide 11 text

CABLES Tools for building real-time applications Intro

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

RUBY CABLES

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

THE RED RUBY PILL?

Slide 17

Slide 17 text

Part 1 RailsConf 2015 ACTION CABLE

Slide 18

Slide 18 text

IN A NUTSHELL Server Client WebSocket Client WebSocket

Slide 19

Slide 19 text

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

Slide 20

Slide 20 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 21

Slide 21 text

PROS & CONS

Slide 22

Slide 22 text

CABLE PROS Zero-configuration

Slide 23

Slide 23 text

CABLE PROS Zero-configuration Channels framework

Slide 24

Slide 24 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 25

Slide 25 text

CABLE PROS Zero-configuration Channels framework JS client that just works

Slide 26

Slide 26 text

CABLE CONS

Slide 27

Slide 27 text

CABLE CONS Lack of transport fallbacks

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

CABLE CONS Lack of transport fallbacks Memory usage

Slide 30

Slide 30 text

MEMORY 20k idle connections MB 0 200 400 600 800 1 000 1 200 1 400 1 600 Go Erlang Action Cable (8x)

Slide 31

Slide 31 text

CABLE PROS Lack of transport fallbacks Memory usage Real-time performance

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

SHOOTOUT Client Server broadcast to all message send message back

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Action Cable Low Latency Crowded Channels CABLE THEOREM

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

CPU

Slide 39

Slide 39 text

CPU

Slide 40

Slide 40 text

WHAT ABOUT REAL LIFE? I WANT TO BELIEVE IN BENCHMARKS

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

–Jon Stenqvist, CEO, Equipe “We've used all kind of push solutions over the years, the latest is faye, pusher, actioncable and X.”

Slide 45

Slide 45 text

EQUIPE “With Action Cable, we could easily have 20+ 1GB dynos running during the weekends, with every growing memory”

Slide 46

Slide 46 text

EQUIPE “After switching to X, we have 4 512MB dynos, very stable at ~200MB memory usage”

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

EQUIPE ActionCable: 20+ 2X (1GB) dynos X: 4 X (0.5GB) dynos $1000 $100

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

X = AnyCable

Slide 51

Slide 51 text

Part 3 ANYCABLE

Slide 52

Slide 52 text

ANYCABLE

Slide 53

Slide 53 text

Client (protocol) Channels Streams Server ACTION CABLE

Slide 54

Slide 54 text

Client (protocol) Channels Streams Server ACTION CABLE

Slide 55

Slide 55 text

ACTION CABLE Client (protocol) Channels Streams Server ?

Slide 56

Slide 56 text

ACTION CABLE Client (protocol) Channels Streams Server ANYCABLE

Slide 57

Slide 57 text

gRPC https://grpc.io

Slide 58

Slide 58 text

gRPC = Google RPC https://grpc.io

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

ANYCABLE Go WS

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

ANYCABLE SERVERS anycable-go erlycable

Slide 64

Slide 64 text

CPU anycable-go erlycable action_cable

Slide 65

Slide 65 text

CPU anycable-go erlycable action_cable

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

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

Slide 68

Slide 68 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 + Remote Disconnect wip (planned for 0.6.0) Custom stream callbacks - Broadcasting +

Slide 69

Slide 69 text

COMPATIBILITY https://medium.com/@leshchuk/from-action-to-any-1e8d863dd4cf

Slide 70

Slide 70 text

MORE FEATURES

Slide 71

Slide 71 text

MORE FEATURES Zero-disconnect deployment

Slide 72

Slide 72 text

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

Slide 73

Slide 73 text

DISCONNECT WebSocket Server Client Connected Client Connected App App RPC RPC

Slide 74

Slide 74 text

DISCONNECT WebSocket Server App App gRPC App App App App Envoy Proxy * https://www.envoyproxy.io

Slide 75

Slide 75 text

MORE FEATURES Zero-disconnect deployment Metrics & Stats

Slide 76

Slide 76 text

METRICS

Slide 77

Slide 77 text

http://anycable.io

Slide 78

Slide 78 text

http://anycable.io

Slide 79

Slide 79 text

github.com/anycable @any_cable ANYCABLE

Slide 80

Slide 80 text

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

Slide 81

Slide 81 text

NON-RAILS

Slide 82

Slide 82 text

github.com/palkan/litecable LITE CABLE

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

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

Slide 85

Slide 85 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 86

Slide 86 text

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

Slide 87

Slide 87 text

PLEZI CABLE

Slide 88

Slide 88 text

PLEZI Iodine–fast concurrent web server for real-time Ruby applications Rack-compatible CPU efficient Less memory than Puma/Passenger Stable?

Slide 89

Slide 89 text

plezi.io github.com/boazsegev/iodine PLEZI

Slide 90

Slide 90 text

Outro RUBY OR NOT © RailsClub Moscow

Slide 91

Slide 91 text

RUBY OR NOT WebSockets in Ruby are possible…

Slide 92

Slide 92 text

RUBY OR NOT WebSockets in Ruby are possible… …but more efficient with the help of other languages

Slide 93

Slide 93 text

ActionCable is usable… RUBY OR NOT

Slide 94

Slide 94 text

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

Slide 95

Slide 95 text

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