Class: RPCBench::Client
- Inherits:
-
Object
- Object
- RPCBench::Client
- Defined in:
- lib/rpc_bench/client.rb
Instance Method Summary collapse
-
#initialize(opts) ⇒ Client
constructor
A new instance of Client.
- #run ⇒ Object
- #validate?(results) ⇒ Boolean
Constructor Details
#initialize(opts) ⇒ Client
Returns a new instance of Client.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rpc_bench/client.rb', line 3 def initialize(opts) @bench_conc = opts[:conc] @bench_num = opts[:num] case opts[:mode] when 'rabbitmq' @driver = RabbitMQ::Client.new opts when 'grpc' @driver = GRPC::Client.new opts when 'zeromq' @driver = ZeroMQ::Client.new opts when 'stomp' @driver = Stomp::Client.new opts else raise RuntimeError.new("failed to initialize driver of '#{opts[:mode]}'") end end |
Instance Method Details
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rpc_bench/client.rb', line 25 def run t_start = Time.now threads = [] (1..@bench_conc).each do |x| threads << Thread.new do @driver.send(1, @bench_num) end end results = threads.map(&:value).flatten unless(validate? results) puts "[error] failed to get accurate result" end @driver.close t_end = Time.now puts "Time: #{t_end - t_start}" end |
#validate?(results) ⇒ Boolean
21 22 23 |
# File 'lib/rpc_bench/client.rb', line 21 def validate? results results.all? {|x| x == 2} end |