1 $: << File.expand_path(File.dirname(__FILE__))
14 inject(0) { |i, s| s += i }
18 sort_by{ rand }.each &block
22 class ServerTestResults
23 def self.open(filename)
24 if File.readable?(filename)
25 new(Marshal.load(File.read(filename)))
31 def initialize(results = [])
36 @results.first[:benchmark]
39 def write(filename='results.dump')
40 puts "writing dump file to #{filename}"
41 File.open(filename, 'w+') do |f|
42 f.write Marshal.dump(@results)
55 @results.map {|r| r[:server] }.uniq.sort
59 server_data = @results.find_all { |r| r[:server] == server }
60 ticks = server_data.map { |d| d[:input] }.uniq
63 measurements = server_data.find_all { |d| d[:input] == c }.map { |d| d[:rps] }
64 datas << [c, measurements.avg]
72 attr_reader :name, :port, :app, :pid
73 def initialize(name, port, &start_block)
83 Process.kill('KILL', @pid) if @pid
91 puts "Starting #{name}"
94 @pid = fork { start_emongrel }
97 workers = 1 if workers <= 0
98 @pid = fork { start_ebb(workers) }
100 @pid = fork { start_mongrel }
102 @pid = fork { start_thin }
104 @pid = fork { start_fcgi }
114 require 'swiftcore/evented_mongrel'
116 Rack::Handler::Mongrel.run(app, :Host => '0.0.0.0', :Port => @port.to_i)
119 def start_ebb(workers = 1)
120 require File.dirname(__FILE__) + '/../ruby_lib/ebb'
121 server = Ebb::start_server(app, :port => @port, :workers => workers)
127 Rack::Handler::Mongrel.run(app, :Port => @port)
132 Rack::Handler::Thin.run(app, :Port => @port)
136 Rack::Handler::FastCGI.run(app, :Port => @port)
140 cmd = ab_cmd.sub('PORT', @port.to_s)
142 puts "#{@name} (#{cmd})"
146 return nil unless r =~ /Requests per second:\s*(\d+\.\d\d)/
148 if r =~ /Complete requests:\s*(\d+)/
149 requests_completed = $1.to_i
151 puts " #{rps} req/sec (#{requests_completed} completed)"
156 :requests_completed => requests_completed,