SlideShare a Scribd company logo
1 of 29
Download to read offline
Who am I?

• Ezra Zygmuntowicz
• Rubyist for 4 years
• Engine Yard Founder and Architect
• Blog: http://brainspl.at
Mongrel
Learning how to walk the dog
What is Mongrel?
Mongrel is an HTTP Server
 Library written by Zed Shaw

• Fast HTTP Parser written in Ragel + C
• Fast URI Classifier written in C
• Stackable Request Handlers
• Flexible Configuration
• Secure and RFC Compliant HTTP Parser
Ragel State Machine
Defined HTTP Parser
Why?
FastCGI is Poop
• HTTP is a well known and well tooled
  protocol
• Mongrel is way easier to setup and use
• Transparent wire protocol
But Rails isn’t Thread Safe!

• Giant Mutex Lock around Rails Dispatch
• Only one request served at a time by one
  mongrel
• Use mongrel_cluster to scale with multiple
  processes
Full Stack Request/Response Life-Cycle


•   Request comes into gateway
    server


•   Rewrite rules are evaluated and
    request gets served directly if it’s
    a static asset


•   Dynamic requests are proxied to
    one Mongrel in the Mongrel
    Cluster


•   Mongrel dispatches request
    through Rails and returns
    response to client
Rails Internal Request/Response Life-Cycle
•   Mongrel Locks Mutex

•   Rails Dispatcher is invoked with
    request/response objects

•   Routing is invoked and returns
    the proper Controller object or
    404 if no route found

•   Filter chain is invoked

•   Controller’s Action is called,
    manipulates Models

•   View is rendered and any after
    filters are called

•   Mongrel Unlocks Mutex

•   Final response or error page
    returned to client
Mongrel != Rails
• Mongrel *is* Thread Safe
• Mongrel is capable of much more then just
  running Rails
• Rails is beautiful for the 80% part of the
  80/20 rule
• What to do when your app needs the
  other 20%?
Handle It!

• Building Mongrel Handlers is easier then
  you think
• Mongrel is *very* high performance
• Ruby not so slow after all? Maybe it’s just
  Rails that is slow?
Rails vs Mongrel Handler in a Hello
           World Battle

  Rails:




 Mongrel
 Handler:
Naive Benchmarks
Mongrel
Handler:
7Mb RAM




Rails:
35Mb RAM
Why the Huge Difference?
• Of course Rails provides much more out of the box
• Our HelloHandler runs in a multi-threaded way,
  hence the 100 concurrent users in our benchmark
• Rails has to run requests in serial, hence the 1
  concurrent user.
What can Custom Mongrel
  Handlers do for me?
  • More concurrent users on fewer processes
  • Higher throughput with less resources
  • Less convenience for developers means you
    don’t need it until you *need* it
Standalone or
 Integrated with Rails?
• Mongrel Handlers can ‘Stack’
• You can use :in_front => true to put a
  custom Mongrel Handler in process with
  your Rails app and have it intercept and
  serve certain urls
• Access to your Rails models and other
  loaded classes
Integrating HelloHandler
    into our Rails app
Another Useless
  Benchmark
Real World Example
     SecureFile
The next logical step?

• Gee, Mongrel without Rails is hella fast
• I’ll start writing more and more of my apps
  as Handlers
• I’ll start implementing the parts of Rails I
  need in my handlers...
Merb
 Started as a hack, Merb == Mongrel + Erb

• No CGI.rb !!
• Clean room implementation of ActionPack
• Thread Safe with configurable Mutex Locks
• Rails compatible REST routing
• No Magic( well less anyway ;)
• It’s what you will end up with if you keep
  writing custom Mongrel Handlers
Dispatching Rails vs Merb
      Rails                     Merb(with ActiveRecord)
 Request comes in                      Request comes in

 **Mutex gets locked**                 Parse CGI + Mime

 Parse CGI + Mime(expensive)           Route recognition

 Route recognition(expensive)          **Mutex gets locked**

 Before Filter Chain                   Before Filter Chain

 Call Controller Action                Call Controller Action

 Render Template                       Render Template

 **Mutex Unlocked**                    **Mutex Unlocked**

 Results returned to client            Results returned to client
Merb Hello World
Routing
• Rails routing is 1800 lines of *very
  complex* non thread-safe code
