关于TrueNAS用sata转接卡的坑
起因
在这炎热的八月,一波一波的高温袭来。终于,以前用haswell平台的旧笔记本改的NAS不堪重负,在陪我度过了4年的时光后,在今年年初开始不断蓝屏重启向我示警,直到今天彻底开不了机了。其实在前几次连续蓝屏后我就有了准备,把重要资料在电脑上备份了一份,所以并没有什么实际上的数据损失,只是又要去弄一台NAS了。
因为之前用的DSM 5系统,对群晖这个品牌还是有一点好感的,但是在看了看现在夸张的成品NAS价格后,我还是准备自己弄一套(主要还是穷)。
手上现在有2*ssd+2*hdd,在组这套NAS的时候我就打算用TrueNAS了,但是两块hdd就很尴尬,只能选条带或者镜像。因为打算把之前放电脑硬盘上的资料再传回来,所以条带自然是不太可能,只好忍痛又买了4块同容量的机械,想着能够组6盘的raidz1/raidz2。但是尴尬的事情随之而来,之前因为预算卡的比较死,主板买的很丐(CPU也没用多好的,确实没啥必要上好主板),主板上只有4个sata接口,要接上这额外的4块硬盘就只能用扩展卡或者IT模式的阵列卡。阵列卡听说很热,而且功耗高,所以我直接买了某宝销量最高的pci x1转sata口的扩展卡,事情也随之变得不对了起来。
问题出现
组好阵列后,跑了个fio试了下,发现在测试集选的够大的情况下(远超过ARC大小),测得的均速只有200M多点。我瞬间就感觉不好了,都说zfs性能差,不至于6盘组raidz都能差到比单盘连续读写还差吧?
不信邪的我开始怀疑是不是买的硬盘中有一块是坏的,开始对单盘逐个进行fio测试,但所有盘似乎都没有明显的问题,不论是连续读写还是4k读写都没发现明显的异常。正当我一筹莫展的时候,目光看向了我那几十块钱买的sata转接器上:“不会是这东西有问题吧?”
于是我将所有硬盘的fio测速同时运行,结果发现连接到转接卡的硬盘似乎总和速度似乎被那块转接芯片限制在大约400MB/s左右。查了查资料,原来这个ASMedia的转接芯片工作在pcie2.0的协议上,在x1的pcie口上,其理论速度也仅500MB/s,于是一切都水落石出了。
在思考再三后,我将ssd从NAS上拆了下来,然后6块机械硬盘采用4块直连主板,2块通过转接卡的形式接入nas,阵列的fio测试数据终于来到了400MB/s左右。可是这样还是有点奇怪,raidz应该比这个速度快更多。在详细的对比了直连主板和扩展卡的fio的单盘测试数据后

fio-3.25
Starting 1 process
Jobs: 1 (f=1): [R(1)][100.0%][r=109MiB/s][r=27.8k IOPS][eta 00m:00s]
iops: (groupid=0, jobs=1): err= 0: pid=2470116: Thu Aug 10 20:04:35 2023
read: IOPS=28.1k, BW=110MiB/s (115MB/s)(1096MiB/10001msec)
slat (nsec): min=3247, max=78393, avg=5030.63, stdev=575.43
clat (usec): min=18, max=2770, avg=30.27, stdev= 9.38
lat (usec): min=28, max=2854, avg=35.35, stdev= 9.50
clat percentiles (usec):
| 1.00th=[ 28], 5.00th=[ 28], 10.00th=[ 28], 20.00th=[ 29],
| 30.00th=[ 30], 40.00th=[ 30], 50.00th=[ 31], 60.00th=[ 31],
| 70.00th=[ 31], 80.00th=[ 31], 90.00th=[ 32], 95.00th=[ 33],
| 99.00th=[ 37], 99.50th=[ 42], 99.90th=[ 165], 99.95th=[ 247],
| 99.99th=[ 260]
bw ( KiB/s): min=109864, max=118200, per=100.00%, avg=112365.05, stdev=2239.38, samples=19
iops : min=27466, max=29550, avg=28091.26, stdev=559.84, samples=19
lat (usec) : 20=0.01%, 50=99.68%, 100=0.16%, 250=0.13%, 500=0.03%
lat (usec) : 750=0.01%
lat (msec) : 4=0.01%
cpu : usr=2.68%, sys=16.98%, ctx=280656, majf=0, minf=14
IO depths : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
issued rwts: total=280650,0,0,0 short=0,0,0,0 dropped=0,0,0,0
latency : target=0, window=0, percentile=100.00%, depth=1
Run status group 0 (all jobs):
READ: bw=110MiB/s (115MB/s), 110MiB/s-110MiB/s (115MB/s-115MB/s), io=1096MiB (1150MB), run=10001-10001msec
Disk stats (read/write):
sda: ios=277593/0, merge=0/0, ticks=8155/0, in_queue=8154, util=99.10%

