SlideShare une entreprise Scribd logo
1  sur  65
Télécharger pour lire hors ligne
Reactor Pattern
                       &

Event-Driven Programming
   A scalable concurrent approach,
   using EventMachine with Thin as an example




                                            Lin Jen-Shin, http://godfat.org/
Reactor Pattern
                            &

     Event-Driven Programming
http://godfat.org/slide/2010-02-29-reactor-pattern-and.pdf




                                             Lin Jen-Shin, http://godfat.org/
Table of Contents
Table of Contents
• concurrency, why and how in network
Table of Contents
• concurrency, why and how in network
• Event-Driven Programming explained in
  Flash with Ruby syntax
Table of Contents
• concurrency, why and how in network
• Event-Driven Programming explained in
  Flash with Ruby syntax

• Reactor Pattern in EventMachine with Thin
Table of Contents
• concurrency, why and how in network
• Event-Driven Programming explained in
  Flash with Ruby syntax

• Reactor Pattern in EventMachine with Thin
• how Thin works
Table of Contents
• concurrency, why and how in network
• Event-Driven Programming explained in
  Flash with Ruby syntax

• Reactor Pattern in EventMachine with Thin
• how Thin works
• how EventMachine works
Table of Contents
• concurrency, why and how in network
• Event-Driven Programming explained in
  Flash with Ruby syntax

• Reactor Pattern in EventMachine with Thin
• how Thin works
• how EventMachine works
concurrency, why
and how in network
concurrency, why
  and how in network
• [network I/O] is slow, we shouldn't wait for
  [network I/O] while make [CPU] idle.
concurrency, why
  and how in network
• [network I/O] is slow, we shouldn't wait for
  [network I/O] while make [CPU] idle.

• you can replace [network I/O] and [CPU]
  with all other resources like [disc I/O],
  [memory I/O], etc.
concurrency, why
  and how in network
• [network I/O] is slow, we shouldn't wait for
  [network I/O] while make [CPU] idle.

• you can replace [network I/O] and [CPU]
  with all other resources like [disc I/O],
  [memory I/O], etc.

• each kernel process/thread for each client
  using a blocking I/O is easy to write but not
  scalable at all
Table of Contents
• concurrency, why and how in network
• Event-Driven Programming explained in
  Flash with Ruby syntax

• Reactor Pattern in EventMachine with Thin
• how Thin works
• how EventMachine works
Event-Driven Programming
         to the rescue
Event-Driven Programming

 • only one process/thread
Event-Driven Programming

 • only one process/thread
 • inversion of control
Event-Driven Programming

 • only one process/thread
 • inversion of control
 • consists of an event loop and various
   event handlers
Event-Driven Programming


 • inversion of control
Event-Driven Programming
loop{
  # you control the flow
  do_something
}
       • inversion of control
Event-Driven Programming
                            register method(:do_something)
loop{                       loop{
  # you control the flow # event loop control the flow,
  do_something                # later it calls your callback
}                             event = pop_event_queue
       • inversion of control dispatch event if event
                            }
Event-Driven Programming
                        register method(:do_something)
                        loop{
                           # event loop control the flow,
                           # later it calls your callback
                           event = pop_event_queue
                           dispatch event if event
                        }
 •   consists of an event loop and various
     event handlers
Event-Driven Programming
                        register method(:do_something)
                        loop{
                           # event loop control the flow,
                           # later it calls your callback
                           event = pop_event_queue
                           dispatch event if event
                        }
 •   consists of an event loop and various
     event handlers
Event-Driven Programming
                        register method(:do_something)
                        loop{
                           # event loop control the flow,
                           # later it calls your callback
                           event = pop_event_queue
                           dispatch event if event
                        }
 •   consists of an event loop and various
     event handlers
Event-Driven Programming
 in Flash with Ruby syntax
Event-Driven Programming
 in Flash with Ruby syntax
  • game loop, an example of event loop
Event-Driven Programming
 in Flash with Ruby syntax
  • game loop, an example of event loop
  • Flash ActionScript, onEnterFrame
Event-Driven Programming
 in Flash with Ruby syntax
  • game loop, an example of event loop
  • Flash ActionScript, onEnterFrame
  • frame by frame
Event-Driven Programming
 in Flash with Ruby syntax

# in each sprite thread
30.times{
  application.draw sprite
  sprite.x += 1
}
sprite.onEnterFrame = lambda{
  sprite.x += 1
}




# in each sprite thread
30.times{
  application.draw sprite
  sprite.x += 1
}
sprite.onEnterFrame = lambda{
  sprite.x += 1
}
application.register sprite
30.times{ # event loop, also called game loop
  events = application.pop_event_queue
  events.each{ |event|
    application.dispatch event
  }
  # model/view separation
  application.draw application.sprites
}
# in each sprite thread
30.times{
  application.draw sprite
  sprite.x += 1
}
Table of Contents
• concurrency, why and how in network
• Event-Driven Programming explained in
  Flash with Ruby syntax

• Reactor Pattern in EventMachine with Thin
• how Thin works
• how EventMachine works
Reactor Pattern
Reactor Pattern
loop{
  data = read
  handle data
}
Reactor Pattern
                register method(:handle)
loop{           loop{
  data = read     data = partial_read
  handle data     event = process data
}                 dispatch event if event
                }
Event-Driven Programming
                        register method(:do_something)
loop{                   loop{
  # you control the flow # event loop control the flow,
  do_something            # later it calls your callback
}                         event = pop_event_queue
                          dispatch event if event
                        }
Reactor Pattern
                register method(:handle)
loop{           loop{
  data = read     data = partial_read
  handle data     event = process data
}                 dispatch event if event
                }
Reactor Pattern




    by wikipedia
Reactor Pattern
• resources # e.g. network I/O




                by wikipedia
Reactor Pattern
• resources # e.g. network I/O
• synchronous event demultiplexer
  # i.e. the blocking event loop




                 by wikipedia
Reactor Pattern
• resources # e.g. network I/O
• synchronous event demultiplexer
  # i.e. the blocking event loop

• dispatcher
  # i.e. handler manager and event dispatcher


                 by wikipedia
Reactor Pattern
• resources # e.g. network I/O
• synchronous event demultiplexer
  # i.e. the blocking event loop

• dispatcher
  # i.e. handler manager and event dispatcher

• request handler # e.g. thin handler
                 by wikipedia
Reactor Pattern
Request
(resource)
Reactor Pattern
                  EventMachine
Request
                  (demultiplexer
(resource)
                   + dispatcher)
Reactor Pattern
                  EventMachine
Request                            Thin (or AMQP)
                  (demultiplexer
(resource)                         (request handler)
                   + dispatcher)
Reactor Pattern
                  EventMachine
Request                                Thin (or AMQP)
                  (demultiplexer
(resource)                             (request handler)
                   + dispatcher)




                                   Rack Thin
                                    handler
Reactor Pattern
                     EventMachine
Request                                         Thin (or AMQP)
                      (demultiplexer
(resource)                                      (request handler)
                       + dispatcher)




                Rack Rails                  Rack Thin
                                 rack env
                 adapter                     handler
Reactor Pattern
                             EventMachine
        Request                                         Thin (or AMQP)
                              (demultiplexer
        (resource)                                      (request handler)
                               + dispatcher)




                        Rack Rails                  Rack Thin
Rails                                    rack env
                         adapter                     handler
your rails
application
                        Reactor Pattern
                                EventMachine
           Request                                         Thin (or AMQP)
                                 (demultiplexer
           (resource)                                      (request handler)
                                  + dispatcher)




                           Rack Rails                  Rack Thin
   Rails                                    rack env
                            adapter                     handler
Reactor Pattern
EventMachine is a generic network I/O server/client
library due to I/O and request handler separation in
                   Reactor Pattern
Reactor Pattern
• EventMachine (Ruby)
Reactor Pattern
• EventMachine (Ruby)
• Twisted (Python)
Reactor Pattern
• EventMachine (Ruby)
• Twisted (Python)
• nodejs (JavaScript in V8)
Reactor Pattern
• EventMachine (Ruby)
• Twisted (Python)
• nodejs (JavaScript in V8)
• libevent and libev (C)
Reactor Pattern
• select (POSIX)
Reactor Pattern
• select (POSIX)
• poll (POSIX)
Reactor Pattern
• select (POSIX)
• poll (POSIX)
• epoll (Linux)
Reactor Pattern
• select (POSIX)
• poll (POSIX)
• epoll (Linux)
• kqueue (BSD, Mac OS X (Darwin))
Table of Contents
• concurrency, why and how in network
• Event-Driven Programming explained in
  Flash with Ruby syntax