• Merb’s router is 200 lines of complex but
  *thread safe* code and much more efficient
  for route matching
Why should you care?
• Rails has gotten 10-20% slower with each recent
  release
• Resident RAM usage per process gets larger as well
• Premature Optimization is blah, blah
• At this point it is not premature anymore ;)
• There is a point where optimization Matters
Merb’s Mongrel
   Handler
Questions?

More Related Content

What's hot

A first look into the Project Loom in Java
A first look into the Project Loom in JavaA first look into the Project Loom in Java
A first look into the Project Loom in JavaLukas Steinbrecher
 
ClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScriptClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScriptEric Normand
 
Green Custard Friday Talk 5: React-Native Performance
Green Custard Friday Talk 5: React-Native PerformanceGreen Custard Friday Talk 5: React-Native Performance
Green Custard Friday Talk 5: React-Native PerformanceGreen Custard
 
Varnish to the rescue
Varnish to the rescueVarnish to the rescue
Varnish to the rescueleafnode
 
Ruby performance - The low hanging fruit
Ruby performance - The low hanging fruitRuby performance - The low hanging fruit
Ruby performance - The low hanging fruitBruce Werdschinski
 
Rails 5 – Amsterdam.rb – Uberous
Rails 5 – Amsterdam.rb – UberousRails 5 – Amsterdam.rb – Uberous
Rails 5 – Amsterdam.rb – UberousJeroen Visser
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmSkills Matter
 
Cassandra Development Nirvana
Cassandra Development Nirvana Cassandra Development Nirvana
Cassandra Development Nirvana DataStax
 
Riak at Posterous
Riak at PosterousRiak at Posterous
Riak at Posterouscapotej
 
The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)danwrong
 
Capybara + RSpec - ruby dsl-based web ui qa automation
Capybara + RSpec - ruby dsl-based web ui qa automationCapybara + RSpec - ruby dsl-based web ui qa automation
Capybara + RSpec - ruby dsl-based web ui qa automationCOMAQA.BY
 
Python to go
Python to goPython to go
Python to goWeng Wei
 
Coffee script final
Coffee script finalCoffee script final
Coffee script finalpriyankazope
 
Through Meteor to the stars - Developing full-stack SPA's with meteor.js
Through Meteor to the stars - Developing full-stack SPA's with meteor.jsThrough Meteor to the stars - Developing full-stack SPA's with meteor.js
Through Meteor to the stars - Developing full-stack SPA's with meteor.jsWekoslav Stefanovski
 
Coding for the cloud - development of modern web applications
Coding for the cloud - development of modern web applicationsCoding for the cloud - development of modern web applications
Coding for the cloud - development of modern web applicationsWekoslav Stefanovski
 

What's hot (19)

A first look into the Project Loom in Java
A first look into the Project Loom in JavaA first look into the Project Loom in Java
A first look into the Project Loom in Java
 
ClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScriptClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScript
 
Green Custard Friday Talk 5: React-Native Performance
Green Custard Friday Talk 5: React-Native PerformanceGreen Custard Friday Talk 5: React-Native Performance
Green Custard Friday Talk 5: React-Native Performance
 
Varnish to the rescue
Varnish to the rescueVarnish to the rescue
Varnish to the rescue
 
Ruby performance - The low hanging fruit
Ruby performance - The low hanging fruitRuby performance - The low hanging fruit
Ruby performance - The low hanging fruit
 
L R U G - JRuby
L R U G - JRubyL R U G - JRuby
L R U G - JRuby
 
Rails 5 – Amsterdam.rb – Uberous
Rails 5 – Amsterdam.rb – UberousRails 5 – Amsterdam.rb – Uberous
Rails 5 – Amsterdam.rb – Uberous
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
 
Netty
NettyNetty
Netty
 
Cassandra Development Nirvana
Cassandra Development Nirvana Cassandra Development Nirvana
Cassandra Development Nirvana
 
Riak at Posterous
Riak at PosterousRiak at Posterous
Riak at Posterous
 
Javascript
JavascriptJavascript
Javascript
 
The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)
 
Ramaze
RamazeRamaze
Ramaze
 
Capybara + RSpec - ruby dsl-based web ui qa automation
Capybara + RSpec - ruby dsl-based web ui qa automationCapybara + RSpec - ruby dsl-based web ui qa automation
Capybara + RSpec - ruby dsl-based web ui qa automation
 
