You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by kc...@apache.org on 2008/06/18 03:19:37 UTC

svn commit: r669031 - in /incubator/thrift/trunk/lib/rb/benchmark: benchmark.rb client.rb

Author: kclark
Date: Tue Jun 17 18:19:37 2008
New Revision: 669031

URL: http://svn.apache.org/viewvc?rev=669031&view=rev
Log:
rb: Catch TransportException errors during the benchmark and report them

Modified:
    incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb
    incubator/thrift/trunk/lib/rb/benchmark/client.rb

Modified: incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb?rev=669031&r1=669030&r2=669031&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb (original)
+++ incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb Tue Jun 17 18:19:37 2008
@@ -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]

Modified: incubator/thrift/trunk/lib/rb/benchmark/client.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/benchmark/client.rb?rev=669031&r1=669030&r2=669031&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/benchmark/client.rb (original)
+++ incubator/thrift/trunk/lib/rb/benchmark/client.rb Tue Jun 17 18:19:37 2008
@@ -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