From d271979bf23cde196fa5f6360240cdb987a72ce8 Mon Sep 17 00:00:00 2001 From: Kevin Clark Date: Wed, 18 Jun 2008 01:19:37 +0000 Subject: [PATCH] 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 --- lib/rb/benchmark/benchmark.rb | 9 +++++++-- lib/rb/benchmark/client.rb | 19 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/rb/benchmark/benchmark.rb b/lib/rb/benchmark/benchmark.rb index e6a1a3b5..327be6ad 100644 --- a/lib/rb/benchmark/benchmark.rb +++ b/lib/rb/benchmark/benchmark.rb @@ -125,6 +125,7 @@ class BenchmarkManager call_times = [] client_times = [] connection_failures = [] + connection_errors = [] shortest_call = 0 shortest_client = 0 longest_call = 0 @@ -151,6 +152,8 @@ class BenchmarkManager cur_client = nil when :connection_failure connection_failures << time + when :connection_error + connection_errors << time end end end @@ -160,6 +163,7 @@ class BenchmarkManager @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 @@ class BenchmarkManager 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 @@ class BenchmarkManager 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 e8d33515..d5de8e7d 100644 --- a/lib/rb/benchmark/client.rb +++ b/lib/rb/benchmark/client.rb @@ -19,18 +19,23 @@ class Client 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 -- 2.17.1