Skip to content

Instantly share code, notes, and snippets.

@hdenman
Last active September 6, 2017 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdenman/b714d42367d1e29f8567e15af0a1bb87 to your computer and use it in GitHub Desktop.
Save hdenman/b714d42367d1e29f8567e15af0a1bb87 to your computer and use it in GitHub Desktop.
Quick-n-dirty Ruby popen3 ssh benchmark
bytes_read = 0
cmd = "ssh -i #{key_file} #{user}@#{ip} 'base64 /dev/urandom'"
Open3.popen3(cmd) do |i, o, e, t| # (in, out, error, monitor thread)
begin
Timeout.timeout(120) do
while readables = IO.select([o, e])[0]
readables.each{|r|
if r == o
dump = ""
begin
o.read_nonblock(4096, dump)
rescue IO::WaitReadable
ensure
bytes_read += dump.length
end
end
if r == e
dump = ""
begin
e.read_nonblock(4096, dump)
rescue IO::WaitReadable
ensure
puts(dump)
end
end
}
end
Process.wait t.pid
end
rescue Timeout::Error => ex
Process.kill 9, t.pid
end
end
puts "run_ssh: " + bytes_read.to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment