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
diff --git a/lib/rb/benchmark/client.rb b/lib/rb/benchmark/client.rb
index d5de8e7..af05117 100644
--- a/lib/rb/benchmark/client.rb
+++ b/lib/rb/benchmark/client.rb
@@ -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
diff --git a/lib/rb/benchmark/server.rb b/lib/rb/benchmark/server.rb
index 5162ac2..37e3358 100644
--- a/lib/rb/benchmark/server.rb
+++ b/lib/rb/benchmark/server.rb
@@ -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