SlideShare una empresa de Scribd logo
1 de 56
Descargar para leer sin conexión
Elixir & Phoenix
Functional |> Concurrent |> Pragmatic |> Fun
Who am I?
• Jared Smith
• Software Engineer at One Month
• @sublimecoder
• www.sublimecoding.com
Lets get started
First lets talk about Erlang
• Elixir runs on the Erlang VM
• Many of the standard lib function calls in Elixir
call Erlang functions directly.
• Elixir piggy backs on the Erlang ecosystem
Why Erlang VM?
• 30 year old battle tested VM
• Highly available, fault tolerant, and distributed
History of Erlang
• Developed by Ericsson
• Used and developed for Telecommunications
• In fact its standard library is the OTP (Open
Telecom Platform)
Telecommunications
• High availability is king
• Remote Telecom switches need to run for years
sometimes with out being disturbed
Built with Erlang
• 50 person engineering team
• managing 900 million users.
• Up to 2 million active users per server.
https://blog.whatsapp.com/196/1-million-is-so-2011
2 Million Active Users?
• Intel Xeon CPU x5675 @ 3.07GHz

24 Cores - 96GB Ram
• Using only 40% of the CPU/Memory
https://blog.whatsapp.com/196/1-million-is-so-2011
So Erlang is pretty awesome
• Wouldn’t it be nice if we could harness this
power?
• Why isn’t everyone using Erlang?
Elixir
• Elixir utilizes much of the power of Erlang
• While giving us a much nicer syntax and api to
work with.
History of Elixir
• Created by Josè Valím - (Joe-zay Val-eem)
• First released in 2012
Elixir’s Strengths
• Concurrency
• Meta-programming Capability
• Transformation of data as a core ideal
Plus it has Ruby like syntax
Pipe Operator
• The following code is valid elixir.
• With the pipe operator we can write our code this
way instead. Keeping us out of nested function
hell.
Pattern Matching
• Pattern matching is a core part of Erlang and
Elixir
What is Pattern Matching?
• Make left side look like the right side
• a = 99
• [a,b,c] = [1,2,3]
• [head | tail] = [1,2,3]
Immutability
• Once you set a value 

it can never change.
Immutability
You’re already familiar with
immutability you just don’t know it.
• a = 99
• We all know 99 is always 99.
• integers are immutable values, even in Ruby.
• You’d be upset if someone monkey patched 99
to be 3 right?
Why is Immutability a good
thing?
• Immutability provides a contract that each piece
of information has one source of truth.
• Concurrency is a natural side effect of
immutability.
Does this mean I can never
change a variable once I set it?
• The short answer is no, you can reassign
variables as much as you like.
• Erlang would not be so kind, but Elixir we have
this luxury.
So how is it immutable if I
can change things?
• You can change things, elixir will just copy the
values you don’t change, but the original
reference stays intact.
• The original reference can then be used in part
or in whole later in the application.
Isn’t this inefficient?
• At first glance it would seem that way, but the
opposite is true.
• Won’t all the old reference values balloon elixirs
memory?
• Yes this means you could have thousands of
unused variables floating in memory
Concurrency
Concurrency fixes
everything
• Because the data is immutable we can rely on it
always being a certain value
• which means we can make our programs
concurrent and not worry.
• Elixir uses its concurrency to help with garbage
collections. Each process gets it own heap
allocated and that heap is garbage collected or
reclaimed as needed for that individual process.
Concurrency
• Elixir will eat as many cores/computers as you
can throw at it.
• It treats each core as though it were a computer
on the network with near zero latency.
Phoenix Framework
Productive |> Reliable |> Fast
Phoenix Framework
• Created by Chris McCord
• Release 1.0 August 28th 2015
Phoenix Framework
• It’s not rails for Elixir
• It has been influence heavily by rails as well as
many other frameworks.
• Focus on API and web sockets
Speed
• Web request response time is often measured in
micro seconds and not milliseconds.
Benchmarks
• Recently benchmarked 2 million+ web socket
connections
• With 2 - 3 second broadcast times to all 2 million
connections
Benchmarks
https://github.com/mroth/phoenix-showdown
iMac Intel Core i7 (4.0 GHz 4 Cores) 32 GB RAM
https://github.com/mroth/phoenix-showdown
2.8 Ghz, 10 core Intel® Xeon 128 GB RAM
Easy Startup
• mix phoenix.new ./app/path/my_app
• mix ecto.create && mix ecto.migrate
• mix phoenix.server
Directory Structure
Web Dir Structure
Mix
• Mix is essentially bundler and rake combined
• Additionally mix is your test runner.
• It’s included with Elixir
Rails like Generators
• mix phoenix.gen.html Post posts title body:text
• mix phoenix.gen.json User users name:string
• mix phoenix.gen.model User users name:string
Concurrency
• Async processing with out the need for
DelayedJob or Resque/sidekiq
• We can write code that looks like this.
Isolated & Concurrent
• Crashes are isolated
• Data is isolated 

