+ All Categories
Home > Documents > Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a...

Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a...

Date post: 06-Aug-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
42
Elixir the only sane choice in an insane world
Transcript
Page 1: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Elixir

the only sane choice in an insane world

Page 2: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Brian Cardarella

CEO of DockYard

Page 3: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

why the insanity?

Page 4: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”
Page 5: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”
Page 6: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

“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

Page 7: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

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

Page 8: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

clean, familiar syntax

mature tooling

built-in unit testing

meta-programming

built-in documentation

pipes

Phoenix

New for Elixir

Page 9: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Pattern Matching

a = 1

Page 10: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Pattern Matching

a = 11 = a

Page 11: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Pattern Matching

[1] = [1]

Page 12: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Pattern Matching

[a] = [1]

a = 1

Page 13: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Pattern Matching

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

a = 1b = 2c = 3

Page 14: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Pattern Matching

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

a = 1b = 2c = 3

Page 15: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Pattern Matching

def foo(1) do …

def foo(2) do …

foo(2)

Page 16: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Pipes

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

Page 17: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Pipes

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

Page 18: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Pipes

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

Page 19: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Scalability

Page 20: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

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

Page 21: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Can Elixir Scale?

Page 22: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

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

Page 23: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

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

Page 24: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Other Examples

• What’s App

• Ejabberd

• Riot Games

Page 25: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

GenServer

Page 26: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”
Page 27: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

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]} endend

Page 28: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

{:ok, pid} = GotoConf.Chicago.Stack.start_link([])=> #PID<N.NNN.N>

GenServer.cast(pid, {:push, “hello”})=> :ok

GenServer.call(pid, :pop)=> “hello”

Page 29: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Supervisors

Page 30: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

{: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

Page 31: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

credit: http://learnyousomeerlang.com/supervisors

Page 32: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”
Page 33: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

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) endend

Page 34: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

{: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: []

Page 35: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

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

Page 36: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Can a language make you happy?(opinions!)

Page 37: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”
Page 38: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”
Page 39: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”
Page 40: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Elixir is a functional programming language

Page 41: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Go learn you some Elixir!

Page 42: Elixir - The only sane choice in an insane world · “What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a “non-scary”

Brian Cardarella

CEO of DockYard

dockyard.com


Recommended