on a linux system I have a directory with about 100.000 files (they contain some statistics data). I have to access them using wildcards and now I experience some performance issues. When accessing a specific file it's really fast:
time ls 19991
19991
real 0m0.004s
user 0m0.000s
sys 0m0.000s
When using wildcards it's (as you would expect) slower:
time ls 19991*
19991
real 0m0.043s
user 0m0.020s
sys 0m0.020s
But: When I try to access the files concurrently ALL access get slow:
i=1; while [ $i -le 10 ]; do (time ls 19991* &) ; let i=i+1; done
19991
19991
real 0m0.248s
user 0m0.010s
sys 0m0.020s
19991
real 0m0.279s
user 0m0.000s
sys 0m0.040s
19991
19991
19991
real 0m0.306s
user 0m0.050s
sys 0m0.000s
real 0m0.236s
user 0m0.010s
sys 0m0.030s
real 0m0.257s
user 0m0.010s
sys 0m0.040s
real 0m0.263s
user 0m0.020s
sys 0m0.020s
19991
19991
real 0m0.196s
user 0m0.030s
sys 0m0.010s
real 0m0.175s
user 0m0.020s
sys 0m0.020s
19991
real 0m0.095s
user 0m0.040s
sys 0m0.000s
19991
real 0m0.158s
user 0m0.020s
sys 0m0.040s
Even if the access is serialized by the kernel, I would expect the first "ls" to take about 40ms, the second 80ms, the third 120ms, ... . But now even the fastest "ls" takes 95ms and most of them about 200ms.
This occurs when using a local filesystem (ext3) and also when using a network-mounted directory (nfs). So I think it has nothing to do with a specific filesystem.
Any ideas what causes this slowdown or how to fix it?