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/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