blob: bd92bde9d401b2797ab45fe36139ce1ecf56bca6 [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
Kevin Clarkd3cee022008-06-18 01:19:09 +000020$:.unshift File.dirname(__FILE__) + '/../lib'
21require 'thrift'
22require 'thrift/server/nonblockingserver'
23$:.unshift File.dirname(__FILE__) + "/gen-rb"
24require 'BenchmarkService'
25
26class Client
Kevin Clarkfdc9c972008-06-18 01:19:46 +000027 def initialize(host, port, clients_per_process, calls_per_client, log_exceptions)
Kevin Clarkd3cee022008-06-18 01:19:09 +000028 @host = host
29 @port = port
30 @clients_per_process = clients_per_process
31 @calls_per_client = calls_per_client
Kevin Clarkfdc9c972008-06-18 01:19:46 +000032 @log_exceptions = log_exceptions
Kevin Clarkd3cee022008-06-18 01:19:09 +000033 end
34
35 def run
36 @clients_per_process.times do
37 socket = Thrift::Socket.new(@host, @port)
38 transport = Thrift::FramedTransport.new(socket)
39 protocol = Thrift::BinaryProtocol.new(transport)
40 client = ThriftBenchmark::BenchmarkService::Client.new(protocol)
41 begin
Kevin Clarkd2719792008-06-18 01:19:37 +000042 start = Time.now
Kevin Clarkd3cee022008-06-18 01:19:09 +000043 transport.open
Kevin Clarkd2719792008-06-18 01:19:37 +000044 Marshal.dump [:start, start], STDOUT
Kevin Clarkfdc9c972008-06-18 01:19:46 +000045 rescue => e
Kevin Clarkd3cee022008-06-18 01:19:09 +000046 Marshal.dump [:connection_failure, Time.now], STDOUT
Kevin Clarkfdc9c972008-06-18 01:19:46 +000047 print_exception e if @log_exceptions
Kevin Clarkd3cee022008-06-18 01:19:09 +000048 else
Kevin Clarkd2719792008-06-18 01:19:37 +000049 begin
50 @calls_per_client.times do
51 Marshal.dump [:call_start, Time.now], STDOUT
52 client.fibonacci(15)
53 Marshal.dump [:call_end, Time.now], STDOUT
54 end
55 transport.close
56 Marshal.dump [:end, Time.now], STDOUT
Kevin Clarkfdc9c972008-06-18 01:19:46 +000057 rescue Thrift::TransportException => e
Kevin Clarkd2719792008-06-18 01:19:37 +000058 Marshal.dump [:connection_error, Time.now], STDOUT
Kevin Clarkfdc9c972008-06-18 01:19:46 +000059 print_exception e if @log_exceptions
Kevin Clarkd3cee022008-06-18 01:19:09 +000060 end
Kevin Clarkd3cee022008-06-18 01:19:09 +000061 end
62 end
63 end
Kevin Clarkfdc9c972008-06-18 01:19:46 +000064
65 def print_exception(e)
66 STDERR.puts "ERROR: #{e.message}"
67 STDERR.puts "\t#{e.backtrace * "\n\t"}"
68 end
Kevin Clarkd3cee022008-06-18 01:19:09 +000069end
70
Kevin Clarkfdc9c972008-06-18 01:19:46 +000071log_exceptions = true if ARGV[0] == '-log-exceptions' and ARGV.shift
72
Kevin Clarkd3cee022008-06-18 01:19:09 +000073host, port, clients_per_process, calls_per_client = ARGV
74
Kevin Clarkfdc9c972008-06-18 01:19:46 +000075Client.new(host, port.to_i, clients_per_process.to_i, calls_per_client.to_i, log_exceptions).run