为什么我的RAID1读写访问速度慢于写访问?

我已经做了一些简单的性能testing,看起来从RAID1读取比写入要慢:

root@dss0:~# for i in 1 2 3; do dd if=/dev/zero of=/dev/sda bs=1048576 count=131072; done 137438953472 bytes (137 GB) copied, 192.349 s, 715 MB/s 137438953472 bytes (137 GB) copied, 192.851 s, 713 MB/s 137438953472 bytes (137 GB) copied, 193.026 s, 712 MB/s root@dss0:~# for i in 1 2 3; do dd if=/dev/sda of=/dev/null bs=1048576 count=131072; done 137438953472 bytes (137 GB) copied, 257.201 s, 534 MB/s 137438953472 bytes (137 GB) copied, 255.522 s, 538 MB/s 137438953472 bytes (137 GB) copied, 259.945 s, 529 MB/s 

我知道dd不是一个性能testing工具,但是这个结果仍然是一个惊喜。

系统由供应商build立,并有一个16 GB的超微主板RAM。 RAID控制器是具有1 GB高速caching的MegaRAID 9271-8i。 SAS-933EL1背板上有8个2 TByte SAS磁盘。 我不确定布线情况,控制器的一个连接器连接到SAS背板,另一个连接到两个保持操作系统的SATA磁盘。

RAID1是用这个命令设置的:

 root@dss0:~# /opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r1 [8:0,8:1,8:2,8:3,8:4,8:5,8:6,8:7] WB NORA Direct -a0 Adapter 0: Created VD 0 Adapter 0: Configured the Adapter!! Exit Code: 0x00 root@dss0:~# /opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -LALL -aALL Adapter 0 -- Virtual Drive Information: Virtual Drive: 0 (Target Id: 0) Name : RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0 Size : 7.275 TB Sector Size : 512 Is VD emulated : No Mirror Data : 7.275 TB State : Optimal Strip Size : 256 KB Number Of Drives : 8 Span Depth : 1 Default Cache Policy: WriteBack, ReadAheadNone, Direct, No Write Cache if Bad BBU Current Cache Policy: WriteBack, ReadAheadNone, Direct, No Write Cache if Bad BBU Default Access Policy: Read/Write Current Access Policy: Read/Write Disk Cache Policy : Disk's Default Encryption Type : None PI type: No PI Is VD Cached: No Exit Code: 0x00 

我希望读访问至less和写访问一样快,甚至更快。 715 MByte / sec的写入速度似乎接近单个SAS / SATA连接器的6 GBit限制。 这可能是SAS背板的configuration或布线问题? 可以用MegaRAID命令查询SAS背板configuration吗? 请指教。

更新

正如Poige和Peter所展示的那样,读取性能低于预期可能是由Linux I / O子系统的高速caching引起的。

在我使用dd命令时使用直接标志

 root@dss0:~# dd if=/dev/sda of=/dev/null bs=1048576 count=131072 iflag=direct 137438953472 bytes (137 GB) copied, 199.862 s, 688 MB/s 

这比写速度慢了10%。 使用oflag = direct不会影响写入速度。

关于写入caching,poige是完全正确的,但这里有更多的细节。

dd与零和使用写入caching是不正确的方式进行基准testing(除非你想testing写caching当然,这可能只对文件系统有用,看看它同步元数据,创build新的文件,等等。 )(可能dd总是错误的基准types,但它适用于非常基本的testing)

我build议你使用至less有一个以下选项的DD:

 conv=fdatasync -> this will make it flush to disk before finishing and calculating speed oflag=direct -> this will make it skip the OS cache but not the disk cache conv=sync -> more like skipping the disk cache too, but not really ... just flushing it every block or something like that. 

也不要使用零。 如果数据可预测为零,则某些智能硬件/软件/固件可能会使用一些快捷方式。 这是尤其如此,如果有压缩,我猜你没有使用。 相反,使用内存中的随机文件(如/ dev / shm)。 urandom很慢,所以你需要暂时写在某个地方再读一遍。 创build一个50MB的随机文件:

 dd if=/dev/urandom of=/dev/shm/randfile bs=1M count=50 

阅读文件多次写入(这里我用猫读了6次):

 dd if=<(cat /dev/shm/randfile{,,,,,}) of= ... conv=fdatasync rm /dev/shm/randfile 

另外请记住,raid1读取在并行操作中速度最快,所以可以独立使用磁盘。 它可能不够聪明,协调磁盘读取不同的磁盘相同的操作的不同部分。

答案的关键是预读 。 曾几何时,我也遇到过这个问题 。

IOW,为了获得最佳的顺序读取性能,所有磁盘应该永久地参与input。

当你使用dd w / o directio (参见man dd )时,写入操作不是立即执行,而是经过OScaching,所以它有更多的机会将所有的磁盘顺序地包含在内,并达到最大的性能。