如果单个目录 (NTFS) 中有大量文件,文件系统性能是否会降低?

tig*_*rou 7 windows-7 ntfs filesystems

我听说如果单个目录中的文件数量变得非常大(例如:>= 10.000.000 个项目),文件系统性能(在 NTFS 分区上)会开始下降。这是真的吗?

如果为真,单个目录中推荐的最大文件数是多少?

编辑:

关于性能:我正在考虑该文件夹内的文件操作(读取、写入、创建、删除)可能会变慢。

tig*_*rou 7

我回答我自己的问题:是的,它肯定更慢。

我写了一个C# Console Application在文件夹中创建许多空文件然后随机访问它们的代码。结果如下:

10 files in a folder        : ~26000 operation/sec
1.000.000 files a in folder : ~6000 operation/sec
Run Code Online (Sandbox Code Playgroud)

这是源代码:

List<string> files = new List<string>();

Console.WriteLine("creating files...");
for (int i = 0; i < 1000 * 1000; i++)
{
    string filename = @"C:\test\" + Guid.NewGuid().ToString();
    using (File.Create(filename));
    files.Add(filename);
}

Console.WriteLine("benchmark...");            
Random r = new Random();
Stopwatch sw = new Stopwatch();
sw.Start();

int count = 0;
while (sw.ElapsedMilliseconds < 5000)
{
    string filename = files[r.Next(files.Count)];
    string text = System.IO.File.ReadAllText(filename);
    count++;
}
Console.WriteLine("{0} operation/sec ", count / 5);
Run Code Online (Sandbox Code Playgroud)

  • 为了发挥作用,您需要*比较一些随机存储和访问 1M 文件的替代*方法。例如,创建 1000 个子文件夹,每个子文件夹包含 1000 个文件,然后随机访问这些 1M 文件。 (2认同)