Elixir the only sane choice in an insane world Brian Cardarella - - PowerPoint PPT Presentation

elixir
SMART_READER_LITE
LIVE PREVIEW

Elixir the only sane choice in an insane world Brian Cardarella - - PowerPoint PPT Presentation

Elixir the only sane choice in an insane world Brian Cardarella CEO of DockYard why the insanity? What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a non-scary syntax,


slide-1
SLIDE 1

Elixir

the only sane choice in an insane world

slide-2
SLIDE 2

Brian Cardarella

CEO of DockYard

slide-3
SLIDE 3

why the insanity?

slide-4
SLIDE 4
slide-5
SLIDE 5
slide-6
SLIDE 6

“What Elixir brings to the table is a complete different surface syntax, inspired by

  • Ruby. What you might call a

“non-scary” syntax, and a load of extra goodies.” — Joe Armstrong

http://joearms.github.io/2013/05/31/a-week-with-elixir.html

slide-7
SLIDE 7

leveraging a battle-tested 30 year old technology easily and manage distributed data via GenServer self-healing through Supervisors quickly scale to meet tomorrow’s demands pattern matching Inherited From Erlang

slide-8
SLIDE 8

clean, familiar syntax mature tooling built-in unit testing meta-programming built-in documentation pipes Phoenix New for Elixir

slide-9
SLIDE 9

Pattern Matching a = 1

slide-10
SLIDE 10

Pattern Matching a = 1 1 = a

slide-11
SLIDE 11

Pattern Matching [1] = [1]

slide-12
SLIDE 12

Pattern Matching [a] = [1] a = 1

slide-13
SLIDE 13

Pattern Matching [a, b, c] = [1, 2, 3] a = 1 b = 2 c = 3

slide-14
SLIDE 14

Pattern Matching [a, b, [c]] = [1, 2, [3]] a = 1 b = 2 c = 3

slide-15
SLIDE 15

Pattern Matching def foo(1) do
 … def foo(2) do
 … foo(2)

slide-16
SLIDE 16

Pipes foo(bar(baz(“hello world”))

slide-17
SLIDE 17

Pipes result = baz(“hello world”) result = bar(result) result = foo(result)

slide-18
SLIDE 18

Pipes “hello world” |> baz() |> bar() |> foo()

slide-19
SLIDE 19

Scalability

slide-20
SLIDE 20

Erlang VM
 (BEAM) Monitors and Schedules its own processes Can distribute processes across all available CPU cores Each process only about 1kb Each process has its own GC

slide-21
SLIDE 21

Can Elixir Scale?

slide-22
SLIDE 22

Case Study - Bleacher Report 150 AWS Instances Servers jammed up with requests Large engineering teams / app Multiple complex caching strategies

8 year old Rails app

slide-23
SLIDE 23

Case Study - Bleacher Report 1/5th the AWS instances 10ms - 30ms average response times Largest average spike: 400ms Largest outlier spike: 800ms About one engineer / app No caching

Elixir / Phoenix rewrite

slide-24
SLIDE 24

Other Examples

  • What’s App
  • Ejabberd
  • Riot Games
slide-25
SLIDE 25

GenServer

slide-26
SLIDE 26
slide-27
SLIDE 27

defmodule GotoConf.Chicago.Stack do use GenServer def start_link(state, opts \\ []) do GenServer.start_link(__MODULE__, state, opts) end def handle_call(:pop, _from, [h | t]) do {:reply, h, t} end def handle_cast({:push, h}, t) do {:noreply, [h | t]} end end

slide-28
SLIDE 28

{:ok, pid} = GotoConf.Chicago.Stack.start_link([]) => #PID<N.NNN.N> GenServer.cast(pid, {:push, “hello”}) => :ok GenServer.call(pid, :pop) => “hello”

slide-29
SLIDE 29

Supervisors

slide-30
SLIDE 30

{:ok, pid} = GotoConf.Chicago.Stack.start_link([]) => #PID<N.NNN.N> GenServer.cast(pid, {:push, “hello”}) => :ok GenServer.cast(pid, {:foo, “uh oh!”}) 15:06:35.157 [error] GenServer #PID<0.165.0> terminating ** (FunctionClauseError) no function clause matching in GotoConf.Chicago.Stack.handle_cast/2 iex:13: GotoConf.Chicago.Stack.handle_cast({:foo, 5}, []) Last message: {:"$gen_cast", {:foo, 5}} State: [] GenServer.cast(pid, {:push, “hello”}) ** (CompileError) iex:1: undefined function pid/0

slide-31
SLIDE 31

credit: http://learnyousomeerlang.com/supervisors

slide-32
SLIDE 32
slide-33
SLIDE 33

defmodule GotoConf.Chicago.Supervisor do use Supervisor def start_link do Supervisor.start_link(__MODULE__, []) end def init([]) do children = [ worker(GotoConf.Chicago.Stack, [[], [name: MyStack]]) ] supervise(children, strategy: :one_for_one) end end

slide-34
SLIDE 34

{:ok, pid} = GotoConf.Chicago.Supervisor.start_link() => #PID<N.NNN.N> GenServer.cast(MyStack, {:push, “hello”}) => :ok GenServer.call(pid, :pop) => “hello” GenServer.cast(pid, {:foo, “uh oh!”}) 15:06:35.157 [error] GenServer #PID<0.165.0> terminating ** (FunctionClauseError) no function clause matching in GotoConf.Chicago.Stack.handle_cast/2 iex:13: GotoConf.Chicago.Stack.handle_cast({:foo, 5}, []) Last message: {:"$gen_cast", {:foo, 5}} State: []

slide-35
SLIDE 35

GenServer.cast(pid, {:foo, “uh oh!”}) 15:06:35.157 [error] GenServer #PID<0.165.0> terminating ** (FunctionClauseError) no function clause matching in GotoConf.Chicago.Stack.handle_cast/2 iex:13: GotoConf.Chicago.Stack.handle_cast({:foo, 5}, []) Last message: {:"$gen_cast", {:foo, 5}} State: [] GenServer.cast(pid, {:push, “hello”}) => :ok

slide-36
SLIDE 36

Can a language make you happy?

(opinions!)

slide-37
SLIDE 37
slide-38
SLIDE 38
slide-39
SLIDE 39
slide-40
SLIDE 40

Elixir is a functional programming language

slide-41
SLIDE 41

Go learn you some Elixir!

slide-42
SLIDE 42

Brian Cardarella

CEO of DockYard

dockyard.com