SlideShare uma empresa Scribd logo
1 de 29
Baixar para ler 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?

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Último (20)

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

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