慢读几百个文件 [英] Slow reading hundreds of files
问题描述
我有问题的多个二进制文件的处理。我有很多很多的文件夹,在每一个有大约200箱文件。
I have problem with processing of more binary files. I have many many folders, in each there is about 200 bin files.
我选择这些目录2,然后从这些2目录中的所有二进制文件(其路径)保存到列表,使一些筛选与此列表。在本月底,在列表是大约200箱文件。
I choose 2 of these directories, then all bin files (their paths) from these 2 directories save to List, and make some filtering with this list. At the end of this, in list is about 200 bin files.
然后我遍历所有过滤的文件,并从每个读取第一个4×8字节(我试过的FileStream
或 BinaryReader
)。所有这些操作需要大约2-6秒,但只在第一次。下一次,它的速度不够快。如果没有用了很长的时间(约30分钟)文件发生,问题再次出现。
Then I'm iterating over all filtered files, and from each read first 4x8 Bytes (I tried FileStream
or BinaryReader
). All this operations take about 2-6 seconds, but only for the first time. Next time it's fast enough. If nothing happens with files for a long time (about 30 minutes), the problem appears again.
所以可能它的一些有关缓存还是什么?
So probably it's something about caching or what?
有人能帮助我吗?谢谢
推荐答案
一种可能就是你的驱动器去睡觉(通常是驱动器将配置15-30分钟后关闭电源)。这可以添加显著延迟(5秒将是一个典型的人物)的硬盘驱动器是跨度备份速度。
One possibility is that your drive is going to sleep (typically a drive will be configured to power down after 15-30 minutes). This can add a significant delay (5 seconds would be a typical figure) as the hard-drive is span back up to speed.
幸运的是,这是测试一件容易的事情。只需设置断电时间,比方说,6小时,再测试,如果行为发生了变化。
Luckily, this is an easy thing to test. Just set the power-down time to, say, 6 hours, and then test if the behaviour has changed.
这篇关于慢读几百个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!