Python to go
Python to goPython to go
Python to go
 
Coffee script final
Coffee script finalCoffee script final
Coffee script final
 
Through Meteor to the stars - Developing full-stack SPA's with meteor.js
Through Meteor to the stars - Developing full-stack SPA's with meteor.jsThrough Meteor to the stars - Developing full-stack SPA's with meteor.js
Through Meteor to the stars - Developing full-stack SPA's with meteor.js
 
Coding for the cloud - development of modern web applications
Coding for the cloud - development of modern web applicationsCoding for the cloud - development of modern web applications
Coding for the cloud - development of modern web applications
 

Viewers also liked

Diapositivas De Lucho
Diapositivas De LuchoDiapositivas De Lucho
Diapositivas De Luchopablo22
 
Daniilids Success Story 1994-97
Daniilids Success Story 1994-97Daniilids Success Story 1994-97
Daniilids Success Story 1994-97LRacademy
 
álbum deFotografias
álbum deFotografiasálbum deFotografias
álbum deFotografiasferlegau
 
西部的歐洲
西部的歐洲 西部的歐洲
西部的歐洲 yolandaho
 
Ecosystem Introductory Presentation
Ecosystem Introductory PresentationEcosystem Introductory Presentation
Ecosystem Introductory Presentationchestertoncc
 
Info Tech Questions
Info Tech QuestionsInfo Tech Questions
Info Tech Questionsgmayman
 
Humanities 191 Chapter Nine Slide Show
Humanities 191 Chapter Nine Slide ShowHumanities 191 Chapter Nine Slide Show
Humanities 191 Chapter Nine Slide Showjjfthomas
 
Introduction to Library Services
Introduction to Library ServicesIntroduction to Library Services
Introduction to Library Servicesgmayman
 
Humanities200801
Humanities200801Humanities200801
Humanities200801jjfthomas
 
Hum Chapter 9
Hum Chapter 9Hum Chapter 9
Hum Chapter 9jjfthomas
 
The Tell Asmar Statues 2750 B
The Tell Asmar Statues 2750 BThe Tell Asmar Statues 2750 B
The Tell Asmar Statues 2750 Bjjfthomas
 
European Art
European ArtEuropean Art
European Artjjfthomas
 
Assyrian Arts
Assyrian ArtsAssyrian Arts
Assyrian Artsjjfthomas
 
Egyptian Architecture
Egyptian ArchitectureEgyptian Architecture
Egyptian Architecturejjfthomas
 
Antecedentes De Etiquetas
Antecedentes De EtiquetasAntecedentes De Etiquetas
Antecedentes De EtiquetasPablo Bicego
 
Ict Short
Ict ShortIct Short
Ict Shortmonofon
 

Viewers also liked (20)

Diapositivas De Lucho
Diapositivas De LuchoDiapositivas De Lucho
Diapositivas De Lucho
 
Daniilids Success Story 1994-97
Daniilids Success Story 1994-97Daniilids Success Story 1994-97
Daniilids Success Story 1994-97
 
álbum deFotografias
álbum deFotografiasálbum deFotografias
álbum deFotografias
 
西部的歐洲
西部的歐洲 西部的歐洲
西部的歐洲
 
奧地利
奧地利奧地利
奧地利
 
Animals
AnimalsAnimals
Animals
 
Ecosystem Introductory Presentation
Ecosystem Introductory PresentationEcosystem Introductory Presentation
Ecosystem Introductory Presentation
 
Info Tech Questions
Info Tech QuestionsInfo Tech Questions
Info Tech Questions
 
Humanities 191 Chapter Nine Slide Show
Humanities 191 Chapter Nine Slide ShowHumanities 191 Chapter Nine Slide Show
Humanities 191 Chapter Nine Slide Show
 
Introduction to Library Services
Introduction to Library ServicesIntroduction to Library Services
Introduction to Library Services
 
Humanities200801
Humanities200801Humanities200801
Humanities200801
 
Hum Chapter 9
Hum Chapter 9Hum Chapter 9
Hum Chapter 9
 
The Tell Asmar Statues 2750 B
The Tell Asmar Statues 2750 BThe Tell Asmar Statues 2750 B
The Tell Asmar Statues 2750 B
 
European Art
European ArtEuropean Art
European Art
 
Assyrian Arts
Assyrian ArtsAssyrian Arts
Assyrian Arts
 
Egyptian Architecture
Egyptian ArchitectureEgyptian Architecture
Egyptian Architecture
 
Antecedentes De Etiquetas
Antecedentes De EtiquetasAntecedentes De Etiquetas
Antecedentes De Etiquetas
 
Era Digital
Era Digital Era Digital
Era Digital
 
Ict Short
Ict ShortIct Short
Ict Short
 
Tour Eiffel
Tour  EiffelTour  Eiffel
Tour Eiffel
 

Similar to Mongrel Handlers

Practical Intro Merb
Practical Intro MerbPractical Intro Merb
Practical Intro MerbPaul Pajo
 
Xen_and_Rails_deployment
Xen_and_Rails_deploymentXen_and_Rails_deployment
Xen_and_Rails_deploymentAbhishek Singh
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Newlink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Newlink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640LLC NewLink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Newlink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Newlink
 
Merb presentation at ORUG
Merb presentation at ORUGMerb presentation at ORUG
Merb presentation at ORUGMatt Aimonetti
 
Deployment with Ruby on Rails
Deployment with Ruby on RailsDeployment with Ruby on Rails
Deployment with Ruby on RailsJonathan Weiss
 
Deploying And Monitoring Rails
Deploying And Monitoring RailsDeploying And Monitoring Rails
Deploying And Monitoring RailsJonathan Weiss
 
The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018Charles Nutter
 
Merb For The Enterprise
Merb For The EnterpriseMerb For The Enterprise
Merb For The EnterpriseMatt Aimonetti
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Coursepeter_marklund
 

Similar to Mongrel Handlers (20)

Practical Intro Merb
Practical Intro MerbPractical Intro Merb
Practical Intro Merb
 
Xen_and_Rails_deployment
Xen_and_Rails_deploymentXen_and_Rails_deployment
Xen_and_Rails_deployment
 
Merb
MerbMerb
Merb
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
re7olabini
re7olabinire7olabini
re7olabini
 
Merb presentation at ORUG
Merb presentation at ORUGMerb presentation at ORUG
Merb presentation at ORUG
 
Deployment with Ruby on Rails
Deployment with Ruby on RailsDeployment with Ruby on Rails
Deployment with Ruby on Rails
 
Rubyhosting
RubyhostingRubyhosting
Rubyhosting
 
Deploying And Monitoring Rails
Deploying And Monitoring RailsDeploying And Monitoring Rails
Deploying And Monitoring Rails
 
Concurrency in ruby
Concurrency in rubyConcurrency in ruby
Concurrency in ruby
 
mtl_rubykaigi
mtl_rubykaigimtl_rubykaigi
mtl_rubykaigi
 
The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018
 
Merb For The Enterprise
Merb For The EnterpriseMerb For The Enterprise
Merb For The Enterprise
 
Scaling the Rails
Scaling the RailsScaling the Rails
Scaling the Rails
 
Merb + Nanite
Merb + NaniteMerb + Nanite
Merb + Nanite
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
 

More from nextlib

Hadoop Map Reduce Arch
Hadoop Map Reduce ArchHadoop Map Reduce Arch
Hadoop Map Reduce Archnextlib
 
D Rb Silicon Valley Ruby Conference
D Rb   Silicon Valley Ruby ConferenceD Rb   Silicon Valley Ruby Conference
D Rb Silicon Valley Ruby Conferencenextlib
 
Multi-core architectures
Multi-core architecturesMulti-core architectures
Multi-core architecturesnextlib
 
Aldous Huxley Brave New World
Aldous Huxley Brave New WorldAldous Huxley Brave New World
Aldous Huxley Brave New Worldnextlib
 
Social Graph
Social GraphSocial Graph
Social Graphnextlib
 
Ajax Prediction
Ajax PredictionAjax Prediction
Ajax Predictionnextlib
 
Closures for Java
Closures for JavaClosures for Java
Closures for Javanextlib
 
A Content-Driven Reputation System for the Wikipedia
A Content-Driven Reputation System for the WikipediaA Content-Driven Reputation System for the Wikipedia
A Content-Driven Reputation System for the Wikipedianextlib
 
SVD review
SVD reviewSVD review
SVD reviewnextlib
 
Blue Ocean Strategy
Blue Ocean StrategyBlue Ocean Strategy
Blue Ocean Strategynextlib
 
日本7-ELEVEN消費心理學
日本7-ELEVEN消費心理學日本7-ELEVEN消費心理學
日本7-ELEVEN消費心理學nextlib
 
Comparing State-of-the-Art Collaborative Filtering Systems
Comparing State-of-the-Art Collaborative Filtering SystemsComparing State-of-the-Art Collaborative Filtering Systems
Comparing State-of-the-Art Collaborative Filtering Systemsnextlib
 
Item Based Collaborative Filtering Recommendation Algorithms
Item Based Collaborative Filtering Recommendation AlgorithmsItem Based Collaborative Filtering Recommendation Algorithms
Item Based Collaborative Filtering Recommendation Algorithmsnextlib
 
Agile Adoption2007
Agile Adoption2007Agile Adoption2007
Agile Adoption2007nextlib
 
Modern Compiler Design
Modern Compiler DesignModern Compiler Design
Modern Compiler Designnextlib
 
透过众神的眼睛--鸟瞰非洲
透过众神的眼睛--鸟瞰非洲透过众神的眼睛--鸟瞰非洲
透过众神的眼睛--鸟瞰非洲nextlib
 
Improving Quality of Search Results Clustering with Approximate Matrix Factor...
Improving Quality of Search Results Clustering with Approximate Matrix Factor...Improving Quality of Search Results Clustering with Approximate Matrix Factor...
Improving Quality of Search Results Clustering with Approximate Matrix Factor...nextlib
 
Support Vector Machines
Support Vector MachinesSupport Vector Machines
Support Vector Machinesnextlib
 
Bigtable
BigtableBigtable
Bigtablenextlib
 

More from nextlib (20)

Nio
NioNio
Nio
 
Hadoop Map Reduce Arch
Hadoop Map Reduce ArchHadoop Map Reduce Arch
Hadoop Map Reduce Arch
 
D Rb Silicon Valley Ruby Conference
D Rb   Silicon Valley Ruby ConferenceD Rb   Silicon Valley Ruby Conference
D Rb Silicon Valley Ruby Conference
 
Multi-core architectures
Multi-core architecturesMulti-core architectures
Multi-core architectures
 
Aldous Huxley Brave New World
Aldous Huxley Brave New WorldAldous Huxley Brave New World
Aldous Huxley Brave New World
 
Social Graph
Social GraphSocial Graph
Social Graph
 
Ajax Prediction
Ajax PredictionAjax Prediction
Ajax Prediction
 
Closures for Java
Closures for JavaClosures for Java
Closures for Java
 
A Content-Driven Reputation System for the Wikipedia
A Content-Driven Reputation System for the WikipediaA Content-Driven Reputation System for the Wikipedia
A Content-Driven Reputation System for the Wikipedia
 
SVD review
SVD reviewSVD review
SVD review
 
Blue Ocean Strategy
Blue Ocean StrategyBlue Ocean Strategy
Blue Ocean Strategy
 
日本7-ELEVEN消費心理學
日本7-ELEVEN消費心理學日本7-ELEVEN消費心理學
日本7-ELEVEN消費心理學
 
Comparing State-of-the-Art Collaborative Filtering Systems
Comparing State-of-the-Art Collaborative Filtering SystemsComparing State-of-the-Art Collaborative Filtering Systems
Comparing State-of-the-Art Collaborative Filtering Systems
 
Item Based Collaborative Filtering Recommendation Algorithms
Item Based Collaborative Filtering Recommendation AlgorithmsItem Based Collaborative Filtering Recommendation Algorithms
Item Based Collaborative Filtering Recommendation Algorithms
 
Agile Adoption2007
Agile Adoption2007Agile Adoption2007
Agile Adoption2007
 
Modern Compiler Design
Modern Compiler DesignModern Compiler Design
Modern Compiler Design
 
透过众神的眼睛--鸟瞰非洲
透过众神的眼睛--鸟瞰非洲透过众神的眼睛--鸟瞰非洲
透过众神的眼睛--鸟瞰非洲
 
Improving Quality of Search Results Clustering with Approximate Matrix Factor...
Improving Quality of Search Results Clustering with Approximate Matrix Factor...Improving Quality of Search Results Clustering with Approximate Matrix Factor...
Improving Quality of Search Results Clustering with Approximate Matrix Factor...
 
