Skip to content

Instantly share code, notes, and snippets.

@sgoings
Created November 17, 2010 20:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgoings/703966 to your computer and use it in GitHub Desktop.
Save sgoings/703966 to your computer and use it in GitHub Desktop.
Rspec Tests for SCP upload transfer performance
require 'net/scp'
describe Net::SCP do
def analyze(filename)
file_size = (File.size(filename)/(1024*1024))
puts "Starting transfer of #{filename}"
start_time = Time.now
yield filename
duration = Time.now - start_time
puts "Finished transfer of #{filename}"
puts "--> Duration: #{duration} seconds (#{(file_size)/duration} megabytes/s)"
end
before(:all) do
hostname = "9.17.164.151"
user = "root"
password = "passw0rd"
@scp = Net::SCP.start(hostname, user, {:password => password})
@scp2 = Net::SCP.start(hostname, user, {:password => password})
puts "Done creating channels"
@filename = "/home/seth/afpcases/systeme.afp"
@remote_path = "/home/seth"
@remote_path2 = "/home/seth/test"
end
it "should show transfer speed of serial uploads" do
analyze(@filename) do
|file|
@scp.upload!(file, @remote_path)
@scp.upload!(file, @remote_path2)
end
end
it "should show transfer speed of simultaneous async channels" do
channels = []
analyze(@filename) do
|file|
channels << @scp.upload(file, @remote_path)
channels << @scp.upload(file, @remote_path2)
channels.each { |ch| ch.wait }
end
end
it "should show transfer speed of simultaneous SCP instances" do
channels = []
analyze(@filename) do
|file|
channels << @scp.upload(file, @remote_path)
channels << @scp2.upload(file, @remote_path2)
channels.each { |ch| ch.wait }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment