This is a response/extension to the Deep directory structure vs. flat directory structure to store millions of files on ext4 article on Medium. Here, I'm benchmarking not only a nesting level of two, but different levels.
This benchmark currently runs on an otherwise idle physical server with this specs:
- HDD: spinning, encrypted (RAID 10)
- CPU: Intel i7-2600 (4 cores + HT @ 3.4GHz)
- RAM: 16GB
For reference, this is the result for a test run with for a depth of 5 and 100k files (output truncated and sorted):
$ ruby benchmark-deep-vs-flat-directories.rb 5 100000
Ruby 2.5.3 x86_64-linux, depth 5, iterations 100000
user system total real
write-5 1.100000 3.390000 4.490000 (242.845647)
write-4 1.000000 3.070000 4.070000 (238.195257)
write-3 1.050000 2.910000 3.960000 (214.014290)
write-2 1.070000 3.160000 4.230000 (414.781391)
write-1 0.810000 1.640000 2.450000 ( 5.496074)
write-0 0.720000 1.580000 2.300000 ( 3.912904)
read-5 0.890000 0.680000 1.570000 ( 1.895553)
read-4 0.670000 0.730000 1.400000 ( 20.789874)
read-3 0.790000 0.910000 1.700000 ( 21.961692)
read-2 0.560000 0.590000 1.150000 ( 1.400197)
read-1 0.570000 0.580000 1.150000 ( 6.023490)
read-0 0.550000 0.470000 1.020000 ( 1.259735)
I'll update this gist with the results, once the benchmark is finished (with 10m files).
That's just the result of a quick copy'n'paste from their documentation. It was faster than to install LibreOffice.
One slight miscalculation ("I have made a terrible mistake"): While preparing this, in my head I've estimated 256^5 (i.e. directories
00
..ff
, 5 levels deep) to be 16,7 million—which means I'm only off by a factor of 64k (256^5 = (2^8)^5 = 2^(8*5) = 2^40)... I don't actually have that many Inodes available :-D"Discovering" this, it doesn't make much sense to continue this benchmark with depth=5. I now need to cleanup 320m directories. Maybe, I'll restart it with depth=3.