(GC is per process, no global pauses)
• Load Balances on IO and CPU - Efficient on a
multicore
Garbage Collection
• No triggering massive garbage collection
• GC per process / end of process life cycle
• Ensuring top 10 percent of requests are not vastly
slower than any other request
Request Pipeline
• Just a series of function calls that transform
data.
• connection 

|> endpoint

|> router

|> pipelines

|> controller
Request Pipeline
• Phoenix makes it easy to add middleware or
plugs to this pipeline. We could easily add
authentication to this.
• connection 

|> endpoint

|> router

|> pipelines

|> authenticate_user

|> controller
Explicitness Over Magic
• Phoenix Removes a lot of the confusion and
“magic” found in rails and replaces it with
explicit calls.
• Models, Controllers and Views are singular
named by convention.
Phoenix Router
Phoenix Router
Phoenix Router
Phoenix Controllers
Phoenix Model
Phoenix View
Phoenix Template
Learn More
• Elixir-Lang on Slack 

https://elixir-slackin.herokuapp.com/
• #elixir-lang on Freenode IRC
• http://www.phoenixframework.org
• http://elixir-lang.org/
• https://github.com/h4cc/awesome-elixir

Más contenido relacionado

La actualidad más candente

PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep InternalEXEM
 
Universal metrics with Apache Beam
Universal metrics with Apache BeamUniversal metrics with Apache Beam
Universal metrics with Apache BeamEtienne Chauchot
 
M|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScaleM|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScaleMariaDB plc
 
Elixir Programming Language 101
Elixir Programming Language 101Elixir Programming Language 101
Elixir Programming Language 101Around25
 
Build Low-Latency Applications in Rust on ScyllaDB
Build Low-Latency Applications in Rust on ScyllaDBBuild Low-Latency Applications in Rust on ScyllaDB
Build Low-Latency Applications in Rust on ScyllaDBScyllaDB
 
Replication in PostgreSQL tutorial given in Postgres Conference 2019
Replication in PostgreSQL tutorial given in Postgres Conference 2019Replication in PostgreSQL tutorial given in Postgres Conference 2019
Replication in PostgreSQL tutorial given in Postgres Conference 2019Abbas Butt
 
Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDPlcplcp1
 
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPFA Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPFoholiab
 
Introduction to Vacuum Freezing and XID
Introduction to Vacuum Freezing and XIDIntroduction to Vacuum Freezing and XID
Introduction to Vacuum Freezing and XIDPGConf APAC
 
MySQL InnoDB Cluster - Advanced Configuration & Operations
MySQL InnoDB Cluster - Advanced Configuration & OperationsMySQL InnoDB Cluster - Advanced Configuration & Operations
MySQL InnoDB Cluster - Advanced Configuration & OperationsFrederic Descamps
 
Best Practices for Middleware and Integration Architecture Modernization with...
Best Practices for Middleware and Integration Architecture Modernization with...Best Practices for Middleware and Integration Architecture Modernization with...
Best Practices for Middleware and Integration Architecture Modernization with...Claus Ibsen
 
