Actor three languages
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Actor three languages

on

  • 1,528 views

 

Statistics

Views

Total Views
1,528
Views on SlideShare
1,520
Embed Views
8

Actions

Likes
3
Downloads
10
Comments
0

2 Embeds 8

https://twitter.com 6
https://si0.twimg.com 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Actor three languages Presentation Transcript

  • 1. Actor based programming In Erlang, Scala and F# Page 1 Actor model baksia , 29.09.2012
  • 2. Agenda• The reason• The Actor Model• Erlang• Scala• F#• OTP and AKKA Page 2 Actor model baksia , 29.09.2012
  • 3. The base of the problem Page 3 Actor model baksia , 29.09.2012
  • 4. Another reason Page 4 Actor model baksia , 29.09.2012
  • 5. Concurrency and shared memory model Page 5 Actor model baksia , 29.09.2012
  • 6. Shared memory model Shared memory Process Process thread thread Process thread Page 6 Actor model baksia , 29.09.2012
  • 7. Problems with shared memory• Race conditions• Block contention• Deadlock Page 7 Actor model baksia , 29.09.2012
  • 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. Pattern Matching Page 9 Actor model baksia , 29.09.2012
  • 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. Crash course in ErlangVariables are immutable Page 11 Actor model baksia , 29.09.2012
  • 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. 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. Actors in Erlang Page 14 Actor model baksia , 29.09.2012
  • 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. Scalatest TestStack Page 16 Actor model baksia , 29.09.2012
  • 17. Scala Actors Page 17 Actor model baksia , 29.09.2012
  • 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. Scala Actor on tuples Page 19 Actor model baksia , 29.09.2012
  • 20. Scala Actor with case classes Page 20 Actor model baksia , 29.09.2012
  • 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. Code example F# Page 22 Actor model baksia , 29.09.2012
  • 23. F# Actor MailboxProcessor Page 23 Actor model baksia , 29.09.2012
  • 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. Supervisors in Erlang/OTP and AKKA Supervisor Process Process Process Page 25 Actor model baksia , 29.09.2012
  • 26. Supervising supervisors RootSupervisor SupervisorSupervisor Process Process Process ProcessProcess Process Page 26 Actor model baksia , 29.09.2012
  • 27. Page 27Actor model baksia , 29.09.2012