Sha256: 0171a26a6b0214b84e8e657d80b12501c28d90fd95a34c08d6901ea076c4b44a

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

require 'rubygems'
require 'ffi-rzmq'

if ARGV.length < 3
  puts "usage: local_lat <connect-to> <message-size> <roundtrip-count>"
  exit
end

link = ARGV[0]
message_size = ARGV[1].to_i
roundtrip_count = ARGV[2].to_i

#link = "tcp://127.0.0.1:5555"

ctx = ZMQ::Context.new
s1 = ctx.socket ZMQ::REQ
s2 = ctx.socket ZMQ::REP

s1.connect link
s2.bind link

poller = ZMQ::Poller.new
poller.register_readable s2
poller.register_readable s1


start_time = Time.now

# kick it off
message = ZMQ::Message.new("a" * message_size)
s1.send message, ZMQ::NOBLOCK
i = roundtrip_count

until i.zero?
  i -= 1
  
  begin
    poller.poll_nonblock
  rescue ZMQ::PollError => e
    puts "efault? [#{e.efault?}]"
    raise
  end

  poller.readables.each do |socket|
    received_message = socket.recv_string ZMQ::NOBLOCK
    socket.send ZMQ::Message.new(received_message), ZMQ::NOBLOCK
  end  
end

elapsed_usecs = (Time.now.to_f - start_time.to_f) * 1_000_000
latency = elapsed_usecs / roundtrip_count / 2

puts "mean latency: %.3f [us]" % latency
puts "received all messages in %.3f seconds" % (elapsed_usecs / 1_000_000)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ffi-rzmq-0.8.2 examples/local_lat_poll.rb
ffi-rzmq-0.8.0 examples/local_lat_poll.rb
ffi-rzmq-0.7.2 examples/local_lat_poll.rb
ffi-rzmq-0.7.1 examples/local_lat_poll.rb
ffi-rzmq-0.7.0 examples/local_lat_poll.rb