SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
Actor based programming
       In Erlang, Scala and F#




                                                         Page 1
                                 Actor model baksia , 29.09.2012
Agenda


• The reason
• The Actor Model
• Erlang
• Scala
• F#
• OTP and AKKA




                                            Page 2
                    Actor model baksia , 29.09.2012
The base of the problem




                                                  Page 3
                          Actor model baksia , 29.09.2012
Another reason




                                         Page 4
                 Actor model baksia , 29.09.2012
Concurrency and shared memory model




                                                       Page 5
                               Actor model baksia , 29.09.2012
Shared memory model



              Shared
              memory

 Process                Process
 thread                 thread


              Process
              thread




                                                      Page 6
                              Actor model baksia , 29.09.2012
Problems with shared memory


• Race conditions
• Block contention
• Deadlock




                                                         Page 7
                                 Actor model baksia , 29.09.2012
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
Pattern Matching




                                           Page 9
                   Actor model baksia , 29.09.2012
Erlang


• The world is concurrent
• Things in the world don't share data
• Things communicate with messages
• Things fail
       - Joe Armstrong




                                                                Page 10
                                         Actor model baksia , 29.09.2012
Crash course in Erlang
Variables are immutable




                                                   Page 11
                            Actor model baksia , 29.09.2012
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
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
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 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
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 *
    • 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
Scala Actor on tuples




                                               Page 19
                        Actor model baksia , 29.09.2012
Scala Actor with case classes




                                                       Page 20
                                Actor model baksia , 29.09.2012
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
Code example F#




                                         Page 22
                  Actor model baksia , 29.09.2012
F# Actor MailboxProcessor




                                                   Page 23
                            Actor model baksia , 29.09.2012
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
Supervisors in Erlang/OTP and AKKA



   Supervisor

                            Process




                  Process
     Process




                                                             Page 25
                                      Actor model baksia , 29.09.2012
Supervising supervisors

  Root
Supervisor




                                 Supervisor
Supervisor
                                                         Process
                       Process



                                 Process      Process
Process      Process


                                                                         Page 26
                                                  Actor model baksia , 29.09.2012
Page 27
Actor model baksia , 29.09.2012

Mais conteúdo relacionado

Último

activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 

Último (20)

activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 

Actor three languages

  • 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 don't share data • Things communicate with messages • Things fail - Joe Armstrong Page 10 Actor model baksia , 29.09.2012
  • 11. Crash course in Erlang Variables 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 Root Supervisor Supervisor Supervisor Process Process Process Process Process Process Page 26 Actor model baksia , 29.09.2012
  • 27. Page 27 Actor model baksia , 29.09.2012