7

我正在尝试使用withrsync并行运行一些实例。我正在运行的命令是这样的:sshGNU parallel

find /tmp/tempfolder -type f -name 'chunck.*' | sort | parallel --gnu -j 4 -v ssh -i access.pem user@server echo {}\; rsync -Havessh -auz -0 --files-from={} ./ user@server:/destination/path

/tmp/tempfolder包含带有前缀的文件chunck,它们包含实际的文件列表。

使用此命令,我得到了 4 个调用rsync,但它们需要一段时间才能开始运行,并且不会一起启动,也不会并行运行。

我究竟做错了什么?

4

1 回答 1

2

确定rsyncs 真的没有并行运行吗?
在命令运行时检查ps | grep rsync将显示哪些 rsync 以及多少个 rsync 实际同时运行。

默认情况下,parallel保留每个作业的打印输出,直到它完成,这样不同命令的输出就不会混在一起:

--group  Group output. Output from each jobs is grouped together and is only printed when the command
         is finished. stderr (standard error) first followed by stdout (standard output). This takes
         some CPU time. In rare situations GNU parallel takes up lots of CPU time and if it is
         acceptable that the outputs from different commands are mixed together, then disabling
         grouping with -u can speedup GNU parallel by a factor of 10.

         --group is the default. Can be reversed with -u.

我的猜测是 rsyncs 实际上是并行运行的,但是从输出中感觉它们是串行运行的。-u选项改变了这一点。

--

例如使用这个 cmd:

$ for i in 1 2 3 ; do echo a$i ; sleep 1 ; done
a1
a2
a3

默认情况下,在全部完成之前,我们不会收到任何反馈:

$ (echo a ; echo b ; echo c ) | parallel 'for i in 1 2 3 ; do echo {}$i ; sleep 1 ; done  ' 
a1
a2
a3
b1
b2
b3
c1
c2
c3

-u东西会立即打印出来:

$ (echo a ; echo b ; echo c ) | parallel -u 'for i in 1 2 3 ; do echo {}$i ; sleep 1 ; done  ' 
a1
b1
c1
a2
b2
c2
a3
b3
c3

在这两种情况下,它都需要 3 秒才能运行,所以它实际上是同时运行的......

于 2014-10-06T09:16:09.787 回答