blob: d5de8e7d27640f4f705e064bdc4406076a2b80a3 [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
8 def initialize(host, port, clients_per_process, calls_per_client)
9 @host = host
10 @port = port
11 @clients_per_process = clients_per_process
12 @calls_per_client = calls_per_client
13 end
14
15 def run
16 @clients_per_process.times do
17 socket = Thrift::Socket.new(@host, @port)
18 transport = Thrift::FramedTransport.new(socket)
19 protocol = Thrift::BinaryProtocol.new(transport)
20 client = ThriftBenchmark::BenchmarkService::Client.new(protocol)
21 begin
Kevin Clarkd2719792008-06-18 01:19:37 +000022 start = Time.now
Kevin Clarkd3cee022008-06-18 01:19:09 +000023 transport.open
Kevin Clarkd2719792008-06-18 01:19:37 +000024 Marshal.dump [:start, start], STDOUT
Kevin Clarkd3cee022008-06-18 01:19:09 +000025 rescue
26 Marshal.dump [:connection_failure, Time.now], STDOUT
27 else
Kevin Clarkd2719792008-06-18 01:19:37 +000028 begin
29 @calls_per_client.times do
30 Marshal.dump [:call_start, Time.now], STDOUT
31 client.fibonacci(15)
32 Marshal.dump [:call_end, Time.now], STDOUT
33 end
34 transport.close
35 Marshal.dump [:end, Time.now], STDOUT
36 rescue Thrift::TransportException
37 Marshal.dump [:connection_error, Time.now], STDOUT
Kevin Clarkd3cee022008-06-18 01:19:09 +000038 end
Kevin Clarkd3cee022008-06-18 01:19:09 +000039 end
40 end
41 end
42end
43
44host, port, clients_per_process, calls_per_client = ARGV
45
46Client.new(host, port.to_i, clients_per_process.to_i, calls_per_client.to_i).run