SlideShare a Scribd company logo
Repeating History…
on purpose…
with Elixir
Barry Jones
Who am I?
• Developer since 98
• Used to run Brightball
– Contract programming business using PHP
– 2008 – 2011
• R.I.P. Code one out for my homies
• PHP, Java, Perl, Python, Ruby, Groovy, Go
– Elixir
• And lots of databases #postgresql
So…another language…?
Rules for learning a language
– Must solve a problem
– Problem not addressed by
current stack
– “Fast” is not a purpose
• Lots of things are fast
– Should be the best solution
• If it’s not, I’d rather learn the
one that is…
I hate new languages
Yeah. Surprise. 
So why the other languages?
• PHP
– Needed to build a site
– Clemson’s options were PHP / Perl
– Perl was badly supported
• Java
– Clemson CPSC
– Also…jobs are good
• Groovy
– Java environment
– Wanted to be productive
• Go
– Great concurrency
– Relatively simple
– Fast compilation
– Portability
– Solves some bloat problems
• Perl
– Sysadmin work
– Installed on all *nix derivatives
• including very old
– Best at text parsing
• Python
– Employer required it
• Ruby
– Incredible productivity
– Library ecosystem
– Monkey patching
– Rails
– Focus on dev efficiency
SO WHY ELIXIR?
I wondered the same thing
"Those who cannot remember the past are
condemned to repeat it."
- George Santayana
"What has been is what will be, and what has
been done is what will be done, and there is
nothing new under the sun."
- Solomon
Elixir isn’t new
• It’s more productive Erlang
• Compiles down to the BEAM (Erlang VM)
• Erlang was born in 1986 (Linux was 1991)
• Erlang/OTP is on version 19
• Erlang libraries work directly in Elixir
– And vice versa
Processor POWER!!!
• Industry focus used to be on Mhz/Ghz
• Growth was steady…but then stalled
• Industry shifted to multicore / concurrency
and trying to put it in their languages
• Lookup “Beowulf Cluster” to see how foreign
“parallel” was at the time
Funny thing…
“Any sufficiently complicated concurrent
program in another language contains an ad hoc
informally-specified bug-ridden slow
implementation of half of Erlang.”
- Robert Virding
Erlang view of the World
• Everything is a process.
• Processes are strongly isolated.
• Process creation and destruction is a lightweight operation.
• Message passing is the only way for processes to interact.
• Processes have unique names.
• If you know the name of a process you can send it a
message.
• Processes share no resources.
• Error handling is non-local.
• Processes do what they are supposed to do or fail.
Message Passing
• Process isolation and message passing
• Passing between threads, cores or machines is
transparent
• Microservice concept…but everywhere and
not terrible
“If Java is the right one to run anywhere, then
Erlang is the right one to run forever.”
– Joe Armstrong
What’s the big deal with Elixir?
• Ruby-like focus on developer productivity
• Functional programming made simple
• Embedded database
• Compiles down to code to run on the BEAM Virtual Machine
• BEAM/OTP is what Erlang runs on
• Erlang/BEAM is the best existing language for concurrency, consistency
and fault tolerance, hot code swapping
– Single Processor
– Multi Processor
– Distributed Multi Machine Cluster
• Erlang does not focus on developer productivity
– Writing Erlang kinda sucks... 
• #1 Problem in Ruby is concurrency model
– Cannot be fixed. It’s the way the language works.
– Enables great things but also causes limitations
So what does that mean?
Standard Web App OTP
What’s the big deal?
• Facebook paid $22 billion for WhatsApp
• WhatsApp had $10 million in revenue
• What was the big deal?
– Erlang/OTP
– 2 million users / server
– No central relay point
– Scales horizontally
– Deploys w/o disconnect
AND HOW DOES ALL THIS WORK?
Why should you care?
Other languages
• Boot up
• Memory is shared
– Where leaks come from
– Changing shared memory requires a mutex lock
• Garbage collector periodically runs
– Pause entire stack
• Requests run in threads in the same process
– Threads are cooperatively scheduled
• Deployment means shutting down current code,
starting new code
Erlang/Elixir/OTP
• No memory is shared
• Data structures are immutable
• Each Erlang process (basically a light thread)
has its own HEAP
– Reclaimed on completion
• Code can be hot deployed
– New code runs next time it’s accessed (existing
code keeps running)
• Processes are prescheduled
Sound familiar?
• Difference is size of the allocations
– An Erlang process is 0.5 kb
– A Go goroutine is 2 kb (version 1.4)
– A Java thread is 1024 kb on 64 bit VM
– PHP request varies by how much is loaded
• Laravel averages 7-12mb / request
Programming Elixir, Chapter 15
Laptop w/ 4 cores and 4gb of RAM counting concurrently
1,000,000 processes =
• 0.48 gb in Elixir
• 1.91 gb in Golang (go routines)
• 977 gb in Java (threads)
• 6,836 gb in PHP (Laravel requests)
LET’S GET STARTED
wait.…we haven’t started yet?
Quick History
• Linux was created in 1991
• Erlang was created in 1987 by Ericson
– Powers about half of global telecom
– Needed distributed, fault tolerant system
– Deploy updates without interrupting existing calls
– OTP = Open Telecom Protocol
– Erlang/OTP 19.0 release in June 2016
• Elixir was created in 2012 by Jose Valim
– Former Rails Core team member
– Elixir 1.3 released in June 2016
The Highlights
It’s huge…we don’t have all night
Immutable Data
• There’s no passing pointers
• Add something to a list, get a new list
• Everything is “message passing”
– Avoids mutex locks
– Enables per-process garbage collection
– Makes calling a function locally, in another process
or on another machine transparent
3 Databases Built In
• ETS – Erlang Term Storage
– In memory table storage for a node
• DETS – Disk-based Erlang Term Storage
– Disk table storage for a node
• Mnesia - #awesome
– A relational/object hybrid data model that is suitable for telecommunications applications.
– A DBMS query language, Query List Comprehension (QLC) as an add-on library.
– Persistence. Tables can be coherently kept on disc and in the main memory.
– Replication. Tables can be replicated at several nodes.
– Atomic transactions. A series of table manipulation operations can be grouped into a single
atomic transaction.
– Location transparency. Programs can be written without knowledge of the actual data
location.
– Extremely fast real-time data searches.
– Schema manipulation routines. The DBMS can be reconfigured at runtime without stopping
the system.
https://blog.codeship.com/elixir-ets-vs-redis/
Preemptive Scheduling
• Context switching among running tasks and
has the power to preempt (interrupt) tasks
and resume them at a later time without the
cooperation of the preempted tasks.
• Cooperative: Running tasks voluntarily release
control
What does that mean?
• Response time consistency
• A tight loop or resource heavy process can’t
cannibalize resources
• Critical for real time systems
• Running a database inside your code would be
unreliable otherwise
Pattern Matching
=
iex> list = [1, 2, [ 3, 4, 5 ] ]
[1, 2, [3, 4, 5]]
iex> [a, b, c ] = list
[1, 2, [3, 4, 5]]
iex> a
1
iex> b
2
iex> c
[3, 4, 5]
Examples from
Programming Elixir 1.3
Works if left can be matched to right
iex> list = [1, 2, 3]
[1, 2, 3]
iex> [a, 1, b ] = list
** (MatchError) no match of right hand side
value: [1, 2, 3]
Pattern Matching Functions
defmodule Factorial do
def of(0), do: 1
def of(n), do: n * of(n-1)
end
defmodule PrintStuff do
def print({:error, stuff}) do
IO.puts “ERROR! #{stuff}”
end
def print({:ok, stuff}), do: IO.puts stuff
end
PrintStuff.print({:ok, stuff})
Loops?
• How do you have a for loop with an
immutable increment?
– Recursion. Lots of recursion.
Stack Overflow
Who knows what a stack overflow is?
Tail Call Optimization
defmodule TailRecursive do
def factorial(n), do: _fact(n, 1)
defp _fact(0, acc), do: acc
defp _fact(n, acc), do: _fact(n-1, acc*n)
end
# defp is private
If the last function called is itself, the
stack doesn’t grow.
Concurrency
pid = spawn(Object, :method, [vars])
# Creates a process
# returns the ID of the process
pid = spawn_link(Object, :method, [vars])
# Creates a process
# returns the ID of the process
# If the process dies, creator should too
Quick Example (from book)
defmodule Link2 do
import :timer, only: [ sleep: 1 ]
def sad_function do
sleep 500
exit(:boom)
end
def run do
spawn_link(Link2, :sad_function, [])
receive do
msg ->
IO.puts "MESSAGE RECEIVED: #{inspect msg}"
after 1000 ->
IO.puts "Nothing happened as far as I am concerned"
end
end
End
Link2.run
# The runtime reports the abnormal termination:
$ elixir -r link2.exs
** (EXIT from #PID<0.35.0>) :boom
That’s where we start
• Building blocks for best practice patterns
– GenServer
– Task (async/await)
– Agent (async / await + state)
– Supervisor / Worker
Fault Tolerance / Supervisors
• Applications operate as a Supervisor tree
• Process is created with another process
dedicated to monitoring it
• Worker process dies, it’s immediately
restarted in original state
– This is how Erlang applications can get
99.9999999% uptime (yes, 9 nines)
HANDLING ERRORS IS CODE SMELL
This is just fun to say
Error that could kill process?
• If you have an error that could kill a process…
– Make sure the process knows how to restart in a
desirable state
• Very different way of thinking about problems
Simple Supervision Example
> Math.Calculate.divide(10,2)
5.0
:ok
> Math.Calculate.divide(34,3)
11.333333333333334
:ok
> Math.Calculate.divide(34,0)
A BIG UGLY ERROR MESSAGE... BUT LITTLE DID YOU KNOW THE PROCESS WAS
RESTARTED AND LIVES!
> Math.Calculate.divide(34,2)
17.0
:OK
https://github.com/kblake/simple-supervision
“Where you’d previously think Object you’ll
begin to think Process“
- Confucius
Dialyzer
• Operators are not overridden
• + is always math
– What’s on either side of it is always a number
• Allows dynamic typing WITH compiler checks
• Best of both worlds, problems of neither
THIS ALL SEEMS REALLY
COMPLICATED
I know right? I’m just here for the web stuff
Phoenix Framework
• Significantly lowers barrier to entry
– Familiar Routes / Controllers
– Flexible Middleware
• Plug
– Excellent web sockets
• Channels
– Excellent / flexible / replaceable database layer
• Ecto
– Best view layer ever
– Pretty dang fast
About that….
Rebuilt brightball.com
• Read about it
http://www.brightball.com/articles/insanity-
with-elixir-phoenix-postgresql
• Summary
– As a dynamic site it’s as fast as my static nginx site
– This is considered normal (and awesome)
Phoenix Channels vs Rails ActionCable
• https://dockyard.com/blog/2016/08/09/phoe
nix-channels-vs-rails-action-cable
• Results
– Rails: 50 rooms, 2500 users - .05s avg
– Rails: 75 rooms, 3750 users – 8s avg, degrading
– Phoenix: 1100 rooms, 55,000 users - .25s avg
• (maxed 55,000 client connections)
Terraform
• Use in your current environment incrementally
– Put Phoenix in front of your app
– Route specific requests to Phoenix
– Pass the rest through to your current app
– Bundled Cowboy webserver used by Heroku, AWS
Cloudfront, Incapsula, etc…it good
• https://medium.com/@sugarpirate/rise-from-
the-ashes-incremental-apis-with-phoenix-
b08cd66bd142#.e1iojykq9
GenStage
• http://elixir-
lang.org/blog/2016/07/14/announcing-
genstage/
• Streaming, auto-scaling data ingestion
Nerves
• http://nerves-project.org/
• ElixirConf was about Phoenix and Nerves
• Nerves is for embedded software
• Fault tolerance, reliability, consistency seem
important for something like that…?
Functional Programming
• What are the gains?
– Readability / Maintainability
– No side effects code
– Simplified testing
– Simplified personnel turnover
– No object inheritance nightmares
– Clear separation of concerns
Objects…so dumb 
• Data tied to Functions
– Breeds repetition
– Weird nesting
– Breeds repetition
– Modify up the tree
– Breeds repetition
• Separate the two
– Data structures
– Functions
– #mindblown
"Object oriented
programs are offered as
alternatives to correct
ones”
- Edsger W. Dijkstra
http://www.yegor256.com/2016/08/15/what-is-wrong-object-oriented-programming.html
Why is it the future?
• Nothing with a shared memory model can match it for distribution…ever
– You can’t pass a memory reference to another machine transparently
• Ruby like productivity
– Minus an eventual full rewrite expectation
• Extremely fast, small footprint, embeddable, consistent, reliable
• Low process overhead ideal for holding connections
• You can easily start SMALL, knowing you have all of the tools to grow/get
crazy when you need them
– Refactoring is just rearranging stuff (yes, really)
– Naturally avoids bloat
• Compiler tells you when stuff isn’t used to make cleanup easy
• But isn’t so strict that it forces you to change them
– Stop worrying about development time OR code performance tradeoffs
Which makes it ideal for…
• Server applications that talk to a lot of things…
• Like web sockets
• Internet of Things devices
• Real time communications
• Low latency applications
• Geographic distribution
– Cluster across data centers…yes, really.
• Avoiding bottlenecks
Resources
• Hack Greenville Slack #elixir-phoenix
• elixir-lang.org
– Books, chat, links, resources, groups
• phoenixframework.org
• Elixir Conf sessions on YouTube
– So much good stuff
– Using Phoenix w/ Riak Core
https://www.youtube.com/watch?v=sYYOLaJ-
VDQ&start=2&autoplay=1
More Resources
• Programming Elixir
• Programming Phoenix
• RedFour (fake company training)
• ElixirForums
• Assorted newsletters
Elixir Tank Game
http://tanx.verse15.net/
Go there now, fight to the death
THANKS!
Questions?

More Related Content

What's hot

Flink Forward SF 2017: Tzu-Li (Gordon) Tai - Joining the Scurry of Squirrels...
Flink Forward SF 2017: Tzu-Li (Gordon) Tai -  Joining the Scurry of Squirrels...Flink Forward SF 2017: Tzu-Li (Gordon) Tai -  Joining the Scurry of Squirrels...
Flink Forward SF 2017: Tzu-Li (Gordon) Tai - Joining the Scurry of Squirrels...
Flink Forward
 
Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvm
deimos
 
IPv4aaS tutorial and hands-on
IPv4aaS tutorial and hands-onIPv4aaS tutorial and hands-on
IPv4aaS tutorial and hands-on
APNIC
 
Introduction to Kotlin coroutines
Introduction to Kotlin coroutinesIntroduction to Kotlin coroutines
Introduction to Kotlin coroutines
Roman Elizarov
 
Experiences with Microservices at Tuenti
Experiences with Microservices at TuentiExperiences with Microservices at Tuenti
Experiences with Microservices at Tuenti
Andrés Viedma Peláez
 
Hybrid concurrency patterns
Hybrid concurrency patternsHybrid concurrency patterns
Hybrid concurrency patterns
Kyle Drake
 
RESTFul Tools For Lazy Experts - CFSummit 2016
RESTFul Tools For Lazy Experts - CFSummit 2016RESTFul Tools For Lazy Experts - CFSummit 2016
RESTFul Tools For Lazy Experts - CFSummit 2016
Ortus Solutions, Corp
 
Erlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web WisdomErlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web Wisdom
guest3933de
 
Pharo: A Reflective System
Pharo: A Reflective SystemPharo: A Reflective System
Pharo: A Reflective System
Marcus Denker
 
Day 8 - jRuby
Day 8 - jRubyDay 8 - jRuby
Day 8 - jRuby
Barry Jones
 
Open Source Swift Under the Hood
Open Source Swift Under the HoodOpen Source Swift Under the Hood
Open Source Swift Under the Hood
C4Media
 
Making Symfony Services async with RabbitMq (and more Symfony)
Making Symfony Services async with RabbitMq (and more Symfony)Making Symfony Services async with RabbitMq (and more Symfony)
Making Symfony Services async with RabbitMq (and more Symfony)
Gaetano Giunta
 
Ruby and Security
Ruby and SecurityRuby and Security
Ruby and Security
Carl Sampson, CSSLP
 
Swift - Under the Hood
Swift - Under the HoodSwift - Under the Hood
Swift - Under the Hood
C4Media
 
NDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business NeedsNDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business Needs
Torben Hoffmann
 
Enterprise messaging
Enterprise messagingEnterprise messaging
Enterprise messaging
ColdFusionConference
 
Erlang: TL;DR
Erlang: TL;DRErlang: TL;DR
Erlang: TL;DR
vorn
 
Balázs Bucsay - XFLTReaT: Building a Tunnel
Balázs Bucsay - XFLTReaT: Building a TunnelBalázs Bucsay - XFLTReaT: Building a Tunnel
Balázs Bucsay - XFLTReaT: Building a Tunnel
hacktivity
 
Ekon20 mORMot WorkShop Delphi
Ekon20 mORMot WorkShop DelphiEkon20 mORMot WorkShop Delphi
Ekon20 mORMot WorkShop Delphi
Arnaud Bouchez
 

What's hot (19)

Flink Forward SF 2017: Tzu-Li (Gordon) Tai - Joining the Scurry of Squirrels...
Flink Forward SF 2017: Tzu-Li (Gordon) Tai -  Joining the Scurry of Squirrels...Flink Forward SF 2017: Tzu-Li (Gordon) Tai -  Joining the Scurry of Squirrels...
Flink Forward SF 2017: Tzu-Li (Gordon) Tai - Joining the Scurry of Squirrels...
 
Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvm
 
IPv4aaS tutorial and hands-on
IPv4aaS tutorial and hands-onIPv4aaS tutorial and hands-on
IPv4aaS tutorial and hands-on
 
Introduction to Kotlin coroutines
Introduction to Kotlin coroutinesIntroduction to Kotlin coroutines
Introduction to Kotlin coroutines
 
Experiences with Microservices at Tuenti
Experiences with Microservices at TuentiExperiences with Microservices at Tuenti
Experiences with Microservices at Tuenti
 
Hybrid concurrency patterns
Hybrid concurrency patternsHybrid concurrency patterns
Hybrid concurrency patterns
 
RESTFul Tools For Lazy Experts - CFSummit 2016
RESTFul Tools For Lazy Experts - CFSummit 2016RESTFul Tools For Lazy Experts - CFSummit 2016
RESTFul Tools For Lazy Experts - CFSummit 2016
 
Erlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web WisdomErlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web Wisdom
 
Pharo: A Reflective System
Pharo: A Reflective SystemPharo: A Reflective System
Pharo: A Reflective System
 
Day 8 - jRuby
Day 8 - jRubyDay 8 - jRuby
Day 8 - jRuby
 
Open Source Swift Under the Hood
Open Source Swift Under the HoodOpen Source Swift Under the Hood
Open Source Swift Under the Hood
 
Making Symfony Services async with RabbitMq (and more Symfony)
Making Symfony Services async with RabbitMq (and more Symfony)Making Symfony Services async with RabbitMq (and more Symfony)
Making Symfony Services async with RabbitMq (and more Symfony)
 
Ruby and Security
Ruby and SecurityRuby and Security
Ruby and Security
 
Swift - Under the Hood
Swift - Under the HoodSwift - Under the Hood
Swift - Under the Hood
 
NDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business NeedsNDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business Needs
 
Enterprise messaging
Enterprise messagingEnterprise messaging
Enterprise messaging
 
Erlang: TL;DR
Erlang: TL;DRErlang: TL;DR
Erlang: TL;DR
 
Balázs Bucsay - XFLTReaT: Building a Tunnel
Balázs Bucsay - XFLTReaT: Building a TunnelBalázs Bucsay - XFLTReaT: Building a Tunnel
Balázs Bucsay - XFLTReaT: Building a Tunnel
 
Ekon20 mORMot WorkShop Delphi
Ekon20 mORMot WorkShop DelphiEkon20 mORMot WorkShop Delphi
Ekon20 mORMot WorkShop Delphi
 

Viewers also liked

PostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty databasePostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty database
Barry Jones
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP Perspective
Barry Jones
 
Test performance indicators
Test performance indicatorsTest performance indicators
Test performance indicators
Idexcel Technologies
 
Pair Programming - the lightning talk
Pair Programming - the lightning talkPair Programming - the lightning talk
Pair Programming - the lightning talk
Barry Jones
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
Barry Jones
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to Ruby
Barry Jones
 
The NoSQL Way in Postgres
The NoSQL Way in PostgresThe NoSQL Way in Postgres
The NoSQL Way in Postgres
EDB
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
anandology
 
RSpec 2 Best practices
RSpec 2 Best practicesRSpec 2 Best practices
RSpec 2 Best practices
Andrea Reginato
 
Testing Metrics
Testing MetricsTesting Metrics
Testing Metrics
PM Venkatesha Babu
 

Viewers also liked (10)

PostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty databasePostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty database
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP Perspective
 
Test performance indicators
Test performance indicatorsTest performance indicators
Test performance indicators
 
Pair Programming - the lightning talk
Pair Programming - the lightning talkPair Programming - the lightning talk
Pair Programming - the lightning talk
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to Ruby
 
The NoSQL Way in Postgres
The NoSQL Way in PostgresThe NoSQL Way in Postgres
The NoSQL Way in Postgres
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
 
RSpec 2 Best practices
RSpec 2 Best practicesRSpec 2 Best practices
RSpec 2 Best practices
 
Testing Metrics
Testing MetricsTesting Metrics
Testing Metrics
 

Similar to Repeating History...On Purpose...with Elixir

Introduction to multicore .ppt
Introduction to multicore .pptIntroduction to multicore .ppt
Introduction to multicore .ppt
Rajagopal Nagarajan
 
Erlang factory SF 2011 "Erlang and the big switch in social games"
Erlang factory SF 2011 "Erlang and the big switch in social games"Erlang factory SF 2011 "Erlang and the big switch in social games"
Erlang factory SF 2011 "Erlang and the big switch in social games"
Paolo Negri
 
Erlang, the big switch in social games
Erlang, the big switch in social gamesErlang, the big switch in social games
Erlang, the big switch in social games
Wooga
 
A sip of Elixir
A sip of ElixirA sip of Elixir
A sip of Elixir
Emanuele DelBono
 
Osdc 2011 michael_neale
Osdc 2011 michael_nealeOsdc 2011 michael_neale
Osdc 2011 michael_neale
Michael Neale
 
Intro to elixir and phoenix
Intro to elixir and phoenixIntro to elixir and phoenix
Intro to elixir and phoenix
Jared Smith
 
Scaling tappsi
Scaling tappsiScaling tappsi
Scaling tappsi
Óscar Andrés López
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
Martijn Verburg
 
Concurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple SpacesConcurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spaces
luccastera
 
Elixir
ElixirElixir
C# Async/Await Explained
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await Explained
Jeremy Likness
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
mperham
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
Martijn Verburg
 
Awesome Concurrency with Elixir Tasks
Awesome Concurrency with Elixir TasksAwesome Concurrency with Elixir Tasks
Awesome Concurrency with Elixir Tasks
Jonathan Magen
 
DevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 SlidesDevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 Slides
Alex Cruise
 
Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...
InfinIT - Innovationsnetværket for it
 
Concurrency & Parallel Programming
Concurrency & Parallel ProgrammingConcurrency & Parallel Programming
Concurrency & Parallel Programming
Ramazan AYYILDIZ
 
Scalable game-servers-tgc
Scalable game-servers-tgcScalable game-servers-tgc
Scalable game-servers-tgc
Ashkan Saeedi Mazdeh
 
Coding For Cores - C# Way
Coding For Cores - C# WayCoding For Cores - C# Way
Coding For Cores - C# Way
Bishnu Rawal
 
MPI, Erlang and the web
MPI, Erlang and the webMPI, Erlang and the web
MPI, Erlang and the web
Lenz Gschwendtner
 

Similar to Repeating History...On Purpose...with Elixir (20)

Introduction to multicore .ppt
Introduction to multicore .pptIntroduction to multicore .ppt
Introduction to multicore .ppt
 
Erlang factory SF 2011 "Erlang and the big switch in social games"
Erlang factory SF 2011 "Erlang and the big switch in social games"Erlang factory SF 2011 "Erlang and the big switch in social games"
Erlang factory SF 2011 "Erlang and the big switch in social games"
 
Erlang, the big switch in social games
Erlang, the big switch in social gamesErlang, the big switch in social games
Erlang, the big switch in social games
 
A sip of Elixir
A sip of ElixirA sip of Elixir
A sip of Elixir
 
Osdc 2011 michael_neale
Osdc 2011 michael_nealeOsdc 2011 michael_neale
Osdc 2011 michael_neale
 
Intro to elixir and phoenix
Intro to elixir and phoenixIntro to elixir and phoenix
Intro to elixir and phoenix
 
Scaling tappsi
Scaling tappsiScaling tappsi
Scaling tappsi
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
Concurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple SpacesConcurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spaces
 
Elixir
ElixirElixir
Elixir
 
C# Async/Await Explained
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await Explained
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
 
Awesome Concurrency with Elixir Tasks
Awesome Concurrency with Elixir TasksAwesome Concurrency with Elixir Tasks
Awesome Concurrency with Elixir Tasks
 
DevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 SlidesDevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 Slides
 
Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...
 
Concurrency & Parallel Programming
Concurrency & Parallel ProgrammingConcurrency & Parallel Programming
Concurrency & Parallel Programming
 
Scalable game-servers-tgc
Scalable game-servers-tgcScalable game-servers-tgc
Scalable game-servers-tgc
 
Coding For Cores - C# Way
Coding For Cores - C# WayCoding For Cores - C# Way
Coding For Cores - C# Way
 
MPI, Erlang and the web
MPI, Erlang and the webMPI, Erlang and the web
MPI, Erlang and the web
 

More from Barry Jones

Day 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureDay 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application Architecture
Barry Jones
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
Barry Jones
 
Day 6 - PostGIS
Day 6 - PostGISDay 6 - PostGIS
Day 6 - PostGIS
Barry Jones
 
Day 4 - Models
Day 4 - ModelsDay 4 - Models
Day 4 - Models
Barry Jones
 
Day 2 - Intro to Rails
Day 2 - Intro to RailsDay 2 - Intro to Rails
Day 2 - Intro to Rails
Barry Jones
 
Protecting Users from Fraud
Protecting Users from FraudProtecting Users from Fraud
Protecting Users from Fraud
Barry Jones
 
AWS re:Invent 2013 Recap
AWS re:Invent 2013 RecapAWS re:Invent 2013 Recap
AWS re:Invent 2013 Recap
Barry Jones
 

More from Barry Jones (7)

Day 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureDay 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application Architecture
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
Day 6 - PostGIS
Day 6 - PostGISDay 6 - PostGIS
Day 6 - PostGIS
 
Day 4 - Models
Day 4 - ModelsDay 4 - Models
Day 4 - Models
 
Day 2 - Intro to Rails
Day 2 - Intro to RailsDay 2 - Intro to Rails
Day 2 - Intro to Rails
 
Protecting Users from Fraud
Protecting Users from FraudProtecting Users from Fraud
Protecting Users from Fraud
 
AWS re:Invent 2013 Recap
AWS re:Invent 2013 RecapAWS re:Invent 2013 Recap
AWS re:Invent 2013 Recap
 

Recently uploaded

Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 

Recently uploaded (20)

Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 

Repeating History...On Purpose...with Elixir

  • 2. Who am I? • Developer since 98 • Used to run Brightball – Contract programming business using PHP – 2008 – 2011 • R.I.P. Code one out for my homies • PHP, Java, Perl, Python, Ruby, Groovy, Go – Elixir • And lots of databases #postgresql
  • 3. So…another language…? Rules for learning a language – Must solve a problem – Problem not addressed by current stack – “Fast” is not a purpose • Lots of things are fast – Should be the best solution • If it’s not, I’d rather learn the one that is… I hate new languages Yeah. Surprise. 
  • 4. So why the other languages? • PHP – Needed to build a site – Clemson’s options were PHP / Perl – Perl was badly supported • Java – Clemson CPSC – Also…jobs are good • Groovy – Java environment – Wanted to be productive • Go – Great concurrency – Relatively simple – Fast compilation – Portability – Solves some bloat problems • Perl – Sysadmin work – Installed on all *nix derivatives • including very old – Best at text parsing • Python – Employer required it • Ruby – Incredible productivity – Library ecosystem – Monkey patching – Rails – Focus on dev efficiency
  • 5. SO WHY ELIXIR? I wondered the same thing
  • 6. "Those who cannot remember the past are condemned to repeat it." - George Santayana "What has been is what will be, and what has been done is what will be done, and there is nothing new under the sun." - Solomon
  • 7. Elixir isn’t new • It’s more productive Erlang • Compiles down to the BEAM (Erlang VM) • Erlang was born in 1986 (Linux was 1991) • Erlang/OTP is on version 19 • Erlang libraries work directly in Elixir – And vice versa
  • 8. Processor POWER!!! • Industry focus used to be on Mhz/Ghz • Growth was steady…but then stalled • Industry shifted to multicore / concurrency and trying to put it in their languages • Lookup “Beowulf Cluster” to see how foreign “parallel” was at the time
  • 9. Funny thing… “Any sufficiently complicated concurrent program in another language contains an ad hoc informally-specified bug-ridden slow implementation of half of Erlang.” - Robert Virding
  • 10. Erlang view of the World • Everything is a process. • Processes are strongly isolated. • Process creation and destruction is a lightweight operation. • Message passing is the only way for processes to interact. • Processes have unique names. • If you know the name of a process you can send it a message. • Processes share no resources. • Error handling is non-local. • Processes do what they are supposed to do or fail.
  • 11. Message Passing • Process isolation and message passing • Passing between threads, cores or machines is transparent • Microservice concept…but everywhere and not terrible
  • 12. “If Java is the right one to run anywhere, then Erlang is the right one to run forever.” – Joe Armstrong
  • 13. What’s the big deal with Elixir? • Ruby-like focus on developer productivity • Functional programming made simple • Embedded database • Compiles down to code to run on the BEAM Virtual Machine • BEAM/OTP is what Erlang runs on • Erlang/BEAM is the best existing language for concurrency, consistency and fault tolerance, hot code swapping – Single Processor – Multi Processor – Distributed Multi Machine Cluster • Erlang does not focus on developer productivity – Writing Erlang kinda sucks...  • #1 Problem in Ruby is concurrency model – Cannot be fixed. It’s the way the language works. – Enables great things but also causes limitations
  • 14. So what does that mean? Standard Web App OTP
  • 15. What’s the big deal? • Facebook paid $22 billion for WhatsApp • WhatsApp had $10 million in revenue • What was the big deal? – Erlang/OTP – 2 million users / server – No central relay point – Scales horizontally – Deploys w/o disconnect
  • 16. AND HOW DOES ALL THIS WORK? Why should you care?
  • 17. Other languages • Boot up • Memory is shared – Where leaks come from – Changing shared memory requires a mutex lock • Garbage collector periodically runs – Pause entire stack • Requests run in threads in the same process – Threads are cooperatively scheduled • Deployment means shutting down current code, starting new code
  • 18. Erlang/Elixir/OTP • No memory is shared • Data structures are immutable • Each Erlang process (basically a light thread) has its own HEAP – Reclaimed on completion • Code can be hot deployed – New code runs next time it’s accessed (existing code keeps running) • Processes are prescheduled
  • 19. Sound familiar? • Difference is size of the allocations – An Erlang process is 0.5 kb – A Go goroutine is 2 kb (version 1.4) – A Java thread is 1024 kb on 64 bit VM – PHP request varies by how much is loaded • Laravel averages 7-12mb / request
  • 20. Programming Elixir, Chapter 15 Laptop w/ 4 cores and 4gb of RAM counting concurrently 1,000,000 processes = • 0.48 gb in Elixir • 1.91 gb in Golang (go routines) • 977 gb in Java (threads) • 6,836 gb in PHP (Laravel requests)
  • 21. LET’S GET STARTED wait.…we haven’t started yet?
  • 22. Quick History • Linux was created in 1991 • Erlang was created in 1987 by Ericson – Powers about half of global telecom – Needed distributed, fault tolerant system – Deploy updates without interrupting existing calls – OTP = Open Telecom Protocol – Erlang/OTP 19.0 release in June 2016 • Elixir was created in 2012 by Jose Valim – Former Rails Core team member – Elixir 1.3 released in June 2016
  • 23. The Highlights It’s huge…we don’t have all night
  • 24. Immutable Data • There’s no passing pointers • Add something to a list, get a new list • Everything is “message passing” – Avoids mutex locks – Enables per-process garbage collection – Makes calling a function locally, in another process or on another machine transparent
  • 25. 3 Databases Built In • ETS – Erlang Term Storage – In memory table storage for a node • DETS – Disk-based Erlang Term Storage – Disk table storage for a node • Mnesia - #awesome – A relational/object hybrid data model that is suitable for telecommunications applications. – A DBMS query language, Query List Comprehension (QLC) as an add-on library. – Persistence. Tables can be coherently kept on disc and in the main memory. – Replication. Tables can be replicated at several nodes. – Atomic transactions. A series of table manipulation operations can be grouped into a single atomic transaction. – Location transparency. Programs can be written without knowledge of the actual data location. – Extremely fast real-time data searches. – Schema manipulation routines. The DBMS can be reconfigured at runtime without stopping the system. https://blog.codeship.com/elixir-ets-vs-redis/
  • 26. Preemptive Scheduling • Context switching among running tasks and has the power to preempt (interrupt) tasks and resume them at a later time without the cooperation of the preempted tasks. • Cooperative: Running tasks voluntarily release control
  • 27. What does that mean? • Response time consistency • A tight loop or resource heavy process can’t cannibalize resources • Critical for real time systems • Running a database inside your code would be unreliable otherwise
  • 28. Pattern Matching = iex> list = [1, 2, [ 3, 4, 5 ] ] [1, 2, [3, 4, 5]] iex> [a, b, c ] = list [1, 2, [3, 4, 5]] iex> a 1 iex> b 2 iex> c [3, 4, 5] Examples from Programming Elixir 1.3 Works if left can be matched to right iex> list = [1, 2, 3] [1, 2, 3] iex> [a, 1, b ] = list ** (MatchError) no match of right hand side value: [1, 2, 3]
  • 29. Pattern Matching Functions defmodule Factorial do def of(0), do: 1 def of(n), do: n * of(n-1) end defmodule PrintStuff do def print({:error, stuff}) do IO.puts “ERROR! #{stuff}” end def print({:ok, stuff}), do: IO.puts stuff end PrintStuff.print({:ok, stuff})
  • 30. Loops? • How do you have a for loop with an immutable increment? – Recursion. Lots of recursion.
  • 31. Stack Overflow Who knows what a stack overflow is?
  • 32. Tail Call Optimization defmodule TailRecursive do def factorial(n), do: _fact(n, 1) defp _fact(0, acc), do: acc defp _fact(n, acc), do: _fact(n-1, acc*n) end # defp is private If the last function called is itself, the stack doesn’t grow.
  • 33. Concurrency pid = spawn(Object, :method, [vars]) # Creates a process # returns the ID of the process pid = spawn_link(Object, :method, [vars]) # Creates a process # returns the ID of the process # If the process dies, creator should too
  • 34. Quick Example (from book) defmodule Link2 do import :timer, only: [ sleep: 1 ] def sad_function do sleep 500 exit(:boom) end def run do spawn_link(Link2, :sad_function, []) receive do msg -> IO.puts "MESSAGE RECEIVED: #{inspect msg}" after 1000 -> IO.puts "Nothing happened as far as I am concerned" end end End Link2.run # The runtime reports the abnormal termination: $ elixir -r link2.exs ** (EXIT from #PID<0.35.0>) :boom
  • 35. That’s where we start • Building blocks for best practice patterns – GenServer – Task (async/await) – Agent (async / await + state) – Supervisor / Worker
  • 36. Fault Tolerance / Supervisors • Applications operate as a Supervisor tree • Process is created with another process dedicated to monitoring it • Worker process dies, it’s immediately restarted in original state – This is how Erlang applications can get 99.9999999% uptime (yes, 9 nines)
  • 37. HANDLING ERRORS IS CODE SMELL This is just fun to say
  • 38. Error that could kill process? • If you have an error that could kill a process… – Make sure the process knows how to restart in a desirable state • Very different way of thinking about problems
  • 39. Simple Supervision Example > Math.Calculate.divide(10,2) 5.0 :ok > Math.Calculate.divide(34,3) 11.333333333333334 :ok > Math.Calculate.divide(34,0) A BIG UGLY ERROR MESSAGE... BUT LITTLE DID YOU KNOW THE PROCESS WAS RESTARTED AND LIVES! > Math.Calculate.divide(34,2) 17.0 :OK https://github.com/kblake/simple-supervision
  • 40. “Where you’d previously think Object you’ll begin to think Process“ - Confucius
  • 41. Dialyzer • Operators are not overridden • + is always math – What’s on either side of it is always a number • Allows dynamic typing WITH compiler checks • Best of both worlds, problems of neither
  • 42. THIS ALL SEEMS REALLY COMPLICATED I know right? I’m just here for the web stuff
  • 43. Phoenix Framework • Significantly lowers barrier to entry – Familiar Routes / Controllers – Flexible Middleware • Plug – Excellent web sockets • Channels – Excellent / flexible / replaceable database layer • Ecto – Best view layer ever – Pretty dang fast
  • 45. Rebuilt brightball.com • Read about it http://www.brightball.com/articles/insanity- with-elixir-phoenix-postgresql • Summary – As a dynamic site it’s as fast as my static nginx site – This is considered normal (and awesome)
  • 46. Phoenix Channels vs Rails ActionCable • https://dockyard.com/blog/2016/08/09/phoe nix-channels-vs-rails-action-cable • Results – Rails: 50 rooms, 2500 users - .05s avg – Rails: 75 rooms, 3750 users – 8s avg, degrading – Phoenix: 1100 rooms, 55,000 users - .25s avg • (maxed 55,000 client connections)
  • 47. Terraform • Use in your current environment incrementally – Put Phoenix in front of your app – Route specific requests to Phoenix – Pass the rest through to your current app – Bundled Cowboy webserver used by Heroku, AWS Cloudfront, Incapsula, etc…it good • https://medium.com/@sugarpirate/rise-from- the-ashes-incremental-apis-with-phoenix- b08cd66bd142#.e1iojykq9
  • 49. Nerves • http://nerves-project.org/ • ElixirConf was about Phoenix and Nerves • Nerves is for embedded software • Fault tolerance, reliability, consistency seem important for something like that…?
  • 50. Functional Programming • What are the gains? – Readability / Maintainability – No side effects code – Simplified testing – Simplified personnel turnover – No object inheritance nightmares – Clear separation of concerns
  • 51. Objects…so dumb  • Data tied to Functions – Breeds repetition – Weird nesting – Breeds repetition – Modify up the tree – Breeds repetition • Separate the two – Data structures – Functions – #mindblown "Object oriented programs are offered as alternatives to correct ones” - Edsger W. Dijkstra http://www.yegor256.com/2016/08/15/what-is-wrong-object-oriented-programming.html
  • 52. Why is it the future? • Nothing with a shared memory model can match it for distribution…ever – You can’t pass a memory reference to another machine transparently • Ruby like productivity – Minus an eventual full rewrite expectation • Extremely fast, small footprint, embeddable, consistent, reliable • Low process overhead ideal for holding connections • You can easily start SMALL, knowing you have all of the tools to grow/get crazy when you need them – Refactoring is just rearranging stuff (yes, really) – Naturally avoids bloat • Compiler tells you when stuff isn’t used to make cleanup easy • But isn’t so strict that it forces you to change them – Stop worrying about development time OR code performance tradeoffs
  • 53. Which makes it ideal for… • Server applications that talk to a lot of things… • Like web sockets • Internet of Things devices • Real time communications • Low latency applications • Geographic distribution – Cluster across data centers…yes, really. • Avoiding bottlenecks
  • 54. Resources • Hack Greenville Slack #elixir-phoenix • elixir-lang.org – Books, chat, links, resources, groups • phoenixframework.org • Elixir Conf sessions on YouTube – So much good stuff – Using Phoenix w/ Riak Core https://www.youtube.com/watch?v=sYYOLaJ- VDQ&start=2&autoplay=1
  • 55. More Resources • Programming Elixir • Programming Phoenix • RedFour (fake company training) • ElixirForums • Assorted newsletters
  • 56. Elixir Tank Game http://tanx.verse15.net/ Go there now, fight to the death