mina-sshd icon indicating copy to clipboard operation
mina-sshd copied to clipboard

Time taking more to open a channel and close a channel.

Open VijayJoinGitHub opened this issue 1 year ago • 2 comments

Version

2.9.2

Bug description

  1.  channel.open(); // takes time , around 579 milli seconds
    
  2. channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED),
    TimeUnit.SECONDS.toMillis(0)); // takes around 287 milli seconds.

In our case for a task completion we run 7 commands so each time 579 + 287 = 866 milli seconds for 7 times almost 6 seconds which is very much delay to display information for front end. attaching a sample code.


import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.security.KeyPair; import java.util.Collection; import java.util.EnumSet; import java.util.Set; import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit;

import org.apache.sshd.client.SshClient; import org.apache.sshd.client.auth.keyboard.UserInteraction; import org.apache.sshd.client.channel.ChannelExec; import org.apache.sshd.client.channel.ClientChannel; import org.apache.sshd.client.channel.ClientChannelEvent; import org.apache.sshd.client.future.AuthFuture; import org.apache.sshd.client.future.ConnectFuture; import org.apache.sshd.client.future.OpenFuture; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.channel.Channel; import org.apache.sshd.common.session.Session; import org.apache.sshd.common.util.io.output.NoCloseOutputStream;

public class SshUtilstest4 {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    SshClient client = SshClient.setUpDefaultClient();
    String command = "uname -a";
    try {
        // Open the client
        client.start();
        long defaultTimeout = 3600;
        try (ClientSession session = client.connect("root", hostname, 22).verify(defaultTimeout, TimeUnit.SECONDS).getSession()) {
            session.addPasswordIdentity("password");
            session.auth().verify(defaultTimeout, TimeUnit.SECONDS);
            try (ByteArrayOutputStream responseStream = new ByteArrayOutputStream(); ByteArrayOutputStream errorStream = new ByteArrayOutputStream();) { // to execute remote commands                   
                ChannelExec channel = session.createExecChannel(command + "\\n");
                channel.setOut(responseStream);
                channel.setErr(errorStream);

                long start = System.currentTimeMillis();
                channel.open().await(); //.verify(defaultTimeout, TimeUnit.SECONDS);
                long end = System.currentTimeMillis();
                System.out.println("Time take to to open a channel in milli seconds=" + (end - start));

                System.out.println("-------------------------------");

                /*
              try (OutputStream pipedIn = channel2.getInvertedIn()) {
                  pipedIn.write(command.getBytes("UTF-8"));
                  pipedIn.flush();
              } catch (Exception e) {
 				// TODO Auto-generated catch block
 				e.printStackTrace();
 			}*/
                System.out.println("Before to close channel responseStream=" + responseStream);

                long start2 = System.currentTimeMillis();
                channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED),
                    TimeUnit.SECONDS.toMillis(0));
                long end2 = System.currentTimeMillis();
                System.out.println("Time take to close the channel by server in milli seconds =" + (end2 - start2));
                System.out.println("After closing the channel responseStream22=" + responseStream);
                // return responseStream.toString();                   
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

}


out put : Time take to to open a channel in milli seconds=579

Before to close channel responseStream= Time take to close the channel by server in milli seconds =287 After closing the channel responseStream22=Linux sudheer-rhel7 3.10.0-1160.90.1.el7.x86_64 #1 SMP Fri Mar 17 08:39:44 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Actual behavior

is this expected behaviour ? Are we missing any input like ptyconfiguration if yes could you please provide me example .

Expected behavior

If this is existing behaviour could you please make this better . previously we are using ganymede which is very much fast total 7 commands can be run in 1 or 1+ seconds only , But with apache mina sshd is takes almost 6 seconds which is time consuming one for us. apachemina-sshd

Relevant log output

No response

Other information

No response

VijayJoinGitHub avatar Jul 07 '23 11:07 VijayJoinGitHub

Please let us know if you need any more information on this. I think the sample programs tells that those two lines taking more.

Thank you in advance.

VijayJoinGitHub avatar Jul 07 '23 15:07 VijayJoinGitHub

Hi, We used streaming with producer consumer concept then commands execution and response is fast enough.

thank you.

VijayJoinGitHub avatar Jul 28 '23 06:07 VijayJoinGitHub