rb: Increase the benchmark startup time and add more hooks

You can now control the number of clients per proc and calls per client with THRIFT_NUM_CALLS and THRIFT_NUM_CLIENTS.
You can also instruct the clients to log exceptions with THRIFT_LOG_EXCEPTIONS=yes


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@669033 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/benchmark/benchmark.rb b/lib/rb/benchmark/benchmark.rb
index 1adc73d..da0c414 100644
--- a/lib/rb/benchmark/benchmark.rb
+++ b/lib/rb/benchmark/benchmark.rb
@@ -30,7 +30,7 @@
     args = (File.basename(@interpreter) == "jruby" ? "-J-server" : "")
     @pipe = IO.popen("#{@interpreter} #{args} #{File.dirname(__FILE__)}/server.rb #{@host} #{@port} #{@serverclass.name}", "r+")
     Marshal.load(@pipe) # wait until the server has started
-    sleep 0.2 # give the server time to actually start spawning sockets
+    sleep 0.4 # give the server time to actually start spawning sockets
   end
 
   def shutdown
@@ -57,6 +57,7 @@
     @calls_per_client = opts.fetch(:calls_per_client, 50)
     @interpreter = opts.fetch(:interpreter, "ruby")
     @server = server
+    @log_exceptions = opts.fetch(:log_exceptions, false)
   end
 
   def run
@@ -65,7 +66,7 @@
     puts "Spawning benchmark processes..."
     @num_processes.times do
       spawn
-      sleep 0.01 # space out spawns
+      sleep 0.02 # space out spawns
     end
     collect_output
     @benchmark_end = Time.now # we know the procs are done here
@@ -75,7 +76,7 @@
   end
 
   def spawn
-    pipe = IO.popen("#{@interpreter} #{File.dirname(__FILE__)}/client.rb #{@host} #{@port} #{@clients_per_process} #{@calls_per_client}")
+    pipe = IO.popen("#{@interpreter} #{File.dirname(__FILE__)}/client.rb #{"-log-exceptions" if @log_exceptions} #{@host} #{@port} #{@clients_per_process} #{@calls_per_client}")
     @pool << pipe
   end
 
@@ -238,8 +239,11 @@
 server = Server.new(args)
 server.start
 
-args = { :num_processes => 40, :clients_per_process => 5, :host => HOST, :port => PORT }
+args = { :num_processes => 40, :host => HOST, :port => PORT }
+args[:clients_per_process] = (ENV['THRIFT_NUM_CLIENTS'] || 5).to_i
+args[:calls_per_client] = (ENV['THRIFT_NUM_CALLS'] || 50).to_i
 args[:interpreter] = ENV['THRIFT_CLIENT_INTERPRETER'] || ENV['THRIFT_INTERPRETER'] || "ruby"
+args[:log_exceptions] = !!ENV['THRIFT_LOG_EXCEPTIONS']
 BenchmarkManager.new(args, server).run
 
 server.shutdown