【问题标题】:xargs parallel tar pipelinexargs 并行 tar 管道
【发布时间】:2021-04-21 00:57:13
【问题描述】:

我正在尝试使用xargs 的 tar 创建/提取作业的并行管道复制一个非常大的文件系统。我似乎无法弄清楚正确的语法。

find image -maxdepth 2 -mindepth 2 -type d -print|xargs -P 48 tar cf - --files-from|(cd /testfiles; tar xf -)

我收到以下错误:

xargs: tar: 由信号 13 终止
xargs: tar: 由信号 13 终止

但是,如果我在没有-P 选项的情况下执行相同的命令,它就会运行。它只是单线程的,需要很长时间才能在 700K 子目录中处理 5000 万个文件。

以下工作,但速度很慢:

find image -maxdepth 2 -mindepth 2 -type d -print|xargs tar cf - --files-from|(cd /testfiles; tar xf -)

那么我错过了什么?

【问题讨论】:

    标签: parallel-processing pipe tar pipeline xargs


    【解决方案1】:

    问题是您的并行管道 stdout 被来自 |(cd /testfiles; tar xf -)

    的“单个”stdin 消耗

    因此,您需要“还”并行化 tar xf - 部分,一种可能的解决方案是将该管道视为“迷你脚本”,然后使用 $@ 获取 xargs 传递的参数:

    find image -maxdepth 2 -mindepth 2 -type d -print| \
      xargs -P 48 sh -c 'tar cf - --files-from $@ | tar -C /testfiles -xf -' -- 
    

    顺便说一句,我也会小心 -P 48,从更多 frugal 值开始,直到您找到对上述 I/O 影响的舒适权衡。

    【讨论】:

      【解决方案2】:

      xargs 中使用-n 1 将使tar 运行之前find 命令的每个输出行。

      find image -maxdepth 2 -mindepth 2 -type d -print|xargs -n 1 -P 48 tar cf - --files-from|(cd /testfiles; tar xf -)
      

      【讨论】:

        猜你喜欢
        • 2018-12-11
        • 2017-09-27
        • 2023-03-03
        • 1970-01-01
        • 2012-07-17
        • 2019-01-15
        • 2016-06-05
        • 2013-04-24
        • 1970-01-01
        相关资源
        最近更新 更多