rb: Catch TransportException errors during the benchmark and report them
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@669031 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/benchmark/benchmark.rb b/lib/rb/benchmark/benchmark.rb
index e6a1a3b..327be6a 100644
--- a/lib/rb/benchmark/benchmark.rb
+++ b/lib/rb/benchmark/benchmark.rb
@@ -125,6 +125,7 @@
call_times = []
client_times = []
connection_failures = []
+ connection_errors = []
shortest_call = 0
shortest_client = 0
longest_call = 0
@@ -151,6 +152,8 @@
cur_client = nil
when :connection_failure
connection_failures << time
+ when :connection_error
+ connection_errors << time
end
end
end
@@ -160,6 +163,7 @@
@report[:total_clients] = client_times.inject(0.0) { |a,t| a += t }
@report[:avg_clients] = @report[:total_clients] / client_times.size
@report[:connection_failures] = connection_failures.size
+ @report[:connection_errors] = connection_errors.size
@report[:shortest_call] = shortest_call
@report[:shortest_client] = shortest_client
@report[:longest_call] = longest_call
@@ -183,7 +187,8 @@
puts
failures = (@report[:connection_failures] > 0)
tabulate fmt,
- [["Connection failures", "%d", *(failures ? [[:red, :bold]] : [])], @report[:connection_failures]],
+ [["Connection failures", "%d", [:red, :bold]], @report[:connection_failures]],
+ [["Connection errors", "%d", [:red, :bold]], @report[:connection_errors]],
["Average time per call", @report[:avg_calls]],
["Average time per client (%d calls)" % @calls_per_client, @report[:avg_clients]],
["Total time for all calls", @report[:total_calls]],
@@ -214,7 +219,7 @@
f = fmt
l, f, c = l if Array === l
fmtstr = "%-#{label_width+1}s #{f}"
- if STDOUT.tty? and c
+ if STDOUT.tty? and c and v.to_i > 0
fmtstr = "\e[#{[*c].map { |x| ANSI[x] } * ";"}m" + fmtstr + "\e[#{ANSI[:reset]}m"
end
puts fmtstr % [l+":", v]
diff --git a/lib/rb/benchmark/client.rb b/lib/rb/benchmark/client.rb
index e8d3351..d5de8e7 100644
--- a/lib/rb/benchmark/client.rb
+++ b/lib/rb/benchmark/client.rb
@@ -19,18 +19,23 @@
protocol = Thrift::BinaryProtocol.new(transport)
client = ThriftBenchmark::BenchmarkService::Client.new(protocol)
begin
+ start = Time.now
transport.open
+ Marshal.dump [:start, start], STDOUT
rescue
Marshal.dump [:connection_failure, Time.now], STDOUT
else
- Marshal.dump [:start, Time.now], STDOUT
- @calls_per_client.times do
- Marshal.dump [:call_start, Time.now], STDOUT
- client.fibonacci(15)
- Marshal.dump [:call_end, Time.now], STDOUT
+ begin
+ @calls_per_client.times do
+ Marshal.dump [:call_start, Time.now], STDOUT
+ client.fibonacci(15)
+ Marshal.dump [:call_end, Time.now], STDOUT
+ end
+ transport.close
+ Marshal.dump [:end, Time.now], STDOUT
+ rescue Thrift::TransportException
+ Marshal.dump [:connection_error, Time.now], STDOUT
end
- transport.close
- Marshal.dump [:end, Time.now], STDOUT
end
end
end