blob: 703dc8f52144d0b5b0c80e353dfecf58a9205bfc [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'
Kevin Clarkd3cee022008-06-18 01:19:09 +000022$:.unshift File.dirname(__FILE__) + "/gen-rb"
Bryan Duxbury0bbef922009-04-07 22:23:40 +000023require 'benchmark_service'
Kevin Clarkd3cee022008-06-18 01:19:09 +000024
25class Client
Kevin Clarkfdc9c972008-06-18 01:19:46 +000026 def initialize(host, port, clients_per_process, calls_per_client, log_exceptions)
Kevin Clarkd3cee022008-06-18 01:19:09 +000027 @host = host
28 @port = port
29 @clients_per_process = clients_per_process
30 @calls_per_client = calls_per_client
Kevin Clarkfdc9c972008-06-18 01:19:46 +000031 @log_exceptions = log_exceptions
Kevin Clarkd3cee022008-06-18 01:19:09 +000032 end
33
34 def run
35 @clients_per_process.times do
36 socket = Thrift::Socket.new(@host, @port)
37 transport = Thrift::FramedTransport.new(socket)
38 protocol = Thrift::BinaryProtocol.new(transport)
39 client = ThriftBenchmark::BenchmarkService::Client.new(protocol)
40 begin
Kevin Clarkd2719792008-06-18 01:19:37 +000041 start = Time.now
Kevin Clarkd3cee022008-06-18 01:19:09 +000042 transport.open
Kevin Clarkd2719792008-06-18 01:19:37 +000043 Marshal.dump [:start, start], STDOUT
Kevin Clarkfdc9c972008-06-18 01:19:46 +000044 rescue => e
Kevin Clarkd3cee022008-06-18 01:19:09 +000045 Marshal.dump [:connection_failure, Time.now], STDOUT
Kevin Clarkfdc9c972008-06-18 01:19:46 +000046 print_exception e if @log_exceptions
Kevin Clarkd3cee022008-06-18 01:19:09 +000047 else
Kevin Clarkd2719792008-06-18 01:19:37 +000048 begin
49 @calls_per_client.times do
50 Marshal.dump [:call_start, Time.now], STDOUT
51 client.fibonacci(15)
52 Marshal.dump [:call_end, Time.now], STDOUT
53 end
54 transport.close
55 Marshal.dump [:end, Time.now], STDOUT
Kevin Clarkfdc9c972008-06-18 01:19:46 +000056 rescue Thrift::TransportException => e
Kevin Clarkd2719792008-06-18 01:19:37 +000057 Marshal.dump [:connection_error, Time.now], STDOUT
Kevin Clarkfdc9c972008-06-18 01:19:46 +000058 print_exception e if @log_exceptions
Kevin Clarkd3cee022008-06-18 01:19:09 +000059 end
Kevin Clarkd3cee022008-06-18 01:19:09 +000060 end
61 end
62 end
Kevin Clarkfdc9c972008-06-18 01:19:46 +000063
64 def print_exception(e)
65 STDERR.puts "ERROR: #{e.message}"
66 STDERR.puts "\t#{e.backtrace * "\n\t"}"
67 end
Kevin Clarkd3cee022008-06-18 01:19:09 +000068end
69
Kevin Clarkfdc9c972008-06-18 01:19:46 +000070log_exceptions = true if ARGV[0] == '-log-exceptions' and ARGV.shift
71
Kevin Clarkd3cee022008-06-18 01:19:09 +000072host, port, clients_per_process, calls_per_client = ARGV
73
Kevin Clarkfdc9c972008-06-18 01:19:46 +000074Client.new(host, port.to_i, clients_per_process.to_i, calls_per_client.to_i, log_exceptions).run