[20180308]测试ARG_MAX参数.txt
--//上个星期遇到的问题,提到ARG_MAX 参数,可以通过$ getconf ARG_MAX 获得.链接
--//http://blog.itpub.net/267265/viewspace-2151445/
--//今天测试看看手工结果如何?
1.环境:
$ cat /etc/issue
CentOS release 6.2 (Final)
Kernel \r on an \m
$ cat /proc/version
Linux version 2.6.32-220.el6.x86_64 (mockbuild@c6b18n3.bsys.dev.centos.org) (gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) ) #1 SMP Tue Dec 6 19:48:22 GMT 2011
$ getconf ARG_MAX
2621440
--//2621440/1024 = 2560
--//这台机器2.5M.奇怪.
--//多数发布版本都是
$ getconf ARG_MAX
131072
--//131072/1024 = 128K
2.手工测试:
$ cd /u01/app/oracle/admin/orcl/adump
$ time ls -1 | xargs echo > /tmp/aa.txt
real 0m0.108s
user 0m0.087s
sys 0m0.024s
$ cat /tmp/aa.txt | tr ' ' '_' |awk '{print length($0)}'
131062
91811
--//第1行占用131062字节.说明一些程序xargs接收按照128K.换1种方式:
$ find . -name "*.aud" | xargs echo > /tmp/ab.txt
$ cat /tmp/ab.txt | tr ' ' '_' |awk '{print length($0)}'
131060
124379
--//基本很接近.
3.既然知道命令行缓存,xargs支持-P参数,
-P max-procs
Run up to max-procs processes at a time; the default is 1. If max-procs is 0, xargs will run as many processes as
possible at a time. Use the -n option with -P; otherwise chances are that only one exec will be done.
--//如果这样-P 仅仅支持2个进程,上面的输出才2行.-s可以改变接收缓存大小.
--//我的测试机器cpu(逻辑)=24个.
$ ls -1 |wc
16283 16283 222875
--//222875/24 = 9286.
$ time find . -name "*.aud" | xargs -s 9400 -P 24 file > /dev/null
real 0m1.288s
user 0m23.277s
sys 0m0.277s
--//这样real仅仅1秒.奇怪user=23秒.
$ time find . -name "*.aud" | xargs file > /dev/null
real 0m9.171s
user 0m9.057s
sys 0m0.132s
--//明显第1种方式快许多.