简体   繁体   English

当文件变大时,小文件的读写速度是否变慢?

[英]Is small size file read/write slower when the file gets bigger?

I am on Ubuntu 12.04 using ext4. 我正在使用ext4的Ubuntu 12.04。 I wrote a python program that does small size (mostly 512 byte) read and write with somewhat random access pattern. 我编写了一个python程序,该程序以较小的访问模式进行较小的读写操作(大部分为512字节)。 I found that as the file gets larger and larger. 我发现随着文件越来越大。 It takes more and more time to do the same number of I/Os. 执行相同数量的I / O所花费的时间越来越多。 The relationship is linear. 该关系是线性的。 In other words, I get O(n 2 ) where n is the cumulative number of I/Os. 换句话说,我得到O(n 2 ),其中n是I / O的累积数量。

I wonder if there is an inherent reason why small I/O being slower as file size increases. 我想知道是否存在一个内在的原因,即随着文件大小的增加,小I / O变慢了。

One more observation: When I mounted a ramdisk and did my File I/O to the ramdisk I do NOT observe this performance degradation. 另一个观察结果:当我安装一个ramdisk并将文件I / O放入该ramdisk时,我没有观察到这种性能下降。

取决于您执行IO的方式,可能是您在保存之前试图过多地调用内存。

When you read 512 bytes out of 1024 bytes large file, the whole file is in cache. 当您从1024个字节的大文件中读取512个字节时,整个文件都在高速缓存中。 As the file size grows, smaller portion of file is in the cache, and data is read from the disk more and more frequently. 随着文件大小的增加,文件的较小部分位于缓存中,并且越来越频繁地从磁盘读取数据。 Ie you get more cache misses as the file grows. 也就是说,随着文件的增长,您将获得更多的缓存未命中。 Maybe this is what you are experiencing. 也许这就是您正在经历的。

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

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