Suppose that you're generating and transferring a file over ssh, for example to create a tar archive of something on a remote server and save it locally:
ssh [...] rem-server 'cd /var/log && tar -cf - .' >/backup/file.tar
If you're experiencing IO problems in this backup process , an interesting question is what buffer size
ssh
uses for its writes, perhaps because you'd like to make a few large writes to disk (for example, at the natural 128 KByte block size for your ZFS fileservers , even when you're writing over NFS) instead of a bunch of smaller ones.
The
ssh
manual page doesn't document anything about this, and there's no options to control it in either
ssh
or ssh_config(5) . On Linux, running over TCP from a remote machine, the answer appears to be that ssh will normally do 32 KByte writes (or 64 KByte writes under some circumstances, possibly if the network is fast enough). It's possible
ssh
will write smaller buffers if the remote command generating the output can't keep up at full network bandwidth, and in general I suspect that there are a lot of things that can change this.
If this is important to you (and I'm not convinced it's important to us), you need to re-buffer the output from
ssh
in some way. The traditional way is to use
dd
, but you need to pick the right options to have
dd
reblock its input . There are other programs floating around but I don't know if any of them are standard.
(Since I looked it up, there's at least the Debian buffer package and mbuffer . There are probably others out there as well that I can't dig up in casual Internet searches.)
Finding out this information requires some way to trace
ssh
's system call activity. On Linux this is most easily done with '
strace
' , and you can narrow down all of the system calls that
ssh
does with '
strace -e
trace-fd=5 ...
'. You might think that you want to trace file descriptor 1 (standard output), but in fact current versions of OpenSSH
ssh
rewires its standard output on to file descriptor 5 and make file descriptor 1 point to /dev/null (which can be very confusing when you first encounter it).
(This is one of those things that I look into, don't find much, and then want to write down my negative results anyway for future use.)