Actor based programming       In Erlang, Scala and F#                                                         Page 1      ...
Agenda• The reason• The Actor Model• Erlang• Scala• F#• OTP and AKKA                                            Page 2    ...
The base of the problem                                                  Page 3                          Actor model baksi...
Another reason                                         Page 4                 Actor model baksia , 29.09.2012
Concurrency and shared memory model                                                       Page 5                          ...
Shared memory model              Shared              memory Process                Process thread                 thread  ...
Problems with shared memory• Race conditions• Block contention• Deadlock                                                  ...
What is the Actor Model• Light weight processes/threads communicating through  messaging   • Messages are buffered in a “m...
Pattern Matching                                           Page 9                   Actor model baksia , 29.09.2012
Erlang• The world is concurrent• Things in the world dont share data• Things communicate with messages• Things fail       ...
Crash course in ErlangVariables are immutable                                                   Page 11                   ...
Atoms and tuples• An atom is a global constant starting with lower case• A tuple is an ordered set of elements• Your Java ...
Spawn and process ID• Spawn “spawns” a new Erlang process (light weight)• Spawn returns a PID (Process identifier)• Receiv...
Actors in Erlang                                          Page 14                   Actor model baksia , 29.09.2012
Crash course in Scala• Object functional programming language• Everything in Scala is an object, even functions• Running o...
Scalatest TestStack                                             Page 16                      Actor model baksia , 29.09.2012
Scala Actors                                      Page 17               Actor model baksia , 29.09.2012
React or receive• React is the “normal” actor, lightweight process• Receive spins out a new Java thread• In the paper *   ...
Scala Actor on tuples                                               Page 19                        Actor model baksia , 29...
Scala Actor with case classes                                                       Page 20                               ...
Crash course in F#• F# is a object functional programming language for the  .Net Framework• Derived from ML and is largely...
Code example F#                                         Page 22                  Actor model baksia , 29.09.2012
F# Actor MailboxProcessor                                                   Page 23                            Actor model...
Let it crash (supervision)• Erlang/OTP• Scala Akka• Erlang designed for five nines 99.999 uptime, record is  nine nines 99...
Supervisors in Erlang/OTP and AKKA   Supervisor                            Process                  Process     Process   ...
Supervising supervisors  RootSupervisor                                 SupervisorSupervisor                              ...
Page 27Actor model baksia , 29.09.2012
Upcoming SlideShare
Loading in...5
×

Actor three languages

1,432

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,432
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
11
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Actor three languages"

  1. 1. Actor based programming In Erlang, Scala and F# Page 1 Actor model baksia , 29.09.2012
  2. 2. Agenda• The reason• The Actor Model• Erlang• Scala• F#• OTP and AKKA Page 2 Actor model baksia , 29.09.2012
  3. 3. The base of the problem Page 3 Actor model baksia , 29.09.2012
  4. 4. Another reason Page 4 Actor model baksia , 29.09.2012
  5. 5. Concurrency and shared memory model Page 5 Actor model baksia , 29.09.2012
  6. 6. Shared memory model Shared memory Process Process thread thread Process thread Page 6 Actor model baksia , 29.09.2012
  7. 7. Problems with shared memory• Race conditions• Block contention• Deadlock Page 7 Actor model baksia , 29.09.2012
  8. 8. What is the Actor Model• Light weight processes/threads communicating through messaging • Messages are buffered in a “mailbox”• No shared state• Isolated from other processes• Normally event systems are inversion of control • Adding a listener to an object • Hard to maintain in large systems• Humans do not share memory, we communicate through messages Page 8 Actor model baksia , 29.09.2012
  9. 9. Pattern Matching Page 9 Actor model baksia , 29.09.2012
  10. 10. Erlang• The world is concurrent• Things in the world dont share data• Things communicate with messages• Things fail - Joe Armstrong Page 10 Actor model baksia , 29.09.2012
  11. 11. Crash course in ErlangVariables are immutable Page 11 Actor model baksia , 29.09.2012
  12. 12. Atoms and tuples• An atom is a global constant starting with lower case• A tuple is an ordered set of elements• Your Java or C# class would be a tuple with an atom identifier Page 12 Actor model baksia , 29.09.2012
  13. 13. Spawn and process ID• Spawn “spawns” a new Erlang process (light weight)• Spawn returns a PID (Process identifier)• Receive waits for a message Page 13 Actor model baksia , 29.09.2012
  14. 14. Actors in Erlang Page 14 Actor model baksia , 29.09.2012
  15. 15. Crash course in Scala• Object functional programming language• Everything in Scala is an object, even functions• Running on JVM and interoperable with Java language • Also runs on Dalvik VM for Android (Java bytecode)• Concurrent oriented programming language• Actor model programming style from Erlang• Interactive shell• No attachment to Oracle Page 15 Actor model baksia , 29.09.2012
  16. 16. Scalatest TestStack Page 16 Actor model baksia , 29.09.2012
  17. 17. Scala Actors Page 17 Actor model baksia , 29.09.2012
  18. 18. React or receive• React is the “normal” actor, lightweight process• Receive spins out a new Java thread• In the paper * • 5000 threads • 1 200 000 actors• React uses partial functions to send the process to the heap• Receive runs on the stack and is heavyweight JVM threads (like Java)*Actors That Unify Threads and Events P. Haller, M. Odersky Page 18 Actor model baksia , 29.09.2012
  19. 19. Scala Actor on tuples Page 19 Actor model baksia , 29.09.2012
  20. 20. Scala Actor with case classes Page 20 Actor model baksia , 29.09.2012
  21. 21. Crash course in F#• F# is a object functional programming language for the .Net Framework• Derived from ML and is largely compatible with OCaml• Interactive shell, script and compiled language• Runs on mono for Posix based systems Page 21 Actor model baksia , 29.09.2012
  22. 22. Code example F# Page 22 Actor model baksia , 29.09.2012
  23. 23. F# Actor MailboxProcessor Page 23 Actor model baksia , 29.09.2012
  24. 24. Let it crash (supervision)• Erlang/OTP• Scala Akka• Erlang designed for five nines 99.999 uptime, record is nine nines 99.999999999• That is 31ms downtime a year Page 24 Actor model baksia , 29.09.2012
  25. 25. Supervisors in Erlang/OTP and AKKA Supervisor Process Process Process Page 25 Actor model baksia , 29.09.2012
  26. 26. Supervising supervisors RootSupervisor SupervisorSupervisor Process Process Process ProcessProcess Process Page 26 Actor model baksia , 29.09.2012
  27. 27. Page 27Actor model baksia , 29.09.2012
  1. A particular slide catching your eye?

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

×