tig*_*rou 7 windows-7 ntfs filesystems
我听说如果单个目录中的文件数量变得非常大(例如:>= 10.000.000 个项目),文件系统性能(在 NTFS 分区上)会开始下降。这是真的吗?
如果为真,单个目录中推荐的最大文件数是多少?
编辑:
关于性能:我正在考虑该文件夹内的文件操作(读取、写入、创建、删除)可能会变慢。
我回答我自己的问题:是的,它肯定更慢。
我写了一个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)