LoginSignup
3
0

ディレクトリ内のファイルを早く削除したい!【async-delete】

Last updated at Posted at 2023-08-30

はじめに

ファイルサーバ環境においては、長期間利用していないファイルが増えると容量の無駄な浪費に繋がる為、定期的なファイル整理と不要なファイル削除は重要な作業になります。

しかし、大量のファイルを一度に削除する場合、削除ファイル数が多いほど削除処理に要する時間も長くなり、複数のユーザーが同時にアクセスするファイルサーバ環境では、削除処理が他の操作と競合することでサーバの負荷が高まり、他のユーザーのアクセスやファイルの操作に影響を与える可能性があります。

そのため、機器の負荷状況やアクセスの集中時間帯を考慮しながら、適切なタイミングで削除作業を行うといった運用上の考慮点が必要になってきます。

本記事では、ファイル共有環境におけるファイル削除において、ディレクトリ内のファイルをクライアントOSの削除コマンドとは別の方法で、ONTAP側で高速に削除を実行するasync-deleteを試す内容になります。

qiita-square

何をしたい?できる?

  • 4KB x100万ファイルの削除を実行
  • NFS mountしたサーバの通常の削除とasync-deleteによる削除時間を比較
  • 特に、async-deleteではNFS Clientからmvコマンドで削除できる点を確認

ONTAPのasync-deleteについて

ONTAP 9.11.1以降で利用できる、大量のデータ削除をNASプロトコルを使用しないでバックグラウンド実行することができる機能で、以下の2つの方法で削除をする事ができます。

  • ONTAP側からディレクトリのパスを直接指定して削除を実行
  • ONTAP側でゴミ箱を設定し、クライアント側で対象のディレクトリ名をゴミ箱名に変更する事で削除

記事における環境情報

本記事では、以下の環境で実施した内容となります。

  • Rocky Linux : 9.2
  • 機種: FAS8200+SATA Disk
  • ONTAP : 9.13.1

環境のイメージとしては以下の通りです。

qiita-square

実施手順

まずは、作成したデータをONTAP側で確認した結果は以下の通りです。

  • 100GBのVolumeが3つ
  • 各Volumeには1,000,000ファイル格納
    (Volume作成時の管理ファイルがあるので端数があります)
> df -h -vserver nfs100 -volume nfs*
Filesystem               total       used      avail capacity  Mounted on
/vol/nfs200/              95GB     8171MB       87GB       8%  /nfs200
/vol/nfs200/.snapshot   5120MB         0B     5120MB       0%  /nfs200/.snapshot
/vol/nfs201/              95GB     8165MB       87GB       8%  /nfs201
/vol/nfs201/.snapshot   5120MB         0B     5120MB       0%  /nfs201/.snapshot
/vol/nfs202/              95GB     8177MB       87GB       8%  /nfs202
/vol/nfs202/.snapshot   5120MB         0B     5120MB       0%  /nfs202/.snapshot
6 entries were displayed.

> df -i -vserver nfs100 -volume nfs*
Filesystem               iused      ifree  %iused  Mounted on
/vol/nfs200/           1000108    2112851     32%  /nfs200
/vol/nfs201/           1000107    2112852     32%  /nfs201
/vol/nfs202/           1000108    2112851     32%  /nfs202
3 entries were displayed.

1. Linuxのrmコマンドでファイルの削除

nfs200というVolumeをNFSのv3でmountします。

>  mount -o v3 172.16.10.240:/nfs200 /mnt

> df -h
ファイルシス          サイズ  使用  残り 使用% マウント位置
devtmpfs                4.0M     0  4.0M    0% /dev
tmpfs                   2.8G     0  2.8G    0% /dev/shm
tmpfs                   1.1G   29M  1.1G    3% /run
/dev/mapper/rl-root      63G   11G   52G   17% /
/dev/mapper/rl-home      31G  265M   31G    1% /home
/dev/sda2              1014M  465M  550M   46% /boot
/dev/sda1               599M  7.0M  592M    2% /boot/efi
tmpfs                   562M   52K  562M    1% /run/user/42
tmpfs                   562M   36K  562M    1% /run/user/1000
172.16.10.240:/nfs200    95G  8.0G   88G    9% /mnt

Storage側で接続状態を確認します。

