I'm in ruby on rails and using the net-ssh gem to ssh into another machine, run some scripts, get the output of the scripts back into rails, then serve that output on my site. This will need to happen a lot, in fact it is the core of my site.
The script itself takes very little time, but the time to response ranges between instant to 15 seconds. The SSH handshake is taking variable time.
Here's my ruby code to do the ssh:
res = []
Net::SSH.start( host, user, :password => pass ) do |ssh|
# execute container
ssh.exec("run script") do |ch, stream, data|
res.push(data)
end
end
res = res.join("")
render text: res
Any idea for how to make this super fast?
I'm wondering if I should be keeping an ssh connection open at all times and add new threads every time I need to run the script (which will be a lot). I've seen people talk about ControlMaster, but not sure how to make that work.