【问题标题】:GNU Parallel | pipe commandGNU 并行 |管道命令
【发布时间】:2017-01-14 02:14:57
【问题描述】:

我在使用 GNU parallel 方面是全新的,在使用 GNU parallel 运行以下命令时,我需要您的建议:

/home/admin/Gfinal/decoder/decdr.pl --gh --w14b /data/tmp/KRX12/a.bin | 
perl  /home/admin/decout/decoder/flow.pl >> /data/tmp/decodedgfile/out_1.txt

我将在文件列表 (.bin) 上运行此命令,那么使用 GNU parallel 实现该目标的最佳(最快)方法是什么?部分命令 (/home/admin/Gfinal/decoder/decdr.pl --gh --w14b) 非常大 (> 2 GB)。

任何帮助将不胜感激。

【问题讨论】:

    标签: linux greenplum gnu-parallel


    【解决方案1】:

    这行得通吗:

    parallel /home/admin/Gfinal/decoder/decdr.pl --gh --w14b {} '|' perl  /home/admin/decout/decoder/flow.pl >> /data/tmp/decodedgfile/out_1.txt ::: /data/tmp/KRX12/*.bin
    

    (如果flow.pl 的输出超出您的磁盘 I/O 可以处理的范围,请尝试parallel --compress)。

    或许:

    parallel /home/admin/Gfinal/decoder/decdr.pl --gh --w14b {} '|' perl  /home/admin/decout/decoder/flow.pl '>>' /data/tmp/decodedgfile/out_{#}.txt ::: /data/tmp/KRX12/*.bin
    

    这取决于您是想要一个输出文件还是每个输入文件一个。

    还花一个小时浏览本教程。您的命令行会因此而爱上您。 man parallel_tutorial

    【讨论】:

    • 非常感谢您的回答 .. 非常感谢您的工作 .. 还有一个问题 ... 正在使用 --pipe after ( /home/admin/Gfinal/decoder/decdr.pl --gh --w14b ) 会让这个过程更快?
    • 不明白。但请尝试并衡量。
    【解决方案2】:

    这里有一些很棒的 gnu-parallel/parallel 视频

    参考youtube Part 1: GNU Parallel script processing and execution

    这里是来自 GNU 网站的链接,用于获取特定于平台的信息。

    参考gnu parallel download information

    "多个输入源

    GNU 并行可以采用命令行中给出的多个输入源。 GNU 然后并行生成输入源的所有组合:

    平行回声 ::: A B C ::: D E F

    输出(顺序可能不同):

    A D

    A E

    A F

    B D

    B E …………

    输入源可以是文件:

    parallel -a abc-file -a def-file echo"
    

    参考GNU-Parallel-Tutorial

    参考管道

    管道容量 管道的容量有限。如果管道已满,则 write(2) 将阻塞或失败,取决于是否设置了 O_NONBLOCK 标志 (见下文)。不同的实现有不同的限制 管道容量。应用程序不应依赖于特定的 容量:一个应用程序应该被设计成一个读取过程 在数据可用时立即使用数据,以便写入过程 不会一直被阻止。

      In Linux versions before 2.6.11, the capacity of a pipe was the same
       as the system page size (e.g., 4096 bytes on i386).  Since Linux
       2.6.11, the pipe capacity is 65536 bytes.  Since Linux 2.6.35, the
       default pipe capacity is 65536 bytes, but the capacity can be queried
       and set using the fcntl(2) F_GETPIPE_SZ and F_SETPIPE_SZ operations.
       See fcntl(2) for more information.
    

    PIPE_BUF POSIX.1 说小于 PIPE_BUF 字节的 write(2)s 必须是 atomic:输出数据以连续的形式写入管道 顺序。超过 PIPE_BUF 字节的写入可能是非原子的: 内核可以将数据与其他进程写入的数据交错。 POSIX.1 要求 PIPE_BUF 至少为 512 字节。 (在 Linux 上, PIPE_BUF 为 4096 字节。)精确的语义取决于 文件描述符是非阻塞的(O_NONBLOCK),是否有 管道的多个写入者,并且在 n 上,要写入的字节数 写:

    参考man7.org pipe

    您可以查看 fcntl F_GETPIPE_SZ 和 F_SETPIPE_SZ 操作以了解更多信息。

    参考fcntl

    一切顺利

    【讨论】:

      最近更新 更多