Forum: Ruby Measuring Network Latency

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8ca6a4ea7ae6e5c065a02ab18e7d4998?d=identicon&s=25 Brian Mac (Guest)
on 2009-01-30 22:41
(Received via mailing list)
i'm looking for ideas of measuring network latency with ruby.  i can't
reliably use net::ping because rdp (remote desktop protocol) traffic
is being prioritized.  i thought i could use Net::PingTCP and get the
duration but users in a remote office are complaining of network
latency when i'm just not seeing it from the code below (even when
using a high count).

here is the the code that i'm working with.  any help or suggestions
would be much appreciated.


$endpoints = {"Office Name" => 'some.ip.address.here'}

def self.latency_summary(ping_count=50)
  $endpoints.sort.each do |k,v|
    sum = 0
    results = Array.new
    ping_count.times {
      p = Net::PingTCP.new(v, 3389)
      p.ping
      results << p.duration
    }

    results.each do |num|
      sum += num
    end

    puts "Avg/Max/Min response time to #{k} for #{ping_count.to_s} TCP
pings: #{(sum/results.length)}.sec / #{results.max}sec / #{results.min}
sec"
  end
end
This topic is locked and can not be replied to.