SlideShare ist ein Scribd-Unternehmen logo
1 von 57
Downloaden Sie, um offline zu lesen
Rack
Elan Meng
Caibangzi.com
IN-SRC Studio
http://www.mengyan.org/blog/
        @dreamwords
elanmeng@in-src.com
Thanks !!
Rack Sales?
Overview
• Why Rack
• What’s Rack
• Rack Middleware
• Rails on Rack
• Example
• Q &A
Problems
• Ruby is popular
• Different web servers (app servers)
• Different web frameworks
• each framework has to write it’s own
  handlers to different web servers
• Not only the handler
We hate duplication!
How?
Abstraction
 Interface
make the simplest
  possible API that
represents a generic
  web application
Request -> Response
Request
•   CGI Envrionment

•   {"HTTP_USER_AGENT"=>"curl/7.12.2 ..."
    "REMOTE_HOST"=>"127.0.0.1",
    "PATH_INFO"=>"/", "HTTP_HOST"=>"ruby-
    lang.org", "SERVER_PROTOCOL"=>"HTTP/1.1",
    "SCRIPT_NAME"=>"", "REQUEST_PATH"=>"/",
    "REMOTE_ADDR"=>"127.0.0.1",
    "HTTP_VERSION"=>"HTTP/1.1",
    "REQUEST_URI"=>"http://ruby-lang.org/",
    "SERVER_PORT"=>"80", "HTTP_PRAGMA"=>"no-
    cache", "QUERY_STRING"=>"",
    "GATEWAY_INTERFACE"=>"CGI/1.1",
    "HTTP_ACCEPT"=>"*/*",
    "REQUEST_METHOD"=>"GET"}
Response
  HTTP/1.1 302

Found Date: Sat, 27 Oct 2007 10:07:53 GMT
Server: Apache/2.0.54 (Debian GNU/Linux)
mod_ssl/2.0.54 OpenSSL/0.9.7e
Location: http://www.ruby-lang.org/
Content-Length: 209
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head> <title>302 Found</title> </head>
<body> <h1>Found</h1> <p>The document has moved <a
href="http://www.ruby-lang.org/">here</a>.
</p> </body></html>
What’s Rack
• Duck-Type
• Ruby object that respond_to? :call
• One argument, the environment variable
• return values
 • status - respond_to? :to_i
 • headers - respond_to? :each, yield key/
    value
 • body - respond_to? :each, yield string
