SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
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?

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
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
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
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
 
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
 
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
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
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
 
"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
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 

Kürzlich hochgeladen (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
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
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
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
 
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
 
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
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
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
 
"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
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
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
 

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