硬盘读取性能问题 [英] Performance issues with hard disk reading

查看:74
本文介绍了硬盘读取性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++程序,该程序从硬盘上读取文件并对文件中的数据进行一些处理。我正在使用标准Win32 API读取文件。我的问题是,该程序有时运行速度非常快,然后突然减慢到以前速度的1/6。如果我多次读取同一文件,那么通常第一次运行是最慢的。然后,它会保持速度,直到我读取其他文件集为止。因此,我显而易见的猜测是分析磁盘访问时间。我使用perfmon实用程序,并测量了程序的IO读取字节/秒。正如预期的那样,读取的字节数存在巨大差异(约5倍)。我的问题是:



(1)。操作系统(在我的情况下为Windows)是否将最近读取的文件缓存在某个地方,以便后续加载更快?



(2)。如果我可以保证我读取的所有文件都位于同一目录中,那么有什么办法可以将它们放置在硬盘中,从而可以更快地访问磁盘?



我能为此做些什么吗?

解决方案

1)Windows确实将最近读取的文件缓存在内存中。这本书 Windows Internals 对此进行了很好的描述作品。 Windows的现代版本还使用一种称为SuperFetch的技术,该技术将根据使用历史记录尝试抢先将磁盘内容提取到内存中,并且ReadyBoost可以缓存到闪存驱动器中,从而可以更快地进行随机访问。所有这些都将提高初次运行后从磁盘访问数据的速度。



2)目录确实不会影响磁盘上的布局。对驱动器进行碎片整理会将文件数据分组在一起。 Windows Vista或更高版本将自动对磁盘进行碎片整理。理想情况下,您希望进行较大的顺序读取并最大程度地减少写入。较小的随机访问和读取的交错写入会严重影响性能。您可以使用 Windows Performance Toolkit 来配置磁盘访问。 p>

I have a C++ program which reads files from the hard disk and does some processing on the data in the files. I am using standard Win32 APIs to read the files. My problem is that this program is blazingly fast some times and then suddenly slows down to 1/6th of the previous speed. If I read the same files again and again over multiple runs, then normally the first run will be the slowest one. Then it maintains the speed until I read some other set of files. So my obvious guess was to profile the disk access time. I used perfmon utility and measured the IO Read Bytes/sec for my program. And as expected there was a huge difference (~ 5 times) in the number of bytes read. My questions are:

(1). Does OS (Windows in my case) cache the recently read files somewhere so that the subsequent loads are faster?

(2). If I can guarantee that all the files I read reside in the same directory then is there any way I can place them in the hard disk so that my disk access time is faster?

Is there anything I can do for this?

解决方案

1) Windows does cache recently read files in memory. The book Windows Internals includes an excellent description of how this works. Modern versions of Windows also use a technology called SuperFetch which will try to preemptively fetch disk contents into memory based on usage history and ReadyBoost which can cache to a flash drive, which allows faster random access. All of these will increase the speed with which data is accessed from disk after the initial run.

2) Directory really doesn't affect layout on disk. Defragmenting your drive will group file data together. Windows Vista on up will automatically defragment your disk. Ideally, you want to do large sequential reads and minimize your writes. Small random accesses and interleaving writes with reads significantly hurts performance. You can use the Windows Performance Toolkit to profile your disk access.

这篇关于硬盘读取性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