> network connections active show -remote-ip 172.16.10.180 -fields cid,proto,service,remote-ip,local-address,node
node         cid       vserver local-address remote-ip     proto service
------------ --------- ------- ------------- ------------- ----- -------
PS-8200cl-01 153525167 nfs100  172.16.10.240 172.16.10.180 TCP   nfs

nfs200というVolume内のdir1を削除します。
(dir1配下に10個のディレクトリと、各ディレクトリに10万ファイルの計100万ファイルが存在)

> time rm -rf /mnt/dir1
real    19m0.427s
user    0m4.689s
sys     1m13.703s

なお、削除はNFSプロトコルで実施しているので、StorageのNFSのOPS値が上がる事が確認できます。

> node run -node PS-8200cl-01 sysstat 1
 CPU     NFS    CIFS    HTTP     Net   kB/s    Disk   kB/s    Tape   kB/s  Cache
                                  in    out    read  write    read  write    age
  4%    1699       0       0     369    426      16      0       0      0   >60
  4%    1594       0       0     329    370      12     24       0      0   >60
  3%    1656       0       0     382    410       0     12       0      0   >60
  3%    1463      77       0     332    385       0     24       0      0   >60
  4%    1643       0       0     353    377      12      0       0      0   >60
  3%    1620       0       0     673    785     400   3468       0      0   >60
  3%    1681      57       0     362    433       0     24       0      0   >60

2. Linuxのrmコマンドでファイルの削除(nconnect=8)

ONTAPでは、NFSのTCP接続ごとに128の同時処理しか実行できないという制約があるので、
nconnectを使うと改善するか確認してみます。
(1クライアントだけで大量の削除なので、期待値は低いですが)

nfs201というVolumeをNFSのv3で、nconnect=8でmountします

>  mount -o v3,nconnect=8 172.16.10.240:/nsf201 /mnt2

>  df -h
ファイルシス          サイズ  使用  残り 使用% マウント位置
devtmpfs                4.0M     0  4.0M    0% /dev
tmpfs                   2.8G     0  2.8G    0% /dev/shm
tmpfs                   1.1G   29M  1.1G    3% /run
/dev/mapper/rl-root      63G   11G   52G   17% /
/dev/mapper/rl-home      31G  265M   31G    1% /home
/dev/sda2              1014M  465M  550M   46% /boot
/dev/sda1               599M  7.0M  592M    2% /boot/efi
tmpfs                   562M   52K  562M    1% /run/user/42
tmpfs                   562M   36K  562M    1% /run/user/1000
172.16.10.240:/nfs201    95G  8.0G   88G    9% /mnt2

Storage側で接続状態を確認します。

> network connections active show -remote-ip 172.16.10.180 -fields cid,proto,service,remote-ip,local-address,node
node         cid       vserver local-address remote-ip     proto service
------------ --------- ------- ------------- ------------- ----- --------
PS-8200cl-01 153525211 nfs100  172.16.10.240 172.16.10.180 UDP   port-map
PS-8200cl-01 153525212 nfs100  172.16.10.240 172.16.10.180 UDP   mount
PS-8200cl-01 153525213 nfs100  172.16.10.240 172.16.10.180 UDP   mount
PS-8200cl-01 153525216 nfs100  172.16.10.240 172.16.10.180 UDP   port-map
PS-8200cl-01 153525217 nfs100  172.16.10.240 172.16.10.180 UDP   mount
PS-8200cl-01 153525218 nfs100  172.16.10.240 172.16.10.180 UDP   mount
PS-8200cl-01 153525220 nfs100  172.16.10.240 172.16.10.180 TCP   nfs
PS-8200cl-01 153525222 nfs100  172.16.10.240 172.16.10.180 TCP   nfs
PS-8200cl-01 153525224 nfs100  172.16.10.240 172.16.10.180 TCP   nfs
PS-8200cl-01 153525226 nfs100  172.16.10.240 172.16.10.180 TCP   nfs
PS-8200cl-01 153525228 nfs100  172.16.10.240 172.16.10.180 TCP   nfs
PS-8200cl-01 153525230 nfs100  172.16.10.240 172.16.10.180 TCP   nfs
PS-8200cl-01 153525232 nfs100  172.16.10.240 172.16.10.180 TCP   nfs
PS-8200cl-01 153525236 nfs100  172.16.10.240 172.16.10.180 TCP   nfs

nfs201というVolume内のdir1を削除します。
(dir1配下に10個のディレクトリと、各ディレクトリに10万ファイルの計100万ファイルが存在)

> time rm -rf /mnt2/dir1
real    19m58.636s
user    0m5.608s
sys     1m19.348s

3. Linuxのmvコマンドでファイル移動(Storageで削除)

3-1 Storage上でasync-deleteのゴミ箱の設定を実施する

ONTAP上でAdvanded Modeから、対象Volumeに対してゴミ箱の有効化とゴミ箱名を設定します。
(Client上で削除対象をゴミ箱名にrenameすると削除されるようになる)

> set advanced

Warning: These advanced commands are potentially dangerous; use them only when directed to do so by NetApp personnel.
Do you want to continue? {y|n}: y

*> volume file async-delete client enable -vserver nfs100 -volume nfs202 -trashbin trash202

Info: Async directory delete from the client has been enabled on volume "nfs202" in Vserver "nfs100".

3-2 Linuxからディレクト名のRename

nfs202いうVolumeをNFSのv3でmountします

>  mount -o v3 172.16.10.240:/nfs202 /mnt3

>  df -h
ファイルシス          サイズ  使用  残り 使用% マウント位置
devtmpfs                4.0M     0  4.0M    0% /dev
tmpfs                   2.8G     0  2.8G    0% /dev/shm
tmpfs                   1.1G   29M  1.1G    3% /run
/dev/mapper/rl-root      63G   11G   52G   17% /
/dev/mapper/rl-home      31G  265M   31G    1% /home
/dev/sda2              1014M  465M  550M   46% /boot
/dev/sda1               599M  7.0M  592M    2% /boot/efi
tmpfs                   562M   52K  562M    1% /run/user/42
tmpfs                   562M   36K  562M    1% /run/user/1000
172.16.10.240:/nfs202    95G  8.0G   88G    9% /mnt3

削除対象ディレクトリをStorage側で設定したゴミ箱名にRenameする事でバックグラウンドでの削除が実行されます。

>  ls /mnt3
dir1

>  time mv /mnt3/dir1 /mnt3/trash202

real    0m0.007s
user    0m0.001s
sys     0m0.004s

>  ls /mnt3

Storage側で確認すると、ゆっくりと削除しているのが確認できるので、
急いで消したい場合は、Storage上で-throttleの値を増やします。(Default5000で最大10万)
操作自体はSVM内の管理操作で実施できます。(Cluterの全体管理でなくてもOK)

-throttleの値を増やして削除を行うと約10分(通常の半分)で削除が完了しました。

> set advanced

Warning: These advanced commands are potentially dangerous; use them only when directed to do so by NetApp personnel.
Do you want to continue? {y|n}: y

*> volume file async-delete show
Vserver      Volume        Job ID  Path            Progress
                                                   (#Files  #Dirs    #Bytes
------------ ------------ -------- --------------- -------------------------
nfs100       nfs202       0:4      /.96_deleting_20230829_043448
                                                        168        0    688128

*> volume file async-delete start -vserver nfs100 -volume nfs202 -path /.96_deleting_20230829_043448 -throttle 100000
[Job 996] Job is queued: Asynchronous directory delete job.


*> volume file async-delete show
Vserver      Volume        Job ID  Path            Progress
                                                   (#Files  #Dirs    #Bytes
------------ ------------ -------- --------------- -------------------------
nfs100       nfs202       0:4      /.96_deleting_20230829_043448
                                                        389        0   3100672
                          0:5      /.96_deleting_20230829_043448
                                                     628075        0

削除については、NFSプロトコルを使ってないので、StorageのNFSのOPS値が上がって無い事が確認できます。

> node run -node PS-8200cl-01 sysstat 1
 CPU     NFS    CIFS    HTTP     Net   kB/s    Disk   kB/s    Tape   kB/s  Cache
                                  in    out    read  write    read  write    age
  9%       0       0       0      19     16    4548  64176       0      0   >60
 10%       0       0       0      45     12       0     24       0      0   >60
  8%       0       0       0      24     19      12      0       0      0   >60
  8%       0       0       0      10      5      16      0       0      0   >60
  8%       0       0       0      45     16       0     24       0      0   >60
  8%       0       0       0      17     12      12     12       0      0   >60
  8%       0       0       0      41      9       0     24       0      0   >60
  9%       0       0       0      44     26       0      0       0      0   >60

参考及びリンク

Delete directories rapidly on the cluster

Manage client rights to delete directories rapidly

NFS in NetApp ONTAP Best practice and implementation guide

3
0
0

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
3
0