Support Vector Machines
Support Vector MachinesSupport Vector Machines
Support Vector Machines
 
Bigtable
BigtableBigtable
Bigtable
 

Recently uploaded

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Recently uploaded (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Mongrel Handlers

  • 1. Who am I? • Ezra Zygmuntowicz • Rubyist for 4 years • Engine Yard Founder and Architect • Blog: http://brainspl.at
  • 4. Mongrel is an HTTP Server Library written by Zed Shaw • Fast HTTP Parser written in Ragel + C • Fast URI Classifier written in C • Stackable Request Handlers • Flexible Configuration • Secure and RFC Compliant HTTP Parser
  • 8. • HTTP is a well known and well tooled protocol • Mongrel is way easier to setup and use • Transparent wire protocol
  • 9. But Rails isn’t Thread Safe! • Giant Mutex Lock around Rails Dispatch • Only one request served at a time by one mongrel • Use mongrel_cluster to scale with multiple processes
  • 10. Full Stack Request/Response Life-Cycle • Request comes into gateway server • Rewrite rules are evaluated and request gets served directly if it’s a static asset • Dynamic requests are proxied to one Mongrel in the Mongrel Cluster • Mongrel dispatches request through Rails and returns response to client
  • 11. Rails Internal Request/Response Life-Cycle • Mongrel Locks Mutex • Rails Dispatcher is invoked with request/response objects • Routing is invoked and returns the proper Controller object or 404 if no route found • Filter chain is invoked • Controller’s Action is called, manipulates Models • View is rendered and any after filters are called • Mongrel Unlocks Mutex • Final response or error page returned to client
  • 12. Mongrel != Rails • Mongrel *is* Thread Safe • Mongrel is capable of much more then just running Rails • Rails is beautiful for the 80% part of the 80/20 rule • What to do when your app needs the other 20%?
  • 13. Handle It! • Building Mongrel Handlers is easier then you think • Mongrel is *very* high performance • Ruby not so slow after all? Maybe it’s just Rails that is slow?
  • 14. Rails vs Mongrel Handler in a Hello World Battle Rails: Mongrel Handler:
  • 16. Why the Huge Difference? • Of course Rails provides much more out of the box • Our HelloHandler runs in a multi-threaded way, hence the 100 concurrent users in our benchmark • Rails has to run requests in serial, hence the 1 concurrent user.
  • 17. What can Custom Mongrel Handlers do for me? • More concurrent users on fewer processes • Higher throughput with less resources • Less convenience for developers means you don’t need it until you *need* it
  • 18. Standalone or Integrated with Rails? • Mongrel Handlers can ‘Stack’ • You can use :in_front => true to put a custom Mongrel Handler in process with your Rails app and have it intercept and serve certain urls • Access to your Rails models and other loaded classes
  • 19. Integrating HelloHandler into our Rails app
  • 20. Another Useless Benchmark
  • 21. Real World Example SecureFile
  • 22. The next logical step? • Gee, Mongrel without Rails is hella fast • I’ll start writing more and more of my apps as Handlers • I’ll start implementing the parts of Rails I need in my handlers...
  • 23. Merb Started as a hack, Merb == Mongrel + Erb • No CGI.rb !! • Clean room implementation of ActionPack • Thread Safe with configurable Mutex Locks • Rails compatible REST routing • No Magic( well less anyway ;) • It’s what you will end up with if you keep writing custom Mongrel Handlers
  • 24. Dispatching Rails vs Merb Rails Merb(with ActiveRecord) Request comes in Request comes in **Mutex gets locked** Parse CGI + Mime Parse CGI + Mime(expensive) Route recognition Route recognition(expensive) **Mutex gets locked** Before Filter Chain Before Filter Chain Call Controller Action Call Controller Action Render Template Render Template **Mutex Unlocked** **Mutex Unlocked** Results returned to client Results returned to client
  • 26. Routing • Rails routing is 1800 lines of *very complex* non thread-safe code • Merb’s router is 200 lines of complex but *thread safe* code and much more efficient for route matching
  • 27. Why should you care? • Rails has gotten 10-20% slower with each recent release • Resident RAM usage per process gets larger as well • Premature Optimization is blah, blah • At this point it is not premature anymore ;) • There is a point where optimization Matters