SlideShare uma empresa Scribd logo
1 de 39
Baixar para ler offline
Building Polyglot Systems
                      With Scalang
                      Cliff Moon
                      @moonpolysoft




Thursday, September 22, 2011
Why Scala and Erlang?


                 • Complementary sets of features.

                 • Compatible type systems.

                 • Separates concerns.




Thursday, September 22, 2011
meter
                                  meter
                                  meter   Collector          streaker
                                  meter
                                  meter
                                  meter
                                  meter
                                  meter
                                  meter
                                  meter
                                  meter   Collector           scylla
                                  meter



                                   REST   REST        REST    REST




                               Boundary Architecture
Thursday, September 22, 2011
First Revision

                 • JInterface and wrappers.

                 • Cumbersome code.

                 • Wrong level of abstraction.

                 • Not performant.



Thursday, September 22, 2011
JInterface Wrappers


                     def task(m : OtpErlangObject, mbox : OtpMbox) = m match {
                       case ETuple(EAtom("cluster"), pid : Pid, ref : Ref) =>




Thursday, September 22, 2011
Scalang


                 • Correctness of behavior.

                 • Performance.

                 • Simplicity.




Thursday, September 22, 2011
Proc      Proc       Proc


                                              Jetlang


                                             Delivery


                                              Codecs


                                              Netty


                                            NIO Sockets




                               Scalang Architecture
Thursday, September 22, 2011
Using Scalang




Thursday, September 22, 2011
Node


                     //make sure epmd is running
                     val node = Node(“scala@localhost.local”, “cookie”)




Thursday, September 22, 2011
Processes

                     class Echo(ctx : ProcessContext) extends Process(ctx) {
                        override def onMessage(msg : Any) = msg match {
                          case (pid : Pid, m : String) =>
                             pid ! m
                        }
                     }
                     val echoPid = node.spawn[Echo](“echo_server”)




Thursday, September 22, 2011
Sending Messages


                 • Send messages to a Pid.

                 • Send messages to a local registered name.

                 • Send messages to a remote registered name.




Thursday, September 22, 2011
Sending Messages - in process


                     aPid ! ‘do_something

                     ‘regname ! ‘do_another_thing

                     (‘regname, ‘erl@localhost.local) ! ‘do_something_else




Thursday, September 22, 2011
Sending Messages - outside proc


                     node.send(aPid, ‘do_something)

                     node.send(‘regname, ‘do_another_thing)

                     node.send( (‘regname, ‘erl@localhost.local), ‘do_something_else)




Thursday, September 22, 2011
Error Handling

                 • Uncaught exceptions in process code.

                 • Implemented via bi-directional links.

                 • Link breakage triggers exit notification.

                 • Links work both intra and inter - node.

                 • Not pre-emptive on the Scalang side.


Thursday, September 22, 2011
Error Handling


                     class ExitHandler(ctx : ProcessContext) extends Process(ctx) {
                       override def trapExit(from : Pid, msg : Any) {
                         log.warn(“exit notification from %s”, from)
                       }
                     }




Thursday, September 22, 2011
Type Mappings
                From Erlang     To Scala     From Scala    To Erlang
                Small Integer   Int          Byte          Small Integer
                Integer         Int          Int           Integer
                Float           Double       Long          Small Bignum
                Boolean         Boolean      Double        Float
                Atom            Symbol       Symbol        Atom
                Reference       Reference    Reference     Reference
                Port            Port         Port          Port
                Pid             Pid          Pid           Pid
                Small Tuple     Tuple        Fun           Fun
                Large Tuple     BigTuple     String        String
                String          String       List          List
                List            List         BigInteger    Large Bignum
                Binary          ByteBuffer   Array[Byte]   Binary
                Small Bignum    Long         ByteBuffer    Binary
                Large Bignum    BigInt       BitString     Bitstring
                Fun             Fun          Tuple         Tuple
                Bitstring       Bitstring    BigTuple      Tuple


Thursday, September 22, 2011
Rich Type Mappings


                 • Invoked for tagged tuples.

                 • User-supplied decode logic.

                 • Avoids performance penalty of reflective instantiation.




Thursday, September 22, 2011
Rich Type Mappings


                     (‘struct, List(      {struct, [
                       (‘key, value),       {key, Value},
                       (‘key2, value2),     {key2, Value2},
                       ... ))               ... ]}




Thursday, September 22, 2011
Rich Type Mappings

              object StructFactory extends TypeFactory {
                def createType(name : Symbol, arity : Int, reader : TermReader) : Any
                = {
                  reader.mark
                  (name, arity) match {
                    case (‘struct,2) => Some(readMap(reader))
                    case _ => reader.reset; None
                  }
                }
              }




Thursday, September 22, 2011
Rich Type Mappings


                     val node = Node(name,cookie,NodeConfig(
                                                    typeFactory = StructFactory))




Thursday, September 22, 2011
Services


                 • Initialization parameters.

                 • Built in call and cast support.

                 • Transparent interoperability with gen_server.




Thursday, September 22, 2011
Services


                 • handleCall - gen_server:call/2 - request & respose

                 • handleCast - gen_server:cast/2 - request

                 • handleInfo - Raw message received.




Thursday, September 22, 2011
Services

                     case class EchoArgs(name : Symbol)
                     class Echo(ctx : ServiceContext[EchoArgs]) extends Service(ctx) {
                       val EchoArgs(name) = ctx.args

                          override def handleCall(from : (Pid,Reference), req : Any) : Any = {
                            (name, req)
                          }
                     }




Thursday, September 22, 2011
Anonymous Processes


                     node.spawn { mbox =>
                       val msg = mbox.receive
                       // do some long running work
                       node.send(‘master, (results, mbox.self) )
                     }




Thursday, September 22, 2011
Runtime Metrics

                 • Message meters per connection.

                 • Execution histograms per process.

                 • Serialization time histograms.

                 • Message queue size gauges.

                 • Internal thread pool metrics.


Thursday, September 22, 2011
Runtime Metrics
Thursday, September 22, 2011
Performance Tuning

                 • ThreadPoolFactory - pluggable thread pool implementations.

                 • Elastic thread pools from overlock.

                 • Threads tuned to max(8, cpu_count * 2).

                 • Beware of starvation.



Thursday, September 22, 2011
Thread Pools

                 • Boss pool - Initial connection and accept handling.

                 • Worker pool - Non blocking reads and writes.

                 • Actor pool - Process callbacks.

                 • Batch Executor - Per-process execution logic.



Thursday, September 22, 2011
Thread Pools


                     val node = Node(name,cookie,NodeConfig(
                                                    poolFactory = MyThreadPools))




Thursday, September 22, 2011
Process Patterns




Thursday, September 22, 2011
Deferred Reply

                     def handleCall(from : (Pid, Reference), msg : Any) : Any = {
                       ctx.node.spawn { mbox =>
                         // long running work
                         reply(from, response)
                       }
                       ‘noreply
                     }




Thursday, September 22, 2011
State Machine


                     class Stateful(ctx : ProcessContext) extends Process(ctx) {
                       @volatile var state = ‘a
                       override def onMessage(msg : Any) = (msg, state) match {
                         case (‘event, ‘a) => ...
                       }
                     }




Thursday, September 22, 2011
Worker Pools

                     class StatelessWorker(ctx : ProcessContext) extends Process(ctx) {
                       def onMessage(msg : Any) = msg match { ... }
                     }

                     //experimental!
                     node.spawn[StatelessWorker](reentrant = true)




Thursday, September 22, 2011
Supervision Trees

                     class TaskMaster(ctx : ProcessContext) extends Process(ctx) {
                       def onMessage(msg : Any) = {
                         //distribute work to workers
                       }

                          override def handleExit(worker : Pid, reason : Any) {
                            //remove worker from pool, or restart
                          }
                     }




Thursday, September 22, 2011
Admin Endpoint


                     class Admin(ctx : ServiceContext[Args]) extends Service(ctx) {
                       def handleCall(from: (Pid,Reference), req : Any) = req match {
                         case (‘reassign, node : Symbol) =>
                           //reassign message stream to new node
                       }
                     }




Thursday, September 22, 2011
Admin Endpoint


                     ok = gen_server:call({admin, backend@data01},
                                                          {reassign, cruncher@data02}).




Thursday, September 22, 2011
Demo!




Thursday, September 22, 2011
Conclusion

                 • Wrap services in Scalang actors.

                 • Throw out your RPC codegen tools.

                 • Embrace a mesh topology.

                 • Let Erlang and Scala do the things they are good at.



Thursday, September 22, 2011
Questions?
                      https://github.com/boundary/scalang
                      https://github.com/boundary/overlock
                      Thank you.




Thursday, September 22, 2011

Mais conteúdo relacionado

Destaque

The Art of Practice Management Dental Pearls - August 2016 - Risky Business
The Art of Practice Management Dental Pearls - August 2016 - Risky BusinessThe Art of Practice Management Dental Pearls - August 2016 - Risky Business
The Art of Practice Management Dental Pearls - August 2016 - Risky BusinessMarianne Harper
 
Bases teóricas para proyecto permacultural de ecodesarrollo
Bases teóricas para proyecto permacultural de ecodesarrolloBases teóricas para proyecto permacultural de ecodesarrollo
Bases teóricas para proyecto permacultural de ecodesarrolloFernando García Méndez
 
Matthias Vallentin - Towards Interactive Network Forensics and Incident Respo...
Matthias Vallentin - Towards Interactive Network Forensics and Incident Respo...Matthias Vallentin - Towards Interactive Network Forensics and Incident Respo...
Matthias Vallentin - Towards Interactive Network Forensics and Incident Respo...boundary_slides
 
Pöttyös túró rudi’s success on facebook
Pöttyös túró rudi’s success on facebook Pöttyös túró rudi’s success on facebook
Pöttyös túró rudi’s success on facebook Istvan Gergely
 
Relationship building and legitimacy at start up companies
Relationship building and legitimacy at start up companiesRelationship building and legitimacy at start up companies
Relationship building and legitimacy at start up companiesIstvan Gergely
 
When bad publicity is good
When bad publicity is goodWhen bad publicity is good
When bad publicity is goodIstvan Gergely
 
Avaluació compartida a l'escola
Avaluació compartida a l'escolaAvaluació compartida a l'escola
Avaluació compartida a l'escolaBictorbictor
 
Presentazione di prova
Presentazione di provaPresentazione di prova
Presentazione di provagloi
 
if then is now verdienmodel 28 nov
if then is now verdienmodel 28 novif then is now verdienmodel 28 nov
if then is now verdienmodel 28 novmenno heling
 
Presentació atletisme
Presentació atletismePresentació atletisme
Presentació atletismeBictorbictor
 
Rugby Cicle Superior
Rugby Cicle SuperiorRugby Cicle Superior
Rugby Cicle SuperiorBictorbictor
 
Sıvı elektrolit
Sıvı elektrolitSıvı elektrolit
Sıvı elektrolitdrgunay
 

Destaque (15)

Warmbloods today article
Warmbloods today articleWarmbloods today article
Warmbloods today article
 
The Art of Practice Management Dental Pearls - August 2016 - Risky Business
The Art of Practice Management Dental Pearls - August 2016 - Risky BusinessThe Art of Practice Management Dental Pearls - August 2016 - Risky Business
The Art of Practice Management Dental Pearls - August 2016 - Risky Business
 
Bases teóricas para proyecto permacultural de ecodesarrollo
Bases teóricas para proyecto permacultural de ecodesarrolloBases teóricas para proyecto permacultural de ecodesarrollo
Bases teóricas para proyecto permacultural de ecodesarrollo
 
Prezume brandthink
Prezume brandthinkPrezume brandthink
Prezume brandthink
 
Lipoma
Lipoma Lipoma
Lipoma
 
Matthias Vallentin - Towards Interactive Network Forensics and Incident Respo...
Matthias Vallentin - Towards Interactive Network Forensics and Incident Respo...Matthias Vallentin - Towards Interactive Network Forensics and Incident Respo...
Matthias Vallentin - Towards Interactive Network Forensics and Incident Respo...
 
Pöttyös túró rudi’s success on facebook
Pöttyös túró rudi’s success on facebook Pöttyös túró rudi’s success on facebook
Pöttyös túró rudi’s success on facebook
 
Relationship building and legitimacy at start up companies
Relationship building and legitimacy at start up companiesRelationship building and legitimacy at start up companies
Relationship building and legitimacy at start up companies
 
When bad publicity is good
When bad publicity is goodWhen bad publicity is good
When bad publicity is good
 
Avaluació compartida a l'escola
Avaluació compartida a l'escolaAvaluació compartida a l'escola
Avaluació compartida a l'escola
 
Presentazione di prova
Presentazione di provaPresentazione di prova
Presentazione di prova
 
if then is now verdienmodel 28 nov
if then is now verdienmodel 28 novif then is now verdienmodel 28 nov
if then is now verdienmodel 28 nov
 
Presentació atletisme
Presentació atletismePresentació atletisme
Presentació atletisme
 
Rugby Cicle Superior
Rugby Cicle SuperiorRugby Cicle Superior
Rugby Cicle Superior
 
Sıvı elektrolit
Sıvı elektrolitSıvı elektrolit
Sıvı elektrolit
 

Semelhante a Cliff Moon - Building Polyglot Distributed Systems with Scalang, Boundary Tech Talks October 6, 2011

IronSmalltalk
IronSmalltalkIronSmalltalk
IronSmalltalkESUG
 
Python internals and how they affect your code - kasra ahmadvand
Python internals and how they affect your code - kasra ahmadvandPython internals and how they affect your code - kasra ahmadvand
Python internals and how they affect your code - kasra ahmadvandirpycon
 
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft..."Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...Dataconomy Media
 
Embedding Languages Without Breaking Tools
Embedding Languages Without Breaking ToolsEmbedding Languages Without Breaking Tools
Embedding Languages Without Breaking ToolsLukas Renggli
 
Summer training vhdl
Summer training vhdlSummer training vhdl
Summer training vhdlArshit Rai
 
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...Antonio Garrote Hernández
 
Android 1.5 to 3.0: a compatibility journey
Android 1.5 to 3.0: a compatibility journeyAndroid 1.5 to 3.0: a compatibility journey
Android 1.5 to 3.0: a compatibility journeyEmanuele Di Saverio
 
Summer training vhdl
Summer training vhdlSummer training vhdl
Summer training vhdlArshit Rai
 
Object Oriented Programming with COBOL
Object Oriented Programming with COBOLObject Oriented Programming with COBOL
Object Oriented Programming with COBOLMicro Focus
 
Smalltalk in a .NET World
Smalltalk in a  .NET WorldSmalltalk in a  .NET World
Smalltalk in a .NET WorldESUG
 
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」Sho Shimizu
 
Sparse Data Structures for Weighted Bipartite Matching
Sparse Data Structures for Weighted Bipartite Matching Sparse Data Structures for Weighted Bipartite Matching
Sparse Data Structures for Weighted Bipartite Matching Jason Riedy
 

Semelhante a Cliff Moon - Building Polyglot Distributed Systems with Scalang, Boundary Tech Talks October 6, 2011 (20)

IronSmalltalk
IronSmalltalkIronSmalltalk
IronSmalltalk
 
Python internals and how they affect your code - kasra ahmadvand
Python internals and how they affect your code - kasra ahmadvandPython internals and how they affect your code - kasra ahmadvand
Python internals and how they affect your code - kasra ahmadvand
 
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft..."Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
 
Embedding Languages Without Breaking Tools
Embedding Languages Without Breaking ToolsEmbedding Languages Without Breaking Tools
Embedding Languages Without Breaking Tools
 
Just entity framework
Just entity frameworkJust entity framework
Just entity framework
 
Summer training vhdl
Summer training vhdlSummer training vhdl
Summer training vhdl
 
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
 
Android 1.5 to 3.0: a compatibility journey
Android 1.5 to 3.0: a compatibility journeyAndroid 1.5 to 3.0: a compatibility journey
Android 1.5 to 3.0: a compatibility journey
 
Summer training vhdl
Summer training vhdlSummer training vhdl
Summer training vhdl
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
OOPSLA Talk on Preon
OOPSLA Talk on PreonOOPSLA Talk on Preon
OOPSLA Talk on Preon
 
Object Oriented Programming with COBOL
Object Oriented Programming with COBOLObject Oriented Programming with COBOL
Object Oriented Programming with COBOL
 
Generics in dot net
Generics in dot netGenerics in dot net
Generics in dot net
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Smalltalk in a .NET World
Smalltalk in a  .NET WorldSmalltalk in a  .NET World
Smalltalk in a .NET World
 
Intro africahackpart2
Intro africahackpart2Intro africahackpart2
Intro africahackpart2
 
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」
 
Sparse Data Structures for Weighted Bipartite Matching
Sparse Data Structures for Weighted Bipartite Matching Sparse Data Structures for Weighted Bipartite Matching
Sparse Data Structures for Weighted Bipartite Matching
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
SDOW (ISWC2011)
SDOW (ISWC2011)SDOW (ISWC2011)
SDOW (ISWC2011)
 

Último

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Último (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Cliff Moon - Building Polyglot Distributed Systems with Scalang, Boundary Tech Talks October 6, 2011

  • 1. Building Polyglot Systems With Scalang Cliff Moon @moonpolysoft Thursday, September 22, 2011
  • 2. Why Scala and Erlang? • Complementary sets of features. • Compatible type systems. • Separates concerns. Thursday, September 22, 2011
  • 3. meter meter meter Collector streaker meter meter meter meter meter meter meter meter Collector scylla meter REST REST REST REST Boundary Architecture Thursday, September 22, 2011
  • 4. First Revision • JInterface and wrappers. • Cumbersome code. • Wrong level of abstraction. • Not performant. Thursday, September 22, 2011
  • 5. JInterface Wrappers def task(m : OtpErlangObject, mbox : OtpMbox) = m match { case ETuple(EAtom("cluster"), pid : Pid, ref : Ref) => Thursday, September 22, 2011
  • 6. Scalang • Correctness of behavior. • Performance. • Simplicity. Thursday, September 22, 2011
  • 7. Proc Proc Proc Jetlang Delivery Codecs Netty NIO Sockets Scalang Architecture Thursday, September 22, 2011
  • 9. Node //make sure epmd is running val node = Node(“scala@localhost.local”, “cookie”) Thursday, September 22, 2011
  • 10. Processes class Echo(ctx : ProcessContext) extends Process(ctx) { override def onMessage(msg : Any) = msg match { case (pid : Pid, m : String) => pid ! m } } val echoPid = node.spawn[Echo](“echo_server”) Thursday, September 22, 2011
  • 11. Sending Messages • Send messages to a Pid. • Send messages to a local registered name. • Send messages to a remote registered name. Thursday, September 22, 2011
  • 12. Sending Messages - in process aPid ! ‘do_something ‘regname ! ‘do_another_thing (‘regname, ‘erl@localhost.local) ! ‘do_something_else Thursday, September 22, 2011
  • 13. Sending Messages - outside proc node.send(aPid, ‘do_something) node.send(‘regname, ‘do_another_thing) node.send( (‘regname, ‘erl@localhost.local), ‘do_something_else) Thursday, September 22, 2011
  • 14. Error Handling • Uncaught exceptions in process code. • Implemented via bi-directional links. • Link breakage triggers exit notification. • Links work both intra and inter - node. • Not pre-emptive on the Scalang side. Thursday, September 22, 2011
  • 15. Error Handling class ExitHandler(ctx : ProcessContext) extends Process(ctx) { override def trapExit(from : Pid, msg : Any) { log.warn(“exit notification from %s”, from) } } Thursday, September 22, 2011
  • 16. Type Mappings From Erlang To Scala From Scala To Erlang Small Integer Int Byte Small Integer Integer Int Int Integer Float Double Long Small Bignum Boolean Boolean Double Float Atom Symbol Symbol Atom Reference Reference Reference Reference Port Port Port Port Pid Pid Pid Pid Small Tuple Tuple Fun Fun Large Tuple BigTuple String String String String List List List List BigInteger Large Bignum Binary ByteBuffer Array[Byte] Binary Small Bignum Long ByteBuffer Binary Large Bignum BigInt BitString Bitstring Fun Fun Tuple Tuple Bitstring Bitstring BigTuple Tuple Thursday, September 22, 2011
  • 17. Rich Type Mappings • Invoked for tagged tuples. • User-supplied decode logic. • Avoids performance penalty of reflective instantiation. Thursday, September 22, 2011
  • 18. Rich Type Mappings (‘struct, List( {struct, [ (‘key, value), {key, Value}, (‘key2, value2), {key2, Value2}, ... )) ... ]} Thursday, September 22, 2011
  • 19. Rich Type Mappings object StructFactory extends TypeFactory { def createType(name : Symbol, arity : Int, reader : TermReader) : Any = { reader.mark (name, arity) match { case (‘struct,2) => Some(readMap(reader)) case _ => reader.reset; None } } } Thursday, September 22, 2011
  • 20. Rich Type Mappings val node = Node(name,cookie,NodeConfig( typeFactory = StructFactory)) Thursday, September 22, 2011
  • 21. Services • Initialization parameters. • Built in call and cast support. • Transparent interoperability with gen_server. Thursday, September 22, 2011
  • 22. Services • handleCall - gen_server:call/2 - request & respose • handleCast - gen_server:cast/2 - request • handleInfo - Raw message received. Thursday, September 22, 2011
  • 23. Services case class EchoArgs(name : Symbol) class Echo(ctx : ServiceContext[EchoArgs]) extends Service(ctx) { val EchoArgs(name) = ctx.args override def handleCall(from : (Pid,Reference), req : Any) : Any = { (name, req) } } Thursday, September 22, 2011
  • 24. Anonymous Processes node.spawn { mbox => val msg = mbox.receive // do some long running work node.send(‘master, (results, mbox.self) ) } Thursday, September 22, 2011
  • 25. Runtime Metrics • Message meters per connection. • Execution histograms per process. • Serialization time histograms. • Message queue size gauges. • Internal thread pool metrics. Thursday, September 22, 2011
  • 27. Performance Tuning • ThreadPoolFactory - pluggable thread pool implementations. • Elastic thread pools from overlock. • Threads tuned to max(8, cpu_count * 2). • Beware of starvation. Thursday, September 22, 2011
  • 28. Thread Pools • Boss pool - Initial connection and accept handling. • Worker pool - Non blocking reads and writes. • Actor pool - Process callbacks. • Batch Executor - Per-process execution logic. Thursday, September 22, 2011
  • 29. Thread Pools val node = Node(name,cookie,NodeConfig( poolFactory = MyThreadPools)) Thursday, September 22, 2011
  • 31. Deferred Reply def handleCall(from : (Pid, Reference), msg : Any) : Any = { ctx.node.spawn { mbox => // long running work reply(from, response) } ‘noreply } Thursday, September 22, 2011
  • 32. State Machine class Stateful(ctx : ProcessContext) extends Process(ctx) { @volatile var state = ‘a override def onMessage(msg : Any) = (msg, state) match { case (‘event, ‘a) => ... } } Thursday, September 22, 2011
  • 33. Worker Pools class StatelessWorker(ctx : ProcessContext) extends Process(ctx) { def onMessage(msg : Any) = msg match { ... } } //experimental! node.spawn[StatelessWorker](reentrant = true) Thursday, September 22, 2011
  • 34. Supervision Trees class TaskMaster(ctx : ProcessContext) extends Process(ctx) { def onMessage(msg : Any) = { //distribute work to workers } override def handleExit(worker : Pid, reason : Any) { //remove worker from pool, or restart } } Thursday, September 22, 2011
  • 35. Admin Endpoint class Admin(ctx : ServiceContext[Args]) extends Service(ctx) { def handleCall(from: (Pid,Reference), req : Any) = req match { case (‘reassign, node : Symbol) => //reassign message stream to new node } } Thursday, September 22, 2011
  • 36. Admin Endpoint ok = gen_server:call({admin, backend@data01}, {reassign, cruncher@data02}). Thursday, September 22, 2011
  • 38. Conclusion • Wrap services in Scalang actors. • Throw out your RPC codegen tools. • Embrace a mesh topology. • Let Erlang and Scala do the things they are good at. Thursday, September 22, 2011
  • 39. Questions? https://github.com/boundary/scalang https://github.com/boundary/overlock Thank you. Thursday, September 22, 2011