AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[xargs](server)

Martin Hope
John Jiang
Asked: 2019-05-01 10:17:47 +0800 CST

为什么 bzip2 -d 并行运行没有充分利用 cpu 资源?

  • 1

我有 1000 个 .bz2 文件和一台 48 核机器。所以我决定并行运行 bzip2 -d 来加快解压速度。但是我发现,cpu under的利用率top很不理想。例如,他们中的大多数人的状态为 D。这是为什么呢?如果我并行运行 awk 命令,利用率可以轻松达到 90%。

ls *.bz2  | xargs -P42 -n1 -I {} bash -c 'bzip2 -d {}'



top - 02:00:18 up 74 days, 18:44,  1 user,  load average: 43.48, 71.56, 98.47
Tasks: 518 total,   1 running, 517 sleeping,   0 stopped,   0 zombie
%Cpu(s): 16.1 us,  0.4 sy,  0.0 ni, 33.4 id, 50.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 26372707+total, 28146360 free,  4073868 used, 23150684+buff/cache
KiB Swap: 16777212 total,  9176276 free,  7600936 used. 25842281+avail Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 93025 xxx  20   0    7908   4208    524 D  22.5  0.0   0:48.88 bzip2
 93033 xxx  20   0    7908   4208    524 D  22.2  0.0   0:49.80 bzip2
 92999 xxx  20   0    7908   4208    524 D  21.9  0.0   0:48.03 bzip2
 93037 xxx  20   0    7908   4204    524 D  21.9  0.0   0:48.23 bzip2
 93028 xxx  20   0    7908   4208    524 D  21.5  0.0   0:50.01 bzip2
 93029 xxx  20   0    7908   4208    524 D  21.2  0.0   0:48.99 bzip2
 93010 xxx  20   0    7908   4208    524 D  20.9  0.0   0:48.67 bzip2
 93000 xxx  20   0    7908   4208    524 D  20.5  0.0   0:46.93 bzip2
 93017 xxx  20   0    7908   4208    524 D  20.5  0.0   0:49.94 bzip2
 93024 xxx  20   0    7908   4208    524 D  20.5  0.0   0:48.33 bzip2
 93012 xxx  20   0    7908   4204    524 D  20.2  0.0   0:50.15 bzip2
 93035 xxx  20   0    7908   4208    524 D  20.2  0.0   0:46.70 bzip2
 93030 xxx  20   0    7908   4208    524 D  19.9  0.0   0:49.31 bzip2
 93009 xxx  20   0    7908   4208    524 D  19.5  0.0   0:50.94 bzip2
 93036 xxx  20   0    7908   4208    524 D  19.5  0.0   0:49.81 bzip2
 93015 xxx  20   0    7908   4208    524 D  19.2  0.0   0:47.92 bzip2
 93018 xxx  20   0    7908   4208    524 D  19.2  0.0   0:46.80 bzip2
 93020 xxx  20   0    7908   4208    524 D  18.9  0.0   0:46.07 bzip2
 93022 xxx  20   0    7908   4208    524 D  18.9  0.0   0:48.09 bzip2
 93034 xxx  20   0    7908   4204    524 D  18.9  0.0   0:45.20 bzip2
 93001 xxx  20   0    7908   4204    524 D  18.5  0.0   0:46.34 bzip2
 93003 xxx  20   0    7908   4208    524 D  18.5  0.0   0:49.36 bzip2
 93007 xxx  20   0    7908   4208    524 D  18.5  0.0   0:40.25 bzip2
 93008 xxx  20   0    7908   4204    524 D  18.5  0.0   0:47.40 bzip2
 93016 xxx  20   0    7908   4208    524 D  18.5  0.0   0:49.45 bzip2
 93026 xxx  20   0    7908   4204    524 D  18.5  0.0   0:49.37 bzip2
 93011 xxx  20   0    7908   4208    524 D  18.2  0.0   0:46.10 bzip2
 93021 xxx  20   0    7908   4208    524 D  18.2  0.0   0:48.18 bzip2
 93031 xxx  20   0    7908   4208    524 D  17.9  0.0   0:47.79 bzip2
 93013 xxx  20   0    7908   4208    524 D  17.5  0.0   0:51.38 bzip2
 93014 xxx  20   0    7908   4208    524 D  17.2  0.0   0:48.84 bzip2
 93032 xxx  20   0    7908   4208    524 D  17.2  0.0   0:50.32 bzip2
 93038 xxx  20   0    7908   4208    524 D  17.2  0.0   0:49.15 bzip2
 93006 xxx  20   0    7908   4208    524 D  16.9  0.0   0:38.50 bzip2
 93027 xxx  20   0    7908   4208    524 D  16.9  0.0   0:44.81 bzip2
 93039 xxx  20   0    7908   4208    524 D  16.9  0.0   0:48.65 bzip2
 93004 xxx  20   0    7908   4208    524 D  16.6  0.0   0:39.21 bzip2
 93040 xxx  20   0    7908   4208    524 D  16.6  0.0   0:44.44 bzip2
 93002 xxx  20   0    7908   4208    524 D  16.2  0.0   0:38.31 bzip2
 93023 xxx  20   0    7908   4204    524 D  16.2  0.0   0:45.50 bzip2
 93019 xxx  20   0    7908   4208    524 D  15.6  0.0   0:46.01 bzip2
 93005 xxx  20   0    7908   4208    524 D  14.9  0.0   0:39.37 bzip2
xargs
  • 1 个回答
  • 124 Views
