SlideShare a Scribd company logo
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......


           ?
Ad

More Related Content

What's hot (20)

Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka Streams
Johan Andrén
 
Reactive mistakes - ScalaDays Chicago 2017
Reactive mistakes -  ScalaDays Chicago 2017Reactive mistakes -  ScalaDays Chicago 2017
Reactive mistakes - ScalaDays Chicago 2017
Petr 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 Framework
DataWorks 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 REEF
Sergiy Matusevych
 
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
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Rooster Tech Talk
Rooster Tech TalkRooster Tech Talk
Rooster Tech Talk
Chris Johnson
 
Deploying Microservice on Docker
Deploying Microservice on DockerDeploying Microservice on Docker
Deploying Microservice on Docker
Knoldus Inc.
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJava
Jobaer 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 Way
Roland Kuhn
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
Ivano Malavolta
 
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
Thomas 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-Java
Kasun 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 Cluster
Konstantin 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 streams
Johan 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 nyc
Petr Zapletal
 
Intro to Functional Programming with RxJava
Intro to Functional Programming with RxJavaIntro to Functional Programming with RxJava
Intro to Functional Programming with RxJava
Mike Nakhimovich
 
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka Streams
Johan Andrén
 
Reactive mistakes - ScalaDays Chicago 2017
Reactive mistakes -  ScalaDays Chicago 2017Reactive mistakes -  ScalaDays Chicago 2017
Reactive mistakes - ScalaDays Chicago 2017
Petr 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 Framework
DataWorks 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 REEF
Sergiy Matusevych
 
Deploying Microservice on Docker
Deploying Microservice on DockerDeploying Microservice on Docker
Deploying Microservice on Docker
Knoldus Inc.
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJava
Jobaer 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 Way
Roland 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 2014
Thomas 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-Java
Kasun 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 Cluster
Konstantin 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 streams
Johan 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 nyc
Petr Zapletal
 
Intro to Functional Programming with RxJava
Intro to Functional Programming with RxJavaIntro to Functional Programming with RxJava
Intro to Functional Programming with RxJava
Mike Nakhimovich
 

Viewers also liked (20)

Reactor Design Pattern
Reactor Design PatternReactor Design Pattern
Reactor Design Pattern
liminescence
 
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
Synapseindiappsdevelopment
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programming
Chaffey College
 
Python geek Event Description
Python geek Event DescriptionPython geek Event Description
Python geek Event Description
Parbhat Puri
 
Django Mini Tutorial
Django Mini TutorialDjango Mini Tutorial
Django Mini Tutorial
Fahri Firdausillah
 
OASIS
OASISOASIS
OASIS
Evin Lachance
 
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
St Louis MUG
 
Anyevent
AnyeventAnyevent
Anyevent
Marian Marinov
 
Docker cloud
Docker cloudDocker cloud
Docker cloud
Rafael Salerno de Oliveira
 
An introduction to predictionIO
An introduction to predictionIOAn introduction to predictionIO
An introduction to predictionIO
Jackson dos Santos Olveira
 
Docker hub
Docker hubDocker hub
Docker hub
Rafael Salerno de Oliveira
 
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
 
Introduction to CFEngine
Introduction to CFEngineIntroduction to CFEngine
Introduction to CFEngine
Jackson dos Santos Olveira
 
Vagrant
VagrantVagrant
Vagrant
Rafael Salerno de Oliveira
 
Apache mahout - introduction
Apache mahout - introductionApache mahout - introduction
Apache mahout - introduction
Jackson dos Santos Olveira
 
Managing computational resources with Apache Mesos
Managing computational resources with Apache MesosManaging computational resources with Apache Mesos
Managing computational resources with Apache Mesos
Jackson 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 Ratpack
Daniel Woods
 
Virtual box
Virtual boxVirtual box
Virtual box
Rafael Salerno de Oliveira
 
Dejan Pekter / Nordeus – Reactor design pattern
Dejan Pekter / Nordeus – Reactor design patternDejan Pekter / Nordeus – Reactor design pattern
Dejan Pekter / Nordeus – Reactor design pattern
ConversionMeetup
 
Reactor Design Pattern
Reactor Design PatternReactor Design Pattern
Reactor Design Pattern
liminescence
 
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
Synapseindiappsdevelopment
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programming
Chaffey College
 
Python geek Event Description
Python geek Event DescriptionPython geek Event Description
Python geek Event Description
Parbhat 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_cd
St Louis MUG
 
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 Mesos
Jackson 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 Ratpack
Daniel Woods
 
Dejan Pekter / Nordeus – Reactor design pattern
Dejan Pekter / Nordeus – Reactor design patternDejan Pekter / Nordeus – Reactor design pattern
Dejan Pekter / Nordeus – Reactor design pattern
ConversionMeetup
 
Ad

Similar to 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
jbandi
 
Evented Ruby VS Node.js
Evented Ruby VS Node.jsEvented Ruby VS Node.js
Evented Ruby VS Node.js
Nitin 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 2011
Lance Ball
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
Peter Lawrey
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
Konrad Malawski
 
Spark on Yarn
Spark on YarnSpark on Yarn
Spark on Yarn
Qubole
 
Building Web APIs that Scale
Building Web APIs that ScaleBuilding Web APIs that Scale
Building Web APIs that Scale
Salesforce Developers
 
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 Reactor
Stéphane Maldini
 
Rack
RackRack
Rack
shen liu
 
Building Distributed Systems in Scala
Building Distributed Systems in ScalaBuilding Distributed Systems in Scala
Building Distributed Systems in Scala
Alex 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 zeromq
Ruben 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 2011
Fabio 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 rails
DNAD
 
Apache con 2011 gd
Apache con 2011 gdApache con 2011 gd
Apache con 2011 gd
Leif Hedstrom
 
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
DataWorks 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 - DATABIZ
DATABIZit
 
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
jbandi
 
Evented Ruby VS Node.js
Evented Ruby VS Node.jsEvented Ruby VS Node.js
Evented Ruby VS Node.js
Nitin 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 2011
Lance Ball
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
Peter Lawrey
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
Konrad Malawski
 
Spark on Yarn
Spark on YarnSpark on Yarn
Spark on Yarn
Qubole
 
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 Reactor
Stéphane Maldini
 
Building Distributed Systems in Scala
Building Distributed Systems in ScalaBuilding Distributed Systems in Scala
Building Distributed Systems in Scala
Alex 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 zeromq
Ruben 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 2011
Fabio 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 rails
DNAD
 
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
DataWorks 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 - DATABIZ
DATABIZit
 
Ad

More from Lin Jen-Shin (8)

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

Recently uploaded (20)

Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 

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...... ?