Time taking more to open a channel and close a channel.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 400
- Avg merge
- 5d 1h
- Merged PRs (30d)
- 1
Description
### 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.

### Relevant log output
_No response_
### Other information
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.