iops: (g=0): rw=read, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=1
fio-3.25
Starting 1 process
Jobs: 1 (f=1): [R(1)][100.0%][r=90.8MiB/s][r=23.2k IOPS][eta 00m:00s]
iops: (groupid=0, jobs=1): err= 0: pid=2474582: Thu Aug 10 20:06:12 2023
read: IOPS=21.9k, BW=85.6MiB/s (89.7MB/s)(856MiB/10001msec)
slat (nsec): min=3317, max=54624, avg=5602.10, stdev=1439.03
clat (usec): min=23, max=31532, avg=39.59, stdev=90.62
lat (usec): min=35, max=31589, avg=45.26, stdev=90.75
clat percentiles (usec):
| 1.00th=[ 37], 5.00th=[ 37], 10.00th=[ 37], 20.00th=[ 38],
| 30.00th=[ 38], 40.00th=[ 38], 50.00th=[ 38], 60.00th=[ 39],
| 70.00th=[ 39], 80.00th=[ 40], 90.00th=[ 44], 95.00th=[ 44],
| 99.00th=[ 50], 99.50th=[ 56], 99.90th=[ 229], 99.95th=[ 237],
| 99.99th=[ 1029]
bw ( KiB/s): min=74120, max=92960, per=99.72%, avg=87399.79, stdev=6061.48, samples=19
iops : min=18530, max=23240, avg=21849.95, stdev=1515.37, samples=19
lat (usec) : 50=99.10%, 100=0.64%, 250=0.24%, 500=0.01%, 750=0.01%
lat (usec) : 1000=0.01%
lat (msec) : 2=0.01%, 4=0.01%, 20=0.01%, 50=0.01%
cpu : usr=2.57%, sys=14.93%, ctx=219145, majf=0, minf=16
IO depths : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
issued rwts: total=219136,0,0,0 short=0,0,0,0 dropped=0,0,0,0
latency : target=0, window=0, percentile=100.00%, depth=1
Run status group 0 (all jobs):
READ: bw=85.6MiB/s (89.7MB/s), 85.6MiB/s-85.6MiB/s (89.7MB/s-89.7MB/s), io=856MiB (898MB), run=10001-10001msec
Disk stats (read/write):
sdg: ios=216665/42, merge=0/0, ticks=8328/88, in_queue=8434, util=99.07%

上面的为直连主板sata的测试结果,在直连主板的情况下,iops平均为28k,波动为1k,测速为110MB/s。但是通过扩展卡的硬盘iops仅有22k,最差的时候甚至仅有18k,速度为85MB/s。那么解决方案也就很明确了,换it模式的阵列卡
后记
在换用it模式的阵列卡后,使用相同的方式测速,所有盘的IOPS测试的平均值为25k,波动为1k,速度为100MB/s。虽然比不上直连主板的性能,但由于阵列的性能瓶颈为最差的那块盘,所以阵列整体的测速要好上很多,在写入两倍arc缓存大小的文件时,速度能达到600-800MB/s。所以,软阵列还是远离这种转接卡比较好 :-(