creating SSH / SFTP session is very slow

1,071 views
Skip to first unread message

Timmy Schweer

unread,
Mar 21, 2013, 6:41:20 AM3/21/13
to sshj-...@googlegroups.com

Hi there,
I created a class that can copy files from one server to another. Currently for every copy job a new SFTP session gets created which is safe in the case of leaving opened sessions. Creating a session takes between 20 - 60 seconds so copying 20 files takes far too long... Are that normal session creation times so I really have to use one session at all or is that somehow an not normal behavior? What could be the reason for so long time? Can I make it faster?

When i switch to use always the same session what would be the best way to make sure the session gets closed no matter if the java process exits with an exception?

looking forward to any reply
greets
Timmy

Thomas H

unread,
Mar 21, 2013, 1:55:39 PM3/21/13
to sshj-...@googlegroups.com
Hi Timmy,
are the servers running on *inux? Than you may be running out of randomness. By default java uses /dev/random to initialize SecureRandom which if I remeber right is used by the DefaultConfig in sshj.
/dev/random will wait until there is enough randomness available and blocks the execution.

Our workarround was, to instantiiate the DefaultConfig [1] only once and not for each client again. I am not sure if this raises a security risk. In our case this was not an issue.


As an alternative you could use /dev/urandom which will return instantly even if there is not enough randomness. It just does some smart stuff to generate more pseudo randomness to fullfill the request.
But we could not figure out a way to configure sshj over the api to tell SecureRandom to use /dev/urandom. This decision is deeply barried within sshj. There is System.properties property you can set, but this will switch the source of randomness for the entire running jvm, what we did not want to do.

Regards
 Thomas



2013/3/21 Timmy Schweer <timmys...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "sshj-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sshj-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Timmy Schweer

unread,
Mar 22, 2013, 7:17:49 AM3/22/13
to sshj-...@googlegroups.com
Thank you very much for your post! =)

creating a default config at the beginning and passing it to the sshclient objects that are created solved my problem!
example:

DefaultConfig sshDefaultConfig = new DefaultConfig();
SSHClient ssh = new SSHClient(sshDefaultConfig);


I wish you a nice weekend

virtualeyes

unread,
Nov 29, 2014, 6:08:08 PM11/29/14
to sshj-...@googlegroups.com, thomas.he...@googlemail.com
Thanks!

This is a serious issue, BTW, or at least has been on my end while testing things out before going into production. The first 2 ssh events are slow-ish but acceptable; after that, unusuably slow, eventually hitting 5 minute proxy server timeout. Making matters worse, simulating frustrated-user by canceling an upload (e.g. reloading web browser page) a few times brings the entire app server to a halt, fun o_O

Generating default config instance at compile time not only solves the problem, performance goes through the roof as well, blazing fast ;-)

Thanks for sharing, wasted an afternoon but could have been much longer...

Venkat Pappula

unread,
Jul 26, 2016, 10:45:04 AM7/26/16
to sshj-users, thomas.he...@googlemail.com
Thank you very much for this post, really saved my time.
 
 

Thomas Isomaki

unread,
Jul 3, 2018, 2:04:39 AM7/3/18
to sshj-users
Thank you, we also did experience slowness in SSHClient instantiation and your suggestion solved our problem ;)
Reply all
Reply to author
Forward
0 new messages