SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
Concurrency, Robustness and Elixir
SoCraTes 2015
Erlang About Erlang
What is Erlang?
Erlang is ...
●
A programming language (Concurrent, Functional)
●
A virtual machine (lightweight, massively concurrent, asynchronous)
●
An ecosystem (OTP, design patterns and libraries for building robust systems)
●
Developed since 1986, Joe Armstrong et al (Ericsson)
●
Open Source since 1998
●
Initially used for telephone switches
●
Now for many other applications requiring High Availability & distributed
concurrency:
➔
ejabberd
➔
CouchDB
➔
GitHub
Elixir The Elixir project
What is Elixir?
Elixir is a functional, concurrent, general-purpose programming language built atop
the Erlang Virtual Machine.
●
Full compatibility with the Erlang universe, compiles to Erlang bytecode
●
Refurbished syntax (Ruby inspired)
●
Aims for enhanced productivity (better build tools, less boilerplate)
●
Extensibility (Structs, Protocols, DSLs -> Clojure inspired)
Quite young -> First commit Jan 9, 2011
Current version 1.0.5
http://elixir-lang.org/
Erlang Computing challenges of the 21st century
4004
8080
186
286
i386
i486
P5 Pentium
P6
P7
Core
Nehalem
Ivy Bridge
Haswell
0.1
1
10
100
1000
10000
MHz
Clock speed limit Multicore Clustering & Cloud High availability
Concurrent
programming
in Elixir
Elixir The Actor model
Process
Mailbox
Msg 1
Msg 2
Msg 3
defmodule ListenerServer do
use GenServer
def init(args) do
Process.register self, :listener
{:ok, []}
end
def handle_cast(:quit, state) do
{:stop, :normal, state}
end
def handle_cast(message, state) do
IO.puts "Got the message '#{message}'"
{:noreply, state}
end
end
Behaviour
{ state }
Elixir The Actor model
Process
Spawn
Send/
Receive
Mailbox
Msg 1
Msg 2
Msg 3
defmodule ListenerServer do
use GenServer
def init(args) do
Process.register self, :listener
{:ok, []}
end
def handle_cast(:quit, state) do
{:stop, :normal, state}
end
def handle_cast(message, state) do
IO.puts "Got the message'"
{:noreply, state}
end
end
Behaviour
{state}
Elixir Actors in Elixir
Erlang / Elixirs key feature: Packing code into small chunks that can be run
independently and concurrently.
Actor Model:
●
Independent asynchronous processes
●
Share nothing with other processes
●
Communication only via messages
●
Messages are stored in the process mailbox until consumed
●
A process can create new processes
●
Processes have an inner state
Elixir processes ...
●
Aren't system threads or processes.
●
Managed by the Erlang Virtual Machine
●
Extremely light-weight, nearly no overhead to create one.
●
Even a modest computer can run > 100000 Elixir processes.
●
Can be changed at run-time (hot-code swapping)
Elixir OOP versus COP
Object oriented programming Concurrent oriented programming
Class Actor
Instance Process
Instantiation Spawn
Constructor Initializer
Prototype Behaviour
Setter/Getter Message
Interface Protocol
Attribute State
Singleton Registered process
pid = spawn function # Start a new process, return its PID
send pid, message # Send message to process with pid
receive do # Try to match messages in process mailbox
match1 -> result1
match2 -> result2
...
after timeout -> result # Result when no message arrived in timeout
end
self # Process ID of current process
Process.list # List all running processes
flush # (iex) Flush mailbox, print all messages
:pman.start # Start Erlang process manager
Elixir Concurrent programming
defmodule Listener do
def listen do
receive do
:quit -> exit(nil)
message -> IO.puts "Got the message '#{message}'"
end
listen
end
end
listener = spawn fn -> Listener.listen end
send listener, "Hello World"
send listener, :quit
Elixir Process programming
defmodule Listener do
def listen do
receive do
:quit -> exit(nil)
{message, from} -> IO.puts "Got the message '#{message}'"
send from, "Thank you for the message!"
end
listen
end
end
listener = spawn fn -> Listener.listen end
send listener, {"Hello World", self}
flush
send listener, :quit
flush
Elixir Process programming
defmodule Listener do
def start do
Process.register self, :listener
listen
end
def listen do
receive do
:quit -> exit(nil)
message -> IO.puts "Got the message '#{message}'"
end
listen
end
end
spawn fn -> Listener.start end
send :listener, "Hello World"
send :listener, :quit
Elixir Process registering
Elixir Process behaviours
Task Asynchronous calculation
Agent State-carrying process
GenServer Generic OTP Server
Supervisor OTP Supervisor
Application OTP Application
GenEvent Generic Event Handler
:gen_fsm Generic Finite State Machine
Elixir Tasks and Agents
# Start an independent task
task = Task.async(fn -> do_some_work() end)
# Collect the result
result = Task.await(task)
Tasks: Independent asynchronous calculations
# Start a new agent
{:ok, agent} = Agent.start(fn -> initial_state end)
# Update the agent state
Agent.update(agent, fn old_state -> new_state end)
# Get the current agent state
Agent.get(agent, fn state -> value end)
# Terminate the agent
Agent.stop(agent)
Agents: Wrappers around state
line = "Freude schöner Götterfunken"
task = Task.async(fn -> String.upcase(line) end)
IO.puts Task.await(task)
task = Task.async(fn -> :timer.sleep(3000);
String.upcase(line) end)
IO.puts "Waiting for the task to complete..."
IO.puts Task.await(task)
Elixir Task and Agent example
{:ok, agent} = Agent.start(fn -> 0 end, [name: :counter])
IO.puts Agent.get(:counter, fn value -> value end)
Agent.update(:counter, fn value -> value+1 end)
IO.puts Agent.get(:counter, fn value -> value end)
Agent.stop(:counter)
Elixir Generic Server Callbacks
defmodule MyServer do
use GenServer
# Initialize server
def init(args), do: {:ok, state}
# Terminate server
def terminate(reason, state), do: {reason, state}
# Call with reply
def handle_call(msg, from, state), do: {:reply, reply, new_state}
# Casts without reply
def handle_cast( msg, state ), do: {:noreply, new_state}
# All other messages
def handle_info( msg, state ), do: {:noreply, new_state}
# Hot code swap
def code_change( vsn, state, extra ), do: {:ok, new_state}
end
defmodule ListenerServer do
use GenServer
# Public API
def start_link, do: GenServer.start_link ListenerServer, []
# Callback functions
def init(args) do
Process.register self, :listener
{:ok, []}
end
def handle_cast(:quit, state) do
{:stop, :normal, state}
end
def handle_cast(message, state) do
IO.puts "Got the message '#{message}'"
{:noreply, state}
end
end
{:ok, pid} = ListenerServer.start_link
GenServer.cast :listener, "Hello"
GenServer.cast :listener, :quit
Elixir Generic Server
defmodule ListenerServer.Supervisor do
import Supervisor.Spec
def start do
children = [ worker(ListenerServer, [], restart: :transient) ]
Supervisor.start_link(children, strategy: :one_for_one)
end
end
ListenerServer.Supervisor.start
GenServer.cast :listener, "Hello"
GenServer.cast :listener, {1,2,3} # Crashes the listener server
GenServer.cast :listener, "Hello World"
GenServer.cast :listener, :quit
Elixir Supervision
defmodule FirstEventHandler do
use GenEvent
def handle_event(message, state) do
IO.puts "The first event handler was notified: '#{message}'"
{:ok, state}
end
end
defmodule SecondEventHandler do
use GenEvent
def handle_event(message, state) do
IO.puts "The second event handler was notified: '#{message}'"
{:ok, state}
end
end
GenEvent.start_link(name: :eventmanager)
GenEvent.add_handler(:eventmanager, FirstEventHandler, nil)
GenEvent.add_handler(:eventmanager, SecondEventHandler, nil)
GenEvent.notify(:eventmanager, "Hi there!")
Elixir Event Handler
defmodule FiniteStateMachine do
@behaviour :gen_fsm
def start_link(_opts) do
:gen_fsm.start_link({:local, FSM}, __MODULE__, [], [])
end
def next_state() do
:gen_fsm.send_event(FSM, :round)
end
def init(_), do: IO.puts "FSM started"; { :ok, :ping, [] }
def ping(:round, state), do: IO.puts "Ping!"; {:next_state, :pong, state}
def pong(:round, state), do: IO.puts "Pong!"; {:next_state, :ping, state}
end
FiniteStateMachine.start_link [] # "FSM started"
FiniteStateMachine.next_state # "Ping!"
FiniteStateMachine.next_state # "Pong!"
FiniteStateMachine.next_state # "Ping!"
FiniteStateMachine.next_state # "Pong!"
Elixir Finite state machine
Elixir OTP
Super-Supervisor
Supervisor Supervisor
Supervisor
Worker Worker Worker
Worker
Worker Worker WorkerHelper Helper
Application
defmodule ExampleApp do
use Application
def start(_type, _args) do
MainSupervisor.start
end
end
Elixir Elixir application project
Build tool mix:
> mix new exampleapp
mix.exs # Mix project definition file
/config/config.exs # Project specific configuration
/lib/ # Source code
/test/ # Tests suites
# Starts the BEAM Erlang Virtual Machine
# and the EPMD Erlang Port Mapper Daemon (default port 4369)
cluster01> elixir --sname node --no-halt --cookie secret_cookie
Elixir Distributed computing: Nodes
# Elixir master node (on same subnet as cluster nodes)
master> iex --sname masternode --cookie secret_cookie
Node.connect :"node@cluster01" # Establish node connection
pid = Node.spawn :"node@cluster01", func # Spawn a process
Node.self # Name of current node
Node.list # List all connected nodes

Contenu connexe

Tendances

Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debuggerIulian Dragos
 
GenRetry: Simple Exponential Backoff in Elixir
GenRetry: Simple Exponential Backoff in ElixirGenRetry: Simple Exponential Backoff in Elixir
GenRetry: Simple Exponential Backoff in ElixirPete Gamache
 
Introduction to Phoenix Framework (Elixir) 2016-01-07
Introduction to Phoenix Framework (Elixir) 2016-01-07Introduction to Phoenix Framework (Elixir) 2016-01-07
Introduction to Phoenix Framework (Elixir) 2016-01-07Svein Fidjestøl
 
Awesome Concurrency with Elixir Tasks
Awesome Concurrency with Elixir TasksAwesome Concurrency with Elixir Tasks
Awesome Concurrency with Elixir TasksJonathan Magen
 
DDD loves Actor Model and Actor Model loves Elixir
DDD loves Actor Model and Actor Model loves ElixirDDD loves Actor Model and Actor Model loves Elixir
DDD loves Actor Model and Actor Model loves ElixirGianluca Padovani
 
c3ee900a-894b-4680-894c-42f77ffd4446-160308162303
c3ee900a-894b-4680-894c-42f77ffd4446-160308162303c3ee900a-894b-4680-894c-42f77ffd4446-160308162303
c3ee900a-894b-4680-894c-42f77ffd4446-160308162303Robert Warren
 
Ansible, Idempotency, and Jenkins
Ansible, Idempotency, and JenkinsAnsible, Idempotency, and Jenkins
Ansible, Idempotency, and Jenkinstylerturk
 
Voice Interfaces Usergroup Berlin - 05-10-2016 : Kay Lerch on Morse-Coder skill
Voice Interfaces Usergroup Berlin - 05-10-2016 : Kay Lerch on Morse-Coder skillVoice Interfaces Usergroup Berlin - 05-10-2016 : Kay Lerch on Morse-Coder skill
Voice Interfaces Usergroup Berlin - 05-10-2016 : Kay Lerch on Morse-Coder skillKay Lerch
 
Nice performance using Sf2 cache wrapping Sf1 application - Paris
Nice performance using Sf2 cache wrapping Sf1 application - ParisNice performance using Sf2 cache wrapping Sf1 application - Paris
Nice performance using Sf2 cache wrapping Sf1 application - ParisMarc Weistroff
 
How Symfony Changed My Life
How Symfony Changed My LifeHow Symfony Changed My Life
How Symfony Changed My LifeMatthias Noback
 
Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Mindfire Solutions
 
Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013Noopur Gupta
 
C# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programmingC# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programmingPraveen Prajapati
 
JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014Noopur Gupta
 
Elm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebElm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebPublitory
 

Tendances (20)

Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debugger
 
GenRetry: Simple Exponential Backoff in Elixir
GenRetry: Simple Exponential Backoff in ElixirGenRetry: Simple Exponential Backoff in Elixir
GenRetry: Simple Exponential Backoff in Elixir
 
Introduction to Phoenix Framework (Elixir) 2016-01-07
Introduction to Phoenix Framework (Elixir) 2016-01-07Introduction to Phoenix Framework (Elixir) 2016-01-07
Introduction to Phoenix Framework (Elixir) 2016-01-07
 
Awesome Concurrency with Elixir Tasks
Awesome Concurrency with Elixir TasksAwesome Concurrency with Elixir Tasks
Awesome Concurrency with Elixir Tasks
 
DDD loves Actor Model and Actor Model loves Elixir
DDD loves Actor Model and Actor Model loves ElixirDDD loves Actor Model and Actor Model loves Elixir
DDD loves Actor Model and Actor Model loves Elixir
 
c3ee900a-894b-4680-894c-42f77ffd4446-160308162303
c3ee900a-894b-4680-894c-42f77ffd4446-160308162303c3ee900a-894b-4680-894c-42f77ffd4446-160308162303
c3ee900a-894b-4680-894c-42f77ffd4446-160308162303
 
CPP03 - Repetition
CPP03 - RepetitionCPP03 - Repetition
CPP03 - Repetition
 
Ansible, Idempotency, and Jenkins
Ansible, Idempotency, and JenkinsAnsible, Idempotency, and Jenkins
Ansible, Idempotency, and Jenkins
 
React Testing
React TestingReact Testing
React Testing
 
Voice Interfaces Usergroup Berlin - 05-10-2016 : Kay Lerch on Morse-Coder skill
Voice Interfaces Usergroup Berlin - 05-10-2016 : Kay Lerch on Morse-Coder skillVoice Interfaces Usergroup Berlin - 05-10-2016 : Kay Lerch on Morse-Coder skill
Voice Interfaces Usergroup Berlin - 05-10-2016 : Kay Lerch on Morse-Coder skill
 
Nice performance using Sf2 cache wrapping Sf1 application - Paris
Nice performance using Sf2 cache wrapping Sf1 application - ParisNice performance using Sf2 cache wrapping Sf1 application - Paris
Nice performance using Sf2 cache wrapping Sf1 application - Paris
 
How Symfony Changed My Life
How Symfony Changed My LifeHow Symfony Changed My Life
How Symfony Changed My Life
 
Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1
 
Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013
 
C# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programmingC# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programming
 
JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014
 
Elixir for Rubyists
Elixir for RubyistsElixir for Rubyists
Elixir for Rubyists
 
2021laravelconftwslides6
2021laravelconftwslides62021laravelconftwslides6
2021laravelconftwslides6
 
Create Your Own Language
Create Your Own LanguageCreate Your Own Language
Create Your Own Language
 
Elm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebElm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and Web
 

Similaire à Concurrency, Robustness & Elixir SoCraTes 2015

Yurii Bodarev - OTP, Phoenix & Ecto: Three Pillars of Elixir
Yurii Bodarev - OTP, Phoenix & Ecto: Three Pillars of ElixirYurii Bodarev - OTP, Phoenix & Ecto: Three Pillars of Elixir
Yurii Bodarev - OTP, Phoenix & Ecto: Three Pillars of ElixirElixir Club
 
Concurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksConcurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksWO Community
 
Introduction to Erlang/(Elixir) at a Webilea Hands-On Session
Introduction to Erlang/(Elixir) at a Webilea Hands-On SessionIntroduction to Erlang/(Elixir) at a Webilea Hands-On Session
Introduction to Erlang/(Elixir) at a Webilea Hands-On SessionAndré Graf
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)jeffz
 
TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...
TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...
TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...tdc-globalcode
 
Concurrency in Elixir with OTP
Concurrency in Elixir with OTPConcurrency in Elixir with OTP
Concurrency in Elixir with OTPJustin Reese
 
Giorgio zoppi cpp11concurrency
Giorgio zoppi cpp11concurrencyGiorgio zoppi cpp11concurrency
Giorgio zoppi cpp11concurrencyGiorgio Zoppi
 
Elixir Into Production
Elixir Into ProductionElixir Into Production
Elixir Into ProductionJamie Winsor
 
Game Analytics Cluster Scheduler
Game Analytics Cluster SchedulerGame Analytics Cluster Scheduler
Game Analytics Cluster Schedulercmmdevries
 
Combining the strength of erlang and Ruby
Combining the strength of erlang and RubyCombining the strength of erlang and Ruby
Combining the strength of erlang and RubyMartin Rehfeld
 
Combining the Strengths or Erlang and Ruby
Combining the Strengths or Erlang and RubyCombining the Strengths or Erlang and Ruby
Combining the Strengths or Erlang and RubyWooga
 
Get into Functional Programming with Clojure
Get into Functional Programming with ClojureGet into Functional Programming with Clojure
Get into Functional Programming with ClojureJohn Stevenson
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to ElixirDiacode
 
Dealing with Python Reactively - PyCon Korea 2017
Dealing with Python Reactively - PyCon Korea 2017Dealing with Python Reactively - PyCon Korea 2017
Dealing with Python Reactively - PyCon Korea 2017Kenneth Ceyer
 
Introduction To Erlang Final
Introduction To Erlang   FinalIntroduction To Erlang   Final
Introduction To Erlang FinalSinarShebl
 

Similaire à Concurrency, Robustness & Elixir SoCraTes 2015 (20)

Elixir concurrency 101
Elixir concurrency 101Elixir concurrency 101
Elixir concurrency 101
 
Yurii Bodarev - OTP, Phoenix & Ecto: Three Pillars of Elixir
Yurii Bodarev - OTP, Phoenix & Ecto: Three Pillars of ElixirYurii Bodarev - OTP, Phoenix & Ecto: Three Pillars of Elixir
Yurii Bodarev - OTP, Phoenix & Ecto: Three Pillars of Elixir
 
Concurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksConcurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background Tasks
 
Introduction to Erlang/(Elixir) at a Webilea Hands-On Session
Introduction to Erlang/(Elixir) at a Webilea Hands-On SessionIntroduction to Erlang/(Elixir) at a Webilea Hands-On Session
Introduction to Erlang/(Elixir) at a Webilea Hands-On Session
 
Node js lecture
Node js lectureNode js lecture
Node js lecture
 
Concurrecny inf sharp
Concurrecny inf sharpConcurrecny inf sharp
Concurrecny inf sharp
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
 
TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...
TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...
TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...
 
Concurrency in Elixir with OTP
Concurrency in Elixir with OTPConcurrency in Elixir with OTP
Concurrency in Elixir with OTP
 
Giorgio zoppi cpp11concurrency
Giorgio zoppi cpp11concurrencyGiorgio zoppi cpp11concurrency
Giorgio zoppi cpp11concurrency
 
Elixir Into Production
Elixir Into ProductionElixir Into Production
Elixir Into Production
 
Celery with python
Celery with pythonCelery with python
Celery with python
 
Game Analytics Cluster Scheduler
Game Analytics Cluster SchedulerGame Analytics Cluster Scheduler
Game Analytics Cluster Scheduler
 
Combining the strength of erlang and Ruby
Combining the strength of erlang and RubyCombining the strength of erlang and Ruby
Combining the strength of erlang and Ruby
 
Combining the Strengths or Erlang and Ruby
Combining the Strengths or Erlang and RubyCombining the Strengths or Erlang and Ruby
Combining the Strengths or Erlang and Ruby
 
Get into Functional Programming with Clojure
Get into Functional Programming with ClojureGet into Functional Programming with Clojure
Get into Functional Programming with Clojure
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
 
Dealing with Python Reactively - PyCon Korea 2017
Dealing with Python Reactively - PyCon Korea 2017Dealing with Python Reactively - PyCon Korea 2017
Dealing with Python Reactively - PyCon Korea 2017
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 
Introduction To Erlang Final
Introduction To Erlang   FinalIntroduction To Erlang   Final
Introduction To Erlang Final
 

Dernier

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 

Dernier (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

Concurrency, Robustness & Elixir SoCraTes 2015

  • 1. Concurrency, Robustness and Elixir SoCraTes 2015
  • 2. Erlang About Erlang What is Erlang? Erlang is ... ● A programming language (Concurrent, Functional) ● A virtual machine (lightweight, massively concurrent, asynchronous) ● An ecosystem (OTP, design patterns and libraries for building robust systems) ● Developed since 1986, Joe Armstrong et al (Ericsson) ● Open Source since 1998 ● Initially used for telephone switches ● Now for many other applications requiring High Availability & distributed concurrency: ➔ ejabberd ➔ CouchDB ➔ GitHub
  • 3. Elixir The Elixir project What is Elixir? Elixir is a functional, concurrent, general-purpose programming language built atop the Erlang Virtual Machine. ● Full compatibility with the Erlang universe, compiles to Erlang bytecode ● Refurbished syntax (Ruby inspired) ● Aims for enhanced productivity (better build tools, less boilerplate) ● Extensibility (Structs, Protocols, DSLs -> Clojure inspired) Quite young -> First commit Jan 9, 2011 Current version 1.0.5 http://elixir-lang.org/
  • 4. Erlang Computing challenges of the 21st century 4004 8080 186 286 i386 i486 P5 Pentium P6 P7 Core Nehalem Ivy Bridge Haswell 0.1 1 10 100 1000 10000 MHz Clock speed limit Multicore Clustering & Cloud High availability
  • 6. Elixir The Actor model Process Mailbox Msg 1 Msg 2 Msg 3 defmodule ListenerServer do use GenServer def init(args) do Process.register self, :listener {:ok, []} end def handle_cast(:quit, state) do {:stop, :normal, state} end def handle_cast(message, state) do IO.puts "Got the message '#{message}'" {:noreply, state} end end Behaviour { state }
  • 7. Elixir The Actor model Process Spawn Send/ Receive Mailbox Msg 1 Msg 2 Msg 3 defmodule ListenerServer do use GenServer def init(args) do Process.register self, :listener {:ok, []} end def handle_cast(:quit, state) do {:stop, :normal, state} end def handle_cast(message, state) do IO.puts "Got the message'" {:noreply, state} end end Behaviour {state}
  • 8. Elixir Actors in Elixir Erlang / Elixirs key feature: Packing code into small chunks that can be run independently and concurrently. Actor Model: ● Independent asynchronous processes ● Share nothing with other processes ● Communication only via messages ● Messages are stored in the process mailbox until consumed ● A process can create new processes ● Processes have an inner state Elixir processes ... ● Aren't system threads or processes. ● Managed by the Erlang Virtual Machine ● Extremely light-weight, nearly no overhead to create one. ● Even a modest computer can run > 100000 Elixir processes. ● Can be changed at run-time (hot-code swapping)
  • 9. Elixir OOP versus COP Object oriented programming Concurrent oriented programming Class Actor Instance Process Instantiation Spawn Constructor Initializer Prototype Behaviour Setter/Getter Message Interface Protocol Attribute State Singleton Registered process
  • 10. pid = spawn function # Start a new process, return its PID send pid, message # Send message to process with pid receive do # Try to match messages in process mailbox match1 -> result1 match2 -> result2 ... after timeout -> result # Result when no message arrived in timeout end self # Process ID of current process Process.list # List all running processes flush # (iex) Flush mailbox, print all messages :pman.start # Start Erlang process manager Elixir Concurrent programming
  • 11. defmodule Listener do def listen do receive do :quit -> exit(nil) message -> IO.puts "Got the message '#{message}'" end listen end end listener = spawn fn -> Listener.listen end send listener, "Hello World" send listener, :quit Elixir Process programming
  • 12. defmodule Listener do def listen do receive do :quit -> exit(nil) {message, from} -> IO.puts "Got the message '#{message}'" send from, "Thank you for the message!" end listen end end listener = spawn fn -> Listener.listen end send listener, {"Hello World", self} flush send listener, :quit flush Elixir Process programming
  • 13. defmodule Listener do def start do Process.register self, :listener listen end def listen do receive do :quit -> exit(nil) message -> IO.puts "Got the message '#{message}'" end listen end end spawn fn -> Listener.start end send :listener, "Hello World" send :listener, :quit Elixir Process registering
  • 14. Elixir Process behaviours Task Asynchronous calculation Agent State-carrying process GenServer Generic OTP Server Supervisor OTP Supervisor Application OTP Application GenEvent Generic Event Handler :gen_fsm Generic Finite State Machine
  • 15. Elixir Tasks and Agents # Start an independent task task = Task.async(fn -> do_some_work() end) # Collect the result result = Task.await(task) Tasks: Independent asynchronous calculations # Start a new agent {:ok, agent} = Agent.start(fn -> initial_state end) # Update the agent state Agent.update(agent, fn old_state -> new_state end) # Get the current agent state Agent.get(agent, fn state -> value end) # Terminate the agent Agent.stop(agent) Agents: Wrappers around state
  • 16. line = "Freude schöner Götterfunken" task = Task.async(fn -> String.upcase(line) end) IO.puts Task.await(task) task = Task.async(fn -> :timer.sleep(3000); String.upcase(line) end) IO.puts "Waiting for the task to complete..." IO.puts Task.await(task) Elixir Task and Agent example {:ok, agent} = Agent.start(fn -> 0 end, [name: :counter]) IO.puts Agent.get(:counter, fn value -> value end) Agent.update(:counter, fn value -> value+1 end) IO.puts Agent.get(:counter, fn value -> value end) Agent.stop(:counter)
  • 17. Elixir Generic Server Callbacks defmodule MyServer do use GenServer # Initialize server def init(args), do: {:ok, state} # Terminate server def terminate(reason, state), do: {reason, state} # Call with reply def handle_call(msg, from, state), do: {:reply, reply, new_state} # Casts without reply def handle_cast( msg, state ), do: {:noreply, new_state} # All other messages def handle_info( msg, state ), do: {:noreply, new_state} # Hot code swap def code_change( vsn, state, extra ), do: {:ok, new_state} end
  • 18. defmodule ListenerServer do use GenServer # Public API def start_link, do: GenServer.start_link ListenerServer, [] # Callback functions def init(args) do Process.register self, :listener {:ok, []} end def handle_cast(:quit, state) do {:stop, :normal, state} end def handle_cast(message, state) do IO.puts "Got the message '#{message}'" {:noreply, state} end end {:ok, pid} = ListenerServer.start_link GenServer.cast :listener, "Hello" GenServer.cast :listener, :quit Elixir Generic Server
  • 19. defmodule ListenerServer.Supervisor do import Supervisor.Spec def start do children = [ worker(ListenerServer, [], restart: :transient) ] Supervisor.start_link(children, strategy: :one_for_one) end end ListenerServer.Supervisor.start GenServer.cast :listener, "Hello" GenServer.cast :listener, {1,2,3} # Crashes the listener server GenServer.cast :listener, "Hello World" GenServer.cast :listener, :quit Elixir Supervision
  • 20. defmodule FirstEventHandler do use GenEvent def handle_event(message, state) do IO.puts "The first event handler was notified: '#{message}'" {:ok, state} end end defmodule SecondEventHandler do use GenEvent def handle_event(message, state) do IO.puts "The second event handler was notified: '#{message}'" {:ok, state} end end GenEvent.start_link(name: :eventmanager) GenEvent.add_handler(:eventmanager, FirstEventHandler, nil) GenEvent.add_handler(:eventmanager, SecondEventHandler, nil) GenEvent.notify(:eventmanager, "Hi there!") Elixir Event Handler
  • 21. defmodule FiniteStateMachine do @behaviour :gen_fsm def start_link(_opts) do :gen_fsm.start_link({:local, FSM}, __MODULE__, [], []) end def next_state() do :gen_fsm.send_event(FSM, :round) end def init(_), do: IO.puts "FSM started"; { :ok, :ping, [] } def ping(:round, state), do: IO.puts "Ping!"; {:next_state, :pong, state} def pong(:round, state), do: IO.puts "Pong!"; {:next_state, :ping, state} end FiniteStateMachine.start_link [] # "FSM started" FiniteStateMachine.next_state # "Ping!" FiniteStateMachine.next_state # "Pong!" FiniteStateMachine.next_state # "Ping!" FiniteStateMachine.next_state # "Pong!" Elixir Finite state machine
  • 22. Elixir OTP Super-Supervisor Supervisor Supervisor Supervisor Worker Worker Worker Worker Worker Worker WorkerHelper Helper Application
  • 23. defmodule ExampleApp do use Application def start(_type, _args) do MainSupervisor.start end end Elixir Elixir application project Build tool mix: > mix new exampleapp mix.exs # Mix project definition file /config/config.exs # Project specific configuration /lib/ # Source code /test/ # Tests suites
  • 24. # Starts the BEAM Erlang Virtual Machine # and the EPMD Erlang Port Mapper Daemon (default port 4369) cluster01> elixir --sname node --no-halt --cookie secret_cookie Elixir Distributed computing: Nodes # Elixir master node (on same subnet as cluster nodes) master> iex --sname masternode --cookie secret_cookie Node.connect :"node@cluster01" # Establish node connection pid = Node.spawn :"node@cluster01", func # Spawn a process Node.self # Name of current node Node.list # List all connected nodes