SlideShare una empresa de Scribd logo
1 de 28
Scala Actors from an Erlang
perspective
Who am I

• Reidar Sollid (Reidar is an ancient Viking name, and
  means warrior and protector of the home)
• I am now a Consutlant at Bouvet
• My background is from R&D and Telecom transport
  networks from Nera Networks( now Ceragon) and
  Ericsson.
Motivation

• Most Scala devs comes from Java
• Hacking Scala with a Java mindset limits your
  use of Scala
• Erlang is a pure actor base language
• Getting the mindset from Erlang into Scala
  broadens the horizon
• Java + Erlang = Scala
The concept of forever




• This is a loaner from Joe Armstrong, he is a lot
  funnier than I am but I guess you get the point
  
• I hope he don’t mind
10 x the size of the
The fly
Nine nines 99.999999999

• Standard for Telecom equipment is five nines 99.999 (5.2
  minutes downtime/year)
• The Ericsson AXD301 has 2 million lines of Erlang code
  and nine nines
Shared memory
Concurrency and shared memory
Erlang

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

• Created and maintained by Ericsson (now open source)
• Functional, single assignment, strict evaluation, dynamic
  typing
• Actor model, concurrent oriented, fault tolerant, soft-real-
  time
• Light weight processes that communicate using message
  passing (an Erlang process is more light weight than a
  Java thread)
• Erlang started life as a modified prolog
• Erlang shell, escript and compiled *.beam bytecode
Variables and pattern matching

• Variables starts with capital letter or
  underscore
• Variables are immutable, Erlang does not have
  mutable variables
• They are variables because they can be
  assigned or not assigned
• Erlang variables are the same as val variables
  in Scala
Erlang variable demo
Scala variable demo
Atoms and tuples

•   An atom is a global constant starting with lower case
•   Scala has an equivalent called Symbol
•   A tuple is an ordered set of elements
•   Erlang doesn’t have classes so we use tuples (see also
    records)
The spawn keyword

• spawn(Fun) -> pid()
• Spawns out a new process and returns the
  Process Identifier <0.13.1>
• Normally we assign the PID to a variable
• Pid = hello_world:start()
The *Real* Erlang "Hello, World!"




 http://egarson.blogspot.com/2008/03/real-erlang-hello-world.html
Pattern Matching




                   , 29.09.2012
Tail recursion




                 @tailrec
Tail recursion




         tail recursion as seen here is not making the memory grow
         because when the virtual machine sees a function calling
         itself in a tail position (the last expression to be evaluated in a
         function), it eliminates the current stack frame.
Scala react or receive

 • React is the “normal” actor, lightweight process
 • Receive spins out a new Java thread
 • In the paper *
       – 1.80GHz Intel Pentium M processor with 1024 MB
         memory, running Sun’s Java HotSpot™VM 1.5.0 under Linux
         2.6.15
       – Max heap size set to 512 MB
       – 5000 threads
       – 600 000 processes (1 200 000 actors)
 • React uses partial functions to send the process to the
   heap, react has return type Nothing
 • Receive runs on the stack and is heavyweight JVM threads
   (like Java)
 *Actors That Unify Threads and Events P. Haller, M. Odersky
Area server Erlang
Area server in Scala
Remote processes Erlang
Remote actors Scala
Supervisors in Erlang/OTP and
AKKA


   Supervisor

                                 Process




                       Process
      Process




                                           Page
                                            , 29.09.2012
  Actor model baksia
Supervising supervisors

  Root
Supervisor




                                        Supervisor
Supervisor
                                                               Process
                              Process



                                        Process      Process
Process             Process



                                                                  Page
                                                                    , 29.09.2012
     Actor model baksia

Más contenido relacionado

Similar a Scala actors erlang

Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threadsmperham
 
Erjang - A journey into Erlang-land
Erjang - A journey into Erlang-landErjang - A journey into Erlang-land
Erjang - A journey into Erlang-landKresten Krab Thorup
 
Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfjexp
 
Scala io2013 : Our journey from UML/MDD to Scala macros
Scala io2013 : Our journey from UML/MDD to Scala macrosScala io2013 : Our journey from UML/MDD to Scala macros
Scala io2013 : Our journey from UML/MDD to Scala macrosebiznext
 
OSGi Community Event 2010 - OSGi and Android
OSGi Community Event 2010 - OSGi and AndroidOSGi Community Event 2010 - OSGi and Android
OSGi Community Event 2010 - OSGi and Androidmfrancis
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and AkkaYung-Lin Ho
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Martijn Verburg
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKAJohan Edstrom
 
Erlang workshopdrammen
Erlang workshopdrammenErlang workshopdrammen
Erlang workshopdrammenReidar Sollid
 
Comparing implementations of the actor model
Comparing implementations of the actor modelComparing implementations of the actor model
Comparing implementations of the actor modelJim Roepcke
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJava Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJAX London
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)Martijn Verburg
 
Migrating to Java 11
Migrating to Java 11Migrating to Java 11
Migrating to Java 11Arto Santala
 
Concurrent processing and distributed computing
Concurrent processing and distributed computingConcurrent processing and distributed computing
Concurrent processing and distributed computingRahul Ramteke
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprisesMike Slinn
 
Breaking The Clustering Limits @ AlphaCSP JavaEdge 2007
Breaking The Clustering Limits @ AlphaCSP JavaEdge 2007Breaking The Clustering Limits @ AlphaCSP JavaEdge 2007
Breaking The Clustering Limits @ AlphaCSP JavaEdge 2007Baruch Sadogursky
 
Scalamen and OT
Scalamen and OTScalamen and OT
Scalamen and OTgetch123
 

