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


           ?

More Related Content

PDF
2010-04-13 Reactor Pattern & Event Driven Programming 2
PPTX
Low latency in java 8 by Peter Lawrey
PDF
Journey into Reactive Streams and Akka Streams
PPTX
REEF: Towards a Big Data Stdlib
PDF
Reactive Streams / Akka Streams - GeeCON Prague 2014
PPTX
Lambdas puzzler - Peter Lawrey
PPTX
Apache Airflow | What Is An Operator
PDF
RxJava@DAUG
2010-04-13 Reactor Pattern & Event Driven Programming 2
Low latency in java 8 by Peter Lawrey
Journey into Reactive Streams and Akka Streams
REEF: Towards a Big Data Stdlib
Reactive Streams / Akka Streams - GeeCON Prague 2014
Lambdas puzzler - Peter Lawrey
Apache Airflow | What Is An Operator
RxJava@DAUG

What's hot (20)

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

Viewers also liked (20)

PPTX
Reactor Design Pattern
PPT
Synapseindia dotnet development chapter 14 event-driven programming
PPT
Ch 3 event driven programming
PDF
Python geek Event Description
PPTX
Django Mini Tutorial
PPT
ODP
2010.1 mandriva linux_installation_using_dual_cd
ODP
Anyevent
PDF
An introduction to predictionIO
PDF
PC = Personal Cloud (or how to use your development machine with Vagrant and ...
PDF
Introduction to CFEngine
PDF
Apache mahout - introduction
PDF
Managing computational resources with Apache Mesos
PPT
Service Oriented UI Architecture in the world of web, desktop, & mobile appli...
PPTX
Building Web Apps in Ratpack
PDF
Dejan Pekter / Nordeus – Reactor design pattern
Reactor Design Pattern
Synapseindia dotnet development chapter 14 event-driven programming
Ch 3 event driven programming
Python geek Event Description
Django Mini Tutorial
2010.1 mandriva linux_installation_using_dual_cd
Anyevent
An introduction to predictionIO
PC = Personal Cloud (or how to use your development machine with Vagrant and ...
Introduction to CFEngine
Apache mahout - introduction
Managing computational resources with Apache Mesos
Service Oriented UI Architecture in the world of web, desktop, & mobile appli...
Building Web Apps in Ratpack
Dejan Pekter / Nordeus – Reactor design pattern
Ad

Similar to 2010-02-09 Reactor Pattern & Event Driven Programming (20)

PPTX
Event and signal driven programming
PPTX
Event and Signal Driven Programming Zendcon 2012
PPTX
Yellow.4 marjan nikolovski hunting rabbits and event-driven programming
PDF
Tutorial on Constructing a Web-Server with Patterns at ADC 2004
PDF
Actors or Not: Async Event Architectures
PPT
Ruby eventmachine pres at rubybdx
PDF
Scaling Ruby with Evented I/O - Ruby underground
PPTX
Event-Based API Patterns and Practices
PPTX
Evented Ruby VS Node.js
KEY
EventMachine
PDF
Building Event Driven Systems
PPTX
Software Architectures, Week 4 - Message-based Architectures, Message Bus
PPTX
Event and signal driven programming techniques
PPT
Nodejs Event Driven Concurrency for Web Applications
PPT
Reactive programming with examples
KEY
Servers with Event Machine - David Troy - RailsConf 2011
PDF
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
KEY
EventMachine for RubyFuZa 2012
PDF
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
Event and signal driven programming
Event and Signal Driven Programming Zendcon 2012
Yellow.4 marjan nikolovski hunting rabbits and event-driven programming
Tutorial on Constructing a Web-Server with Patterns at ADC 2004
Actors or Not: Async Event Architectures
Ruby eventmachine pres at rubybdx
Scaling Ruby with Evented I/O - Ruby underground
Event-Based API Patterns and Practices
Evented Ruby VS Node.js
EventMachine
Building Event Driven Systems
Software Architectures, Week 4 - Message-based Architectures, Message Bus
Event and signal driven programming techniques
Nodejs Event Driven Concurrency for Web Applications
Reactive programming with examples
Servers with Event Machine - David Troy - RailsConf 2011
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
EventMachine for RubyFuZa 2012
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation

More from Lin Jen-Shin (8)

PDF
Server Development Workflow For PicCollage
PDF
The Architecture of PicCollage Server
PDF
Concurrent Ruby Application Servers
PDF
2012 05-08-lambda-draft
PDF
2010 04-24-cerealize
PDF
2008-12-21 Rubinius
PDF
2008-01-25 Tangible Value
PDF
2007-06-24 The Lost Piece
Server Development Workflow For PicCollage
The Architecture of PicCollage Server
Concurrent Ruby Application Servers
2012 05-08-lambda-draft
2010 04-24-cerealize
2008-12-21 Rubinius
2008-01-25 Tangible Value
2007-06-24 The Lost Piece

Recently uploaded (20)

PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Advanced IT Governance
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
KodekX | Application Modernization Development
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Modernizing your data center with Dell and AMD
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Dropbox Q2 2025 Financial Results & Investor Presentation
The AUB Centre for AI in Media Proposal.docx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Understanding_Digital_Forensics_Presentation.pptx
Advanced IT Governance
madgavkar20181017ppt McKinsey Presentation.pdf
Transforming Manufacturing operations through Intelligent Integrations
Network Security Unit 5.pdf for BCA BBA.
KodekX | Application Modernization Development
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Modernizing your data center with Dell and AMD
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Mobile App Security Testing_ A Comprehensive Guide.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Sensors and Actuators in IoT Systems using pdf
Review of recent advances in non-invasive hemoglobin estimation
Chapter 3 Spatial Domain Image Processing.pdf
MYSQL Presentation for SQL database connectivity
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

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