Thread: [JSch-users] Optimizing JSch SSH Shell IO Performance
Status: Alpha
Brought to you by:
ymnk
From: William B. <wba...@gm...> - 2011-02-16 02:35:00
|
This is in regards to shell mode. I wish to be able to optimize performance, mainly in regards to receiving data back from the output stream. This is code I have cobbled together from examples. It reads both STDIN and STDERR. I assume the only way to optimize would be to decrease the thread wait time on reading from the channels. But, maybe someone has done performance optimization and has some insights that I may be missing. Code snippet: out = channel.getOutputStream(); in = channel.getInputStream(); err = channel.getExtInputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); out.write(command.getBytes()); out.flush(); . . . private static String send(InputStream in, InputStream err, byte[] buffer, ByteArrayOutputStream bos, ChannelShell channel){ int exitStatus = 0; try { final long endTime = System.currentTimeMillis() + TIMEOUT; while (System.currentTimeMillis() < endTime) { while (in.available() > 0) { int count = in.read(buffer, 0, DEFAULT_BUFFER_SIZE); if (count >= 0) { bos.write(buffer, 0, count); } else { break; } } while (err.available() > 0) { int count = err.read(buffer, 0, DEFAULT_BUFFER_SIZE); if (count >= 0) { bos.write(buffer, 0, count); } else { break; } } if (channel.isClosed()) { exitStatus = channel.getExitStatus(); break; } try { //Thread.sleep(POLL_TIMEOUT); Thread.sleep(1000); } catch (InterruptedException e) { //("Ignoring interrupt."); } } } catch (IOException ioe) { // TODO: Add catch code ioe.printStackTrace(); } bos.reset(); return bos.toString();; } Also, can these affect performance: session.connect(3 * 1000); // making a connection with timeout. channel.connect(3 * 1000); TIA! |