Kevin Clark | d3cee02 | 2008-06-18 01:19:09 +0000 | [diff] [blame^] | 1 | $:.unshift File.dirname(__FILE__) + '/../lib' |
| 2 | require 'thrift' |
| 3 | require 'thrift/server/nonblockingserver' |
| 4 | $:.unshift File.dirname(__FILE__) + "/gen-rb" |
| 5 | require 'BenchmarkService' |
| 6 | |
| 7 | class 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 |
| 22 | transport.open |
| 23 | rescue |
| 24 | Marshal.dump [:connection_failure, Time.now], STDOUT |
| 25 | else |
| 26 | Marshal.dump [:start, Time.now], STDOUT |
| 27 | @calls_per_client.times do |
| 28 | Marshal.dump [:call_start, Time.now], STDOUT |
| 29 | client.fibonacci(15) |
| 30 | Marshal.dump [:call_end, Time.now], STDOUT |
| 31 | end |
| 32 | transport.close |
| 33 | Marshal.dump [:end, Time.now], STDOUT |
| 34 | end |
| 35 | end |
| 36 | end |
| 37 | end |
| 38 | |
| 39 | host, port, clients_per_process, calls_per_client = ARGV |
| 40 | |
| 41 | Client.new(host, port.to_i, clients_per_process.to_i, calls_per_client.to_i).run |