From: Kevin Clark Date: Wed, 18 Jun 2008 01:19:46 +0000 (+0000) Subject: rb: Increase the benchmark startup time and add more hooks X-Git-Tag: 0.2.0~518 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=fdc9c976f9d219ee693674fe6a45fafe21796ac4;p=common%2Fthrift.git 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 1adc73d2..da0c4143 100644 --- a/lib/rb/benchmark/benchmark.rb +++ b/lib/rb/benchmark/benchmark.rb @@ -30,7 +30,7 @@ class Server 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 @@ class BenchmarkManager @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 @@ class BenchmarkManager 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 @@ class BenchmarkManager 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 @@ args[:class] = resolve_const(ENV['THRIFT_SERVER']) || Thrift::NonblockingServer 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 d5de8e7d..af05117f 100644 --- a/lib/rb/benchmark/client.rb +++ b/lib/rb/benchmark/client.rb @@ -5,11 +5,12 @@ $:.unshift File.dirname(__FILE__) + "/gen-rb" 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 @@ class Client 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 @@ class Client 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 5162ac23..37e33584 100644 --- a/lib/rb/benchmark/server.rb +++ b/lib/rb/benchmark/server.rb @@ -50,15 +50,15 @@ def resolve_const(const) 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