LoginSignup
0

More than 5 years have passed since last update.

tmpwatch の速度

Last updated at Posted at 2017-07-29

tmpwatchfind のコマンドラインの比較とか言及してるところは多いけど、実際の処理速度とかに言及してるところがなかったので、とりあずやってみる。

なお、実行コマンドの間に、

# sync && sysctl -w vm.drop_caches=3

を実行してキャッシュの影響を排除する。

tmpwatch とは

RedHat 系に用意されてる、ログ削除用ツール。

ぐぐって下さい。

準備

まず適当なファイルを毎分つくるスクリプト作成

make_tmp.sh
#!/bin/bash

arr=($(date '+%Y/%m/%d/%H/%M %Y%m%d%H%M'))
mkdir -p /home/bunzaemon/test/tmpwatch/${arr[0]}
mkdir -p /home/bunzaemon/test/find/${arr[0]}
for i in $(seq 0 999 ) ; do
    echo "sample" > /home/bunzaemon/test/tmpwatch/${arr[0]}/${arr[1]}_$i
    echo "sample" > /home/bunzaemon/test/find/${arr[0]}/${arr[1]}_$i
done

で cron で毎分回す。

* * * * * /bin/bash /home/bunzaemon/test/make_temp.sh

あとは、適当に待つ1

状態と検索条件

$ pwd
/home/bunzaemon/test
$ find find/ -type f | wc -l
1249000
$ find tmpwatch/ -type f | wc -l
1249000

最終修正2が10時間以上前のものを条件にした。

検索だけ

削除させず、検索だけ。

$ time find find -type f -a -mmin +600 > /dev/null
find find -type f -a -mmin +600 > /dev/null  1.16s user 14.63s system 33% cpu 46.532 total

$ time tmpwatch -t -m 10 ./tmpwatch > /dev/null
tmpwatch -t -m 10 ./tmpwatch > /dev/null  4.20s user 14.81s system 36% cpu 52.384 total

検索と削除

$ time find find -type f -a -mmin +600 -delete
find find -type f -a -mmin +600 -delete  1.00s user 23.64s system 28% cpu 1:25.61 total

$ time tmpwatch -m 10 ./tmpwatch
tmpwatch -m 10 ./tmpwatch  4.02s user 24.85s system 38% cpu 1:15.61 total

うーーーん。結局は誤差範囲程度と考えるべき?

複数回検証する気にはならんかったから、これで止め。

memo

純粋に比較するなら -d をつけるべきだった、、、

  • tmpwatch は、通常は空になったディレクトリも削除してくれる。
    • '-d' を指定して排除しない事も出来る。
  • debian 系には、 tmpwatch がない。
    • CentOS 系の /etc/cron.daily/tmpwatch の代わりに /etc/default/rcS3

  1. ディスクフルと、inode 枯渇に気をつける。 

  2. アクセスではない。 

  3. ん? /var/tmp の挙動は?? 

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0