Slide 1

Slide 1 text

Rubyists: Have a sip of Elixir RUBYCONF | 18 Nov 2014 | SAN DEIGO BENJAMIN TAN WEI HAO @BENTANWEIHAO

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Thanks!

Slide 4

Slide 4 text

We are (always!) hiring! Thanks!

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Backstory

Slide 21

Slide 21 text

Joe Armstrong, Erlang inventor

Slide 22

Slide 22 text

Mike Williams Robert Virding Bjarne Dacker

Slide 23

Slide 23 text

Switch

Slide 24

Slide 24 text

Switch

Slide 25

Slide 25 text

Switch

Slide 26

Slide 26 text

Switch

Slide 27

Slide 27 text

Switch Switch Switch

Slide 28

Slide 28 text

Who uses Erlang

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

✔ Standard Library ✔ Tooling ✔ Metaprogramming ✔ Syntax ✔ Interoperability

Slide 31

Slide 31 text

why learn Elixir

Slide 32

Slide 32 text

TOOLS the ✔ Interactive Elixir ✔ mix build tool

Slide 33

Slide 33 text

iex

Slide 34

Slide 34 text

mix

Slide 35

Slide 35 text

PIPE Operator the *Awesome*

Slide 36

Slide 36 text

The Pipe operator

Slide 37

Slide 37 text

The Pipe operator FAIL:

Slide 38

Slide 38 text

The Pipe operator FAIL: WITH PIPES:

Slide 39

Slide 39 text

WITH PIPES: WITH PIPES + SYNTAX SUGAR!

Slide 40

Slide 40 text

WITH PIPES: WITH PIPES + SYNTAX SUGAR! Function Capture

Slide 41

Slide 41 text

A Real World EXAMPLE OUTPUT:

Slide 42

Slide 42 text

A Real World EXAMPLE

Slide 43

Slide 43 text

A Real World EXAMPLE

Slide 44

Slide 44 text

A Real World EXAMPLE

Slide 45

Slide 45 text

A Real World EXAMPLE

Slide 46

Slide 46 text

A Real World EXAMPLE

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

Concurrency model Actor

Slide 50

Slide 50 text

1. is a Process An Actor:

Slide 51

Slide 51 text

1. is a Process 2. performs a specific task An Actor:

Slide 52

Slide 52 text

1. is a Process 2. performs a specific task 3. can send and receive a message An Actor:

Slide 53

Slide 53 text

1. is a Process 2. performs a specific task 3. can send and receive a message 4. responds to specific types of messages An Actor:

Slide 54

Slide 54 text

1. is a Process 2. performs a specific task 3. can send and receive a message 4. responds to specific types of messages 5. no shared memory with other processes An Actor:

Slide 55

Slide 55 text

processes THE BASIC CONCURRENCY PRIMITIVE

Slide 56

Slide 56 text

This is a Process <0.88.0>

Slide 57

Slide 57 text

<0.88.0> This is a Process ID (pid)

Slide 58

Slide 58 text

a Process communicates <0.81.0> by sending messages <0.88.0> send <0.81.0>, “OHAI”

Slide 59

Slide 59 text

a Process communicates <0.81.0> <0.88.0> send <0.88.0>,“WASSAP” and receiving messages.

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

hello ACKERMANN A CONCURRENCY DEMO

Slide 62

Slide 62 text

The Ackermann function

Slide 63

Slide 63 text

The Ackermann function

Slide 64

Slide 64 text

The Ackermann function

Slide 65

Slide 65 text

The Ackermann function

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

.

Slide 69

Slide 69 text

Step 1: spawn a Process

Slide 70

Slide 70 text

Step 1: spawn a Process <0.61.0>

Slide 71

Slide 71 text

<0.61.0> Step 2: Send a Message send w1, {1, 2}

Slide 72

Slide 72 text

<0.61.0> Step 2: Send a Message send w1, {1, 2}

Slide 73

Slide 73 text

<0.61.0> Step 2: Send a Message send w1, {1, 2}

Slide 74

Slide 74 text

<0.61.0> Step 2: Send a Message send w1, {1, 2}

Slide 75

Slide 75 text

<0.61.0> Step 2: Send a Message send w1, “LOLWUT”

Slide 76

Slide 76 text

<0.61.0> Step 2: Send a Message send w1, “LOLWUT”

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

fault tolerance STAYING UP WHEN SH*T HAPPENS

Slide 83

Slide 83 text

Supervisor A Supervision Tree Worker

Slide 84

Slide 84 text

Supervisor A Supervision Tree hierachy Worker

Slide 85

Slide 85 text

<0.81.0> Supervisor: Detected <0.81.0> died!

Slide 86

Slide 86 text

Supervisor: Restart child! <0.88.0>

Slide 87

Slide 87 text

<0.81.0> Supervisor: Detected <0.81.0> died!

Slide 88

Slide 88 text

<0.81.0> Supervisor: Kill, kill, kill!!! <0.79.0> <0.80.0>

Slide 89

Slide 89 text

Supervisor: Restart all the children! <0.88.0> <0.89.0> <0.90.0>

Slide 90

Slide 90 text

Supervisor: Restart all the children! <0.88.0> <0.89.0> <0.90.0>

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

let’s build HTTP LOAD TESTER

Slide 94

Slide 94 text

AN Example Run of Blitzy

Slide 95

Slide 95 text

AN Example Run of Blitzy

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

The Protocol Coordinator Process n = 3 # = 0 Coordinator: I need to handle 3 workers. I have received messages from 0 workers.

Slide 98

Slide 98 text

The Protocol Coordinator Process Worker Process send ,{:ok,5000} Worker: Hey Coordinator, yahoo.com took 5000 msecs. <0.81.0> n = 3 # = 0

Slide 99

Slide 99 text

The Protocol Coordinator Process Coordinator: Ok, now I have 2 more workers to hear from. n = 3 # = 1

Slide 100

Slide 100 text

The Protocol Coordinator Process Worker Process send ,{:error, :404} Worker: Hey Coordinator, yahoo.com errored out. <0.83.0> n = 3 # = 1

Slide 101

Slide 101 text

The Protocol Coordinator Process Coordinator: Ok, now I have 1 more worker to hear from. n = 3 # = 2

Slide 102

Slide 102 text

A Serial HTTP LOAD TESTER

Slide 103

Slide 103 text

Worker Process http://www.yahoo.com |> HTTP Client

Slide 104

Slide 104 text

HTTP Client http://www.yahoo.com |> {:ok, %{status_code: 200}} {:error, %{reason: :timeout}}

Slide 105

Slide 105 text

HTTP Client http://www.yahoo.com |> {:ok, %{status_code: 200}} |> do_request/2 {:ok, 5000}

Slide 106

Slide 106 text

HTTP Client http://www.yahoo.com |> |> do_request/2 {:error, %{reason: :timeout}} {:error,:timeout}

Slide 107

Slide 107 text

HTTP Client http://www.yahoo.com |> |> do_request/2 {:error, %{reason: :404}} {:error,:unknown}

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

{:error,:timeout} {:ok, 5000} n = 3 # = 1

Slide 110

Slide 110 text

Coordinator Process

Slide 111

Slide 111 text

Coordinator Process Hi, I am Coordinator. n = 3 # = 0

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

n = 3 # = 3 BASE CASE: ! ! ! ! ! ! PROCESSED WORKERS == NUMBER OF WORKERS SAME VALUE!

Slide 114

Slide 114 text

{:ok, 5000} n = 3 # = 1

Slide 115

Slide 115 text

{:error,:timeout} n = 3 # = 1

Slide 116

Slide 116 text

Running the program

Slide 117

Slide 117 text

Running the program

Slide 118

Slide 118 text

TASKS EXECUTING COMPUTATIONS ASYNCHRONOUSLY

Slide 119

Slide 119 text

Tasks Example

Slide 120

Slide 120 text

Tasks Example

Slide 121

Slide 121 text

Running the program n = 3 # = 0

Slide 122

Slide 122 text

Running the program n = 3 # = 0 worker 1

Slide 123

Slide 123 text

Running the program n = 3 # = 1 worker 2

Slide 124

Slide 124 text

Running the program n = 3 # = 2 worker 3

Slide 125

Slide 125 text

Running the program n = 3 # = 3 RESULT: 2 succeeded, 1 failure.

Slide 126

Slide 126 text

No content

Slide 127

Slide 127 text

A Concurrent HTTP LOAD TESTER

Slide 128

Slide 128 text

Running the program

Slide 129

Slide 129 text

Serial: Concurrent:

Slide 130

Slide 130 text

Running the program n = 3 # = 0 worker 1 worker 2 worker 3

Slide 131

Slide 131 text

No content

Slide 132

Slide 132 text

A Distributed HTTP LOAD TESTER

Slide 133

Slide 133 text

Erlang Runtime System Erlang Runtime System A B C send(B,  Msg) Network

Slide 134

Slide 134 text

Erlang Runtime System Erlang Runtime System A B C send(C, Msg) Network

Slide 135

Slide 135 text

Running the program

Slide 136

Slide 136 text

Running the program MASTER

Slide 137

Slide 137 text

Running the program MASTER SLAVE 1 SLAVE 2 SLAVE 3

Slide 138

Slide 138 text

Running the program

Slide 139

Slide 139 text

Running the program

Slide 140

Slide 140 text

Running the program

Slide 141

Slide 141 text

Running the program

Slide 142

Slide 142 text

No content

Slide 143

Slide 143 text

No content

Slide 144

Slide 144 text

Running the program

Slide 145

Slide 145 text

Running the program

Slide 146

Slide 146 text

No content

Slide 147

Slide 147 text

No content

Slide 148

Slide 148 text

No content

Slide 149

Slide 149 text

Chris McCord! @chrismccord

Slide 150

Slide 150 text

http://www.elixirsips.com

Slide 151

Slide 151 text

No content

Slide 152

Slide 152 text

No content

Slide 153

Slide 153 text

http://benjamintanweihao.github.io

Slide 154

Slide 154 text

No content

Slide 155

Slide 155 text

Coming Soon-ish!

Slide 156

Slide 156 text

HEATHER MILLER for the slide designs I stole. Credits My HUI LING, for letting me ignore her. http://misterjazzz.deviantart.com/art/Constructicons-with-Prowl-C-446618997 http://thisotplife.tumblr.com http://battlefordreamisland.wikia.com/ Image Credits Network by Brennan Novak from The Noun Project Fork by Dmitry Baranovskiy from The Noun Project

Slide 157

Slide 157 text

Fin. Questions? Thank you! BENJAMIN TAN WEI HAO @BENTANWEIHAO