Martin Hope
gordo911
Asked: 2013-06-19 03:39:32 +0800 CST

如何使用 xargs 处理以空格分隔的环境变量

  • 2

我正在尝试并行多次执行长时间运行的过程。每次执行进程的参数都存储在一个以空格分隔的环境变量中。这是我要执行的人为示例:

$ echo -e 1 2 3 4 | xargs --max-procs=3 --max-args=1 --replace=% echo % is the number being processed

这是该命令的输出:

1 2 3 4 is the number being processed

为什么 max-args 似乎被忽略了?然后我尝试显式设置分隔符以提供更好的结果:

$ echo -e 1 2 3 4 | xargs -d " " --max-procs=3 --max-args=1 --replace=% echo % is the number being processed
1 is the number being processed
2 is the number being processed
3 is the number being processed
4
 is the number being processed

xargs 在处理第 4 个参数时在做什么?

经过一番搜索,我确实设法几乎得到了我想要的东西。参数被正确处理,但并行性不起作用(使用此处未显示的另一个命令验证):

$ echo -e 1 2 3 4 | xargs -n 1 | xargs --max-procs=3 --max-args=1 --replace=% echo % is the number being processed
1 is the number being processed
2 is the number being processed
3 is the number being processed
4 is the number being processed

我错过了什么?

xargs
  • 3 个回答
  • 2591 Views
Martin Hope
Kornel
Asked: 2010-03-31 16:37:19 +0800 CST

换行符分隔的 xargs

  • 64

是否可以仅xargs使用换行符作为分隔符?(如果重要的话,在 Linux 和 OS X 上的 bash 中)

我知道-0可以使用,但它是 PITA,因为并非每个命令都支持 NUL 分隔的输出。

linux bash xargs
  • 6 个回答
  • 51623 Views
Martin Hope
user58852
Asked: 2010-02-14 06:27:03 +0800 CST

想知道为什么 sed 不能像我预期的那样使用 xargs

  • 1

我想知道为什么以下命令不起作用:

sudo find . -name index.htm | xargs -0 sudo sed -i 's/pattern1/pattern2/g'

当分别运行这两个命令时,它们按预期工作,find找到了我需要更改的所有文件,并sed根据正则表达式正确替换了文本(显然,当我单独运行 sed 命令时,我提供了一个文件名作为参数)。当它们与 xargs -0 一起运行时,我得到了

sed:
    ./index.htm
    ./folder1/index.htm
    ./folder1/subfolder2/index.htm
    ...
    ...
    ./lastfolder/index.htm: No such file or directory

我最终使用

sudo find . -name index.htm -exec sudo sed -i 's/pattern1/pattern2/g' {} \;

它工作得很好,我只是好奇为什么使用 xargs 不起作用....

rhel5 sed xargs
  • 2 个回答
  • 333 Views
Martin Hope
Gregg Lind
Asked: 2010-01-20 15:57:28 +0800 CST

xargs --max-proc 拆分每个 proc 的输出?

  • 4

我最近发现了这个xargs --max-procs功能。

如何通过proc拆分命令的输出?我应该只创建一个 mycommand --logfile $LOGFILE,还是可以从 xargs 本身来做?

一个例子(对于 womble):

假设我有脚本 myprocessor.sh 和文件列表。他们可以按任何顺序进行,但我想保留每个单独的日志记录,然后:

find $MY_FILE_TREE --print0 | xargs --null --max-procs 3 --max-args 1 --no-run-if-empty myprocess.sh  

可能是我要运行的并行作业。如果myprocessor.sh是嘴巴,那么我希望能够将每个调用打印到不同的日志。否则,每个的标准输出都是相同的,并且日志会变得混乱。

unix xargs
  • 3 个回答
  • 2341 Views
Martin Hope
styts
Asked: 2010-01-14 07:46:40 +0800 CST

应用多个 .patch 文件

  • 11

我有一个包含.patch文件的目录,使用 diff 生成。

我想将所有这些补丁应用patch -p1到另一个目录。

但是补丁只需要一个文件,除非我cat.

xargs使用或类似工具应用多个文件的命令是什么。

bash diff patch-management xargs
  • 5 个回答
  • 29848 Views
Martin Hope
Geo
Asked: 2009-06-30 05:07:06 +0800 CST

是否构建了 svn 每晚提交脚本来捕获所有可能的场景?

  • 0

我有一个每晚的 svn 提交脚本,它应该考虑到所有可能的场景并将新的东西提交到我们的 svn 存储库。基本上我正在运行以下步骤:

  1. svn status [path] 添加任何新文件
  2. svn status [path] 删除任何手动删除的文件
  3. 转储mysql开发数据库
  4. svn 使用默认消息提交所有上述更改。

这是我们正在使用的脚本:

#!/bin/bash
echo "Adding new files to the nightly commit"
svn status  [path] | grep ? | sed 's/[?MD]//g' | xargs  -I {} svn add {}
echo "Removing files manually deleted"
svn status  [path] | grep ! | sed 's/[!]//g' | xargs -I {} svn del {}
echo "Dumping our development database"
mysqldump  --add-drop-database --add-locks --create-options --disable-keys --extended-insert --result-file=/repopath/database.sql databasename
svn commit /repopath/ -m "Nightly Automatic commit of changes"

我只是想确保 ? 和 !被照顾,而且我没有任何其他我没有想到的场景。对此脚本的任何帮助或改进都将非常有帮助。随意使用此脚本来完成任何 SysAdmin 任务。

linux scripting svn bash xargs
  • 2 个回答
  • 485 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve