Changeset 992

Show
Ignore:
Timestamp:
11/13/07 16:32:11 (1 year ago)
Author:
wyca..@gmail.com
Message:

New benchmarkers for Rails and Merb

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • apps/benchmark/app/controllers/perf.rb

    r973 r992  
    1313    render 
    1414  end 
     15   
     16  def complex_partials 
     17    @times = params[:id].to_i 
     18    render 
     19  end 
    1520end 
  • apps/benchmark/script/benchmark

    r978 r992  
    11#!/usr/bin/env ruby 
    2 err = STDERR.dup 
    3 STDERR.reopen("/dev/null") 
     2require 'open3' 
     3begin 
     4  err = STDERR.dup 
    45 
    5 GC.disable 
    6 GC.disable 
     6  err.puts "* Starting Merb" 
     7  ENV["EVENT"] = "1" 
     8  `merb -d -e production` 
     9  pid = File.read("#{File.dirname(__FILE__)}/../log/merb.4000.pid") 
    710 
    8 err.puts "* Starting Merb" 
    9 ENV["EVENT"] = "1" 
    10 `merb -d -e production` 
    11 pid = File.read("#{File.dirname(__FILE__)}/../log/merb.4000.pid") 
    12 sleep 5 
     11  ps = `ps aux #{pid}` 
     12  memsize = (ps.split("\n")[1].split[5].to_f / 10.24).round / 100.0 
    1313 
    14 ps = `ps aux #{pid}` 
    15 memsize = (ps.split("\n")[1].split[5].to_f / 10.24).round / 100.0 
     14  err.puts "* Memory size before benchmarking: #{memsize}MB" 
    1615 
    17 err.puts "* Memory size before benchmarking: #{memsize}MB" 
     16  TIMES = ARGV.find{|x| x =~ /^-t/ }[2..-1].to_i rescue 1000 
     17  CNCRC = ARGV.find{|x| x =~ /^-c/ }[2..-1].to_i rescue 5 
    1818 
    19 def get_rps(str) 
    20   "     " + str.find {|x| x =~ /Requests per second/ } 
     19  def call_ab(msg, url) 
     20    print "  ** #{msg} " 
     21    Open3.popen3("ab -n#{TIMES} -c#{CNCRC} http://127.0.0.1:4000/perf/#{url}") do |strin, out, err| 
     22      while true 
     23        error, output = err.gets, out.gets 
     24        next unless (error || output) 
     25        print "." if  error =~ /Completed/ 
     26        STDOUT.flush 
     27        output = out.gets 
     28        if (output =~ /Requests per second/) 
     29          puts "\n     " + output 
     30          break 
     31        end 
     32        sleep 0.1 
     33      end 
     34    end 
     35  end 
     36 
     37  def get_rps(str) 
     38    GC.start 
     39    sleep 1 
     40    "     " + str.find {|x| x =~ /Requests per second/ }     
     41  end 
     42 
     43 
     44  err.puts "* Benchmarks (These may take a while)" 
     45  err.puts "* Requests per benchmark: #{TIMES}" 
     46  err.puts "* Concurrency:            #{CNCRC}" 
     47 
     48  err.puts 
     49 
     50  sleep 1 
     51   
     52  call_ab("Render a string", "string") 
     53  call_ab("Render a simple template", "simple_template") 
     54 
     55  [1,10,100].each do |number| 
     56    call_ab("Render #{number} simple partial#{'s' if number > 1}", "partials/#{number}") 
     57  end 
     58 
     59  [1,10,100].each do |number| 
     60    call_ab("Render #{number} nested partial#{'s' if number > 1}", "complex_partials/#{number}") 
     61  end 
     62 
     63  ps = `ps aux #{pid}` 
     64  memsize = (ps.split("\n")[1].split[5].to_f / 10.24).round / 100.0 
     65 
     66  err.puts  
     67  err.puts "* Memory size after benchmarking: #{memsize}MB" 
     68ensure 
     69  `merb -k all` 
    2170end 
    2271 
    23 TIMES = ARGV.find{|x| x =~ /^-t/ }[2..-1].to_i rescue 1000 
    24 CNCRC = ARGV.find{|x| x =~ /^-c/ }[2..-1].to_i rescue 5 
    25  
    26 err.puts "* Benchmarks (These may take a while)" 
    27 err.puts "* Requests per benchmark: #{TIMES}" 
    28 err.puts "* Concurrency:            #{CNCRC}" 
    29  
    30 err.puts 
    31  
    32 err.puts "  ** Render a string" 
    33 bench = `ab -n#{TIMES} -c#{CNCRC} http://127.0.0.1:4000/perf/string` 
    34 err.puts get_rps(bench) 
    35  
    36 err.puts "  ** Render a simple template" 
    37 bench = `ab -n#{TIMES} -c#{CNCRC} http://127.0.0.1:4000/perf/simple_template` 
    38 err.puts get_rps(bench) 
    39  
    40 err.puts "  ** Render a single partial" 
    41 bench = `ab -n#{TIMES} -c#{CNCRC} http://127.0.0.1:4000/perf/partials/1` 
    42 err.puts get_rps(bench) 
    43  
    44 err.puts "  ** Render ten partials" 
    45 bench = `ab -n#{TIMES} -c#{CNCRC} http://127.0.0.1:4000/perf/partials/10` 
    46 err.puts get_rps(bench) 
    47  
    48 err.puts "  ** Render 100 partials" 
    49 bench = `ab -n#{TIMES} -c#{CNCRC} http://127.0.0.1:4000/perf/partials/100` 
    50 err.puts get_rps(bench) 
    51  
    52 ps = `ps aux #{pid}` 
    53 memsize = (ps.split("\n")[1].split[5].to_f / 10.24).round / 100.0 
    54  
    55 err.puts  
    56 err.puts "* Memory size after benchmarking: #{memsize}MB" 
    57  
    58 `merb -k all` 
    59  
  • apps/moved_to_rubyforge/merki/trunk/framework/merb/template/erubis.rb

    r939 r992  
    44    class ErubisViewContext < ViewContext 
    55      include ::Merb::ErubisCaptureMixin 
     6       
     7      public 
     8      def partial(template, opts={}) 
     9 
     10        puts 
     11        puts 
     12        puts "Inside new partial" 
     13        puts 
     14        puts 
     15 
     16        unless @_template_format 
     17          @web_controller.choose_template_format(Merb.available_mime_types, {}) 
     18        end 
     19 
     20        template = @web_controller._cached_partials["#{template}.#{@_template_format}"] ||= 
     21          @web_controller.send(:find_partial, template) 
     22 
     23        if with = opts.delete(:with) 
     24          as = opts.delete(:as) || template.match(/(.*\/_)([^\.]*)/)[2] 
     25          @_merb_partial_locals = opts         
     26          sent_template = [with].flatten.map do |temp| 
     27            @_merb_partial_locals[as.to_sym] = temp 
     28            send(template.gsub("/", "__").gsub(".", "_")) rescue "" 
     29          end.join 
     30        else 
     31          @_merb_partial_locals = opts         
     32          sent_template = send(template.gsub("/", "__").gsub(".", "_")) rescue nil 
     33        end 
     34 
     35        return sent_template if sent_template 
     36 
     37        raise Merb::ControllerExceptions::TemplateNotFound, "No template matched at #{template}" 
     38      end 
     39 
     40      def method_missing(sym, *args, &blk) 
     41        @_merb_partial_locals[sym] || @web_controller.send(sym, *args, &blk) rescue super 
     42      end 
     43       
    644    end 
    745     
  • apps/rails_benchmark/app/controllers/perf_controller.rb

    r978 r992  
    1111    @times = params[:id].to_i 
    1212  end   
     13 
     14  def complex_partials 
     15    @times = params[:id].to_i 
     16  end 
    1317   
    1418end 
  • apps/rails_benchmark/script/benchmark

    r978 r992  
    11#!/usr/bin/env ruby 
    2 err = STDERR.dup 
    3 STDERR.reopen("/dev/null") 
     2require 'open3' 
     3$stdout.sync = true 
     4begin 
     5  err = STDERR.dup 
    46 
    5 if File.exists?("#{File.dirname(__FILE__)}/../log/mongrel.pid") 
     7  if File.exists?("#{File.dirname(__FILE__)}/../log/mongrel.pid") 
     8    `mongrel_rails stop` 
     9  end 
     10 
     11  err.puts "* Starting Rails" 
     12  ENV["EVENT"] = "1" 
     13  `mongrel_rails start -d -p 4000 -e production` 
     14  sleep 1 
     15  puts Dir[File.join(File.expand_path(__FILE__), "..", "log", "*.pid")] 
     16  puts Dir["#{File.dirname(__FILE__)}/../log/*.pid"].inspect 
     17  pid = File.read("#{File.dirname(__FILE__)}/../log/mongrel.pid") 
     18 
     19  ps = `ps aux #{pid}` 
     20  memsize = (ps.split("\n")[1].split[5].to_f / 10.24).round / 100.0 
     21 
     22  err.puts "* Memory size before benchmarking: #{memsize}MB" 
     23 
     24  TIMES = ARGV.find{|x| x =~ /^-t/ }[2..-1].to_i rescue 1000 
     25  CNCRC = ARGV.find{|x| x =~ /^-c/ }[2..-1].to_i rescue 5 
     26 
     27  def call_ab(msg, url) 
     28    print "  ** #{msg} " 
     29    Open3.popen3("ab -n#{TIMES} -c#{CNCRC} http://127.0.0.1:4000/perf/#{url}") do |strin, out, err| 
     30      while true 
     31        error, output = err.gets, out.gets 
     32        next unless (error || output) 
     33        print "." if  error =~ /Completed/ 
     34        STDOUT.flush 
     35        output = out.gets 
     36        if (output =~ /Requests per second/) 
     37          puts "\n     " + output 
     38          break 
     39        end 
     40        sleep 0.05 
     41      end 
     42    end 
     43  end 
     44 
     45  def get_rps(str) 
     46    GC.start 
     47    sleep 1 
     48    "     " + str.find {|x| x =~ /Requests per second/ }     
     49  end 
     50 
     51 
     52  err.puts "* Benchmarks (These may take a while)" 
     53  err.puts "* Requests per benchmark: #{TIMES}" 
     54  err.puts "* Concurrency:            #{CNCRC}" 
     55 
     56  err.puts 
     57 
     58   
     59  call_ab("Render a string", "string") 
     60  call_ab("Render a simple template", "simple_template") 
     61 
     62  [1,10,100].each do |number| 
     63    call_ab("Render #{number} simple partial#{'s' if number > 1}", "partials/#{number}") 
     64  end 
     65 
     66  [1,10,100].each do |number| 
     67    call_ab("Render #{number} nested partial#{'s' if number > 1}", "complex_partials/#{number}") 
     68  end 
     69 
     70  ps = `ps aux #{pid}` 
     71  memsize = (ps.split("\n")[1].split[5].to_f / 10.24).round / 100.0 
     72 
     73  err.puts  
     74  err.puts "* Memory size after benchmarking: #{memsize}MB" 
     75ensure 
    676  `mongrel_rails stop` 
    777end 
    8  
    9 err.puts "* Starting Rails" 
    10 ENV["EVENT"] = "1" 
    11 `mongrel_rails start -d -p 4000 -e production` 
    12 sleep 1 
    13 pid = File.read("#{File.dirname(__FILE__)}/../log/mongrel.pid") 
    14 sleep 5 
    15  
    16 ps = `ps aux #{pid}` 
    17 memsize = (ps.split("\n")[1].split[5].to_f / 10.24).round / 100.0 
    18  
    19 err.puts "* Memory size before benchmarking: #{memsize}MB" 
    20  
    21 def get_rps(str) 
    22   "     " + str.find {|x| x =~ /Requests per second/ } 
    23 end 
    24  
    25 TIMES = ARGV.find{|x| x =~ /^-t/ }[2..-1].to_i rescue 10_000 
    26 CNCRC = ARGV.find{|x| x =~ /^-c/ }[2..-1].to_i rescue 5 
    27  
    28 err.puts "* Benchmarks (These may take a while)" 
    29 err.puts "* Requests per benchmark: #{TIMES}" 
    30 err.puts "* Concurrency:            #{CNCRC}" 
    31  
    32 err.puts 
    33  
    34 err.puts "  ** Render a string" 
    35 bench = `ab -n#{TIMES} -c#{CNCRC} http://127.0.0.1:4000/perf/string` 
    36 err.puts get_rps(bench) 
    37  
    38 err.puts "  ** Render a simple template" 
    39 bench = `ab -n#{TIMES} -c#{CNCRC} http://127.0.0.1:4000/perf/simple_template` 
    40 err.puts get_rps(bench) 
    41  
    42 err.puts "  ** Render a single partial" 
    43 bench = `ab -n#{TIMES} -c#{CNCRC} http://127.0.0.1:4000/perf/partials/1` 
    44 err.puts get_rps(bench) 
    45  
    46 err.puts "  ** Render ten partials" 
    47 bench = `ab -n#{TIMES} -c#{CNCRC} http://127.0.0.1:4000/perf/partials/10` 
    48 err.puts get_rps(bench) 
    49  
    50 err.puts "  ** Render 100 partials" 
    51 bench = `ab -n#{TIMES} -c#{CNCRC} http://127.0.0.1:4000/perf/partials/100` 
    52 err.puts get_rps(bench) 
    53  
    54 ps = `ps aux #{pid}` 
    55 memsize = (ps.split("\n")[1].split[5].to_f / 10.24).round / 100.0 
    56  
    57 err.puts  
    58 err.puts "* Memory size after benchmarking: #{memsize}MB" 
    59  
    60 `mongrel_rails stop` 
     78