blob: af05117fea98a42fd5d6b649aee428aa2b89bd7c [file] [log] [blame]
Kevin Clarkd3cee022008-06-18 01:19:09 +00001$:.unshift File.dirname(__FILE__) + '/../lib'
2require 'thrift'
3require 'thrift/server/nonblockingserver'
4$:.unshift File.dirname(__FILE__) + "/gen-rb"
5require 'BenchmarkService'
6
7class Client
Kevin Clarkfdc9c972008-06-18 01:19:46 +00008 def initialize(host, port, clients_per_process, calls_per_client, log_exceptions)
Kevin Clarkd3cee022008-06-18 01:19:09 +00009 @host = host
10 @port = port
11 @clients_per_process = clients_per_process
12 @calls_per_client = calls_per_client
Kevin Clarkfdc9c972008-06-18 01:19:46 +000013 @log_exceptions = log_exceptions
Kevin Clarkd3cee022008-06-18 01:19:09 +000014 end
15
16 def run
17 @clients_per_process.times do
18 socket = Thrift::Socket.new(@host, @port)
19 transport = Thrift::FramedTransport.new(socket)
20 protocol = Thrift::BinaryProtocol.new(transport)
21 client = ThriftBenchmark::BenchmarkService::Client.new(protocol)
22 begin
Kevin Clarkd2719792008-06-18 01:19:37 +000023 start = Time.now
Kevin Clarkd3cee022008-06-18 01:19:09 +000024 transport.open
Kevin Clarkd2719792008-06-18 01:19:37 +000025 Marshal.dump [:start, start], STDOUT
Kevin Clarkfdc9c972008-06-18 01:19:46 +000026 rescue => e
Kevin Clarkd3cee022008-06-18 01:19:09 +000027 Marshal.dump [:connection_failure, Time.now], STDOUT
Kevin Clarkfdc9c972008-06-18 01:19:46 +000028 print_exception e if @log_exceptions
Kevin Clarkd3cee022008-06-18 01:19:09 +000029 else
Kevin Clarkd2719792008-06-18 01:19:37 +000030 begin
31 @calls_per_client.times do
32 Marshal.dump [:call_start, Time.now], STDOUT
33 client.fibonacci(15)
34 Marshal.dump [:call_end, Time.now], STDOUT
35 end
36 transport.close
37 Marshal.dump [:end, Time.now], STDOUT
Kevin Clarkfdc9c972008-06-18 01:19:46 +000038 rescue Thrift::TransportException => e
Kevin Clarkd2719792008-06-18 01:19:37 +000039 Marshal.dump [:connection_error, Time.now], STDOUT
Kevin Clarkfdc9c972008-06-18 01:19:46 +000040 print_exception e if @log_exceptions
Kevin Clarkd3cee022008-06-18 01:19:09 +000041 end
Kevin Clarkd3cee022008-06-18 01:19:09 +000042 end
43 end
44 end
Kevin Clarkfdc9c972008-06-18 01:19:46 +000045
46 def print_exception(e)
47 STDERR.puts "ERROR: #{e.message}"
48 STDERR.puts "\t#{e.backtrace * "\n\t"}"
49 end
Kevin Clarkd3cee022008-06-18 01:19:09 +000050end
51
Kevin Clarkfdc9c972008-06-18 01:19:46 +000052log_exceptions = true if ARGV[0] == '-log-exceptions' and ARGV.shift
53
Kevin Clarkd3cee022008-06-18 01:19:09 +000054host, port, clients_per_process, calls_per_client = ARGV
55
Kevin Clarkfdc9c972008-06-18 01:19:46 +000056Client.new(host, port.to_i, clients_per_process.to_i, calls_per_client.to_i, log_exceptions).run