Author: kclark
Date: Tue Jun 17 18:19:46 2008
New Revision: 669033

URL: http://svn.apache.org/viewvc?rev=669033&view=rev
Log:
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

Modified:
    incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb
    incubator/thrift/trunk/lib/rb/benchmark/client.rb
    incubator/thrift/trunk/lib/rb/benchmark/server.rb

Modified: incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb?rev=669033&r1=669032&r2=669033&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb (original)
+++ incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb Tue Jun 17 18:19:46 
2008
@@ -30,7 +30,7 @@
     args = (File.basename(@interpreter) == "jruby" ? "-J-server" : "")
     @pipe = IO.popen("[EMAIL PROTECTED] #{args} 
#{File.dirname(__FILE__)}/server.rb [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL 
PROTECTED]", "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("[EMAIL PROTECTED] #{File.dirname(__FILE__)}/client.rb 
[EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED]")
+    pipe = IO.popen("[EMAIL PROTECTED] #{File.dirname(__FILE__)}/client.rb 
#{"-log-exceptions" if @log_exceptions} [EMAIL PROTECTED] [EMAIL PROTECTED] 
[EMAIL PROTECTED] [EMAIL PROTECTED]")
     @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

Modified: incubator/thrift/trunk/lib/rb/benchmark/client.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/benchmark/client.rb?rev=669033&r1=669032&r2=669033&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/benchmark/client.rb (original)
+++ incubator/thrift/trunk/lib/rb/benchmark/client.rb Tue Jun 17 18:19:46 2008
@@ -5,11 +5,12 @@
 require 'BenchmarkService'
 
 class Client
-  def initialize(host, port, clients_per_process, calls_per_client)
+  def initialize(host, port, clients_per_process, calls_per_client, 
log_exceptions)
     @host = host
     @port = port
     @clients_per_process = clients_per_process
     @calls_per_client = calls_per_client
+    @log_exceptions = log_exceptions
   end
 
   def run
@@ -22,8 +23,9 @@
         start = Time.now
         transport.open
         Marshal.dump [:start, start], STDOUT
-      rescue
+      rescue => e
         Marshal.dump [:connection_failure, Time.now], STDOUT
+        print_exception e if @log_exceptions
       else
         begin
           @calls_per_client.times do
@@ -33,14 +35,22 @@
           end
           transport.close
           Marshal.dump [:end, Time.now], STDOUT
-        rescue Thrift::TransportException
+        rescue Thrift::TransportException => e
           Marshal.dump [:connection_error, Time.now], STDOUT
+          print_exception e if @log_exceptions
         end
       end
     end
   end
+
+  def print_exception(e)
+    STDERR.puts "ERROR: #{e.message}"
+    STDERR.puts "\t#{e.backtrace * "\n\t"}"
+  end
 end
 
+log_exceptions = true if ARGV[0] == '-log-exceptions' and ARGV.shift
+
 host, port, clients_per_process, calls_per_client = ARGV
 
-Client.new(host, port.to_i, clients_per_process.to_i, 
calls_per_client.to_i).run
+Client.new(host, port.to_i, clients_per_process.to_i, calls_per_client.to_i, 
log_exceptions).run

Modified: incubator/thrift/trunk/lib/rb/benchmark/server.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/benchmark/server.rb?rev=669033&r1=669032&r2=669033&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/benchmark/server.rb (original)
+++ incubator/thrift/trunk/lib/rb/benchmark/server.rb Tue Jun 17 18:19:46 2008
@@ -50,15 +50,15 @@
   const and const.split('::').inject(Object) { |k,c| k.const_get(c) }
 end
 
+host, port, serverklass = ARGV
+
+Server.start_server(host, port.to_i, resolve_const(serverklass))
+
 # let our host know that the interpreter has started
 # ideally we'd wait until the server was serving, but we don't have a hook for 
that
 Marshal.dump(:started, STDOUT)
 STDOUT.flush
 
-host, port, serverklass = ARGV
-
-Server.start_server(host, port.to_i, resolve_const(serverklass))
-
 Marshal.load(STDIN) # wait until we're instructed to shut down
 
 Server.shutdown


Reply via email to