Skip to content
Browse files

Add benchmark tool for the Rails Dispatcher.

  • Loading branch information...
1 parent dc0217a commit e086712b4a9bfaed826511abfeda10f855f012fc @FooBarWidget FooBarWidget committed Apr 1, 2008
Showing with 69 additions and 0 deletions.
  1. +46 −0 benchmark/dispatcher.rb
  2. +23 −0 test/stub/http_request.yml
View
46 benchmark/dispatcher.rb
@@ -0,0 +1,46 @@
+#!/usr/bin/env ruby
+# Benchmark raw speed of the Rails dispatcher.
+PASSENGER_ROOT = File.expand_path("#{File.dirname(__FILE__)}/..")
+$LOAD_PATH << "#{PASSENGER_ROOT}/lib"
+ENV["RAILS_ENV"] = "production"
+
+require 'yaml'
+require 'benchmark'
+require 'passenger/request_handler'
+require 'config/environment'
+require 'dispatcher'
+
+include Passenger
+
+class OutputChannel
+ def write(data)
+ # Black hole
+ end
+end
+
+def start(iterations)
+ headers = YAML.load_file("#{PASSENGER_ROOT}/test/stub/http_request.yml")
+ output = OutputChannel.new
+ milestone = iterations / 10
+ milestone = 1 if milestone == 0
+ result = Benchmark.measure do
+ iterations.times do |i|
+ cgi = CGIFixed.new(headers, output, STDOUT)
+ ::Dispatcher.dispatch(cgi,
+ ::ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS,
+ cgi.stdoutput)
+ if i % milestone == 0 && i != 0
+ puts "Completed #{i} requests"
+ end
+ end
+ end
+ puts "#{iterations} requests: #{result}"
+ printf "Speed: %.2f requests/sec\n", iterations / result.total.to_f
+end
+
+puts "Benchmark started."
+t = Thread.new do
+ #start(ARGV[0] ? ARGV[0].to_i : 1000)
+end
+start(ARGV[0] ? ARGV[0].to_i : 1000)
+t.join
View
23 test/stub/http_request.yml
@@ -0,0 +1,23 @@
+---
+SERVER_NAME: rails.test
+HTTP_ACCEPT_ENCODING: gzip,deflate
+HTTP_USER_AGENT: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9b3pre) Gecko/2008020507 Firefox/3.0b3pre
+HTTP_CACHE_CONTROL: max-age=0
+HTTP_IF_NONE_MATCH: "\"4b3ecee644e12a7a2203be7484eaecfc\""
+HTTP_ACCEPT_LANGUAGE: en-us,en;q=0.5
+HTTP_HOST: rails.test
+SERVER_ADDR: 127.0.0.1
+SERVER_PROTOCOL: HTTP/1.1
+HTTP_KEEP_ALIVE: "300"
+REMOTE_ADDR: 127.0.0.1
+SERVER_SOFTWARE: Apache/2.2.4 (Ubuntu) mod_fastcgi/2.4.2 PHP/5.2.3-1ubuntu6.3 mod_ssl/2.2.4 OpenSSL/0.9.8e Phusion_Passenger/0.9.6
+HTTP_ACCEPT_CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+DOCUMENT_ROOT: /var/www/projects/app1-foobar/public
+REQUEST_URI: /
+SERVER_PORT: "80"
+QUERY_STRING: ""
+REMOTE_PORT: "36128"
+SERVER_ADMIN: "[no address given]"
+HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
+HTTP_CONNECTION: keep-alive
+REQUEST_METHOD: GET

0 comments on commit e086712

Please sign in to comment.
Something went wrong with that request. Please try again.