Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client...
Transcript of Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client...
![Page 1: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/1.jpg)
Reactor Pattern&
Event-Driven ProgrammingA scalable concurrent approach,using EventMachine with Thin as an example
Lin Jen-Shin, http://godfat.org/
![Page 2: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/2.jpg)
Reactor Pattern&
Event-Driven Programminghttp://godfat.org/slide/2010-02-29-reactor-pattern-and.pdf
Lin Jen-Shin, http://godfat.org/
![Page 3: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/3.jpg)
Table of Contents
![Page 4: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/4.jpg)
Table of Contents
•concurrency, why and how in network
![Page 5: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/5.jpg)
Table of Contents
•concurrency, why and how in network
•Event-Driven Programming explained in Flash with Ruby syntax
![Page 6: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/6.jpg)
Table of Contents
•concurrency, why and how in network
•Event-Driven Programming explained in Flash with Ruby syntax
•Reactor Pattern in EventMachine with Thin
![Page 7: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/7.jpg)
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
![Page 8: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/8.jpg)
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
![Page 9: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/9.jpg)
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
![Page 10: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/10.jpg)
concurrency, whyand how in network
![Page 11: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/11.jpg)
concurrency, whyand how in network
• [network I/O] is slow, we shouldn't wait for [network I/O] while make [CPU] idle.
![Page 12: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/12.jpg)
concurrency, whyand 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.
![Page 13: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/13.jpg)
concurrency, whyand 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
![Page 14: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/14.jpg)
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
![Page 15: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/15.jpg)
Event-Driven Programmingto the rescue
![Page 16: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/16.jpg)
Event-Driven Programming
•only one process/thread
![Page 17: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/17.jpg)
Event-Driven Programming
•only one process/thread
• inversion of control
![Page 18: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/18.jpg)
Event-Driven Programming
•only one process/thread
• inversion of control
•consists of an event loop and variousevent handlers
![Page 19: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/19.jpg)
Event-Driven Programming
• inversion of control
![Page 20: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/20.jpg)
Event-Driven Programmingloop{ # you control the flow do_something}
• inversion of control
![Page 21: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/21.jpg)
Event-Driven Programmingloop{ # you control the flow do_something}
• inversion of control
register method(:do_something)loop{ # event loop control the flow, # later it calls your callback event = pop_event_queue dispatch event if event}
![Page 22: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/22.jpg)
•consists of an event loop and variousevent handlers
Event-Driven Programmingregister method(:do_something)loop{ # event loop control the flow, # later it calls your callback event = pop_event_queue dispatch event if event}
![Page 23: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/23.jpg)
•consists of an event loop and variousevent handlers
Event-Driven Programmingregister method(:do_something)loop{ # event loop control the flow, # later it calls your callback event = pop_event_queue dispatch event if event}
![Page 24: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/24.jpg)
•consists of an event loop and variousevent handlers
Event-Driven Programmingregister method(:do_something)loop{ # event loop control the flow, # later it calls your callback event = pop_event_queue dispatch event if event}
![Page 25: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/25.jpg)
Event-Driven Programmingin Flash with Ruby syntax
![Page 26: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/26.jpg)
Event-Driven Programmingin Flash with Ruby syntax•game loop, an example of event loop
![Page 27: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/27.jpg)
Event-Driven Programmingin Flash with Ruby syntax•game loop, an example of event loop
•Flash ActionScript, onEnterFrame
![Page 28: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/28.jpg)
Event-Driven Programmingin Flash with Ruby syntax•game loop, an example of event loop
•Flash ActionScript, onEnterFrame
• frame by frame
![Page 29: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/29.jpg)
Event-Driven Programmingin Flash with Ruby syntax
# in each sprite thread30.times{ application.draw sprite sprite.x += 1}
![Page 30: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/30.jpg)
# in each sprite thread30.times{ application.draw sprite sprite.x += 1}
sprite.onEnterFrame = lambda{ sprite.x += 1}
![Page 31: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/31.jpg)
application.register sprite30.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 thread30.times{ application.draw sprite sprite.x += 1}
sprite.onEnterFrame = lambda{ sprite.x += 1}
![Page 32: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/32.jpg)
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
![Page 33: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/33.jpg)
Reactor Pattern
![Page 34: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/34.jpg)
Reactor Patternloop{ data = read handle data}
![Page 35: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/35.jpg)
Reactor Patternloop{ data = read handle data}
register method(:handle)loop{ data = partial_read event = process data dispatch event if event}
![Page 36: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/36.jpg)
Event-Driven Programmingloop{ # you control the flow do_something}
register method(:do_something)loop{ # event loop control the flow, # later it calls your callback event = pop_event_queue dispatch event if event}
![Page 37: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/37.jpg)
Reactor Patternloop{ data = read handle data}
register method(:handle)loop{ data = partial_read event = process data dispatch event if event}
![Page 38: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/38.jpg)
Reactor Pattern
by wikipedia
![Page 39: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/39.jpg)
• resources # e.g. network I/O
Reactor Pattern
by wikipedia
![Page 40: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/40.jpg)
• resources # e.g. network I/O
• synchronous event demultiplexer# i.e. the blocking event loop
Reactor Pattern
by wikipedia
![Page 41: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/41.jpg)
• resources # e.g. network I/O
• synchronous event demultiplexer# i.e. the blocking event loop
•dispatcher# i.e. handler manager and event dispatcher
Reactor Pattern
by wikipedia
![Page 42: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/42.jpg)
• 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
Reactor Pattern
by wikipedia
![Page 43: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/43.jpg)
Reactor PatternRequest
(resource)
![Page 44: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/44.jpg)
Reactor PatternRequest
(resource)EventMachine (demultiplexer + dispatcher)
![Page 45: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/45.jpg)
Reactor PatternRequest
(resource)Thin (or AMQP)(request handler)
EventMachine (demultiplexer + dispatcher)
![Page 46: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/46.jpg)
Reactor PatternRequest
(resource)Thin (or AMQP)(request handler)
Rack Thin handler
EventMachine (demultiplexer + dispatcher)
![Page 47: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/47.jpg)
Reactor PatternRequest
(resource)Thin (or AMQP)(request handler)
Rack Thin handler
EventMachine (demultiplexer + dispatcher)
Rack Rails adapter rack env
![Page 48: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/48.jpg)
Reactor PatternRequest
(resource)Thin (or AMQP)(request handler)
Rack Thin handler
EventMachine (demultiplexer + dispatcher)
Rails Rack Rails adapter rack env
![Page 49: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/49.jpg)
Reactor PatternRequest
(resource)Thin (or AMQP)(request handler)
Rack Thin handler
EventMachine (demultiplexer + dispatcher)
Rails
your rails application
Rack Rails adapter rack env
![Page 50: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/50.jpg)
Reactor PatternEventMachine is a generic network I/O server/clientlibrary due to I/O and request handler separation in
Reactor Pattern
![Page 51: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/51.jpg)
•EventMachine (Ruby)
Reactor Pattern
![Page 52: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/52.jpg)
•EventMachine (Ruby)
•Twisted (Python)
Reactor Pattern
![Page 53: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/53.jpg)
•EventMachine (Ruby)
•Twisted (Python)
•nodejs (JavaScript in V8)
Reactor Pattern
![Page 54: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/54.jpg)
•EventMachine (Ruby)
•Twisted (Python)
•nodejs (JavaScript in V8)
• libevent and libev (C)
Reactor Pattern
![Page 55: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/55.jpg)
• select (POSIX)
Reactor Pattern
![Page 56: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/56.jpg)
• select (POSIX)
•poll (POSIX)
Reactor Pattern
![Page 57: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/57.jpg)
• select (POSIX)
•poll (POSIX)
•epoll (Linux)
Reactor Pattern
![Page 58: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/58.jpg)
• select (POSIX)
•poll (POSIX)
•epoll (Linux)
•kqueue (BSD, Mac OS X (Darwin))
Reactor Pattern
![Page 59: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/59.jpg)
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
![Page 60: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/60.jpg)
how Thin works•Thin::Server
![Page 61: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/61.jpg)
how Thin works•Thin::Server
•Thin::Backends::TcpServer# communicate with EventMachine
![Page 62: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/62.jpg)
how Thin works•Thin::Server
•Thin::Backends::TcpServer# communicate with EventMachine
•Thin::Connection# EventMachine event handler
![Page 63: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/63.jpg)
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
![Page 64: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/64.jpg)
how Thin works
Sorry! To be continued......
![Page 65: Reactor Pattern Event-Driven Programming · EventMachine is a generic network I/O server/client library due to I/O and request handler separation in Reactor Pattern](https://reader035.fdocuments.us/reader035/viewer/2022081522/5f655f744f3b5d33bc3d213d/html5/thumbnails/65.jpg)
how Thin works
Sorry! To be continued......
?