Net::SSH performance question.

Discussion in 'Ruby' started by knohr, May 7, 2007.

  1. knohr

    knohr Guest

    I am using Net::SSH to execute scripts on a remote server. The script
    that it executes takes a long time to complete, and dumps allot of
    stuff to stdout. If i allow the script to run as is, this causes ruby
    (on the local machine) to eat up massive amounts of cycles, as it
    parses the stdout. Redirecting the stdout to /dev/null on the remote
    box will fix the performance issue, but will cause me to lose my SSH
    session due to inactivity.

    Is there is a way to optimize the following code, (maybe having STDOUT
    have a low buffer size)?
    keep in mind:
    A: i need ssh session to be persistent
    B: i cannot modify the settings on the server
    C: i really don't want to rewrite the perl script *~2000 lines*
    D: i would prefer that the script does not move past the shell.perl
    line until the script has completed on the remote box.


    Net::SSH.start('foo', :username=>'bar', :password=>'') do |session|
    copy_file(session, '/tmp/file')
    shell = session.shell.sync
    shell.mv ("/tmp/file .")
    shell.perl "test"
    puts "done"
    end
    knohr, May 7, 2007
    #1
    1. Advertising

  2. knohr

    Robert Dober Guest

    On 5/7/07, knohr <> wrote:
    > I am using Net::SSH to execute scripts on a remote server. The script
    > that it executes takes a long time to complete, and dumps allot of
    > stuff to stdout. If i allow the script to run as is, this causes ruby
    > (on the local machine) to eat up massive amounts of cycles, as it
    > parses the stdout. Redirecting the stdout to /dev/null on the remote
    > box will fix the performance issue, but will cause me to lose my SSH
    > session due to inactivity.
    >
    > Is there is a way to optimize the following code, (maybe having STDOUT
    > have a low buffer size)?
    > keep in mind:
    > A: i need ssh session to be persistent
    > B: i cannot modify the settings on the server
    > C: i really don't want to rewrite the perl script *~2000 lines*
    > D: i would prefer that the script does not move past the shell.perl
    > line until the script has completed on the remote box.
    >
    >
    > Net::SSH.start('foo', :username=>'bar', :password=>'') do |session|
    > copy_file(session, '/tmp/file')
    > shell = session.shell.sync
    > shell.mv ("/tmp/file .")
    > shell.perl "test"
    > puts "done"
    > end
    >

    Hmm there is one question I would have? What do you need as
    result/output, if I understood correctly nothing?
    In that case maybe not using shell should help, the following works
    perfectly on my box

    Net::SSH.start( 'localhost' ) do |session|
    session.open_channel do | channel |
    channel.on_data do | ch, data |
    puts data
    end
    channel.exec "find /home/robert -exec ls -ltr {} \\; >/dev/null"
    end
    session.loop
    end

    It waits until the channel is closed.

    HTH
    Robert

    --
    You see things; and you say Why?
    But I dream things that never were; and I say Why not?
    -- George Bernard Shaw
    Robert Dober, May 7, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. loial
    Replies:
    0
    Views:
    385
    loial
    Feb 3, 2009
  2. loial
    Replies:
    0
    Views:
    389
    loial
    Feb 10, 2009
  3. Tench Johnson
    Replies:
    1
    Views:
    276
    Biff Tannen
    Apr 23, 2010
  4. salamond

    net/ssh in ruby. ssh.exec fails

    salamond, Feb 17, 2011, in forum: Ruby
    Replies:
    0
    Views:
    221
    salamond
    Feb 17, 2011
  5. Replies:
    0
    Views:
    79
Loading...

Share This Page