7 require 'swiftcore/evented_mongrel'
15 @headers["X-Served-By"] = URI("http://rack.rubyforge.org")
16 @headers["Content-Type"] = 'text/plain'
17 "Camping works! " * 5000
32 inject(0) { |i, s| s += i }
36 sort_by{ rand }.each &block
42 attr_reader :name, :port, :app
43 def initialize(name, port, &start_block)
46 puts "Starting #{name}"
47 @pid = fork { start_block.call }
56 Process.kill('KILL', @pid)
59 def run_trial(concurrency)
60 print "#{@name} with concurrency #{concurrency}..."
62 r = %x{ab -q -c #{concurrency} -n 1000 http://0.0.0.0:#{@port}/ | grep "Requests per second" }
63 raise "couldn't match rps in #{r.inspect}" unless r =~ /Requests per second:\s*(\d+\.\d\d)/
69 :concurrency => concurrency,
76 def all_tests(dump_file = "./benchmarks.ruby_dump")
78 if File.readable?(dump_file)
79 $results = Marshal.load(File.read(dump_file))
84 app = Rack::Adapter::Camping.new(CampApp)
87 servers << ServerTest.new('evented mongrel', 4001) do
89 Rack::Handler::Mongrel.run(app, :Port => 4001)
92 servers << ServerTest.new('ebb', 4002) do
93 server = Ebb::Server.new(app, :Port => 4002)
97 servers << ServerTest.new('thin', 4003) do
98 Rack::Handler::Thin.run(app, :Port => 4003)
102 ([1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91, 100]*3).rand_each do |concurrency|
103 servers.rand_each do |server|
104 $results << server.run_trial(concurrency)
105 sleep 0.5 # give the other process some time to cool down?
110 puts "killing servers"
111 servers.each { |server| server.kill }
112 unless $results.empty?
113 puts "writing to dump file #{dump_file}"
114 File.open(dump_file, 'w+') do |f|
115 f.write Marshal.dump($results)
124 # server = Ebb::Server.new(app, :Port => 4001)
128 # # Rack::Handler::Mongrel.run(app, :Port => 4002)