Similar a Scala actors erlang (20)

Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
Erjang - A journey into Erlang-land
Erjang - A journey into Erlang-landErjang - A journey into Erlang-land
Erjang - A journey into Erlang-land
 
Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdf
 
Scala io2013 : Our journey from UML/MDD to Scala macros
Scala io2013 : Our journey from UML/MDD to Scala macrosScala io2013 : Our journey from UML/MDD to Scala macros
Scala io2013 : Our journey from UML/MDD to Scala macros
 
OSGi Community Event 2010 - OSGi and Android
OSGi Community Event 2010 - OSGi and AndroidOSGi Community Event 2010 - OSGi and Android
OSGi Community Event 2010 - OSGi and Android
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKA
 
Erlang workshopdrammen
Erlang workshopdrammenErlang workshopdrammen
Erlang workshopdrammen
 
Comparing implementations of the actor model
Comparing implementations of the actor modelComparing implementations of the actor model
Comparing implementations of the actor model
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJava Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
 
Scala goods bads
Scala goods badsScala goods bads
Scala goods bads
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)
 
Migrating to Java 11
Migrating to Java 11Migrating to Java 11
Migrating to Java 11
 
Concurrent processing and distributed computing
Concurrent processing and distributed computingConcurrent processing and distributed computing
Concurrent processing and distributed computing
 
Stackato v4
Stackato v4Stackato v4
Stackato v4
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprises
 
Breaking The Clustering Limits @ AlphaCSP JavaEdge 2007
Breaking The Clustering Limits @ AlphaCSP JavaEdge 2007Breaking The Clustering Limits @ AlphaCSP JavaEdge 2007
Breaking The Clustering Limits @ AlphaCSP JavaEdge 2007
 
Scalamen and OT
Scalamen and OTScalamen and OT
Scalamen and OT
 

Último

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Último (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

Scala actors erlang

  • 1. Scala Actors from an Erlang perspective
  • 2. Who am I • Reidar Sollid (Reidar is an ancient Viking name, and means warrior and protector of the home) • I am now a Consutlant at Bouvet • My background is from R&D and Telecom transport networks from Nera Networks( now Ceragon) and Ericsson.
  • 3. Motivation • Most Scala devs comes from Java • Hacking Scala with a Java mindset limits your use of Scala • Erlang is a pure actor base language • Getting the mindset from Erlang into Scala broadens the horizon • Java + Erlang = Scala
  • 4. The concept of forever • This is a loaner from Joe Armstrong, he is a lot funnier than I am but I guess you get the point  • I hope he don’t mind
  • 5.
  • 6. 10 x the size of the
  • 8. Nine nines 99.999999999 • Standard for Telecom equipment is five nines 99.999 (5.2 minutes downtime/year) • The Ericsson AXD301 has 2 million lines of Erlang code and nine nines
  • 11. Erlang • The world is concurrent • Things in the world don't share data • Things communicate with messages • Things fail – Joe Armstrong
  • 12. What is Erlang • Created and maintained by Ericsson (now open source) • Functional, single assignment, strict evaluation, dynamic typing • Actor model, concurrent oriented, fault tolerant, soft-real- time • Light weight processes that communicate using message passing (an Erlang process is more light weight than a Java thread) • Erlang started life as a modified prolog • Erlang shell, escript and compiled *.beam bytecode
  • 13. Variables and pattern matching • Variables starts with capital letter or underscore • Variables are immutable, Erlang does not have mutable variables • They are variables because they can be assigned or not assigned • Erlang variables are the same as val variables in Scala
  • 16. Atoms and tuples • An atom is a global constant starting with lower case • Scala has an equivalent called Symbol • A tuple is an ordered set of elements • Erlang doesn’t have classes so we use tuples (see also records)
  • 17. The spawn keyword • spawn(Fun) -> pid() • Spawns out a new process and returns the Process Identifier <0.13.1> • Normally we assign the PID to a variable • Pid = hello_world:start()
  • 18. The *Real* Erlang "Hello, World!" http://egarson.blogspot.com/2008/03/real-erlang-hello-world.html
  • 19. Pattern Matching , 29.09.2012
  • 20. Tail recursion @tailrec
  • 21. Tail recursion tail recursion as seen here is not making the memory grow because when the virtual machine sees a function calling itself in a tail position (the last expression to be evaluated in a function), it eliminates the current stack frame.
  • 22. Scala react or receive • React is the “normal” actor, lightweight process • Receive spins out a new Java thread • In the paper * – 1.80GHz Intel Pentium M processor with 1024 MB memory, running Sun’s Java HotSpot™VM 1.5.0 under Linux 2.6.15 – Max heap size set to 512 MB – 5000 threads – 600 000 processes (1 200 000 actors) • React uses partial functions to send the process to the heap, react has return type Nothing • Receive runs on the stack and is heavyweight JVM threads (like Java) *Actors That Unify Threads and Events P. Haller, M. Odersky
  • 24. Area server in Scala
  • 27. Supervisors in Erlang/OTP and AKKA Supervisor Process Process Process Page , 29.09.2012 Actor model baksia
  • 28. Supervising supervisors Root Supervisor Supervisor Supervisor Process Process Process Process Process Process Page , 29.09.2012 Actor model baksia

Notas del editor

  1. Imaging somewhere in the universe an Iron Ball
  2. 10 times the size of the earth, and every 10th million year a fly
  3. Lands on the Iron Ball and wonders around a bit.The time it for the fly to wear down the Iron Ball is tiny winy bit of time in the concept of forever.
  4. Erlang do have shared memory, light weight processes that communicate through messages
  5. val variable = 3;Variable = 3.
  6. 1 200 000 actors since the queues are actors as well
  7. Pid = spawn(fun()-&gt;area_server:loop() end).Pid = {circle, 2.3}.Pid =
  8. Show receiveWithin