lambda { |env|
	 [
	 	 200,
	 	 {'Content-Type' => 'text/
plain', 'Content-Length' => '16'},
	 	 ["Beijing on Rails"]
	 ]
}
app = lambda { |env|
	 [
	 	 200,
	 	 {'Content-Type' => 'text/
plain', 'Content-Length' => ’16’},
	 	 ["Beijing on Rails"]
	 ]
}

run app
rackup config.ru
curl http://localhost:9292/
Beijing on Rails
%w(rubygems rack).each { |dep| require dep }

Rack::Handler::Mongrel.run(app, :Port =>
3000)
Rack Middleware


                  Framework
HTTP
                     APP
Rack Middleware


                  Framework
HTTP
                     APP




           Rack
module Rack
  class BeijingOnRails
    def initialize(app)
      @app = app
    end

    def call(env)
      ... ...
      status, headers body = @app.call(env)
      ... ...

      [status, header, body]
    end
  end
end
app = Rack::CommonLogger.new(
       Rack::ShowExceptions.new(
          Rack::ShowStatus.new(
          Rack::Lint.new(app))))
Rack Middleware


                      Framework
HTTP
                         APP




         Middleware
Rack Middleware

• Chain of Responsibilities
app = Rack::CommonLogger.new(
       Rack::ShowExceptions.new(
          Rack::ShowStatus.new(
          Rack::Lint.new(app))))
Rack Distribution

• Specification
• Handlers
• Adapters
• Middlewares
• Utilities
Rack - Specification
• Rack::Lint
specify "notices status errors" do
  lambda {
    Rack::Lint.new(lambda { |env|
                     ["cc", {}, ""]
                   }).call(env({}))
  }.should.raise(Rack::Lint::LintError).
    message.should.match(/must be >=100 seen as integer/)

  lambda {
    Rack::Lint.new(lambda { |env|
                     [42, {}, ""]
                   }).call(env({}))
  }.should.raise(Rack::Lint::LintError).
    message.should.match(/must be >=100 seen as integer/)
end
Rack - Handlers
• CGI
• FastCGI
• Mongrel
• WEBrick
• Thin
• Passenger
• Unicorn
Rack - Adapters

• Camping
• Merb
• Rails
• Sinatra
• ......
Rack - Middleware

• Rack::Static & Rack::File
• Rack::CommonLogger
• Rack::Reloader
• Rack::ShowExceptions
Rack - Utilities
• Rackup
 • a useful tool for running Rack
    applications
• Rackup::Builder
 • DSL to configure middleware and build
    up applications easily
app = Rack::Builder.new do

   use Rack::CommonLogger
   use Rack::ShowExceptions
   use Rack::ShowStatus
   use Rack::Lint
   run MyRackApp.new

 end

 Rack::Handler::Mongrel.run app, :Port => 8080
Rails on Rack
The most important
change in Rails over the
 past year - its move to
     become Rack-
                  - Ben Scofield
Rails on Rack
• first commit - Ezra & Josh on June 2008
Rails on Rack
• Merb & Rails merge
• ActionController::Dispatcher.new
• ActionController::MiddlewareStack
• ActionController -> Rack Middleware
 •   ActionDispatch::Failsafe

 •   ActionDispatch::ShowExceptions


• Plugin -> Rack Middleware
 •   Hoptoad_notifier plugin -> Rack::Hoptoad.
app = Rack::Builder.new {
  use Rails::Rack::LogTailer unless options[:detach]
  use Rails::Rack::Debugger if options[:debugger]

  map "/" do
    use Rails::Rack::Static
    run ActionController::Dispatcher.new
  end
}.to_app
# RAILS_ROOT/config.ru
require "config/environment"

use Rails::Rack::LogTailer
use Rails::Rack::Static
run ActionController::Dispatcher.new




rackup
Metal
• bypass some of the normal overhead of the
  Rails stack
• specify certain routes and code to execute
  when those routes are hit.
• avoid the entirety of ActionController
• Rails::Rack::Metal
• ActionController::MiddlewareStack
$ script/generate metal poller


class Poller
  def self.call(env)
    if env["PATH_INFO"] =~ /^/poller/
      [200, {"Content-Type" => "text/html"},
["Hello, World!"]]
    else
      [404, {"Content-Type" => "text/html"},
["Not Found"]]
    end
  end
end
Rack::Metal
def call(env)
  @metals.keys.each do |app|
    result = app.call(env)
    return result unless result[0].to_i ==
404
  end
  @app.call(env)
end
Response Timer
module Rack
  class Runtime
    def initialize(app, name = nil)
      @app = app
      @header_name = "X-Runtime"
      @header_name << "-#{name}" if name
    end

    def call(env)
      start_time = Time.now
      status, headers, body = @app.call(env)
      request_time = Time.now - start_time

      if !headers.has_key?(@header_name)
        headers[@header_name] = "%0.6f" % request_time
      end

      [status, headers, body]
    end
  end
end
http://github.com/rack/rack-contrib
CodeRack
• http://coderack.org/
• a competition to develop most useful and
  top quality Rack middlewares.
• 1 DAY LEFT
WRAP UP
Rack is a beautiful thing
                    - Ryan Bates
References

• Introducing Rack - Christian Neukirchen
• http://rack.rubyforge.org/
• RailsCasts 151: Rack Middleware
• http://heroku.com/how/architecture
Q &A

• Rack
• Ruby on Rails
• Caibangzi.com
• Mutual Fund & Investment
Why not simply string
•   Ruby 1.8

    •   String was a collection of bytes

    •   String’s :each method iterated over lines of data

•   Ruby 1.9

    •   String is now a collection of encoded data. (Raw
        bytes and encoding information)

    •   :each has been removed from String and it’s no
        longer Enumerable

Weitere ähnliche Inhalte

Was ist angesagt?

OpenTox API introductory presentation
OpenTox API introductory presentationOpenTox API introductory presentation
OpenTox API introductory presentationPantelis Sopasakis
 
A introduction to Laravel framework
A introduction to Laravel frameworkA introduction to Laravel framework
A introduction to Laravel frameworkPhu Luong Trong
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5Bukhori Aqid
 
Apache Camel K - Copenhagen
Apache Camel K - CopenhagenApache Camel K - Copenhagen
Apache Camel K - CopenhagenClaus Ibsen
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5Soheil Khodayari
 
API Development with Laravel
API Development with LaravelAPI Development with Laravel
API Development with LaravelMichael Peacock
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)daylerees
 
What's New in Laravel 5 (Laravel Meetup - 23th Apr 15, Yogyakarta, ID)
What's New in Laravel 5 (Laravel Meetup - 23th Apr 15, Yogyakarta, ID)What's New in Laravel 5 (Laravel Meetup - 23th Apr 15, Yogyakarta, ID)
What's New in Laravel 5 (Laravel Meetup - 23th Apr 15, Yogyakarta, ID)Roes Wibowo
 
State of integration with Apache Camel (ApacheCon 2019)
State of integration with Apache Camel (ApacheCon 2019)State of integration with Apache Camel (ApacheCon 2019)
State of integration with Apache Camel (ApacheCon 2019)Claus Ibsen
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camelkrasserm
 
Http programming in play
Http programming in playHttp programming in play
Http programming in playKnoldus Inc.
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
An Introduction to Akka http
An Introduction to Akka httpAn Introduction to Akka http
An Introduction to Akka httpKnoldus Inc.
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache CamelClaus Ibsen
 
VJUG24 - Reactive Integrations with Akka Streams
VJUG24  - Reactive Integrations with Akka StreamsVJUG24  - Reactive Integrations with Akka Streams
VJUG24 - Reactive Integrations with Akka StreamsJohan Andrén
 

Was ist angesagt? (20)

OpenTox API introductory presentation
OpenTox API introductory presentationOpenTox API introductory presentation
OpenTox API introductory presentation
 
Going serverless
Going serverlessGoing serverless
Going serverless
 
A introduction to Laravel framework
A introduction to Laravel frameworkA introduction to Laravel framework
A introduction to Laravel framework
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
Apache Camel K - Copenhagen
Apache Camel K - CopenhagenApache Camel K - Copenhagen
Apache Camel K - Copenhagen
 
Intro to Laravel
Intro to LaravelIntro to Laravel
Intro to Laravel
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5
 
Pie on AWS
Pie on AWSPie on AWS
Pie on AWS
 
API Development with Laravel
API Development with LaravelAPI Development with Laravel
API Development with Laravel
 
Rails engines
Rails enginesRails engines
Rails engines
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
 
What's New in Laravel 5 (Laravel Meetup - 23th Apr 15, Yogyakarta, ID)
What's New in Laravel 5 (Laravel Meetup - 23th Apr 15, Yogyakarta, ID)What's New in Laravel 5 (Laravel Meetup - 23th Apr 15, Yogyakarta, ID)
What's New in Laravel 5 (Laravel Meetup - 23th Apr 15, Yogyakarta, ID)
 
State of integration with Apache Camel (ApacheCon 2019)
State of integration with Apache Camel (ApacheCon 2019)State of integration with Apache Camel (ApacheCon 2019)
State of integration with Apache Camel (ApacheCon 2019)
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camel
 
Http programming in play
Http programming in playHttp programming in play
Http programming in play
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
An Introduction to Akka http
An Introduction to Akka httpAn Introduction to Akka http
An Introduction to Akka http
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
 
VJUG24 - Reactive Integrations with Akka Streams
VJUG24  - Reactive Integrations with Akka StreamsVJUG24  - Reactive Integrations with Akka Streams
VJUG24 - Reactive Integrations with Akka Streams
 

Ähnlich wie Rack Sales Overview

.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011Fabio Akita
 
09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do railsDNAD
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Racksickill
 
Rails Request & Middlewares
Rails Request & MiddlewaresRails Request & Middlewares
Rails Request & MiddlewaresSantosh Wadghule
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileAmazon Web Services Japan
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareAlona Mekhovova
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011Lance Ball
 
Rails request & middlewares
Rails request & middlewaresRails request & middlewares
Rails request & middlewaresSantosh Wadghule
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发shaokun
 
Sinatra Introduction
Sinatra IntroductionSinatra Introduction
Sinatra IntroductionYi-Ting Cheng
 
Rails in the bowels
Rails in the bowelsRails in the bowels
Rails in the bowelsCreditas
 
Universal JavaScript
Universal JavaScriptUniversal JavaScript
Universal JavaScript名辰 洪
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Viral Solani
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortegaarman o
 
Building Better Web APIs with Rails
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with RailsAll Things Open
 

Ähnlich wie Rack Sales Overview (20)

Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
 
Wider than rails
Wider than railsWider than rails
Wider than rails
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011
 
09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Rails Request & Middlewares
Rails Request & MiddlewaresRails Request & Middlewares
Rails Request & Middlewares
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
 
Rack
RackRack
Rack
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
Sinatra
SinatraSinatra
Sinatra
 
Rails request & middlewares
Rails request & middlewaresRails request & middlewares
Rails request & middlewares
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发
 
Sinatra Introduction
Sinatra IntroductionSinatra Introduction
Sinatra Introduction
 
Speedy TDD with Rails
Speedy TDD with RailsSpeedy TDD with Rails
Speedy TDD with Rails
 
Rails in the bowels
Rails in the bowelsRails in the bowels
Rails in the bowels
 
Universal JavaScript
Universal JavaScriptUniversal JavaScript
Universal JavaScript
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
Building Better Web APIs with Rails
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with Rails
 

Mehr von shen liu

A~Z Of Accelerator
A~Z Of AcceleratorA~Z Of Accelerator
A~Z Of Acceleratorshen liu
 
Jquery In Rails
Jquery In RailsJquery In Rails
Jquery In Railsshen liu
 
Rails + JCR
Rails + JCRRails + JCR
Rails + JCRshen liu
 
Legal contracts 2.0
Legal contracts 2.0Legal contracts 2.0
Legal contracts 2.0shen liu
 
危机模拟
危机模拟危机模拟
危机模拟shen liu
 
技术周报
技术周报技术周报
技术周报shen liu
 
Hong Qiangning in QConBeijing
Hong Qiangning in QConBeijingHong Qiangning in QConBeijing
Hong Qiangning in QConBeijingshen liu
 
InfoQ China Intro
InfoQ  China  IntroInfoQ  China  Intro
InfoQ China Introshen liu
 
QCon Beijing 2009 Intro
QCon Beijing 2009 IntroQCon Beijing 2009 Intro
QCon Beijing 2009 Introshen liu
 

Mehr von shen liu (10)

A~Z Of Accelerator
A~Z Of AcceleratorA~Z Of Accelerator
A~Z Of Accelerator
 
Jquery In Rails
Jquery In RailsJquery In Rails
Jquery In Rails
 
Rails + JCR
Rails + JCRRails + JCR
Rails + JCR
 
Legal contracts 2.0
Legal contracts 2.0Legal contracts 2.0
Legal contracts 2.0
 
危机模拟
危机模拟危机模拟
危机模拟
 
决策
决策决策
决策
 
技术周报
技术周报技术周报
技术周报
 
Hong Qiangning in QConBeijing
Hong Qiangning in QConBeijingHong Qiangning in QConBeijing
Hong Qiangning in QConBeijing
 
InfoQ China Intro
InfoQ  China  IntroInfoQ  China  Intro
InfoQ China Intro
 
QCon Beijing 2009 Intro
QCon Beijing 2009 IntroQCon Beijing 2009 Intro
QCon Beijing 2009 Intro
 

Kürzlich hochgeladen

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
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
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
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
 

Kürzlich hochgeladen (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
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
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
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
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Rack Sales Overview

  • 2.
  • 10.
  • 11. Overview • Why Rack • What’s Rack • Rack Middleware • Rails on Rack • Example • Q &A
  • 12. Problems • Ruby is popular • Different web servers (app servers) • Different web frameworks • each framework has to write it’s own handlers to different web servers • Not only the handler
  • 14. How?
  • 16. make the simplest possible API that represents a generic web application
  • 18. Request • CGI Envrionment • {"HTTP_USER_AGENT"=>"curl/7.12.2 ..." "REMOTE_HOST"=>"127.0.0.1", "PATH_INFO"=>"/", "HTTP_HOST"=>"ruby- lang.org", "SERVER_PROTOCOL"=>"HTTP/1.1", "SCRIPT_NAME"=>"", "REQUEST_PATH"=>"/", "REMOTE_ADDR"=>"127.0.0.1", "HTTP_VERSION"=>"HTTP/1.1", "REQUEST_URI"=>"http://ruby-lang.org/", "SERVER_PORT"=>"80", "HTTP_PRAGMA"=>"no- cache", "QUERY_STRING"=>"", "GATEWAY_INTERFACE"=>"CGI/1.1", "HTTP_ACCEPT"=>"*/*", "REQUEST_METHOD"=>"GET"}
  • 19. Response HTTP/1.1 302 Found Date: Sat, 27 Oct 2007 10:07:53 GMT Server: Apache/2.0.54 (Debian GNU/Linux) mod_ssl/2.0.54 OpenSSL/0.9.7e Location: http://www.ruby-lang.org/ Content-Length: 209 Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>302 Found</title> </head> <body> <h1>Found</h1> <p>The document has moved <a href="http://www.ruby-lang.org/">here</a>. </p> </body></html>
  • 20. What’s Rack • Duck-Type • Ruby object that respond_to? :call • One argument, the environment variable • return values • status - respond_to? :to_i • headers - respond_to? :each, yield key/ value • body - respond_to? :each, yield string
  • 21. lambda { |env| [ 200, {'Content-Type' => 'text/ plain', 'Content-Length' => '16'}, ["Beijing on Rails"] ] }
  • 22. app = lambda { |env| [ 200, {'Content-Type' => 'text/ plain', 'Content-Length' => ’16’}, ["Beijing on Rails"] ] } run app
  • 26. %w(rubygems rack).each { |dep| require dep } Rack::Handler::Mongrel.run(app, :Port => 3000)
  • 27. Rack Middleware Framework HTTP APP
  • 28. Rack Middleware Framework HTTP APP Rack
  • 29. module Rack class BeijingOnRails def initialize(app) @app = app end def call(env) ... ... status, headers body = @app.call(env) ... ... [status, header, body] end end end
  • 30. app = Rack::CommonLogger.new( Rack::ShowExceptions.new( Rack::ShowStatus.new( Rack::Lint.new(app))))
  • 31. Rack Middleware Framework HTTP APP Middleware
  • 32. Rack Middleware • Chain of Responsibilities app = Rack::CommonLogger.new( Rack::ShowExceptions.new( Rack::ShowStatus.new( Rack::Lint.new(app))))
  • 33. Rack Distribution • Specification • Handlers • Adapters • Middlewares • Utilities
  • 34. Rack - Specification • Rack::Lint specify "notices status errors" do lambda { Rack::Lint.new(lambda { |env| ["cc", {}, ""] }).call(env({})) }.should.raise(Rack::Lint::LintError). message.should.match(/must be >=100 seen as integer/) lambda { Rack::Lint.new(lambda { |env| [42, {}, ""] }).call(env({})) }.should.raise(Rack::Lint::LintError). message.should.match(/must be >=100 seen as integer/) end
  • 35. Rack - Handlers • CGI • FastCGI • Mongrel • WEBrick • Thin • Passenger • Unicorn
  • 36. Rack - Adapters • Camping • Merb • Rails • Sinatra • ......
  • 37. Rack - Middleware • Rack::Static & Rack::File • Rack::CommonLogger • Rack::Reloader • Rack::ShowExceptions
  • 38. Rack - Utilities • Rackup • a useful tool for running Rack applications • Rackup::Builder • DSL to configure middleware and build up applications easily
  • 39. app = Rack::Builder.new do use Rack::CommonLogger use Rack::ShowExceptions use Rack::ShowStatus use Rack::Lint run MyRackApp.new end Rack::Handler::Mongrel.run app, :Port => 8080
  • 41. The most important change in Rails over the past year - its move to become Rack- - Ben Scofield
  • 42. Rails on Rack • first commit - Ezra & Josh on June 2008
  • 43. Rails on Rack • Merb & Rails merge • ActionController::Dispatcher.new • ActionController::MiddlewareStack • ActionController -> Rack Middleware • ActionDispatch::Failsafe • ActionDispatch::ShowExceptions • Plugin -> Rack Middleware • Hoptoad_notifier plugin -> Rack::Hoptoad.
  • 44. app = Rack::Builder.new { use Rails::Rack::LogTailer unless options[:detach] use Rails::Rack::Debugger if options[:debugger] map "/" do use Rails::Rack::Static run ActionController::Dispatcher.new end }.to_app
  • 45. # RAILS_ROOT/config.ru require "config/environment" use Rails::Rack::LogTailer use Rails::Rack::Static run ActionController::Dispatcher.new rackup
  • 46. Metal • bypass some of the normal overhead of the Rails stack • specify certain routes and code to execute when those routes are hit. • avoid the entirety of ActionController • Rails::Rack::Metal • ActionController::MiddlewareStack
  • 47. $ script/generate metal poller class Poller def self.call(env) if env["PATH_INFO"] =~ /^/poller/ [200, {"Content-Type" => "text/html"}, ["Hello, World!"]] else [404, {"Content-Type" => "text/html"}, ["Not Found"]] end end end
  • 48. Rack::Metal def call(env) @metals.keys.each do |app| result = app.call(env) return result unless result[0].to_i == 404 end @app.call(env) end
  • 50. module Rack class Runtime def initialize(app, name = nil) @app = app @header_name = "X-Runtime" @header_name << "-#{name}" if name end def call(env) start_time = Time.now status, headers, body = @app.call(env) request_time = Time.now - start_time if !headers.has_key?(@header_name) headers[@header_name] = "%0.6f" % request_time end [status, headers, body] end end end
  • 52. CodeRack • http://coderack.org/ • a competition to develop most useful and top quality Rack middlewares. • 1 DAY LEFT
  • 54. Rack is a beautiful thing - Ryan Bates
  • 55. References • Introducing Rack - Christian Neukirchen • http://rack.rubyforge.org/ • RailsCasts 151: Rack Middleware • http://heroku.com/how/architecture
  • 56. Q &A • Rack • Ruby on Rails • Caibangzi.com • Mutual Fund & Investment
  • 57. Why not simply string • Ruby 1.8 • String was a collection of bytes • String’s :each method iterated over lines of data • Ruby 1.9 • String is now a collection of encoded data. (Raw bytes and encoding information) • :each has been removed from String and it’s no longer Enumerable