scp.py icon indicating copy to clipboard operation
scp.py copied to clipboard

Slowness

Open carolinux opened this issue 9 years ago • 11 comments

Hello! Thank you for this module. I noticed the transfer time can be quite slow (compared to command line scp). An order of magnitude or more slower. Is this an issue of the scp module or perhaps of the underlying paramiko/ssh settings?

carolinux avatar May 23 '16 17:05 carolinux

Are you talking about a single file? Multiple small files?

Have this ever been benchmarked?

remram44 avatar May 23 '16 18:05 remram44

single file around 30 MBs.

carolinux avatar May 23 '16 20:05 carolinux

Probably a paramiko issue 😢

Have you tried specifying a different buff_size?

remram44 avatar May 23 '16 20:05 remram44

def get_ssh_connection():
    host = data_server
    ssh = SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.load_system_host_keys()
    try:
        ssh.connect(data_server, username="root")
    except:
        password = getpass.getpass("SSH password for {}@{} : ".format("root", data_server))
        ssh.connect(data_server, username="root", password=password)
    return ssh


def scp_to_server(local_filenames, remote_directory, skip_if_exists=True):
    ssh_cli = get_ssh_connection()
    scp_cli = scp.SCPClient(ssh_cli.get_transport())

Ok, where would I add the bufsize? Do I need a channel object and if so, how do I give to the SCPClient? (just in case it's convenient for you to answer, I will look at it later myself also)

carolinux avatar May 23 '16 20:05 carolinux

Last line:

scp_cli = scp.SCPClient(ssh_cli.get_transport(), buff_size=2*1024*1024)

remram44 avatar May 23 '16 21:05 remram44

Thank you! I will report back when I benchmark it, because I think more people may find it useful.

carolinux avatar May 23 '16 21:05 carolinux

Bad news: I didn't perceive a difference one way or the other.

carolinux avatar Jul 01 '16 14:07 carolinux

@carolinux are you comparing transfer speed of scp without compression to your code? I made the mistake of not setting client.connect(compress=True) so my transfers were considerably slower compared to my normal usage of scp -C

bandophahita avatar Jul 28 '16 19:07 bandophahita

any update on this, am having a similar issue

john-dowling avatar Dec 08 '17 16:12 john-dowling

(Oops)

I can't reproduce the issue, so it's pretty hard. It shouldn't be much slower, and if it is, that's probably an issue with Paramiko. But we can run more tests.

remram44 avatar Dec 08 '17 22:12 remram44

I ran some tests and I really don't see much of a slowdown.

NYC MacBook to GCE: 14.605 / 14.248, French server to GCE: 13.114, 13.294

Data

MacBook (New York) -> Google Cloud (us-central1-c): 100MB

/usr/bin/scpscp.py
14.56315.142392
14.45914.081794
14.8414.152773
14.36214.174169
15.17514.07147
14.46514.245316
14.8414.053202
14.46414.059526
14.49713.943941
14.45314.419479
14.66214.142728
14.50513.978535
14.54414.187512
14.38314.549694
14.86514.518703

Online.net server (France) -> Google Cloud (us-central1-c): 15MB

/usr/bin/scpscp.py
4.35611.241386
10.04223.640888
8.80515.00032
5.7844.558009
6.61118.062356
23.20632.331319
30.93428.441495
16.55723.172128
28.78222.457937
37.94318.350743
3.142.257147
3.042.339132
3.1362.088671
3.0412.080863
7.6498.392694
10.07712.570131
12.09511.449674
11.2179.9099
14.23410.832424
18.75214.649188
17.1759.148867
13.6189.986314
10.29115.070032
14.2511.0324

If you see a really significant difference, do you mind sharing a bit more on your setup? Which OS? Is the machine CPU bound? High latency? Are you running on a very fast link?

remram44 avatar Dec 09 '17 05:12 remram44