mongrel2, a short introduction
DESCRIPTION
Short introduction to Mongrel2, it illustrates some basics, refer to the Mongrel2 doc for more in depth information.TRANSCRIPT
![Page 1: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/1.jpg)
Mongrel2an introduction
Paolo Negri - @hungryblankBerlin Ruby User Group 7th Oct 2010
![Page 2: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/2.jpg)
1st somethingabout
Mongrel1
![Page 3: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/3.jpg)
Mongrel1
“Mongrel is a small library that provides a very fast HTTP 1.1 server for Ruby web applications.”
(Mongrel README)
![Page 4: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/4.jpg)
Mongrel1
“Unicorn is copyright 2009 by all contributors.
It is based on Mongrel”
(Unicorn README)
![Page 5: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/5.jpg)
Mongrel1
“Thin is a Ruby web server that glues together 3 of the best Ruby libraries in web history:
• the Mongrel parser...”
(Thin homepage)
![Page 6: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/6.jpg)
Mongrel1
“Back then I wrote a little Ruby web server called Ebb that was meant to be a faster Mongrel.
That code was the starting point for Node”
(Ryan Dahl, node.js author)
![Page 7: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/7.jpg)
Mongrel2 and Mongrel1share
• HTTP parser
• author - @zedshaw
![Page 8: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/8.jpg)
Mongrel2is a web server
• application
• language
• network architecture } agnostic
![Page 9: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/9.jpg)
• Focus on HTTP
• Not for a specific language
• Use it with Ruby, Python, C++, PHP, Haskell, Common Lisp, Perl, .NET, Clojure, Lua ...
Mongrel2Language Agnostic
![Page 10: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/10.jpg)
Mongrel2MVC configuration
SQLite3Database
MongrelProcess
m2sh
M V C
![Page 11: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/11.jpg)
Mongrel2MVC configuration
SQLite3Database
MongrelProcess
m2sh
M V C
Configuration is stored in SQLite3 database
![Page 12: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/12.jpg)
Mongrel2MVC configuration
SQLite3Database
MongrelProcess
m2sh
M V C
m2sh writes/reads configuration
![Page 13: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/13.jpg)
Mongrel2MVC configuration
SQLite3Database
MongrelProcess
m2sh
M V C
Mongrel reads config from SQLite3 and runs accordingly
![Page 14: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/14.jpg)
Mongrel2m2sh - query
$ m2sh servers -db tests/config.sqlite
SERVERS:------ test localhost AC1F8236-5919-4696-9D40-0F38DE9E5861
$ m2sh hosts -db tests/config.sqlite -server test
HOSTS in test:----- 1 localhost
![Page 15: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/15.jpg)
Mongrel2m2sh - launch/manage
$ m2sh start -db tests/config.sqlite \ -host localhost -sudo
$ m2sh reload -db tests/config.sqlite \ -host localhost
![Page 16: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/16.jpg)
Mongrel2Configuration
Load a configuration file with m2sh
$ m2sh load -config \ examples/config/sample.conf
![Page 17: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/17.jpg)
Mongrel2Configuration
main = Server( uuid="f400bf85-4538-4f7a-8908-67e313d515c2", access_log="/logs/access.log", error_log="/logs/error.log", chroot="./", default_host="localhost", name="test", pid_file="/run/mongrel2.pid", port=6767, hosts = [ Host(name="localhost", routes={ '/tests/': Dir(base='tests/', index_file='index.html', default_ctype='text/plain') }) ] )
![Page 18: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/18.jpg)
Mongrel2Configuration
main = Server( uuid="f400bf85-4538-4f7a-8908-67e313d515c2", access_log="/logs/access.log", error_log="/logs/error.log", chroot="./", default_host="localhost", name="test", pid_file="/run/mongrel2.pid", port=6767, hosts = [ Host(name="localhost", routes={ '/tests/': Dir(base='tests/', index_file='index.html', default_ctype='text/plain') }) ] )
Unique server identifier
![Page 19: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/19.jpg)
Mongrel2Configuration
main = Server( uuid="f400bf85-4538-4f7a-8908-67e313d515c2", access_log="/logs/access.log", error_log="/logs/error.log", chroot="./", default_host="localhost", name="test", pid_file="/run/mongrel2.pid", port=6767, hosts = [ Host(name="localhost", routes={ '/tests/': Dir(base='tests/', index_file='index.html', default_ctype='text/plain') }) ] )
logfiles, port, server name, pid...
![Page 20: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/20.jpg)
Mongrel2Configuration
• Server
• Host
• Route
• Dir
• Proxy
• Handler
![Page 21: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/21.jpg)
• Server
• Host
• Route
• Dir
• Proxy
• Handler
Mongrel2Configuration
Is the root element of a configuration
![Page 22: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/22.jpg)
• Server
• Host
• Route
• Dir
• Proxy
• Handler
Mongrel2Configuration
DNS hostname to answer for
A server can contain multiple hosts
![Page 23: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/23.jpg)
• Server
• Host
• Route
• Dir
• Proxy
• Handler
Mongrel2Configuration
URL paths and patterns to match
example ‘/images/’
![Page 24: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/24.jpg)
• Server
• Host
• Route
• Dir
• Proxy
• Handler
Mongrel2Configuration
Serves files out of a directory
(full 304 and ETag support)
![Page 25: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/25.jpg)
• Server
• Host
• Route
• Dir
• Proxy
• Handler
Mongrel2Configuration
Requests matching the route are sent to another HTTP server
![Page 26: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/26.jpg)
• Server
• Host
• Route
• Dir
• Proxy
• Handler
Mongrel2Configuration
“A Handler is the best part of Mongrel2”
![Page 27: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/27.jpg)
Mongrel2Handler
mongrel2
handler
browser
![Page 28: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/28.jpg)
Mongrel2Handler
mongrel2
handler
browser
![Page 29: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/29.jpg)
Mongrel2Handler
mongrel2
handler
browser
![Page 30: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/30.jpg)
Mongrel2Handler
mongrel2
handler
browser
![Page 31: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/31.jpg)
• Handlers receive asynchronous requests from Mongrel2
• Handlers and Mongrel2 communicate via ØMQ sockets
Mongrel2Handler
![Page 32: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/32.jpg)
Mongrel2Handlermongrel2
ØMQ sockets
handlerhandler
handler
![Page 33: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/33.jpg)
Mongrel2Handlermongrel2
handlerhandler
handler
Push/Pull Pub/Sub
Requests Responses
![Page 34: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/34.jpg)
Mongrel2Handlermongrel2
handlerhandler
handler
Push/Pull Pub/Sub
Requests Responses
Round robindistribution
![Page 35: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/35.jpg)
Mongrel2Handlermongrel2
handlerhandler
handler
Push/Pull Pub/Sub
Requests Responses
Target up to128 clients
![Page 36: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/36.jpg)
Mongrel2Handler
handlerhandler
handler
Push/Pull Pub/Sub
Requests Responses
UUID ID PATH SIZE:HEADERS,SIZE:BODY
![Page 37: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/37.jpg)
Mongrel2Handler
handlerhandler
handler
Push/Pull Pub/Sub
Requests Responses
UUID SIZE:ID ID ID, BODY
![Page 38: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/38.jpg)
• One or many handlers
• Increase/decrease # of handlers while the server is running, no reload/restart needed
• UUID are used to route messages
Mongrel2Handler
![Page 39: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/39.jpg)
• Communication with handler completely async
• ØMQ sockets can work over different transports (tcp, domain sockets...)
• Messages to/from handler built on netstrings (D. J. Bernstein) are easy to parse
Mongrel2Handler
![Page 40: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/40.jpg)
• http://github.com/perplexes/m2r
• JRuby or ruby 1.9.2
• Simple handler or Rack enabled
Mongrel2Ruby Handler
![Page 41: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/41.jpg)
Mongrel2Ruby Handler
• Run any Rack app using mongrel2, now!
![Page 42: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/42.jpg)
Mongrel2Questions
?
![Page 43: Mongrel2, a short introduction](https://reader033.vdocuments.us/reader033/viewer/2022060117/55878e6bd8b42a485d8b4638/html5/thumbnails/43.jpg)
Thanks!
Paolo Negri@hungryblank