更新

更新

我做了一些简单的性能测试,似乎从我的 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不是一个性能测试工具,但是这个结果还是令人惊讶。

系统由供应商构建,配有 Supermicro 主板和 16 GB RAM。RAID 控制器是 MegaRAID 9271-8i,缓存为 1 GB。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

我希望读取访问至少与写入访问一样快,甚至可能更快。715 MByte/sec 的写入速度似乎接近单个 SAS/SATA 连接器的 6 GBit 限制。这可能是 SAS 背板的配置或布线问题吗?可以使用 MegaRAID 命令查询 SAS 背板配置吗?请提供建议。

更新

正如 poige 和 Peter 所解释的,读取性能比预期慢可能是由 Linux I/O 子系统的缓存引起的。

当在 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 不会影响写入速度。

答案1

poige 关于写入缓存的说法完全正确,但这里还有更多细节。

使用零进行 dd 并使用写入缓存并不是进行基准测试的正确方法(当然,除非您想测试写入缓存,这可能仅对文件系统有用,以查看它同步元数据、创建新文件等的程度)(并且 dd 可能始终是错误的基准测试类型,但它适用于非常基本的测试)

我建议您使用 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 很慢,所以你需要将它临时写入某个地方以便再次读取。创建一个 50MB 的随机文件:

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

多次读取文件以将其写入(这里我使用 cat 读取了 6 次):

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

rm /dev/shm/randfile

还要记住,raid1 在并行操作时读取速度最快,因此磁盘可以独立使用。协调磁盘以使用不同的磁盘读取同一操作的不同部分可能不够智能。

答案2

回答你问题的关键是预读曾经,我也正好有这个问题

换句话说,为了获得最佳的顺序读取性能,所有磁盘都应永久参与输入。

当您使用ddw/o directio(参见man dd)时,写入操作不会立即执行,而是通过 OS 缓存,因此它有更多机会按顺序涉及所有磁盘并实现最大可能的性能。

相关内容