SlideShare a Scribd company logo
1 of 45
Download to read offline
Joe Armstrong
Erlang
Though OOP came from many motivations, two were central.
The large scale one was to find a better module scheme for
complex systems involving hiding of details, and the small
scale one was to find a more flexible version of assignment,
and then to try to eliminate it altogether.
...doing encapsulation right is a commitment not just to
abstraction of state, but to eliminate state oriented
metaphors from programming.
The Early History of Smalltalk
Alan Kay
for i in {objects, processes}
{
create very large numbers of $i
$i work the same way on all OS's
$i's are garbage collected
$i are location transparent
$i cannot damage other $i
$i are defined in the language
creating and destroying $i is light-weight
}
Erlang is Smalltalk
as Alan Kay wanted
it
- Niall Dalton
How do we build systems that run
forever, are scalable, fault-tolerant,
evolve with time and work
reasonably well works despite
errors in the software?
Difficult
To make
a fault-tolerant system
you need at least
two
computers
this is
Distributed
Programming
Simplify the problem
no sharing
pure message passing
no locks
This is
Concurrency
Oriented
Programming
Concurrency Oriented Programming
●
A style of programming where
concurrency is used to structure the
application
●
Large numbers of processes
●
Complete isolation of
processes
●
No sharing of data
●
Location transparency
●
Pure message passing
My first message is that
concurrency
is best regarded as a program
structuring principle”
Structured concurrent programming
– Tony Hoare
Redmond, July 2001
COP Design Rules
1) Identify the concurrent operations in your problem
2) Identify the message channels
3) Write down the set of message seen on each channel
4) Write down the protocols
5) Write the code
Try to make the design isomorphic to the problem – ie a
1:1 correspondence between the process/message
structure in the model and the problem.
Who am I?
Inventor of Erlang, UBF
Chief designer of OTP
Founder of the company Bluetail
Currently
Senior System Architect
Ericsson AB
Current Interests
Concurrency Oriented Programming
Multi-core CPUs
FPGAs
Cats
Motorbikes
How do we correct hardware failures?
Replicate the hardware
How do we correct software errors?
Having two identical copies of the software
won't work – both will fail at the same time
and for the same reason
Why does your computer crash?
Which fails more often, hardware or software?
Architecture
Talk organisation
Introduction Erlang
Programming techniques
Programming fault-
tolerant systems
Building an
application
OTP Case studies
Conclusions
API's and protocols
It works!
History
1986 – Pots Erlang (in Prolog)
1987 – ACS/Dunder
1988 – Erlang -> Strand (fails)
1989 – JAM (Joe's abstract machine)
1990 – Erlang syntax changes (70x faster)
1991 – Distribution
1992 – Mobility Server
1993 – Erlang Systems AB
1995 – AXE-N collapses. AXD starts
1996 – OTP starts
1998 – AXD deployed. Erlang Banned. Open Source Erlang.
Bluetail formed
1999 – BMR sold
2000 – Alteon buys Blutail. Nortel buys Alteon
2002 – UBF. Concurrency Oriented Programming
2003 – Ph.D. Thesis - Making reliable systems
2006 – Multi-core Erlang
How do we make systems?
Systems are made of black boxes (components)
Black boxes execute concurrently
Black boxes communicate
How the black box works internally is irrelevant
Failures inside one black box should not crash
another black box
Problem domain
●
Highly concurrent (hundreds of thousands
of parallel activities)
●
Real time
●
Distributed
●
High Availability (down times of
minutes/year – never down)
●
Complex software (million of lines of code)
●
Continuous operation (years)
●
Continuous evolution
●
In service upgrade
Architecture
Philosophy
Way of doing things
Construction Guidelines
Programming examples
Philosophy
Concurrency Oriented Programming
1. COPLs support processes
2. Processes are Isolated
3. Each process has a unique unforgeable Id
4. There is no shared state between processes
5. Message passing is unreliable
6. It should be possible to detect failure in
another processes and we should know the reason
for failure
System requirements
R1. Concurrency processes
R2. Error encapsulation isolation
R3. Fault detection what failed
R4. Fault identification why it failed
R5. Live code upgrade evolving systems
R6. Stable storage crash recovery
Isolation
. Hardware
components operate
concurrently are
isolated and
communicate by
message passing
Consequences of Isolation
Processes have share nothing semantics and data must be
copied
Message passing is the only way to exchange data
Message passing is asynchronous
GOOD STUFF
Processes
Copying
Message passing
Language
My program should not be able to crash your program
Need strong isolation and concurrency
Processes are OK – threads are not (threads have
shared resources)
Can't use OS processes (Heavy – semantics depends on
OS)
Isolation
My program should not be able to
crash your program.
This is the single most important property that a system
component must have
All things are not equally important
Erlang
Lightweight processes (lighter than OS threads)
Good isolation (not perfect yet ...)
Programs never loose control
Error detection primitives
Reason for failure is known
Exceptions
Garbage collected memory
Lots of processes
Functional Agner Krarup Erlang (1878-1929)
Erlang in
11 minutes
Erlang
You can create a parallel process
Pid = spawn(fun() -> ... end).
then send it a message
Pid ! Msg
and then wait for a reply
receive
{Pid, Rely} ->
Actions
end
It typically takes 1 microsecond to
create a process or send a message
Processes are
isolated
Generalisation
Client
Pid = spawn(fun() -> loop() end)
Pid ! {self(), 21},
receive
{Pid, Val} -> ...
end
Server
loop() ->
receive
{From, X} ->
From ! {self(), 2*X},
loop()
end.
A simple process
Client
Double = fun(X) -> 2 *X end,
Pid = spawn(fun() -> loop(Double) end)
Pid ! {self(), 21},
receive
{Pid, Val} -> ...
end
Server
loop(F) ->
receive
{From, X} ->
From ! {self(), F(X)},
loop(F)
end.
Generalised
A generic server
-module(gserver).
-export([start/1, rpc/2, code_change/2]).
start(Fun) ->
spawn(fun() -> loop(Fun) end).
rpc(Pid, Q) ->
Pid ! {self(), Q},
receive
{Pid, Reply} ->
Reply
end.
code_change(Pid, Fun1) ->
Pid ! {swap_code, Fun1}.
loop(F) ->
receive
{swap_code, F1} ->
loop(F1);
{Pid, X} ->
Pid ! {self(), F(X)},
loop(F);
end.
Double = fun(X) -> 2*X end,
Pid = gserver:start(Double),
...
Triple = fun(X) -> 3*X end,
gserver:code_change(Pid, Triple)
A generic server with data
-module(gserver).
-export([start/2, rpc/2, code_change/2]).
start(Fun, Data) ->
spawn(fun() -> loop(Fun, Data) end).
rpc(Pid, Q) ->
Pid ! {self(), Q},
receive
{Pid, Reply} ->
Reply
end.
code_change(Pid, Fun1) ->
Pid ! {swap_code, Fun1}.
loop(F, Data) ->
receive
{swap_code, F1} ->
loop(F1, Data);
{Pid, X} ->
{Reply, Data1} = F(X),
Pid ! {self(), Reply},
loop(F, Data1);
end.
Trapping errors
In Pid1 ...
Pid2 = spawn_link(fun() -> ... end).
process_flag(trap_exit, true)
...
receive
{'EXIT', Pid, Why} ->
Actions
end.
Pid1
Pid1 Pid2
1/0
{'EXIT', Pid1, badarith}
error detection + reason for failure (slide 10)
Why remote trapping of errors?
To do fault-tolerant
computing you need
at least TWO
computers
Computer1
Computer1 Computer2
Error
{'EXIT', Computer2, Reason}
Which means you
can't share data
Programming for errors
If you can't do what you want to do try and do
something simpler
Workers
Supervisor
Links
The supervisor monitors the
workers and restarts them if
they fail
A supervision hierarchy
Workers
Supervisor and worker
Links
Supervisor
Links
Workers
OTP behaviours
Generic libraries for building
components of a real-time system.
Includes
Client-server
Finite State machine
Supervisor
Event Handler
Applications
Systems
case studies
Ericsson AXD301 (in Engine)
Size = 1136150 lines Erlang
Dirty functions = 0.359%
Availability = 99.9999999%
Alteon (Nortel) SSL accelerator
Size = 74440 line Erlang
Dirty functions = 0.82%
Ref: Armstrong Ph.D. thesis
Ericsson AXD301 (part of “Engine”)
Ericsson GPRS system
Alteon (Nortel) SSL accelerator
Alteon (Nortel) SSL VPN
Teba Bank (credit card system – South Africa)
T-mobile SMS system (UK)
Kreditor (Sweden)
jabber.org
Commercial Successes
How do we make systems?
Systems are made of black boxes (components)
Black boxes execute concurrently
Black boxes communicate with defined (universal)
protocols
The protocol is checked externally
How the black box works internally is irrelevant
Protocol checker
APIs done wrong
+type file:open(fileName(), read | write) ->
{ok, fileHandle()}
| {error, string()}.
+type file:read_line(fileHandle()) ->
{ok, string()} | eof.
+type file:close(fileHandle()) ->
true.
+deftype fileName() = [int()]
+deftype string() = [int()].
+deftype fileHandle() = pid(). silly() ->
{ok, H} = file:open("foo.dat", read),
file:close(H),
file:read_line(H).
APIs with state
+type start x file:open(fileName(), read | write) ->
{ok, fileHandle()} x ready
| {error, string()} x stop.
+type ready x file:read_line(fileHandle()) ->
{ok, string()} x ready
| eof x atEof.
+type atEof | ready x file:close(fileHandle()) ->
true x stop.
+type atEof | ready x file:rewind(fileHandle()) ->
true x ready.
silly() ->
{ok, H} = file:open("foo.dat", read),
file:close(H),
file:read_line(H).
Protocols or APIs
+state start x {open, fileName(), read | write} ->
{ok, fileHandle()} x ready
| {error, string()} x stop.
+state ready x {read_line, fileHandle()} ->
{ok, string()} x ready
| eof x atEof.
+state ready | atEof x {close, fileHandle()}->
true x stop.
+state ready | atEof x {rewind, fileHandle()) ->
true x ready
How things work
inside the black
box is irrelevant
Check the protocol at the
boundaries to the black box
Finally
My program should not be able to
crash your program.
This is the single most important property that a system
component must have
All things are not equally important

More Related Content

What's hot

Language Design Trade-offs
Language Design Trade-offsLanguage Design Trade-offs
Language Design Trade-offsAndrey Breslav
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futureTakayuki Muranushi
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSkills Matter
 
Understanding Android Benchmarks
Understanding Android BenchmarksUnderstanding Android Benchmarks
Understanding Android BenchmarksKoan-Sin Tan
 
A Sneak Peek of MLIR in TensorFlow
A Sneak Peek of MLIR in TensorFlowA Sneak Peek of MLIR in TensorFlow
A Sneak Peek of MLIR in TensorFlowKoan-Sin Tan
 
Python Introduction | JNTUA | R19 | UNIT 1
Python Introduction | JNTUA | R19 | UNIT 1 Python Introduction | JNTUA | R19 | UNIT 1
Python Introduction | JNTUA | R19 | UNIT 1 FabMinds
 
Avro - More Than Just a Serialization Framework - CHUG - 20120416
Avro - More Than Just a Serialization Framework - CHUG - 20120416Avro - More Than Just a Serialization Framework - CHUG - 20120416
Avro - More Than Just a Serialization Framework - CHUG - 20120416Chicago Hadoop Users Group
 
Building a Pipeline for State-of-the-Art Natural Language Processing Using Hu...
Building a Pipeline for State-of-the-Art Natural Language Processing Using Hu...Building a Pipeline for State-of-the-Art Natural Language Processing Using Hu...
Building a Pipeline for State-of-the-Art Natural Language Processing Using Hu...Databricks
 
Async and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NLAsync and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NLArie Leeuwesteijn
 
Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924yohanbeschi
 
Ry pyconjp2015 karaoke
Ry pyconjp2015 karaokeRy pyconjp2015 karaoke
Ry pyconjp2015 karaokeRenyuan Lyu
 
Clojure - An Introduction for Java Programmers
Clojure - An Introduction for Java ProgrammersClojure - An Introduction for Java Programmers
Clojure - An Introduction for Java Programmerselliando dias
 
The Ruby Plumber's Guide to *nix
The Ruby Plumber's Guide to *nixThe Ruby Plumber's Guide to *nix
The Ruby Plumber's Guide to *nixEleanor McHugh
 
Parallel Programming in .NET
Parallel Programming in .NETParallel Programming in .NET
Parallel Programming in .NETSANKARSAN BOSE
 
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
Python for Science and Engineering: a presentation to A*STAR and the Singapor...Python for Science and Engineering: a presentation to A*STAR and the Singapor...
Python for Science and Engineering: a presentation to A*STAR and the Singapor...pythoncharmers
 

What's hot (20)

Pfm technical-inside
Pfm technical-insidePfm technical-inside
Pfm technical-inside
 
effective_r27
effective_r27effective_r27
effective_r27
 
Language Design Trade-offs
Language Design Trade-offsLanguage Design Trade-offs
Language Design Trade-offs
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_future
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
Advance ROP Attacks
Advance ROP AttacksAdvance ROP Attacks
Advance ROP Attacks
 
Understanding Android Benchmarks
Understanding Android BenchmarksUnderstanding Android Benchmarks
Understanding Android Benchmarks
 
A Sneak Peek of MLIR in TensorFlow
A Sneak Peek of MLIR in TensorFlowA Sneak Peek of MLIR in TensorFlow
A Sneak Peek of MLIR in TensorFlow
 
Ekon24 mORMot 2
Ekon24 mORMot 2Ekon24 mORMot 2
Ekon24 mORMot 2
 
Python Introduction | JNTUA | R19 | UNIT 1
Python Introduction | JNTUA | R19 | UNIT 1 Python Introduction | JNTUA | R19 | UNIT 1
Python Introduction | JNTUA | R19 | UNIT 1
 
Avro - More Than Just a Serialization Framework - CHUG - 20120416
Avro - More Than Just a Serialization Framework - CHUG - 20120416Avro - More Than Just a Serialization Framework - CHUG - 20120416
Avro - More Than Just a Serialization Framework - CHUG - 20120416
 
Building a Pipeline for State-of-the-Art Natural Language Processing Using Hu...
Building a Pipeline for State-of-the-Art Natural Language Processing Using Hu...Building a Pipeline for State-of-the-Art Natural Language Processing Using Hu...
Building a Pipeline for State-of-the-Art Natural Language Processing Using Hu...
 
Async and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NLAsync and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NL
 
Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924
 
ROS distributed architecture
ROS  distributed architectureROS  distributed architecture
ROS distributed architecture
 
Ry pyconjp2015 karaoke
Ry pyconjp2015 karaokeRy pyconjp2015 karaoke
Ry pyconjp2015 karaoke
 
Clojure - An Introduction for Java Programmers
Clojure - An Introduction for Java ProgrammersClojure - An Introduction for Java Programmers
Clojure - An Introduction for Java Programmers
 
The Ruby Plumber's Guide to *nix
The Ruby Plumber's Guide to *nixThe Ruby Plumber's Guide to *nix
The Ruby Plumber's Guide to *nix
 
Parallel Programming in .NET
Parallel Programming in .NETParallel Programming in .NET
Parallel Programming in .NET
 
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
Python for Science and Engineering: a presentation to A*STAR and the Singapor...Python for Science and Engineering: a presentation to A*STAR and the Singapor...
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
 

Similar to Erlang

Joe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystemsJoe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystemsSentifi
 
Keynote joearmstrong
Keynote joearmstrongKeynote joearmstrong
Keynote joearmstrongSentifi
 
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...siouxhotornot
 
Introduction To Erlang Final
Introduction To Erlang   FinalIntroduction To Erlang   Final
Introduction To Erlang FinalSinarShebl
 
An introduction to erlang
An introduction to erlangAn introduction to erlang
An introduction to erlangMirko Bonadei
 
Osdc 2011 michael_neale
Osdc 2011 michael_nealeOsdc 2011 michael_neale
Osdc 2011 michael_nealeMichael Neale
 
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 Wisdomguest3933de
 
Erlang Developments: The Good, The Bad and The Ugly
Erlang Developments: The Good, The Bad and The UglyErlang Developments: The Good, The Bad and The Ugly
Erlang Developments: The Good, The Bad and The Uglyenriquepazperez
 
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
 
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 NeedsTorben Hoffmann
 
Erlang Message Passing Concurrency, For The Win
Erlang  Message  Passing  Concurrency,  For  The  WinErlang  Message  Passing  Concurrency,  For  The  Win
Erlang Message Passing Concurrency, For The Winl xf
 
Migration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsMigration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsZvi Avraham
 
[CCC-28c3] Post Memory Corruption Memory Analysis
[CCC-28c3] Post Memory Corruption Memory Analysis[CCC-28c3] Post Memory Corruption Memory Analysis
[CCC-28c3] Post Memory Corruption Memory AnalysisMoabi.com
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010Clay Helberg
 
Input and Output Devices and Systems
Input and Output Devices and SystemsInput and Output Devices and Systems
Input and Output Devices and SystemsNajma Alam
 
PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operationsgrim_radical
 

Similar to Erlang (20)

Joe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystemsJoe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystems
 
Keynote joearmstrong
Keynote joearmstrongKeynote joearmstrong
Keynote joearmstrong
 
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
 
Introduction To Erlang Final
Introduction To Erlang   FinalIntroduction To Erlang   Final
Introduction To Erlang Final
 
Erlang OTP
Erlang OTPErlang OTP
Erlang OTP
 
An introduction to erlang
An introduction to erlangAn introduction to erlang
An introduction to erlang
 
Erlang, an overview
Erlang, an overviewErlang, an overview
Erlang, an overview
 
Osdc 2011 michael_neale
Osdc 2011 michael_nealeOsdc 2011 michael_neale
Osdc 2011 michael_neale
 
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
 
Disrupt
DisruptDisrupt
Disrupt
 
Erlang
ErlangErlang
Erlang
 
Erlang Developments: The Good, The Bad and The Ugly
Erlang Developments: The Good, The Bad and The UglyErlang Developments: The Good, The Bad and The Ugly
Erlang Developments: The Good, The Bad and The Ugly
 
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
 
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
 
Erlang Message Passing Concurrency, For The Win
Erlang  Message  Passing  Concurrency,  For  The  WinErlang  Message  Passing  Concurrency,  For  The  Win
Erlang Message Passing Concurrency, For The Win
 
Migration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsMigration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming Models
 
[CCC-28c3] Post Memory Corruption Memory Analysis
[CCC-28c3] Post Memory Corruption Memory Analysis[CCC-28c3] Post Memory Corruption Memory Analysis
[CCC-28c3] Post Memory Corruption Memory Analysis
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
 
Input and Output Devices and Systems
Input and Output Devices and SystemsInput and Output Devices and Systems
Input and Output Devices and Systems
 
PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operations
 

More from ESUG

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingESUG
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in PharoESUG
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapESUG
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoESUG
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...ESUG
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsESUG
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6ESUG
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingESUG
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesESUG
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportESUG
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsESUG
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector TuningESUG
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FutureESUG
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the DebuggerESUG
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing ScoreESUG
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptESUG
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocESUG
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsESUG
 

More from ESUG (20)

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
 

Recently uploaded

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

Erlang

  • 2.
  • 3. Though OOP came from many motivations, two were central. The large scale one was to find a better module scheme for complex systems involving hiding of details, and the small scale one was to find a more flexible version of assignment, and then to try to eliminate it altogether. ...doing encapsulation right is a commitment not just to abstraction of state, but to eliminate state oriented metaphors from programming. The Early History of Smalltalk Alan Kay
  • 4. for i in {objects, processes} { create very large numbers of $i $i work the same way on all OS's $i's are garbage collected $i are location transparent $i cannot damage other $i $i are defined in the language creating and destroying $i is light-weight }
  • 5. Erlang is Smalltalk as Alan Kay wanted it - Niall Dalton
  • 6. How do we build systems that run forever, are scalable, fault-tolerant, evolve with time and work reasonably well works despite errors in the software?
  • 8. To make a fault-tolerant system you need at least two computers
  • 10. Simplify the problem no sharing pure message passing no locks
  • 12. Concurrency Oriented Programming ● A style of programming where concurrency is used to structure the application ● Large numbers of processes ● Complete isolation of processes ● No sharing of data ● Location transparency ● Pure message passing My first message is that concurrency is best regarded as a program structuring principle” Structured concurrent programming – Tony Hoare Redmond, July 2001
  • 13. COP Design Rules 1) Identify the concurrent operations in your problem 2) Identify the message channels 3) Write down the set of message seen on each channel 4) Write down the protocols 5) Write the code Try to make the design isomorphic to the problem – ie a 1:1 correspondence between the process/message structure in the model and the problem.
  • 14. Who am I? Inventor of Erlang, UBF Chief designer of OTP Founder of the company Bluetail Currently Senior System Architect Ericsson AB Current Interests Concurrency Oriented Programming Multi-core CPUs FPGAs Cats Motorbikes
  • 15. How do we correct hardware failures? Replicate the hardware How do we correct software errors? Having two identical copies of the software won't work – both will fail at the same time and for the same reason Why does your computer crash? Which fails more often, hardware or software?
  • 16. Architecture Talk organisation Introduction Erlang Programming techniques Programming fault- tolerant systems Building an application OTP Case studies Conclusions API's and protocols It works!
  • 17. History 1986 – Pots Erlang (in Prolog) 1987 – ACS/Dunder 1988 – Erlang -> Strand (fails) 1989 – JAM (Joe's abstract machine) 1990 – Erlang syntax changes (70x faster) 1991 – Distribution 1992 – Mobility Server 1993 – Erlang Systems AB 1995 – AXE-N collapses. AXD starts 1996 – OTP starts 1998 – AXD deployed. Erlang Banned. Open Source Erlang. Bluetail formed 1999 – BMR sold 2000 – Alteon buys Blutail. Nortel buys Alteon 2002 – UBF. Concurrency Oriented Programming 2003 – Ph.D. Thesis - Making reliable systems 2006 – Multi-core Erlang
  • 18. How do we make systems? Systems are made of black boxes (components) Black boxes execute concurrently Black boxes communicate How the black box works internally is irrelevant Failures inside one black box should not crash another black box
  • 19. Problem domain ● Highly concurrent (hundreds of thousands of parallel activities) ● Real time ● Distributed ● High Availability (down times of minutes/year – never down) ● Complex software (million of lines of code) ● Continuous operation (years) ● Continuous evolution ● In service upgrade
  • 20. Architecture Philosophy Way of doing things Construction Guidelines Programming examples
  • 21. Philosophy Concurrency Oriented Programming 1. COPLs support processes 2. Processes are Isolated 3. Each process has a unique unforgeable Id 4. There is no shared state between processes 5. Message passing is unreliable 6. It should be possible to detect failure in another processes and we should know the reason for failure
  • 22. System requirements R1. Concurrency processes R2. Error encapsulation isolation R3. Fault detection what failed R4. Fault identification why it failed R5. Live code upgrade evolving systems R6. Stable storage crash recovery
  • 23. Isolation . Hardware components operate concurrently are isolated and communicate by message passing
  • 24. Consequences of Isolation Processes have share nothing semantics and data must be copied Message passing is the only way to exchange data Message passing is asynchronous
  • 26. Language My program should not be able to crash your program Need strong isolation and concurrency Processes are OK – threads are not (threads have shared resources) Can't use OS processes (Heavy – semantics depends on OS)
  • 27. Isolation My program should not be able to crash your program. This is the single most important property that a system component must have All things are not equally important
  • 28. Erlang Lightweight processes (lighter than OS threads) Good isolation (not perfect yet ...) Programs never loose control Error detection primitives Reason for failure is known Exceptions Garbage collected memory Lots of processes Functional Agner Krarup Erlang (1878-1929)
  • 30. Erlang You can create a parallel process Pid = spawn(fun() -> ... end). then send it a message Pid ! Msg and then wait for a reply receive {Pid, Rely} -> Actions end It typically takes 1 microsecond to create a process or send a message Processes are isolated
  • 31. Generalisation Client Pid = spawn(fun() -> loop() end) Pid ! {self(), 21}, receive {Pid, Val} -> ... end Server loop() -> receive {From, X} -> From ! {self(), 2*X}, loop() end. A simple process Client Double = fun(X) -> 2 *X end, Pid = spawn(fun() -> loop(Double) end) Pid ! {self(), 21}, receive {Pid, Val} -> ... end Server loop(F) -> receive {From, X} -> From ! {self(), F(X)}, loop(F) end. Generalised
  • 32. A generic server -module(gserver). -export([start/1, rpc/2, code_change/2]). start(Fun) -> spawn(fun() -> loop(Fun) end). rpc(Pid, Q) -> Pid ! {self(), Q}, receive {Pid, Reply} -> Reply end. code_change(Pid, Fun1) -> Pid ! {swap_code, Fun1}. loop(F) -> receive {swap_code, F1} -> loop(F1); {Pid, X} -> Pid ! {self(), F(X)}, loop(F); end. Double = fun(X) -> 2*X end, Pid = gserver:start(Double), ... Triple = fun(X) -> 3*X end, gserver:code_change(Pid, Triple)
  • 33. A generic server with data -module(gserver). -export([start/2, rpc/2, code_change/2]). start(Fun, Data) -> spawn(fun() -> loop(Fun, Data) end). rpc(Pid, Q) -> Pid ! {self(), Q}, receive {Pid, Reply} -> Reply end. code_change(Pid, Fun1) -> Pid ! {swap_code, Fun1}. loop(F, Data) -> receive {swap_code, F1} -> loop(F1, Data); {Pid, X} -> {Reply, Data1} = F(X), Pid ! {self(), Reply}, loop(F, Data1); end.
  • 34. Trapping errors In Pid1 ... Pid2 = spawn_link(fun() -> ... end). process_flag(trap_exit, true) ... receive {'EXIT', Pid, Why} -> Actions end. Pid1 Pid1 Pid2 1/0 {'EXIT', Pid1, badarith} error detection + reason for failure (slide 10)
  • 35. Why remote trapping of errors? To do fault-tolerant computing you need at least TWO computers Computer1 Computer1 Computer2 Error {'EXIT', Computer2, Reason} Which means you can't share data
  • 36. Programming for errors If you can't do what you want to do try and do something simpler Workers Supervisor Links The supervisor monitors the workers and restarts them if they fail
  • 37. A supervision hierarchy Workers Supervisor and worker Links Supervisor Links Workers
  • 38. OTP behaviours Generic libraries for building components of a real-time system. Includes Client-server Finite State machine Supervisor Event Handler Applications Systems
  • 39. case studies Ericsson AXD301 (in Engine) Size = 1136150 lines Erlang Dirty functions = 0.359% Availability = 99.9999999% Alteon (Nortel) SSL accelerator Size = 74440 line Erlang Dirty functions = 0.82% Ref: Armstrong Ph.D. thesis
  • 40. Ericsson AXD301 (part of “Engine”) Ericsson GPRS system Alteon (Nortel) SSL accelerator Alteon (Nortel) SSL VPN Teba Bank (credit card system – South Africa) T-mobile SMS system (UK) Kreditor (Sweden) jabber.org Commercial Successes
  • 41. How do we make systems? Systems are made of black boxes (components) Black boxes execute concurrently Black boxes communicate with defined (universal) protocols The protocol is checked externally How the black box works internally is irrelevant Protocol checker
  • 42. APIs done wrong +type file:open(fileName(), read | write) -> {ok, fileHandle()} | {error, string()}. +type file:read_line(fileHandle()) -> {ok, string()} | eof. +type file:close(fileHandle()) -> true. +deftype fileName() = [int()] +deftype string() = [int()]. +deftype fileHandle() = pid(). silly() -> {ok, H} = file:open("foo.dat", read), file:close(H), file:read_line(H).
  • 43. APIs with state +type start x file:open(fileName(), read | write) -> {ok, fileHandle()} x ready | {error, string()} x stop. +type ready x file:read_line(fileHandle()) -> {ok, string()} x ready | eof x atEof. +type atEof | ready x file:close(fileHandle()) -> true x stop. +type atEof | ready x file:rewind(fileHandle()) -> true x ready. silly() -> {ok, H} = file:open("foo.dat", read), file:close(H), file:read_line(H).
  • 44. Protocols or APIs +state start x {open, fileName(), read | write} -> {ok, fileHandle()} x ready | {error, string()} x stop. +state ready x {read_line, fileHandle()} -> {ok, string()} x ready | eof x atEof. +state ready | atEof x {close, fileHandle()}-> true x stop. +state ready | atEof x {rewind, fileHandle()) -> true x ready How things work inside the black box is irrelevant Check the protocol at the boundaries to the black box
  • 45. Finally My program should not be able to crash your program. This is the single most important property that a system component must have All things are not equally important