Why is rsync -avz faster than scp -r?
Rsync will obviously be faster than scp if the target already contains some of the source files, since rsync only copies the differences. But I suspect your question was about doing a straightforward copy to an empty target.
You've passed the -z
option to rsync
; this turns on compression. If the network bandwidth is the limiting factor (it often is), compression can improve the transfer speed by a noticeable amount.
You can also enable compression with scp
by passing the -C
option. This should about even things out with rsync. Compression is not enabled by default in ssh because it saves bandwidth but adds latency and CPU overhead; latency is bad for interactive sessions (this doesn't apply to scp
), and the CPU overhead is useless if the files you're copying are already compressed.
Older versions of rsync
used rsh rather than ssh as the default transport layer, so a fair comparison would be between rsync
and rcp
. But ssh has been the default since 2.6.0 released on 2004-01-01.
With identical compression settings, I'd expect rsync
and scp
to have essentially the same speed. Please share benchmarks if you find otherwise.
try scp in a fast way
scp -p -C -o 'CompressionLevel 9' -o 'IPQoS throughput' -c arcfour machine:file .
these options speed up scp 5 times in my setup compared to plain scp machine:file .
Update, 2017
Actually scp is slow due to poor management of TCP details such as MTU and buffer size. Luckily this has been fixed by the HPN SSH project. To my understanding you can use HPN SSH as a transport for rsync.
It used to be the other way around, but I believe rsync's speed has improved greatly the past few revisions. It also depends on how many files you're copying. If it's a lot, rsync will usually be faster because scp spawns a new process for each file you're copying. You can try weakening the cipher scp uses to see if it speeds up. Last I recall, the arcfour cipher was the fastest.