简体   繁体   English

比较从文件系统读取()所需的时间

[英]Comparing time taken to read() from file system

I have created a program that measures that time taken for a read() to be performed on a file and I do this several times to determine the block size of my file system. 我已经创建了一个程序,该程序测量对文件执行read()所花费的时间,并且我多次执行此程序以确定文件系统的块大小。

My question: After plotting this data, everytime I try it, no matter the size I am reading in each iteration, the first read takes significantly longer time compared to any other read. 我的问题:在绘制这些数据之后,每次尝试时,无论我在每次迭代中读取的大小如何,与任何其他读取相比,第一次读取都将花费更长的时间。 I know that once a block has completed reading, the time to do the next read in the new block will take a bit more time (which I have observed in my plot) but this first read value is much higher than that too. 我知道,一旦一个块完成读取,在新块中进行下一个读取的时间将花费更多时间(我在我的绘图中已经观察到),但是这个第一个读取值也要高得多。

Does anyone have a filesystems/OS based answer to why this is the case? 是否有人对这种情况有一个基于文件系统/ OS的答案?

I can think of a couple of reasons why this might be the case. 我可以想到几个可能的原因。 The file system might cache (pre-fetch) the data read from disk, so that even if it only returns (say) 1 block to your program, it might have actually read multiple blocks from the disk; 文件系统可能会缓存(预取)从磁盘读取的数据,因此,即使它仅向程序返回(例如)1个块,它实际上也可能已经从磁盘读取了多个块; so that the next time you do a read, you're actually just pulling more from that cached data. 这样,下次您进行读取时,您实际上只是从缓存的数据中提取了更多信息。 It's also perhaps possible that doing the first read might involve the read head having to move to the start of the file? 进行第一次读取还可能涉及读取头必须移至文件的开头吗? This is probably very file-system-dependent. 这可能是非常依赖文件系统的。 I think that cacheing is more likely to be the cause? 我认为缓存更可能是原因?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM