Functions +Messages + Concurrency       = Erlang    Joe Armstrong
Concurrent   programming             Functional                          programmingConcurrency Orientedprogramming       ...
Problem domainHighly concurrent (hundreds of thousands of parallelactivities)Real timeDistributedHigh Availability (down t...
ErlangVery light-weight processesVery fast message passingTotal separation between processesAutomatic marshalling/demarsha...
Concurrent   programming             Functional                          programmingConcurrency Orientedprogramming       ...
2002
Fraction of Chip reachable in one clock cycle [source] Erik Hagersten http://www.sics.se/files/projects/ multicore/day2007...
Clock FrequencyClock frequency trend for Intel Cpus (Linux Journal)Read: Clock rate verses IPC. The end of the road forCon...
Due to hardware changes:Each year your sequential programs will go slowerEach year your concurrent programs will go faster
2005 – 2015Paradigm shift in      CPU architectures
Three NewArchitectures
ONE - Multi core
TWO -GPUsCell Computers
THREE – network onIntel Polaris – 2007   Chip (NOC)1 Tflop at 24 Watts
ASCI RED- 1997   - 1997                 - First machine over 1 Tera                  Flop                 - 2,500 sq ft fl...
2 cores wont hurt you4 cores will hurt a little8 cores will hurt a bit16 will start hurting32 cores will hurt a lot (2009)...
GoalMake my program run N times faster on anN core CPU with no changes to the program no pain and sufferingCan we do this?...
Due to hardware changes:Each year your sequential programs will go slowerEach year your concurrent programs will go faster
Concurrent   programming             Functional                          programmingConcurrency Orientedprogramming       ...
To makea fault-tolerant system   you need at least      two      computers
If one computer crashesthe other must take over= No Shared data= Distributed programming= Pure Message passing
To do fault tolerant computing weneed at least two isolated computers     = Concurrent programming       with pure message...
To do very fault tolerant computingwe need lots of isolated computers       = Scalable
Fault tolerance Distribution Concurrency  Scalabilityare inseparable
Concurrent   programming             Functional                          programmingConcurrency Orientedprogramming       ...
Two models of ConcurrencyShared Memory - mutexes - threads - locksMessage Passing - messages - processes
Shared  MemoryProgramming
Shared memory
Problem 1            Your program            crashes in            the critical region            having corrupted        ...
Problem 2Sweden           ?           Australia Where do we (physically) locate the shared memory? Impossible to get low-l...
Thread SafetyErlang programs areautomatically threadsafe if they dont usean external resource.
Sharing is the property that   preventsfault tolerance      andThread safety
Message  PassingConcurrency
No sharingPure message passingNo locksLots of computers (= fault tolerantscalable ...)Functional programming (no sideeffec...
Concurrent   programming             Functional                          programmingConcurrency Orientedprogramming       ...
What is COP?                                        Machine                                        Process                ...
Why is COP nice?We intuitively understand concurrencyThe world is parallelThe world is distributedMaking a real-world appl...
Concurrency Oriented Programming A style of programming whereconcurrency is used to structure theapplication              ...
Examples of COP architecturesremember – no shared memory– pure message passingEmailGoogle – map – reduce (450,000machines)...
Concurrent   programming             Functional                          programmingConcurrency Orientedprogramming       ...
Functional programming
Scary stuff
Or easy?fac(0) -> 1;fac(N) -> N*fac(N-1).
Why is FP good?Side effects are strictly controlled              If you call the         same function twice with         ...
Referential transparency  In    Out      In,S   Out,S S     SOOP              FP
Functional programming languages    FLPs carry state with them   wherever the flow of control   goes. Different FPLs provi...
Why is this important?Compositional propertiesOutput of one function must be input to nextf(g(h(i(k(X)))))Echo “foo” | k |...
FP is on the rise Haskell Erlang OCaml, F#
BAD STUFF                                           Very very badThreadsSharingMutexes - LocksSynchronized methodsMutable ...
GOOD STUFFProcessesControlled side effectsPure functionsCopyingPure Message passingFailure detection
Concurrent   programming             Functional                          programmingConcurrency Orientedprogramming       ...
Erlang in 11 MinutesSequential Erlang 5 examplesConcurrent Erlang 2 examplesDistributed Erlang 1 exampleFault-tolerant Erl...
Sequential Erlang                Factorial   -module(math).                            -export([fac/1]).  Dynamic types  P...
Sequential Erlangappend   append([H|T], L) -> [H|append(T, L)];         append([],    L) -> L.sort     sort([Pivot|T]) -> ...
Concurrent Erlangspawn      Pid = spawn(fun() -> loop(0) end) send      Pid ! Message,           ..... receive   receive  ...
Distributed ErlangPid = spawn(Fun@Node)alive(Node),.....not_alive(Node)
Fault-tolerant Erlang     ...     case (catch foo(A, B)) of         {abnormal_case1, Y} ->            ...         {EXIT, O...
Monitor a process   ...   process_flag(trap_exit, true),   Pid = spawn_link(fun() -> ... end),   receive         {EXIT, Pi...
Bit Syntax - parsing IP datagrams-define(IP_VERSION, 4).-define(IP_MIN_HDR_LEN,5).DgramSize = size(Dgram),case Dgram of <<...
Bit syntax – unpacking MPEG data
Some codeloop() ->   receive      {email,From,Subject,Text} = Email ->         {ok, S} = file:open("inbox",[append,write])...
Programming Multicore computers is difficultbecause of shared mutable state.Functional programming languages have no share...
- Use “lots” of processes- Avoid sequential bottlenecks- Use “large computation”  small data transfer (if  possible)- New ...
Commercial projectsEricsson AXD301 (part of “Engine”)Ericsson GPRS systemAlteon (Nortel) SSL acceleratorAlteon (Nortel) SS...
Finally  Weve known how to program parallel  computers for the last twenty yearsWe can make highly reliable fault tolerant...
Questions?
Keynote joearmstrong
Keynote joearmstrong
Keynote joearmstrong
Keynote joearmstrong
Keynote joearmstrong
Keynote joearmstrong
Keynote joearmstrong
Upcoming SlideShare
Loading in...5
×

Keynote joearmstrong

333

Published on

Published in: Technology, News & Politics
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
333
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Keynote joearmstrong

  1. 1. Functions +Messages + Concurrency = Erlang Joe Armstrong
  2. 2. Concurrent programming Functional programmingConcurrency Orientedprogramming Erlang Fault Multicore tolerance
  3. 3. Problem domainHighly concurrent (hundreds of thousands of parallelactivities)Real timeDistributedHigh Availability (down times of minutes/year – never down)Complex software (million of lines of code)Continuous operation (years)Continuous evolutionIn service upgrade
  4. 4. ErlangVery light-weight processesVery fast message passingTotal separation between processesAutomatic marshalling/demarshallingFast sequential codeStrict functional codeDynamic typingTransparent distributionCompose sequential AND concurrent code
  5. 5. Concurrent programming Functional programmingConcurrency Orientedprogramming Erlang Fault Multicore tolerance
  6. 6. 2002
  7. 7. Fraction of Chip reachable in one clock cycle [source] Erik Hagersten http://www.sics.se/files/projects/ multicore/day2007/ErikH-intro.pdf
  8. 8. Clock FrequencyClock frequency trend for Intel Cpus (Linux Journal)Read: Clock rate verses IPC. The end of the road forConventional Microarchitectures. Agarwal et.al 2000
  9. 9. Due to hardware changes:Each year your sequential programs will go slowerEach year your concurrent programs will go faster
  10. 10. 2005 – 2015Paradigm shift in CPU architectures
  11. 11. Three NewArchitectures
  12. 12. ONE - Multi core
  13. 13. TWO -GPUsCell Computers
  14. 14. THREE – network onIntel Polaris – 2007 Chip (NOC)1 Tflop at 24 Watts
  15. 15. ASCI RED- 1997 - 1997 - First machine over 1 Tera Flop - 2,500 sq ft floor space 104 cabinets - 9326 pentium pro processors - 850 KW
  16. 16. 2 cores wont hurt you4 cores will hurt a little8 cores will hurt a bit16 will start hurting32 cores will hurt a lot (2009)...1 M cores ouch (2019) (complete paradigm shift)1997 1 Tflop = 850 KW2007 1 Tflop = 24 W (factor 35,000)2017 1 Tflop = ?
  17. 17. GoalMake my program run N times faster on anN core CPU with no changes to the program no pain and sufferingCan we do this?Yes Sometimes (often)
  18. 18. Due to hardware changes:Each year your sequential programs will go slowerEach year your concurrent programs will go faster
  19. 19. Concurrent programming Functional programmingConcurrency Orientedprogramming Erlang Fault Multicore tolerance
  20. 20. To makea fault-tolerant system you need at least two computers
  21. 21. If one computer crashesthe other must take over= No Shared data= Distributed programming= Pure Message passing
  22. 22. To do fault tolerant computing weneed at least two isolated computers = Concurrent programming with pure message passing
  23. 23. To do very fault tolerant computingwe need lots of isolated computers = Scalable
  24. 24. Fault tolerance Distribution Concurrency Scalabilityare inseparable
  25. 25. Concurrent programming Functional programmingConcurrency Orientedprogramming Erlang Fault Multicore tolerance
  26. 26. Two models of ConcurrencyShared Memory - mutexes - threads - locksMessage Passing - messages - processes
  27. 27. Shared MemoryProgramming
  28. 28. Shared memory
  29. 29. Problem 1 Your program crashes in the critical region having corrupted memory
  30. 30. Problem 2Sweden ? Australia Where do we (physically) locate the shared memory? Impossible to get low-latency and make consistent (violates laws of physics)
  31. 31. Thread SafetyErlang programs areautomatically threadsafe if they dont usean external resource.
  32. 32. Sharing is the property that preventsfault tolerance andThread safety
  33. 33. Message PassingConcurrency
  34. 34. No sharingPure message passingNo locksLots of computers (= fault tolerantscalable ...)Functional programming (no sideeffects)
  35. 35. Concurrent programming Functional programmingConcurrency Orientedprogramming Erlang Fault Multicore tolerance
  36. 36. What is COP? Machine Process Message Large number of processes Complete isolation between processes Location transparency No Sharing of data Pure message passing systems
  37. 37. Why is COP nice?We intuitively understand concurrencyThe world is parallelThe world is distributedMaking a real-world application is based onobservation of the concurrency patterns andmessage channels in the applicationEasy to make scalable, distributed applications
  38. 38. Concurrency Oriented Programming A style of programming whereconcurrency is used to structure theapplication My first message is thatLarge numbers of processes concurrencyComplete isolation of is best regarded as a program processes structuring principle”No sharing of dataLocation transparencyPure message passing Structured concurrent programming – Tony Hoare
  39. 39. Examples of COP architecturesremember – no shared memory– pure message passingEmailGoogle – map – reduce (450,000machines)People (no shared state, messagepassing via voiceGrams, wavingarms, non-reliable etc.)
  40. 40. Concurrent programming Functional programmingConcurrency Orientedprogramming Erlang Fault Multicore tolerance
  41. 41. Functional programming
  42. 42. Scary stuff
  43. 43. Or easy?fac(0) -> 1;fac(N) -> N*fac(N-1).
  44. 44. Why is FP good?Side effects are strictly controlled If you call the same function twice with the same arguments it should return the same value
  45. 45. Referential transparency In Out In,S Out,S S SOOP FP
  46. 46. Functional programming languages FLPs carry state with them wherever the flow of control goes. Different FPLs provide different notations and In,S Out,S mechanisms for hiding this from the user. In Erlang we hide the state in a process. In Haskell in a monad FLPs have are based on a formal FP mathematical model Lambda calculus (Pi calc, CSP)
  47. 47. Why is this important?Compositional propertiesOutput of one function must be input to nextf(g(h(i(k(X)))))Echo “foo” | k | i | h | g | fNo mutable state means nothing to lock andautomatic thread safety when parallelisedCan reuse pure functions
  48. 48. FP is on the rise Haskell Erlang OCaml, F#
  49. 49. BAD STUFF Very very badThreadsSharingMutexes - LocksSynchronized methodsMutable state Mutable state is the root of all evil FPLs have no mutable state
  50. 50. GOOD STUFFProcessesControlled side effectsPure functionsCopyingPure Message passingFailure detection
  51. 51. Concurrent programming Functional programmingConcurrency Orientedprogramming Erlang Fault Multicore tolerance
  52. 52. Erlang in 11 MinutesSequential Erlang 5 examplesConcurrent Erlang 2 examplesDistributed Erlang 1 exampleFault-tolerant Erlang 2 examplesBit syntax 1 example
  53. 53. Sequential Erlang Factorial -module(math). -export([fac/1]). Dynamic types Pattern matching fac(N) when N > 0 -> N*fac(N-1); No mutable data fac(0) -> 1 structures > math:fac(25).Binary Tree Search 15511210043330985984000000 lookup(Key, {Key, Val,_,_}) -> {ok, Val}; lookup(Key, {Key1,Val,S,B}) when Key < Key1 -> lookup(Key, S); lookup(Key, {Key1, Val, S, B})-> lookup(Key, B); lookup(key, nil) -> not_found.
  54. 54. Sequential Erlangappend append([H|T], L) -> [H|append(T, L)]; append([], L) -> L.sort sort([Pivot|T]) -> sort([X||X <- T, X < Pivot]) ++ [Pivot] ++ sort([X||X <- T, X >= Pivot]); sort([]) -> []. > Adder = fun(N) -> fun(X) -> X + N end end. adder #Fun > G = Adder(10). #Fun > G(5). 15
  55. 55. Concurrent Erlangspawn Pid = spawn(fun() -> loop(0) end) send Pid ! Message, ..... receive receive Message1 -> Actions1; Message2 -> Actions2; ... after Time -> TimeOutActions end The concurrency is in the language NOT the OS
  56. 56. Distributed ErlangPid = spawn(Fun@Node)alive(Node),.....not_alive(Node)
  57. 57. Fault-tolerant Erlang ... case (catch foo(A, B)) of {abnormal_case1, Y} -> ... {EXIT, Opps} -> ... Val -> ... end, ... foo(A, B) -> ... throw({abnormal_case1, ...})
  58. 58. Monitor a process ... process_flag(trap_exit, true), Pid = spawn_link(fun() -> ... end), receive {EXIT, Pid, Why} -> ... end
  59. 59. Bit Syntax - parsing IP datagrams-define(IP_VERSION, 4).-define(IP_MIN_HDR_LEN,5).DgramSize = size(Dgram),case Dgram of <<?IP_VERSION:4, HLen:4, SrvcType:8, TotLen:16, ID:16, Flgs:3, This code parses the FragOff:13, TTL:8, Proto:8, HdrChkSum:16, header and extracts SrcIP:32, DestIP:32, Body/binary>> when the data from an IP HLen >= 5, 4*HLen =< DgramSize -> OptsLen = 4*(HLen - ?IP_MIN_HDR_LEN), protocol version 4 <<Opts:OptsLen/binary,Data/binary>> = Body, datagram ...
  60. 60. Bit syntax – unpacking MPEG data
  61. 61. Some codeloop() -> receive {email,From,Subject,Text} = Email -> {ok, S} = file:open("inbox",[append,write]), io:format(S, "~p.~n",[Email]), file:close(S); {msg, From, Message} -> io:format("msg (~s) ~s~n", [From, Message]); {From, get, File} -> From ! file:read_file(File) end, loop().Mike ! {email, "joe", "dinner", "see you at 18.00"}.Helen ! {msg, "joe", "Can you buy some milk on your wayhome?"}
  62. 62. Programming Multicore computers is difficultbecause of shared mutable state.Functional programming languages have no sharedstate and no mutable stateErlang has the right intrinsic properties forprogramming multicore computers (concurrencymaps to the multiple CPUs, non-mutability means wedont get any problems with memory corruption)
  63. 63. - Use “lots” of processes- Avoid sequential bottlenecks- Use “large computation” small data transfer (if possible)- New abstractions (pmap, mapreduce)
  64. 64. Commercial projectsEricsson AXD301 (part of “Engine”)Ericsson GPRS systemAlteon (Nortel) SSL acceleratorAlteon (Nortel) SSL VPNTeba Bank (credit card system – South Africa)T-mobile SMS system (UK)Kreditor (Sweden)SynapseTail-fjabber.org /uses ejabberd)Twitter (uses ejabberd)Lshift (RabbitMQ) AMQP (Advanced Message Queuing protocol)
  65. 65. Finally Weve known how to program parallel computers for the last twenty yearsWe can make highly reliable fault tolerant distributed real-time systems ww.erlang.org
  66. 66. Questions?
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×