哪个更快,找到“执行”或“查找|” xargs -0'? [英] Which is faster, 'find -exec' or 'find | xargs -0'?

查看:123
本文介绍了哪个更快,找到“执行”或“查找|” xargs -0'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Web应用程序中,我使用PHP脚本来呈现页面,然后从中生成静态HTML文件。静态HTML被提供给用户来加速性能。 HTML文件最终会变陈旧,需要删除。



我在两种写驱逐脚本的方法之间进行辩论。



第一个是使用单个find命令,比如

  find / var / www / cache -type f  - mmin +10 -exec rm \ {} \; 

第二种形式是通过xargs进行管道操作,如$ / b
$ b

  find / var / www / cache -type f -mmin +10 -print0 | xargs -0 rm 

第一个表单调用 rm 为每个文件找到,而第二种形式只是将所有文件名发送到一个 rm (但是文件列表可能很长)。



哪种形式会更快?



在我的情况下,缓存目录是在几个Web服务器之间共享的,所以这些都是通过NFS完成的,如果这对于这个问题很重要的话。 b $ b

解决方案

我期望xargs版本稍微快一点,因为您不会为每个文件名产生一个进程。但是,如果实际上有很多不同,我会感到惊讶。如果你担心xargs发送给每个rm的长列表,你可以使用-l和xargs来限制它使用的标记的数量。但是,xargs知道最长的cmdline长度,不会超出这个范围。


In my web application I render pages using PHP script, and then generate static HTML files from them. The static HTML are served to the users to speed up performance. The HTML files become stale eventually, and need to be deleted.

I am debating between two ways to write the eviction script.

The first is using a single find command, like

find /var/www/cache -type f -mmin +10 -exec rm \{} \;

The second form is by piping through xargs, something like

find /var/www/cache -type f -mmin +10 -print0 | xargs -0 rm

The first form invokes rm for each file it finds, while the second form just sends all the file names to a single rm (but the file list might be very long).

Which form would be faster?

In my case, the cache directory is shared between a few web servers, so this is all done over NFS, if that matters for this issue.

解决方案

I expect the xargs version to be slightly faster as you aren't spawning a process for each filename. But, I would be surprised if there was actually much difference in practice. If you're worried about the long list xargs sends to each invocation of rm, you can use -l with xargs to limit the number of tokens it will use. However, xargs knows the longest cmdline length and won't go beyond that.

这篇关于哪个更快,找到“执行”或“查找|” xargs -0'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