4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Goでduを高速化してみた

Posted at

背景

後輩: ホームディレクトリのディスク使用率が100%になったみたいです!新規でログインできなくなりやした!
ワタシ: 犯人をさがせー
後輩: dfしたけど100%ってことしかわからんとです....
ワタシ: duで調べるんやで! -sk?オプションはググって!
後輩: ググって実行したんですけど、めっちゃ時間かかって返ってこないっす....
ワタシ: 待つしかないなー\(^o^)/

ワタシだけかもしれませんが、duってオプション覚えられなくないですか?
あと、遅くないですか?

こんな出力にしたいな

ファイルパス ファイル数 容量
grepableにしたいよね〜

実装

Goにはゴルーチンという必殺の武器があるので、並列実行で早くなりますな!
https://github.com/kuritayu/infra-tools/blob/master/cmd/rapidu/main.go

ベンチマーク

環境はMac、timeの出力結果。ファイル数598909、容量129755.2 MB

du -sk /Users  0.58s user 11.63s system 57% cpu 21.387 total
/Users 598909 files 129755.2 MB     # 実際の出力結果
rapidu /Users  5.44s user 27.37s system 232% cpu 14.114 total

7秒早くなった。出力結果をシンプルにできた!

4
1
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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?