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

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
Encapsulation_ Review paper, used for researhc scholars
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Approach and Philosophy of On baking technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation theory and applications.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
Big Data Technologies - Introduction.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation_ Review paper, used for researhc scholars
Diabetes mellitus diagnosis method based random forest with bat algorithm
Approach and Philosophy of On baking technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Empathic Computing: Creating Shared Understanding
Spectral efficient network and resource selection model in 5G networks
Mobile App Security Testing_ A Comprehensive Guide.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Spectroscopy.pptx food analysis technology
Encapsulation theory and applications.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
cuic standard and advanced reporting.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
A Presentation on Artificial Intelligence
Big Data Technologies - Introduction.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

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