Rust - mmap 简单写性能比较测试
测试环境
CPU
笔记本 i5-1135G7
硬盘
笔记本 三星 SSD PCI 接口
操作系统
ubuntu 20.04
crate
memmap2 v0.5
测试场景
测试结果为 10 次写入的平均值。
同步
*不同步 metadata
*memmap2 flush():Flushes outstanding memory map modifications to disk.When this method returns with a non-error result, all outstanding changes to a file-backed memory map are guaranteed to be durably stored. The file’s metadata (including last modification timestamp) may not be updated.
*std:fs:File sync_data():This function is similar to sync_all, except that it might not synchronize file metadata to the filesystem.This is intended for use cases that must synchronize content, but don’t need the metadata on disk. The goal of this method is to reduce disk operations.
异步
*memmap2 flush_async():Asynchronously flushes outstanding memory map modifications to disk.This method initiates flushing modified pages to durable storage, but it will not wait for the operation to complete before returning. The file’s metadata (including last modification timestamp) may not be updated.
*std:fs:File flush():Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
总结
在写性能上 mmap 并未表现出明显的优势,在文件变大时表现反而比 File 略逊,但在测试过程中发现 mmap 的表现更稳定一些。此外,由于 mmap 不支持动态改变大小,在创建文件时都设置了文件大小,如果不事先设置文件大小,File 的性能会出现下降。
版权声明: 本文为 InfoQ 作者【山】的原创文章。
原文链接:【http://xie.infoq.cn/article/abcc1967e644500dc1b053d8d】。
本文遵守【CC-BY 4.0】协议,转载请保留原文出处及本版权声明。
评论