Kafka Tutorial: Advanced Producers
Kafka Tutorial: Advanced ProducersKafka Tutorial: Advanced Producers
Kafka Tutorial: Advanced ProducersJean-Paul Azar
 
MySQL Shell - the best DBA tool !
MySQL Shell - the best DBA tool !MySQL Shell - the best DBA tool !
MySQL Shell - the best DBA tool !Frederic Descamps
 
Centralized log-management-with-elastic-stack
Centralized log-management-with-elastic-stackCentralized log-management-with-elastic-stack
Centralized log-management-with-elastic-stackRich Lee
 
Using Time Window Compaction Strategy For Time Series Workloads
Using Time Window Compaction Strategy For Time Series WorkloadsUsing Time Window Compaction Strategy For Time Series Workloads
Using Time Window Compaction Strategy For Time Series WorkloadsJeff Jirsa
 
PostgreSQL Tuning: O elefante mais rápido que um leopardo
PostgreSQL Tuning: O elefante mais rápido que um leopardoPostgreSQL Tuning: O elefante mais rápido que um leopardo
PostgreSQL Tuning: O elefante mais rápido que um leopardoelliando dias
 

La actualidad más candente (20)

PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep Internal
 
Universal metrics with Apache Beam
Universal metrics with Apache BeamUniversal metrics with Apache Beam
Universal metrics with Apache Beam
 
M|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScaleM|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScale
 
ELK Stack
ELK StackELK Stack
ELK Stack
 
Elixir Programming Language 101
Elixir Programming Language 101Elixir Programming Language 101
Elixir Programming Language 101
 
Build Low-Latency Applications in Rust on ScyllaDB
Build Low-Latency Applications in Rust on ScyllaDBBuild Low-Latency Applications in Rust on ScyllaDB
Build Low-Latency Applications in Rust on ScyllaDB
 
Replication in PostgreSQL tutorial given in Postgres Conference 2019
Replication in PostgreSQL tutorial given in Postgres Conference 2019Replication in PostgreSQL tutorial given in Postgres Conference 2019
Replication in PostgreSQL tutorial given in Postgres Conference 2019
 
Clean Code
Clean CodeClean Code
Clean Code
 
Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDP
 
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPFA Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
 
Introduction to Vacuum Freezing and XID
Introduction to Vacuum Freezing and XIDIntroduction to Vacuum Freezing and XID
Introduction to Vacuum Freezing and XID
 
Building Netty Servers
Building Netty ServersBuilding Netty Servers
Building Netty Servers
 
MySQL InnoDB Cluster - Advanced Configuration & Operations
MySQL InnoDB Cluster - Advanced Configuration & OperationsMySQL InnoDB Cluster - Advanced Configuration & Operations
MySQL InnoDB Cluster - Advanced Configuration & Operations
 
Best Practices for Middleware and Integration Architecture Modernization with...
Best Practices for Middleware and Integration Architecture Modernization with...Best Practices for Middleware and Integration Architecture Modernization with...
Best Practices for Middleware and Integration Architecture Modernization with...
 
Kafka Tutorial: Advanced Producers
Kafka Tutorial: Advanced ProducersKafka Tutorial: Advanced Producers
Kafka Tutorial: Advanced Producers
 
MySQL Shell - the best DBA tool !
MySQL Shell - the best DBA tool !MySQL Shell - the best DBA tool !
MySQL Shell - the best DBA tool !
 
Centralized log-management-with-elastic-stack
Centralized log-management-with-elastic-stackCentralized log-management-with-elastic-stack
Centralized log-management-with-elastic-stack
 
Using Time Window Compaction Strategy For Time Series Workloads
Using Time Window Compaction Strategy For Time Series WorkloadsUsing Time Window Compaction Strategy For Time Series Workloads
Using Time Window Compaction Strategy For Time Series Workloads
 
PostgreSQL Tuning: O elefante mais rápido que um leopardo
PostgreSQL Tuning: O elefante mais rápido que um leopardoPostgreSQL Tuning: O elefante mais rápido que um leopardo
PostgreSQL Tuning: O elefante mais rápido que um leopardo
 
Linux Programming
Linux ProgrammingLinux Programming
Linux Programming
 

Similar a Intro to elixir and phoenix

Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threadsmperham
 
Repeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirRepeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirBarry Jones
 
C# Async/Await Explained
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await ExplainedJeremy Likness
 
Concurrency & Parallel Programming
Concurrency & Parallel ProgrammingConcurrency & Parallel Programming
Concurrency & Parallel ProgrammingRamazan AYYILDIZ
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012Eonblast
 
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 gamesWooga
 
The Economies of Scaling Software
The Economies of Scaling SoftwareThe Economies of Scaling Software
The Economies of Scaling SoftwareAbdelmonaim Remani
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Newlink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Newlink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640LLC NewLink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Newlink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Newlink
 
The economies of scaling software - Abdel Remani
The economies of scaling software - Abdel RemaniThe economies of scaling software - Abdel Remani
The economies of scaling software - Abdel Remanijaxconf
 

Similar a Intro to elixir and phoenix (20)

Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
Elixir
ElixirElixir
Elixir
 
Scalable game-servers-tgc
Scalable game-servers-tgcScalable game-servers-tgc
Scalable game-servers-tgc
 
Repeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirRepeating History...On Purpose...with Elixir
Repeating History...On Purpose...with Elixir
 
C# Async/Await Explained
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await Explained
 
Scaling tappsi
Scaling tappsiScaling tappsi
Scaling tappsi
 
From Ruby to Elixir
From Ruby to ElixirFrom Ruby to Elixir
From Ruby to Elixir
 
Concurrency & Parallel Programming
Concurrency & Parallel ProgrammingConcurrency & Parallel Programming
Concurrency & Parallel Programming
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012
 
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
 
Scheduling Thread
Scheduling  ThreadScheduling  Thread
Scheduling Thread
 
The Economies of Scaling Software
The Economies of Scaling SoftwareThe Economies of Scaling Software
The Economies of Scaling Software
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
The economies of scaling software - Abdel Remani
The economies of scaling software - Abdel RemaniThe economies of scaling software - Abdel Remani
The economies of scaling software - Abdel Remani
 
Erlang/Elixir and OTP
Erlang/Elixir and OTPErlang/Elixir and OTP
Erlang/Elixir and OTP
 

Último

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Último (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Intro to elixir and phoenix

  • 1. Elixir & Phoenix Functional |> Concurrent |> Pragmatic |> Fun
  • 2. Who am I? • Jared Smith • Software Engineer at One Month • @sublimecoder • www.sublimecoding.com
  • 4. First lets talk about Erlang • Elixir runs on the Erlang VM • Many of the standard lib function calls in Elixir call Erlang functions directly. • Elixir piggy backs on the Erlang ecosystem
  • 5. Why Erlang VM? • 30 year old battle tested VM • Highly available, fault tolerant, and distributed
  • 6. History of Erlang • Developed by Ericsson • Used and developed for Telecommunications • In fact its standard library is the OTP (Open Telecom Platform)
  • 7. Telecommunications • High availability is king • Remote Telecom switches need to run for years sometimes with out being disturbed
  • 8. Built with Erlang • 50 person engineering team • managing 900 million users. • Up to 2 million active users per server. https://blog.whatsapp.com/196/1-million-is-so-2011
  • 9. 2 Million Active Users? • Intel Xeon CPU x5675 @ 3.07GHz
 24 Cores - 96GB Ram • Using only 40% of the CPU/Memory https://blog.whatsapp.com/196/1-million-is-so-2011
  • 10. So Erlang is pretty awesome • Wouldn’t it be nice if we could harness this power? • Why isn’t everyone using Erlang?
  • 11. Elixir • Elixir utilizes much of the power of Erlang • While giving us a much nicer syntax and api to work with.
  • 12. History of Elixir • Created by Josè Valím - (Joe-zay Val-eem) • First released in 2012
  • 13. Elixir’s Strengths • Concurrency • Meta-programming Capability • Transformation of data as a core ideal
  • 14. Plus it has Ruby like syntax
  • 15. Pipe Operator • The following code is valid elixir. • With the pipe operator we can write our code this way instead. Keeping us out of nested function hell.
  • 16. Pattern Matching • Pattern matching is a core part of Erlang and Elixir
  • 17. What is Pattern Matching? • Make left side look like the right side • a = 99 • [a,b,c] = [1,2,3] • [head | tail] = [1,2,3]
  • 18. Immutability • Once you set a value 
 it can never change.
  • 20. You’re already familiar with immutability you just don’t know it. • a = 99 • We all know 99 is always 99. • integers are immutable values, even in Ruby. • You’d be upset if someone monkey patched 99 to be 3 right?
  • 21. Why is Immutability a good thing? • Immutability provides a contract that each piece of information has one source of truth. • Concurrency is a natural side effect of immutability.
  • 22. Does this mean I can never change a variable once I set it? • The short answer is no, you can reassign variables as much as you like. • Erlang would not be so kind, but Elixir we have this luxury.
  • 23. So how is it immutable if I can change things? • You can change things, elixir will just copy the values you don’t change, but the original reference stays intact. • The original reference can then be used in part or in whole later in the application.
  • 24. Isn’t this inefficient? • At first glance it would seem that way, but the opposite is true. • Won’t all the old reference values balloon elixirs memory? • Yes this means you could have thousands of unused variables floating in memory
  • 26. Concurrency fixes everything • Because the data is immutable we can rely on it always being a certain value • which means we can make our programs concurrent and not worry. • Elixir uses its concurrency to help with garbage collections. Each process gets it own heap allocated and that heap is garbage collected or reclaimed as needed for that individual process.
  • 27. Concurrency • Elixir will eat as many cores/computers as you can throw at it. • It treats each core as though it were a computer on the network with near zero latency.
  • 28.
  • 30. Phoenix Framework • Created by Chris McCord • Release 1.0 August 28th 2015
  • 31.
  • 32. Phoenix Framework • It’s not rails for Elixir • It has been influence heavily by rails as well as many other frameworks. • Focus on API and web sockets
  • 33. Speed • Web request response time is often measured in micro seconds and not milliseconds.
  • 34. Benchmarks • Recently benchmarked 2 million+ web socket connections • With 2 - 3 second broadcast times to all 2 million connections
  • 38. Easy Startup • mix phoenix.new ./app/path/my_app • mix ecto.create && mix ecto.migrate • mix phoenix.server
  • 41. Mix • Mix is essentially bundler and rake combined • Additionally mix is your test runner. • It’s included with Elixir
  • 42. Rails like Generators • mix phoenix.gen.html Post posts title body:text • mix phoenix.gen.json User users name:string • mix phoenix.gen.model User users name:string
  • 43. Concurrency • Async processing with out the need for DelayedJob or Resque/sidekiq • We can write code that looks like this.
  • 44. Isolated & Concurrent • Crashes are isolated • Data is isolated 
 (GC is per process, no global pauses) • Load Balances on IO and CPU - Efficient on a multicore
  • 45. Garbage Collection • No triggering massive garbage collection • GC per process / end of process life cycle • Ensuring top 10 percent of requests are not vastly slower than any other request
  • 46. Request Pipeline • Just a series of function calls that transform data. • connection 
 |> endpoint
 |> router
 |> pipelines
 |> controller
  • 47. Request Pipeline • Phoenix makes it easy to add middleware or plugs to this pipeline. We could easily add authentication to this. • connection 
 |> endpoint
 |> router
 |> pipelines
 |> authenticate_user
 |> controller
  • 48. Explicitness Over Magic • Phoenix Removes a lot of the confusion and “magic” found in rails and replaces it with explicit calls. • Models, Controllers and Views are singular named by convention.
  • 56. Learn More • Elixir-Lang on Slack 
 https://elixir-slackin.herokuapp.com/ • #elixir-lang on Freenode IRC • http://www.phoenixframework.org • http://elixir-lang.org/ • https://github.com/h4cc/awesome-elixir