测试磁盘随机读取时间
2013-04-19 14:12
357 查看
写了一个测试磁盘寻道(+旋转)时间的程序,方法如下:创建一个大文件(如果太小,文件所有内容都在一个磁道上),使O_DIRECT打开文件,随机选择一个位置(4k的倍数),读取4K(文件系统块)大小的数据。
测试程序分别执行1、10、100、1000、10000次随机读文件操作,结果发现在1000次以内,消耗的时间总是1-3ms,超过10000才会略有大的增长,但也在1s范围内。发现DIRECTIO根本没有生效,百思不得其解。
仔细阅读了man手册上关于O_DIRECT的说明:
Try to minimize cache effects of the I/O to and from this file. In general this will degrade performance, but it is useful in special situations, such as when applications do their own caching. File I/O is done directly to/from user space buffers. The I/O is synchronous, i.e., at the completion of a read(2) or write(2), data is guaranteed to have been transferred. Under Linux 2.4 transfer sizes, and the alignment of user buffer and file offset must all be multiples of the logical block size of the file system. Under Linux 2.6 alignment to 512-byte boundaries suffices.
使用DIRECTIO要求缓冲区、offset跟块大小对齐,而程序中的缓冲区在栈上分配的,块对齐的几率很低。怎么保证内存跟块大小(4096B)对齐呢?man posix_memalign。
int posix_memalign(void **memptr, size_t alignment, size_t size);
void *memalign(size_t boundary, size_t size);
经过修改后,程序工作正常,测试结果如下:执行10000次随机读请求,平均读时间为3.6ms,因为文件的顺序性,这里测试的随机性不是太好。
参考资料:
http://www.ukuug.org/events/linux2001/papers/html/AArcangeli-o_direct.html
http://ender.hitidea.org/tag/o_direct/
测试程序分别执行1、10、100、1000、10000次随机读文件操作,结果发现在1000次以内,消耗的时间总是1-3ms,超过10000才会略有大的增长,但也在1s范围内。发现DIRECTIO根本没有生效,百思不得其解。
仔细阅读了man手册上关于O_DIRECT的说明:
Try to minimize cache effects of the I/O to and from this file. In general this will degrade performance, but it is useful in special situations, such as when applications do their own caching. File I/O is done directly to/from user space buffers. The I/O is synchronous, i.e., at the completion of a read(2) or write(2), data is guaranteed to have been transferred. Under Linux 2.4 transfer sizes, and the alignment of user buffer and file offset must all be multiples of the logical block size of the file system. Under Linux 2.6 alignment to 512-byte boundaries suffices.
使用DIRECTIO要求缓冲区、offset跟块大小对齐,而程序中的缓冲区在栈上分配的,块对齐的几率很低。怎么保证内存跟块大小(4096B)对齐呢?man posix_memalign。
int posix_memalign(void **memptr, size_t alignment, size_t size);
void *memalign(size_t boundary, size_t size);
经过修改后,程序工作正常,测试结果如下:执行10000次随机读请求,平均读时间为3.6ms,因为文件的顺序性,这里测试的随机性不是太好。
参考资料:
http://www.ukuug.org/events/linux2001/papers/html/AArcangeli-o_direct.html
http://ender.hitidea.org/tag/o_direct/
相关文章推荐
- linux命令dd:数据备份与恢复,切割还原大文件,测试读取写入磁盘速度
- Windows 安装到vhd虚拟磁盘中(转),还没有时间测试!
- java:24G文件写入所要时间23.9分,读取只有67秒(1G内存测试)
- Mysql取随机数据效率测试(400W条中读取100条)
- 【计算机视觉】OpenCV读取视频获取时间戳等信息(PS:经测试并不是时间戳,与FFMPEG时间戳不一样)
- 随机生成测试用例(以当前时间为随机种子)
- 大部分的CPU时间用于等待磁盘去读取数据
- history命令添加时间---测试磁盘写入速度
- 测试磁盘读取速度
- history命令添加时间---测试磁盘写入速度
- Jmeter中随机读取测试文件的内容
- 读取系统时间作为seed 随机打印数字
- 测试用指定块大小读取文件时间的代码
- java:24G文件写入所要时间23.9分,读取只有67秒(1G内存测试)
- java:24G文件写入所要时间23.9分,读取只有67秒(1G内存测试)
- 2.1-2.4.文件读取时间测试
- linux系统稳定性测试-sysbench-磁盘IO性能测试-随机读
- Linux——测试磁盘读取性能
- 磁盘读取数据时间
- Elastic测试笔记:logstash读取redis,指定时间字段