SlideShare une entreprise Scribd logo
1  sur  36
Télécharger pour lire hors ligne
Jobim: an Actors
Library for the Clojure
Programming Language


         Antonio Garrote
      María N. Moreno García
Clojure

• New Lisp dialect
• Hosted: JVM, CLR
• Focus on concurrency: (STM, Agents,
  futures, fork-join, java.util.concurrent.*)
Distributed concurrent
applications in Clojure?

“Given the diversity, sophistication, maturity,
interoperability,robustness etc of these options, it's
unlikely I'm going to fiddle around with some
language-specific solution.”

 Rich Hickey
Distributed applications
      on the JVM
• JINI
• Java Spaces
• JMS
• Terracota
• RabbitMQ
• ZeroMQ
• Gearman
Problems

• Different computational models
• Hard to port code from one solution to
  other
• Friction with Clojure semantics
Extending Clojure

• Computational model?
• Suitable notation?
• Underlying implementation?
Computational Model
Actors: components

• Named channel (PID)      PID




• Message box                    MBox
                                        Execution
                                         Context



• Execution context

Computation based on the exchange of messages
Actors: mobile
                processes
PID3                                        PID1


                 Execution                                Execution
       MBox                                        MBox
                  Context                                  Context
                                    Msg




               PID3                                PID3




                PID2


                                      Execution
                             MBox
                                       Context
Notation
Actors: minimal
     interface
(def *pid* (spawn f))

(is (= *pid* (self)))

(send! *pid* msg)

(def msg (receive *pid*))
Selective Reception
(let [p (promise)
      pid (spawn
           #(let [a (receive odd?)
                  b (receive even?)]
              (deliver p [a b])))]

  (send! pid 2)
  (send! pid 1)

  (is (= @p [1 2])))
Implementation
Message Box

• Lamina - Z. Tellman (https://github.com/
  ztellman/lamina)
• Transforms Clojure sequences into event-
  driven channels
• Synchronous and asynchronous interface
PIDs/Channel Names

• Plain Java strings: easy to exchange
• Globally unique identifiers for actors across
  all the nodes in a Jobim cluster
• Generated by Jobim’s runtime
• GUID node + process counter
Execution context
• Threaded actors:
 - Java thread per actor
 - End of thread execution, releases
     resources
 -   Threaded actors do not scale (~2000
     threads per node max.)
Execution context

• Evented actors (Scala):
 - Actors context = closure + callback
     functions
 -   Small number of reactor threads execute
     all the evented threads
(spawn
             #(loop []
               (let [[from msg] (receive)]
Threaded          (send! from msg)
                  (recur))))



            (spawn-evented
              #(react-loop []
                 (react [[from msg]]
Evented                 (send! from msg)
                        (react-recur))))
react-loop
               Callbacks+Contexts queues



Events



                                                  listen-once

         Reactor1        ...       ReactorN                       publish

                                                     react-recur

                     Multiplexer

                                                      react-future
                                     Messages


                                                thread- publish
                                                                    handler
                                                 pool
Distribution
3 problems


Messaging    Coordination   Serialization
Modular solution
            Protocols: jobim.services.*


Messaging         Coordination      Serialization




                     Plugins
Coordination

• Name service
• Membership groups: presence
• Distributed agreement: 2PC protocol
Coordination

• Apache ZooKeeper plugin
 - Light-weight
 - Scalable
 - Small set of primitives to build
    sophisticated coordination protocols
Coordination: name
 service - group
  membership
(nodes)

(resolve-node-name node-name)

(register-name name *pid*)

(def *pid* (resolve-name name))
Coordination: 2PC -
group membership


   (link *pid1* *pid2*)



         Signal
Messaging

• TCP plugin: Netty, Z.Tellman’s Aleph
  [https://github.com/ztellman/aleph]
• RabbitMQ plugin
• ZeroMQ plugin
Serialization

• Java Serialization plugin
• JSON plugin
• Kryo serialization library plugin (Yahoo S4)
Behaviours
Reusing distributed
     components?
• Encapsulate distributed patterns
• Hide message passing logic
• Building blocks for larger distributed
  systems
• Built using Clojure protocols
• Threaded and evented versions
Behaviours

• Supervisor
• Generic Server
• FSM
• Event Manager / Event Handler
• Generic TCP server
;; FSM Lock type

(def-fsm Lock
  (init [this code] [:locked {:so-far [] :code code}])
  (next-transition [this state-name state-data message]
                    (let [[topic _] message]
                      (condp = [state-name topic]
                        [:locked :button] handle-button
                        [:open   :lock] handle-lock
                        action-ignore)))
  (handle-info [this current-state current-data message]
               (do
                 (cond-match
                   [[?from :state] message] (send! from current-state))
                 (action-next-state current-state current-data))))
Demo
Future work

• Benchmarking + Performance
• Packaging / deployment / managing of
  distributed apps
• Missing functionality
Code+deps

• https://github.com/antoniogarrote/jobim

   [jobim-core "0.1.2-SNAPSHOT"]

 [jobim-rabbitmq "0.1.1-SNAPSHOT"]

 [jobim-zeromq "0.1.1-SNAPSHOT"] *

Contenu connexe

Tendances

NS-2 Tutorial
NS-2 TutorialNS-2 Tutorial
NS-2 Tutorial
code453
 
Kafka replication apachecon_2013
Kafka replication apachecon_2013Kafka replication apachecon_2013
Kafka replication apachecon_2013
Jun Rao
 
Network emulator
Network emulatorNetwork emulator
Network emulator
jeromy fu
 

Tendances (18)

Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
~Ns2~
~Ns2~~Ns2~
~Ns2~
 
Distributed System by Pratik Tambekar
Distributed System by Pratik TambekarDistributed System by Pratik Tambekar
Distributed System by Pratik Tambekar
 
Protocol implementation on NS2
Protocol implementation on NS2Protocol implementation on NS2
Protocol implementation on NS2
 
FOSDEM2015: Live migration for containers is around the corner
FOSDEM2015: Live migration for containers is around the cornerFOSDEM2015: Live migration for containers is around the corner
FOSDEM2015: Live migration for containers is around the corner
 
Ns2
Ns2Ns2
Ns2
 
Introduction to NS2 - Cont..
Introduction to NS2 - Cont..Introduction to NS2 - Cont..
Introduction to NS2 - Cont..
 
Twisted: a quick introduction
Twisted: a quick introductionTwisted: a quick introduction
Twisted: a quick introduction
 
Ns2 introduction 2
Ns2 introduction 2Ns2 introduction 2
Ns2 introduction 2
 
GopherCon 2017 - Writing Networking Clients in Go: The Design & Implementati...
GopherCon 2017 -  Writing Networking Clients in Go: The Design & Implementati...GopherCon 2017 -  Writing Networking Clients in Go: The Design & Implementati...
GopherCon 2017 - Writing Networking Clients in Go: The Design & Implementati...
 
NS-2 Tutorial
NS-2 TutorialNS-2 Tutorial
NS-2 Tutorial
 
Tut hemant ns2
Tut hemant ns2Tut hemant ns2
Tut hemant ns2
 
Adaptive Linear Solvers and Eigensolvers
Adaptive Linear Solvers and EigensolversAdaptive Linear Solvers and Eigensolvers
Adaptive Linear Solvers and Eigensolvers
 
Towards Chainer v1.5
Towards Chainer v1.5Towards Chainer v1.5
Towards Chainer v1.5
 
Kafka replication apachecon_2013
Kafka replication apachecon_2013Kafka replication apachecon_2013
Kafka replication apachecon_2013
 
Network emulator
Network emulatorNetwork emulator
Network emulator
 
An Introduction to the Formalised Memory Model for Linux Kernel
An Introduction to the Formalised Memory Model for Linux KernelAn Introduction to the Formalised Memory Model for Linux Kernel
An Introduction to the Formalised Memory Model for Linux Kernel
 
Hs java open_party
Hs java open_partyHs java open_party
Hs java open_party
 

Similaire à 4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Programming Language

Unified Messaging and Data Streaming 101
Unified Messaging and Data Streaming 101Unified Messaging and Data Streaming 101
Unified Messaging and Data Streaming 101
Timothy Spann
 
Scaling Django with gevent
Scaling Django with geventScaling Django with gevent
Scaling Django with gevent
Mahendra M
 

Similaire à 4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Programming Language (20)

Architectures with Windows Azure
Architectures with Windows AzureArchitectures with Windows Azure
Architectures with Windows Azure
 
DevoxxFR 2016 - 3 degrees of MoM
DevoxxFR 2016 - 3 degrees of MoMDevoxxFR 2016 - 3 degrees of MoM
DevoxxFR 2016 - 3 degrees of MoM
 
Python twisted
Python twistedPython twisted
Python twisted
 
Citi TechTalk Session 2: Kafka Deep Dive
Citi TechTalk Session 2: Kafka Deep DiveCiti TechTalk Session 2: Kafka Deep Dive
Citi TechTalk Session 2: Kafka Deep Dive
 
Unified Messaging and Data Streaming 101
Unified Messaging and Data Streaming 101Unified Messaging and Data Streaming 101
Unified Messaging and Data Streaming 101
 
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
 
Natural Language Processing with CNTK and Apache Spark with Ali Zaidi
Natural Language Processing with CNTK and Apache Spark with Ali ZaidiNatural Language Processing with CNTK and Apache Spark with Ali Zaidi
Natural Language Processing with CNTK and Apache Spark with Ali Zaidi
 
End to End Processing of 3.7 Million Telemetry Events per Second using Lambda...
End to End Processing of 3.7 Million Telemetry Events per Second using Lambda...End to End Processing of 3.7 Million Telemetry Events per Second using Lambda...
End to End Processing of 3.7 Million Telemetry Events per Second using Lambda...
 
ROS distributed architecture
ROS  distributed architectureROS  distributed architecture
ROS distributed architecture
 
Kafka practical experience
Kafka practical experienceKafka practical experience
Kafka practical experience
 
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
 
I can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and SpringI can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and Spring
 
Scaling Django with gevent
Scaling Django with geventScaling Django with gevent
Scaling Django with gevent
 
05 defense
05 defense05 defense
05 defense
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
Stream-Native Processing with Pulsar Functions
Stream-Native Processing with Pulsar FunctionsStream-Native Processing with Pulsar Functions
Stream-Native Processing with Pulsar Functions
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and Reactor
 
Strata Singapore: Gearpump Real time DAG-Processing with Akka at Scale
Strata Singapore: GearpumpReal time DAG-Processing with Akka at ScaleStrata Singapore: GearpumpReal time DAG-Processing with Akka at Scale
Strata Singapore: Gearpump Real time DAG-Processing with Akka at Scale
 
Dragoncraft Architectural Overview
Dragoncraft Architectural OverviewDragoncraft Architectural Overview
Dragoncraft Architectural Overview
 

Plus de Antonio Garrote Hernández (7)

API Modeling Framework: a toolbox ofr API specs. Gluecon 2017
API Modeling Framework: a toolbox ofr API specs. Gluecon 2017API Modeling Framework: a toolbox ofr API specs. Gluecon 2017
API Modeling Framework: a toolbox ofr API specs. Gluecon 2017
 
Linked Data APIs (Funding Circle May 2015)
Linked Data APIs (Funding Circle May 2015)Linked Data APIs (Funding Circle May 2015)
Linked Data APIs (Funding Circle May 2015)
 
Message Passing Concurrency in Clojure using Kilim
Message Passing Concurrency in Clojure using KilimMessage Passing Concurrency in Clojure using Kilim
Message Passing Concurrency in Clojure using Kilim
 
RESTful writable APIs for the web of Linked Data using relational storage sol...
RESTful writable APIs for the web of Linked Data using relational storage sol...RESTful writable APIs for the web of Linked Data using relational storage sol...
RESTful writable APIs for the web of Linked Data using relational storage sol...
 
lisp (vs ruby) metaprogramming
lisp (vs ruby) metaprogramminglisp (vs ruby) metaprogramming
lisp (vs ruby) metaprogramming
 
Developing Distributed Semantic Systems
Developing Distributed Semantic SystemsDeveloping Distributed Semantic Systems
Developing Distributed Semantic Systems
 
Egearmand: an Erlang Gearman daemon
Egearmand: an Erlang Gearman daemonEgearmand: an Erlang Gearman daemon
Egearmand: an Erlang Gearman daemon
 

Dernier

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Dernier (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Programming Language

  • 1. Jobim: an Actors Library for the Clojure Programming Language Antonio Garrote María N. Moreno García
  • 2. Clojure • New Lisp dialect • Hosted: JVM, CLR • Focus on concurrency: (STM, Agents, futures, fork-join, java.util.concurrent.*)
  • 3. Distributed concurrent applications in Clojure? “Given the diversity, sophistication, maturity, interoperability,robustness etc of these options, it's unlikely I'm going to fiddle around with some language-specific solution.” Rich Hickey
  • 4. Distributed applications on the JVM • JINI • Java Spaces • JMS • Terracota • RabbitMQ • ZeroMQ • Gearman
  • 5. Problems • Different computational models • Hard to port code from one solution to other • Friction with Clojure semantics
  • 6. Extending Clojure • Computational model? • Suitable notation? • Underlying implementation?
  • 7.
  • 9. Actors: components • Named channel (PID) PID • Message box MBox Execution Context • Execution context Computation based on the exchange of messages
  • 10. Actors: mobile processes PID3 PID1 Execution Execution MBox MBox Context Context Msg PID3 PID3 PID2 Execution MBox Context
  • 12. Actors: minimal interface (def *pid* (spawn f)) (is (= *pid* (self))) (send! *pid* msg) (def msg (receive *pid*))
  • 13. Selective Reception (let [p (promise) pid (spawn #(let [a (receive odd?) b (receive even?)] (deliver p [a b])))] (send! pid 2) (send! pid 1) (is (= @p [1 2])))
  • 15. Message Box • Lamina - Z. Tellman (https://github.com/ ztellman/lamina) • Transforms Clojure sequences into event- driven channels • Synchronous and asynchronous interface
  • 16. PIDs/Channel Names • Plain Java strings: easy to exchange • Globally unique identifiers for actors across all the nodes in a Jobim cluster • Generated by Jobim’s runtime • GUID node + process counter
  • 17. Execution context • Threaded actors: - Java thread per actor - End of thread execution, releases resources - Threaded actors do not scale (~2000 threads per node max.)
  • 18. Execution context • Evented actors (Scala): - Actors context = closure + callback functions - Small number of reactor threads execute all the evented threads
  • 19. (spawn #(loop [] (let [[from msg] (receive)] Threaded (send! from msg) (recur)))) (spawn-evented #(react-loop [] (react [[from msg]] Evented (send! from msg) (react-recur))))
  • 20. react-loop Callbacks+Contexts queues Events listen-once Reactor1 ... ReactorN publish react-recur Multiplexer react-future Messages thread- publish handler pool
  • 22. 3 problems Messaging Coordination Serialization
  • 23. Modular solution Protocols: jobim.services.* Messaging Coordination Serialization Plugins
  • 24. Coordination • Name service • Membership groups: presence • Distributed agreement: 2PC protocol
  • 25. Coordination • Apache ZooKeeper plugin - Light-weight - Scalable - Small set of primitives to build sophisticated coordination protocols
  • 26. Coordination: name service - group membership (nodes) (resolve-node-name node-name) (register-name name *pid*) (def *pid* (resolve-name name))
  • 27. Coordination: 2PC - group membership (link *pid1* *pid2*) Signal
  • 28. Messaging • TCP plugin: Netty, Z.Tellman’s Aleph [https://github.com/ztellman/aleph] • RabbitMQ plugin • ZeroMQ plugin
  • 29. Serialization • Java Serialization plugin • JSON plugin • Kryo serialization library plugin (Yahoo S4)
  • 31. Reusing distributed components? • Encapsulate distributed patterns • Hide message passing logic • Building blocks for larger distributed systems • Built using Clojure protocols • Threaded and evented versions
  • 32. Behaviours • Supervisor • Generic Server • FSM • Event Manager / Event Handler • Generic TCP server
  • 33. ;; FSM Lock type (def-fsm Lock (init [this code] [:locked {:so-far [] :code code}]) (next-transition [this state-name state-data message] (let [[topic _] message] (condp = [state-name topic] [:locked :button] handle-button [:open :lock] handle-lock action-ignore))) (handle-info [this current-state current-data message] (do (cond-match [[?from :state] message] (send! from current-state)) (action-next-state current-state current-data))))
  • 34. Demo
  • 35. Future work • Benchmarking + Performance • Packaging / deployment / managing of distributed apps • Missing functionality
  • 36. Code+deps • https://github.com/antoniogarrote/jobim [jobim-core "0.1.2-SNAPSHOT"] [jobim-rabbitmq "0.1.1-SNAPSHOT"] [jobim-zeromq "0.1.1-SNAPSHOT"] *