• Reactor Pattern in EventMachine with Thin
• how Thin works
• how EventMachine works
how Thin works
• Thin::Server
how Thin works
• Thin::Server
• Thin::Backends::TcpServer
 # communicate with EventMachine
how Thin works
• Thin::Server
• Thin::Backends::TcpServer
 # communicate with EventMachine

• Thin::Connection
 # EventMachine event handler
how Thin works
• Thin::Server
• Thin::Backends::TcpServer
 # communicate with EventMachine

• Thin::Connection
 # EventMachine event handler

• Thin::Request
 # partial HTTP request parsing
 # Rack env builder
how Thin works
Sorry! To be continued......
how Thin works
Sorry! To be continued......


           ?

Contenu connexe

Tendances

Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsJohan Andrén
 
Reactive mistakes - ScalaDays Chicago 2017
Reactive mistakes -  ScalaDays Chicago 2017Reactive mistakes -  ScalaDays Chicago 2017
Reactive mistakes - ScalaDays Chicago 2017Petr Zapletal
 
How to Improve the Observability of Apache Cassandra and Kafka applications...
How to Improve the Observability of Apache Cassandra and Kafka applications...How to Improve the Observability of Apache Cassandra and Kafka applications...
How to Improve the Observability of Apache Cassandra and Kafka applications...Paul Brebner
 
Topic Modeling via Tensor Factorization Use Case for Apache REEF Framework
Topic Modeling via Tensor Factorization Use Case for Apache REEF FrameworkTopic Modeling via Tensor Factorization Use Case for Apache REEF Framework
Topic Modeling via Tensor Factorization Use Case for Apache REEF FrameworkDataWorks Summit
 
Topic Modeling via Tensor Factorization - Use Case for Apache REEF
Topic Modeling via Tensor Factorization - Use Case for Apache REEFTopic Modeling via Tensor Factorization - Use Case for Apache REEF
Topic Modeling via Tensor Factorization - Use Case for Apache REEFSergiy Matusevych
 
Deploying Microservice on Docker
Deploying Microservice on DockerDeploying Microservice on Docker
Deploying Microservice on DockerKnoldus Inc.
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJavaJobaer Chowdhury
 
Reactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayReactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayRoland Kuhn
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014Thomas Lockney
 
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaKasun Indrasiri
 
Developing distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterDeveloping distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterKonstantin Tsykulenko
 
Beam me up, Samza!
Beam me up, Samza!Beam me up, Samza!
Beam me up, Samza!Xinyu Liu
 
Exactly-Once Made Easy: Transactional Messaging Improvement for Usability and...
Exactly-Once Made Easy: Transactional Messaging Improvement for Usability and...Exactly-Once Made Easy: Transactional Messaging Improvement for Usability and...
Exactly-Once Made Easy: Transactional Messaging Improvement for Usability and...HostedbyConfluent
 
Scala usergroup stockholm - reactive integrations with akka streams
Scala usergroup stockholm - reactive integrations with akka streamsScala usergroup stockholm - reactive integrations with akka streams
Scala usergroup stockholm - reactive integrations with akka streamsJohan Andrén
 
Internship final report@Treasure Data Inc.
Internship final report@Treasure Data Inc.Internship final report@Treasure Data Inc.
Internship final report@Treasure Data Inc.Ryuichi ITO
 
Reactive mistakes reactive nyc
Reactive mistakes   reactive nycReactive mistakes   reactive nyc
Reactive mistakes reactive nycPetr Zapletal
 
Intro to Functional Programming with RxJava
Intro to Functional Programming with RxJavaIntro to Functional Programming with RxJava
Intro to Functional Programming with RxJavaMike Nakhimovich
 

Tendances (20)

Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka Streams
 
Reactive mistakes - ScalaDays Chicago 2017
Reactive mistakes -  ScalaDays Chicago 2017Reactive mistakes -  ScalaDays Chicago 2017
Reactive mistakes - ScalaDays Chicago 2017
 
How to Improve the Observability of Apache Cassandra and Kafka applications...
How to Improve the Observability of Apache Cassandra and Kafka applications...How to Improve the Observability of Apache Cassandra and Kafka applications...
How to Improve the Observability of Apache Cassandra and Kafka applications...
 
Topic Modeling via Tensor Factorization Use Case for Apache REEF Framework
Topic Modeling via Tensor Factorization Use Case for Apache REEF FrameworkTopic Modeling via Tensor Factorization Use Case for Apache REEF Framework
Topic Modeling via Tensor Factorization Use Case for Apache REEF Framework
 
Topic Modeling via Tensor Factorization - Use Case for Apache REEF
Topic Modeling via Tensor Factorization - Use Case for Apache REEFTopic Modeling via Tensor Factorization - Use Case for Apache REEF
Topic Modeling via Tensor Factorization - Use Case for Apache REEF
 
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
Javantura v3 - Going Reactive with RxJava – Hrvoje CrnjakJavantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
 
Rooster Tech Talk
Rooster Tech TalkRooster Tech Talk
Rooster Tech Talk
 
Deploying Microservice on Docker
Deploying Microservice on DockerDeploying Microservice on Docker
Deploying Microservice on Docker
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJava
 
Reactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayReactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive Way
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014
 
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-Java
 
Developing distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterDeveloping distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka Cluster
 
Beam me up, Samza!
Beam me up, Samza!Beam me up, Samza!
Beam me up, Samza!
 
Exactly-Once Made Easy: Transactional Messaging Improvement for Usability and...
Exactly-Once Made Easy: Transactional Messaging Improvement for Usability and...Exactly-Once Made Easy: Transactional Messaging Improvement for Usability and...
Exactly-Once Made Easy: Transactional Messaging Improvement for Usability and...
 
Scala usergroup stockholm - reactive integrations with akka streams
Scala usergroup stockholm - reactive integrations with akka streamsScala usergroup stockholm - reactive integrations with akka streams
Scala usergroup stockholm - reactive integrations with akka streams
 
Internship final report@Treasure Data Inc.
Internship final report@Treasure Data Inc.Internship final report@Treasure Data Inc.
Internship final report@Treasure Data Inc.
 
Reactive mistakes reactive nyc
Reactive mistakes   reactive nycReactive mistakes   reactive nyc
Reactive mistakes reactive nyc
 
Intro to Functional Programming with RxJava
Intro to Functional Programming with RxJavaIntro to Functional Programming with RxJava
Intro to Functional Programming with RxJava
 

En vedette

Reactor Design Pattern
Reactor Design PatternReactor Design Pattern
Reactor Design Patternliminescence
 
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindia dotnet development  chapter 14 event-driven programmingSynapseindia dotnet development  chapter 14 event-driven programming
Synapseindia dotnet development chapter 14 event-driven programmingSynapseindiappsdevelopment
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programmingChaffey College
 
Python geek Event Description
Python geek Event DescriptionPython geek Event Description
Python geek Event DescriptionParbhat Puri
 
2010.1 mandriva linux_installation_using_dual_cd
2010.1 mandriva linux_installation_using_dual_cd2010.1 mandriva linux_installation_using_dual_cd
2010.1 mandriva linux_installation_using_dual_cdSt Louis MUG
 
(WRK302) Event-Driven Programming
(WRK302) Event-Driven Programming(WRK302) Event-Driven Programming
(WRK302) Event-Driven ProgrammingAmazon Web Services
 
PC = Personal Cloud (or how to use your development machine with Vagrant and ...
PC = Personal Cloud (or how to use your development machine with Vagrant and ...PC = Personal Cloud (or how to use your development machine with Vagrant and ...
PC = Personal Cloud (or how to use your development machine with Vagrant and ...Codemotion
 
Managing computational resources with Apache Mesos
Managing computational resources with Apache MesosManaging computational resources with Apache Mesos
Managing computational resources with Apache MesosJackson dos Santos Olveira
 
Service Oriented UI Architecture in the world of web, desktop, & mobile appli...
Service Oriented UI Architecture in the world of web, desktop, & mobile appli...Service Oriented UI Architecture in the world of web, desktop, & mobile appli...
Service Oriented UI Architecture in the world of web, desktop, & mobile appli...Axway Appcelerator
 
Building Web Apps in Ratpack
Building Web Apps in RatpackBuilding Web Apps in Ratpack
Building Web Apps in RatpackDaniel Woods
 

En vedette (20)

Reactor Design Pattern
Reactor Design PatternReactor Design Pattern
Reactor Design Pattern
 
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindia dotnet development  chapter 14 event-driven programmingSynapseindia dotnet development  chapter 14 event-driven programming
Synapseindia dotnet development chapter 14 event-driven programming
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programming
 
Python geek Event Description
Python geek Event DescriptionPython geek Event Description
Python geek Event Description
 
Django Mini Tutorial
Django Mini TutorialDjango Mini Tutorial
Django Mini Tutorial
 
OASIS
OASISOASIS
OASIS
 
2010.1 mandriva linux_installation_using_dual_cd
2010.1 mandriva linux_installation_using_dual_cd2010.1 mandriva linux_installation_using_dual_cd
2010.1 mandriva linux_installation_using_dual_cd
 
Anyevent
AnyeventAnyevent
Anyevent
 
(WRK302) Event-Driven Programming
(WRK302) Event-Driven Programming(WRK302) Event-Driven Programming
(WRK302) Event-Driven Programming
 
Docker cloud
Docker cloudDocker cloud
Docker cloud
 
An introduction to predictionIO
An introduction to predictionIOAn introduction to predictionIO
An introduction to predictionIO
 
Docker hub
Docker hubDocker hub
Docker hub
 
PC = Personal Cloud (or how to use your development machine with Vagrant and ...
PC = Personal Cloud (or how to use your development machine with Vagrant and ...PC = Personal Cloud (or how to use your development machine with Vagrant and ...
PC = Personal Cloud (or how to use your development machine with Vagrant and ...
 
Introduction to CFEngine
Introduction to CFEngineIntroduction to CFEngine
Introduction to CFEngine
 
Vagrant
VagrantVagrant
Vagrant
 
Apache mahout - introduction
Apache mahout - introductionApache mahout - introduction
Apache mahout - introduction
 
Managing computational resources with Apache Mesos
Managing computational resources with Apache MesosManaging computational resources with Apache Mesos
Managing computational resources with Apache Mesos
 
Service Oriented UI Architecture in the world of web, desktop, & mobile appli...
Service Oriented UI Architecture in the world of web, desktop, & mobile appli...Service Oriented UI Architecture in the world of web, desktop, & mobile appli...
Service Oriented UI Architecture in the world of web, desktop, & mobile appli...
 
Building Web Apps in Ratpack
Building Web Apps in RatpackBuilding Web Apps in Ratpack
Building Web Apps in Ratpack
 
Virtual box
Virtual boxVirtual box
Virtual box
 

Similaire à 2010-02-09 Reactor Pattern & Event Driven Programming

vert.x - asynchronous event-driven web applications on the JVM
vert.x - asynchronous event-driven web applications on the JVMvert.x - asynchronous event-driven web applications on the JVM
vert.x - asynchronous event-driven web applications on the JVMjbandi
 
Evented Ruby VS Node.js
Evented Ruby VS Node.jsEvented Ruby VS Node.js
Evented Ruby VS Node.jsNitin Gupta
 
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...Twilio Inc
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011Lance Ball
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examplesPeter Lawrey
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsKonrad Malawski
 
Spark on Yarn
Spark on YarnSpark on Yarn
Spark on YarnQubole
 
Event Sourcing - what could possibly go wrong?
Event Sourcing - what could possibly go wrong?Event Sourcing - what could possibly go wrong?
Event Sourcing - what could possibly go wrong?Andrzej Ludwikowski
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorStéphane Maldini
 
Building Distributed Systems in Scala
Building Distributed Systems in ScalaBuilding Distributed Systems in Scala
Building Distributed Systems in ScalaAlex Payne
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqRuben Tan
 
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...Codemotion
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011Fabio Akita
 
09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do railsDNAD
 
Deploying Apache Flume to enable low-latency analytics
Deploying Apache Flume to enable low-latency analyticsDeploying Apache Flume to enable low-latency analytics
Deploying Apache Flume to enable low-latency analyticsDataWorks Summit
 
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...Scala Italy
 
Scala in increasingly demanding environments - DATABIZ
Scala in increasingly demanding environments - DATABIZScala in increasingly demanding environments - DATABIZ
Scala in increasingly demanding environments - DATABIZDATABIZit
 

Similaire à 2010-02-09 Reactor Pattern & Event Driven Programming (20)

vert.x - asynchronous event-driven web applications on the JVM
vert.x - asynchronous event-driven web applications on the JVMvert.x - asynchronous event-driven web applications on the JVM
vert.x - asynchronous event-driven web applications on the JVM
 
Evented Ruby VS Node.js
Evented Ruby VS Node.jsEvented Ruby VS Node.js
Evented Ruby VS Node.js
 
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
 
Spark on Yarn
Spark on YarnSpark on Yarn
Spark on Yarn
 
Building Web APIs that Scale
Building Web APIs that ScaleBuilding Web APIs that Scale
Building Web APIs that Scale
 
Event Sourcing - what could possibly go wrong?
Event Sourcing - what could possibly go wrong?Event Sourcing - what could possibly go wrong?
Event Sourcing - what could possibly go wrong?
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and Reactor
 
Rack
RackRack
Rack
 
Building Distributed Systems in Scala
Building Distributed Systems in ScalaBuilding Distributed Systems in Scala
Building Distributed Systems in Scala
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromq
 
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011
 
09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails
 
Apache con 2011 gd
Apache con 2011 gdApache con 2011 gd
Apache con 2011 gd
 
Deploying Apache Flume to enable low-latency analytics
Deploying Apache Flume to enable low-latency analyticsDeploying Apache Flume to enable low-latency analytics
Deploying Apache Flume to enable low-latency analytics
 
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
 
Scala in increasingly demanding environments - DATABIZ
Scala in increasingly demanding environments - DATABIZScala in increasingly demanding environments - DATABIZ
Scala in increasingly demanding environments - DATABIZ
 

Plus de Lin Jen-Shin

Server Development Workflow For PicCollage
Server Development Workflow For PicCollageServer Development Workflow For PicCollage
Server Development Workflow For PicCollageLin Jen-Shin
 
The Architecture of PicCollage Server
The Architecture of PicCollage ServerThe Architecture of PicCollage Server
The Architecture of PicCollage ServerLin Jen-Shin
 
Concurrent Ruby Application Servers
Concurrent Ruby Application ServersConcurrent Ruby Application Servers
Concurrent Ruby Application ServersLin Jen-Shin
 
2012 05-08-lambda-draft
2012 05-08-lambda-draft2012 05-08-lambda-draft
2012 05-08-lambda-draftLin Jen-Shin
 
2010 04-24-cerealize
2010 04-24-cerealize2010 04-24-cerealize
2010 04-24-cerealizeLin Jen-Shin
 
2008-12-21 Rubinius
2008-12-21 Rubinius2008-12-21 Rubinius
2008-12-21 RubiniusLin Jen-Shin
 
2008-01-25 Tangible Value
2008-01-25 Tangible Value2008-01-25 Tangible Value
2008-01-25 Tangible ValueLin Jen-Shin
 
2007-06-24 The Lost Piece
2007-06-24 The Lost Piece2007-06-24 The Lost Piece
2007-06-24 The Lost PieceLin Jen-Shin
 

Plus de Lin Jen-Shin (8)

Server Development Workflow For PicCollage
Server Development Workflow For PicCollageServer Development Workflow For PicCollage
Server Development Workflow For PicCollage
 
The Architecture of PicCollage Server
The Architecture of PicCollage ServerThe Architecture of PicCollage Server
The Architecture of PicCollage Server
 
Concurrent Ruby Application Servers
Concurrent Ruby Application ServersConcurrent Ruby Application Servers
Concurrent Ruby Application Servers
 
2012 05-08-lambda-draft
2012 05-08-lambda-draft2012 05-08-lambda-draft
2012 05-08-lambda-draft
 
2010 04-24-cerealize
2010 04-24-cerealize2010 04-24-cerealize
2010 04-24-cerealize
 
2008-12-21 Rubinius
2008-12-21 Rubinius2008-12-21 Rubinius
2008-12-21 Rubinius
 
2008-01-25 Tangible Value
2008-01-25 Tangible Value2008-01-25 Tangible Value
2008-01-25 Tangible Value
 
2007-06-24 The Lost Piece
2007-06-24 The Lost Piece2007-06-24 The Lost Piece
2007-06-24 The Lost Piece
 

Dernier

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Dernier (20)

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
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...
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

2010-02-09 Reactor Pattern & Event Driven Programming

  • 1. Reactor Pattern & Event-Driven Programming A scalable concurrent approach, using EventMachine with Thin as an example Lin Jen-Shin, http://godfat.org/
  • 2. Reactor Pattern & Event-Driven Programming http://godfat.org/slide/2010-02-29-reactor-pattern-and.pdf Lin Jen-Shin, http://godfat.org/
  • 4. Table of Contents • concurrency, why and how in network
  • 5. Table of Contents • concurrency, why and how in network • Event-Driven Programming explained in Flash with Ruby syntax
  • 6. Table of Contents • concurrency, why and how in network • Event-Driven Programming explained in Flash with Ruby syntax • Reactor Pattern in EventMachine with Thin
  • 7. Table of Contents • concurrency, why and how in network • Event-Driven Programming explained in Flash with Ruby syntax • Reactor Pattern in EventMachine with Thin • how Thin works
  • 8. Table of Contents • concurrency, why and how in network • Event-Driven Programming explained in Flash with Ruby syntax • Reactor Pattern in EventMachine with Thin • how Thin works • how EventMachine works
  • 9. Table of Contents • concurrency, why and how in network • Event-Driven Programming explained in Flash with Ruby syntax • Reactor Pattern in EventMachine with Thin • how Thin works • how EventMachine works
  • 11. concurrency, why and how in network • [network I/O] is slow, we shouldn't wait for [network I/O] while make [CPU] idle.
  • 12. concurrency, why and how in network • [network I/O] is slow, we shouldn't wait for [network I/O] while make [CPU] idle. • you can replace [network I/O] and [CPU] with all other resources like [disc I/O], [memory I/O], etc.
  • 13. concurrency, why and how in network • [network I/O] is slow, we shouldn't wait for [network I/O] while make [CPU] idle. • you can replace [network I/O] and [CPU] with all other resources like [disc I/O], [memory I/O], etc. • each kernel process/thread for each client using a blocking I/O is easy to write but not scalable at all
  • 14. Table of Contents • concurrency, why and how in network • Event-Driven Programming explained in Flash with Ruby syntax • Reactor Pattern in EventMachine with Thin • how Thin works • how EventMachine works
  • 15. Event-Driven Programming to the rescue
  • 16. Event-Driven Programming • only one process/thread
  • 17. Event-Driven Programming • only one process/thread • inversion of control
  • 18. Event-Driven Programming • only one process/thread • inversion of control • consists of an event loop and various event handlers
  • 19. Event-Driven Programming • inversion of control
  • 20. Event-Driven Programming loop{ # you control the flow do_something } • inversion of control
  • 21. Event-Driven Programming register method(:do_something) loop{ loop{ # you control the flow # event loop control the flow, do_something # later it calls your callback } event = pop_event_queue • inversion of control dispatch event if event }
  • 22. Event-Driven Programming register method(:do_something) loop{ # event loop control the flow, # later it calls your callback event = pop_event_queue dispatch event if event } • consists of an event loop and various event handlers
  • 23. Event-Driven Programming register method(:do_something) loop{ # event loop control the flow, # later it calls your callback event = pop_event_queue dispatch event if event } • consists of an event loop and various event handlers
  • 24. Event-Driven Programming register method(:do_something) loop{ # event loop control the flow, # later it calls your callback event = pop_event_queue dispatch event if event } • consists of an event loop and various event handlers
  • 25. Event-Driven Programming in Flash with Ruby syntax
  • 26. Event-Driven Programming in Flash with Ruby syntax • game loop, an example of event loop
  • 27. Event-Driven Programming in Flash with Ruby syntax • game loop, an example of event loop • Flash ActionScript, onEnterFrame
  • 28. Event-Driven Programming in Flash with Ruby syntax • game loop, an example of event loop • Flash ActionScript, onEnterFrame • frame by frame
  • 29. Event-Driven Programming in Flash with Ruby syntax # in each sprite thread 30.times{ application.draw sprite sprite.x += 1 }
  • 30. sprite.onEnterFrame = lambda{ sprite.x += 1 } # in each sprite thread 30.times{ application.draw sprite sprite.x += 1 }
  • 31. sprite.onEnterFrame = lambda{ sprite.x += 1 } application.register sprite 30.times{ # event loop, also called game loop events = application.pop_event_queue events.each{ |event| application.dispatch event } # model/view separation application.draw application.sprites } # in each sprite thread 30.times{ application.draw sprite sprite.x += 1 }
  • 32. Table of Contents • concurrency, why and how in network • Event-Driven Programming explained in Flash with Ruby syntax • Reactor Pattern in EventMachine with Thin • how Thin works • how EventMachine works
  • 34. Reactor Pattern loop{ data = read handle data }
  • 35. Reactor Pattern register method(:handle) loop{ loop{ data = read data = partial_read handle data event = process data } dispatch event if event }
  • 36. Event-Driven Programming register method(:do_something) loop{ loop{ # you control the flow # event loop control the flow, do_something # later it calls your callback } event = pop_event_queue dispatch event if event }
  • 37. Reactor Pattern register method(:handle) loop{ loop{ data = read data = partial_read handle data event = process data } dispatch event if event }
  • 38. Reactor Pattern by wikipedia
  • 39. Reactor Pattern • resources # e.g. network I/O by wikipedia
  • 40. Reactor Pattern • resources # e.g. network I/O • synchronous event demultiplexer # i.e. the blocking event loop by wikipedia
  • 41. Reactor Pattern • resources # e.g. network I/O • synchronous event demultiplexer # i.e. the blocking event loop • dispatcher # i.e. handler manager and event dispatcher by wikipedia
  • 42. Reactor Pattern • resources # e.g. network I/O • synchronous event demultiplexer # i.e. the blocking event loop • dispatcher # i.e. handler manager and event dispatcher • request handler # e.g. thin handler by wikipedia
  • 44. Reactor Pattern EventMachine Request (demultiplexer (resource) + dispatcher)
  • 45. Reactor Pattern EventMachine Request Thin (or AMQP) (demultiplexer (resource) (request handler) + dispatcher)
  • 46. Reactor Pattern EventMachine Request Thin (or AMQP) (demultiplexer (resource) (request handler) + dispatcher) Rack Thin handler
  • 47. Reactor Pattern EventMachine Request Thin (or AMQP) (demultiplexer (resource) (request handler) + dispatcher) Rack Rails Rack Thin rack env adapter handler
  • 48. Reactor Pattern EventMachine Request Thin (or AMQP) (demultiplexer (resource) (request handler) + dispatcher) Rack Rails Rack Thin Rails rack env adapter handler
  • 49. your rails application Reactor Pattern EventMachine Request Thin (or AMQP) (demultiplexer (resource) (request handler) + dispatcher) Rack Rails Rack Thin Rails rack env adapter handler
  • 50. Reactor Pattern EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern
  • 52. Reactor Pattern • EventMachine (Ruby) • Twisted (Python)
  • 53. Reactor Pattern • EventMachine (Ruby) • Twisted (Python) • nodejs (JavaScript in V8)
  • 54. Reactor Pattern • EventMachine (Ruby) • Twisted (Python) • nodejs (JavaScript in V8) • libevent and libev (C)
  • 56. Reactor Pattern • select (POSIX) • poll (POSIX)
  • 57. Reactor Pattern • select (POSIX) • poll (POSIX) • epoll (Linux)
  • 58. Reactor Pattern • select (POSIX) • poll (POSIX) • epoll (Linux) • kqueue (BSD, Mac OS X (Darwin))
  • 59. Table of Contents • concurrency, why and how in network • Event-Driven Programming explained in Flash with Ruby syntax • Reactor Pattern in EventMachine with Thin • how Thin works • how EventMachine works
  • 60. how Thin works • Thin::Server
  • 61. how Thin works • Thin::Server • Thin::Backends::TcpServer # communicate with EventMachine
  • 62. how Thin works • Thin::Server • Thin::Backends::TcpServer # communicate with EventMachine • Thin::Connection # EventMachine event handler
  • 63. how Thin works • Thin::Server • Thin::Backends::TcpServer # communicate with EventMachine • Thin::Connection # EventMachine event handler • Thin::Request # partial HTTP request parsing # Rack env builder
  • 64. how Thin works Sorry! To be continued......
  • 65. how Thin works Sorry! To be continued...... ?