ZFS在FreeBSD上读取速度非常慢

我有一个FreeBSD 10.0系统,在这个系统上,我的MySQL运行着其存储在ZFS上的InnoDB数据库文件。 似乎几个月来一直很好,但最近,似乎突然间,performance已经触底。 在围绕MySQLdebugging了一阵子之后,我终于决定只是看看从文件系统读取数据库文件是否缓慢。

我选了一个数据库文件大约是16GB的表,运行:

time cat table.ibd > /dev/null 

并得到:

 cat table.ibd > /dev/null 1.24s user 64.35s system 0% cpu 1:00:34.65 total 

相比之下,生活在同一个系统上的UFS文件副本(有一些变化,我确定:数据库是活的)给了我:

 cat table.ibd > /dev/null 0.20s user 9.34s system 5% cpu 9.550 total 

以下是此系统上的非默认ZFS选项:

 /boot/loader.conf: vfs.zfs.arc_max=17179869184 

 /etc/sysctl.conf: vfs.zfs.prefetch_disable=1 

 zfs get: recordsize 16K compression on atime off primarycache metadata zfs:zfs_nocacheflush 1 

此文件系统上有12个快照。 (这看起来太过分了,我要看看是否可以删除其中的任何一个)

此池(或系统上的任何其他池)没有L2ARC。

我已经尝试了所有三个primarycache的值,我已经尝试重新启用预取,其中没有任何似乎有任何重大影响。

zpool是四个双盘镜像:

 % zpool status mysqlrot pool: mysqlrot state: ONLINE scan: scrub repaired 0 in 9h45m with 0 errors on Fri Jun 26 12:46:33 2015 config: NAME STATE READ WRITE CKSUM mysqlrot ONLINE 0 0 0 mirror-0 ONLINE 0 0 0 mfid9 ONLINE 0 0 0 mfid10 ONLINE 0 0 0 mirror-1 ONLINE 0 0 0 mfid11 ONLINE 0 0 0 mfid12 ONLINE 0 0 0 mirror-2 ONLINE 0 0 0 mfid13 ONLINE 0 0 0 mfid14 ONLINE 0 0 0 mirror-3 ONLINE 0 0 0 mfid15 ONLINE 0 0 0 mfid16 ONLINE 0 0 0 spares mfid19 AVAIL errors: No known data errors 

奇怪的是原始设备是如何build立的。 存储控制器是一个MFI控制器,并且每个原始磁盘实际上都在MFI控制器中configuration为一个单磁盘RAID0卷:

 % sudo mfiutil show volumes mfi0 Volumes: Id Size Level Stripe State Cache Name mfid0 ( 185G) RAID-1 64K OPTIMAL Disabled <OS> mfid1 ( 558G) RAID-0 64K OPTIMAL Disabled <DB0A> mfid2 ( 558G) RAID-0 64K OPTIMAL Disabled <DB0B> mfid3 ( 558G) RAID-0 64K OPTIMAL Disabled <DB1A> mfid4 ( 558G) RAID-0 64K OPTIMAL Disabled <DB1B> mfid5 ( 558G) RAID-0 64K OPTIMAL Disabled <DB2A> mfid6 ( 558G) RAID-0 64K OPTIMAL Disabled <DB2B> mfid7 ( 558G) RAID-0 64K OPTIMAL Disabled <DB3A> mfid8 ( 558G) RAID-0 64K OPTIMAL Disabled <DB3B> mfid9 ( 558G) RAID-0 64K OPTIMAL Disabled <DB4A> mfid10 ( 558G) RAID-0 64K OPTIMAL Disabled <DB4B> mfid11 ( 558G) RAID-0 64K OPTIMAL Disabled <DB5A> mfid12 ( 558G) RAID-0 64K OPTIMAL Disabled <DB5B> mfid13 ( 558G) RAID-0 64K OPTIMAL Disabled <DB6A> mfid14 ( 558G) RAID-0 64K OPTIMAL Disabled <DB6B> mfid15 ( 558G) RAID-0 64K OPTIMAL Disabled <DB7A> mfid16 ( 558G) RAID-0 64K OPTIMAL Disabled <DB7B> mfid17 ( 558G) RAID-0 64K OPTIMAL Disabled <DB8A> mfid18 ( 558G) RAID-0 64K OPTIMAL Disabled <DB8B> mfid19 ( 558G) RAID-0 64K OPTIMAL Disabled <SPARE0> 

没有任何错误,我已经能够find任何日志文件或工具。

任何人有任何想法在哪里看?


各种数据:

 % zpool list mysqlrot NAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT mysqlrot 2.17T 1.49T 701G 68% 1.00x ONLINE - 

将15.3GB文件复制受影响的文件系统(来自UFS文件系统):

 % time sudo cp test.file /var/lib/mysql/mysqlrot/test.file sudo cp test.file /var/lib/mysql/mysqlrot/test.file 0.02s user 44.23s system 1% cpu 1:06.93 total 

(这是66.93秒)

受影响的文件系统读取相同的文件:

 # time cat test.file > /dev/null cat test.file > /dev/null 4.23s user 268.50s system 0% cpu 25:29.27 total 

(这是1529.27秒:几乎比写的长23倍)。

有趣的是, cpperformance远远好于cat

 % time sudo cp /var/lib/mysql/v4netrot/test.file /dev/null sudo cp /var/lib/mysql/v4netrot/test.file /dev/null 0.03s user 33.63s system 0% cpu 3:05.99 total 

(185.99秒)


iostat复制期间的数据

  extended device statistics device r/sw/s kr/s kw/s qlen svc_t %b mfid0 0.0 0.6 0.0 8.8 0 0.6 0 mfid1 0.4 12.6 2.7 70.5 0 0.5 0 mfid2 1.8 12.8 10.8 70.5 0 1.6 2 mfid3 0.2 10.0 1.5 92.4 0 0.7 0 mfid4 0.0 10.4 0.0 92.4 0 0.5 0 mfid5 0.2 9.4 1.2 39.7 0 0.5 0 mfid6 0.6 9.8 3.9 39.7 0 0.6 0 mfid7 0.6 4.8 0.3 46.1 0 0.9 0 mfid8 1.8 4.8 11.4 46.1 0 0.8 0 mfid9 0.4 1327.2 2.9 26686.5 0 0.5 23 mfid10 0.8 1328.2 1.8 26686.5 0 0.5 20 mfid11 1.4 1304.8 8.4 26357.6 0 0.5 23 mfid12 1.4 1304.6 2.6 26357.6 0 0.6 31 mfid13 1.6 1120.6 3.5 26194.2 0 0.6 25 mfid14 0.4 1122.6 2.7 26194.2 0 0.5 22 mfid15 0.8 1406.6 5.5 26188.5 0 0.5 22 mfid16 1.0 1174.6 2.0 21534.3 10 4.9 74 mfid17 5.8 24.2 152.9 300.6 0 0.3 0 mfid18 4.0 23.6 76.7 300.6 0 0.3 0 mfid19 0.0 0.0 0.0 0.0 0 0.0 0 

千瓦/秒的数据范围从17k到25k左右,在驱动器之间非常一致。

以下地点开始时,

  extended device statistics device r/sw/s kr/s kw/s qlen svc_t %b mfid0 0.0 0.0 0.0 0.0 0 0.0 0 mfid1 0.4 17.2 11.4 63.4 0 0.5 0 mfid2 0.0 17.0 0.0 63.4 0 0.4 0 mfid3 0.0 14.0 0.0 56.4 0 0.4 0 mfid4 0.4 13.6 0.2 56.4 0 0.4 0 mfid5 0.8 9.6 4.8 37.3 0 0.8 0 mfid6 0.0 9.8 0.0 37.3 0 0.4 0 mfid7 0.2 3.8 17.2 11.9 0 0.6 0 mfid8 0.2 3.8 1.4 11.9 0 0.5 0 mfid9 1208.8 0.0 6831.4 0.0 0 0.1 11 mfid10 129.4 0.0 780.7 0.0 0 0.2 2 mfid11 906.4 0.0 5858.5 0.0 0 0.1 10 mfid12 600.5 0.0 2673.0 0.0 0 0.1 5 mfid13 136.2 0.0 803.9 0.0 0 0.2 3 mfid14 316.1 0.0 1895.3 0.0 0 0.1 4 mfid15 243.6 0.0 1414.5 0.0 0 0.1 2 mfid16 129.0 0.0 768.8 0.0 0 0.2 2 mfid17 3.8 25.8 29.8 274.1 0 0.2 0 mfid18 6.0 25.6 96.6 274.1 0 0.2 0 mfid19 0.0 0.0 0.0 0.0 0 0.0 0 

kr / s数字是非常不一致的,但这些都是有代表性的数字。

iostat while cp ing(到/ dev / null):

  extended device statistics device r/sw/s kr/s kw/s qlen svc_t %b mfid0 0.0 0.0 0.0 0.0 0 0.0 0 mfid1 21.0 66.6 107.6 2351.7 0 0.9 6 mfid2 17.6 66.8 106.8 2351.7 0 1.0 6 mfid3 17.6 39.0 116.9 2111.3 0 1.1 6 mfid4 18.8 39.6 99.8 2111.3 0 1.3 7 mfid5 23.2 62.4 172.2 2076.1 0 1.1 7 mfid6 23.0 62.0 130.0 2076.1 0 1.4 9 mfid7 16.2 62.6 112.6 2125.3 0 1.0 6 mfid8 17.4 63.0 107.6 2125.3 0 0.7 4 mfid9 237.5 44.6 5140.6 807.0 0 3.1 22 mfid10 263.7 43.6 5530.5 807.0 0 1.5 14 mfid11 252.7 55.8 5297.6 802.4 0 2.6 20 mfid12 298.1 55.6 5361.9 802.4 0 2.5 21 mfid13 275.3 46.2 5116.4 801.4 0 2.8 22 mfid14 252.9 42.4 5107.7 801.4 2 3.1 21 mfid15 270.9 43.8 4546.5 943.7 0 1.2 12 mfid16 257.7 44.0 5642.5 943.7 0 2.5 19 mfid17 7.8 23.0 73.1 244.9 0 0.3 0 mfid18 0.8 24.2 44.4 244.9 0 0.2 0 mfid19 0.0 0.0 0.0 0.0 0 0.0 0 

它似乎不受CPU限制。 top显示从受影响的文件系统到/dev/nullcp消耗大约18​​%的一个核心(48个),其余核心显示超过95%的空闲。

 last pid: 12474; load averages: 1.65, 1.26, 1.14 up 39+05:42:19 14:29:08 147 processes: 1 running, 146 sleeping CPU 0: 0.0% user, 0.0% nice, 1.6% system, 0.0% interrupt, 98.4% idle CPU 1: 0.0% user, 0.0% nice, 1.2% system, 0.0% interrupt, 98.8% idle CPU 2: 0.4% user, 0.0% nice, 0.8% system, 0.0% interrupt, 98.8% idle CPU 3: 0.0% user, 0.0% nice, 1.2% system, 0.0% interrupt, 98.8% idle CPU 4: 0.0% user, 0.0% nice, 2.3% system, 0.0% interrupt, 97.7% idle CPU 5: 0.0% user, 0.0% nice, 0.4% system, 0.0% interrupt, 99.6% idle CPU 6: 0.0% user, 0.0% nice, 1.2% system, 0.0% interrupt, 98.8% idle CPU 7: 0.0% user, 0.0% nice, 2.7% system, 0.0% interrupt, 97.3% idle CPU 8: 0.4% user, 0.0% nice, 1.9% system, 0.0% interrupt, 97.7% idle CPU 9: 0.0% user, 0.0% nice, 2.3% system, 0.0% interrupt, 97.7% idle CPU 10: 0.4% user, 0.0% nice, 1.9% system, 1.2% interrupt, 96.5% idle CPU 11: 0.0% user, 0.0% nice, 3.9% system, 0.0% interrupt, 96.1% idle CPU 12: 0.0% user, 0.0% nice, 1.6% system, 0.8% interrupt, 97.7% idle CPU 13: 0.0% user, 0.0% nice, 2.7% system, 0.0% interrupt, 97.3% idle CPU 14: 0.0% user, 0.0% nice, 1.6% system, 0.0% interrupt, 98.4% idle CPU 15: 0.4% user, 0.0% nice, 1.2% system, 0.0% interrupt, 98.4% idle CPU 16: 0.0% user, 0.0% nice, 1.6% system, 0.0% interrupt, 98.4% idle CPU 17: 0.4% user, 0.0% nice, 3.1% system, 0.0% interrupt, 96.5% idle CPU 18: 0.0% user, 0.0% nice, 0.4% system, 0.0% interrupt, 99.6% idle CPU 19: 0.8% user, 0.0% nice, 0.8% system, 0.0% interrupt, 98.4% idle CPU 20: 0.0% user, 0.0% nice, 2.7% system, 0.0% interrupt, 97.3% idle CPU 21: 0.4% user, 0.0% nice, 1.9% system, 0.0% interrupt, 97.7% idle CPU 22: 0.0% user, 0.0% nice, 2.3% system, 0.0% interrupt, 97.7% idle CPU 23: 0.4% user, 0.0% nice, 1.2% system, 0.0% interrupt, 98.4% idle CPU 24: 0.0% user, 0.0% nice, 1.2% system, 0.0% interrupt, 98.8% idle CPU 25: 0.8% user, 0.0% nice, 0.8% system, 0.0% interrupt, 98.4% idle CPU 26: 0.4% user, 0.0% nice, 0.8% system, 0.0% interrupt, 98.8% idle CPU 27: 0.0% user, 0.0% nice, 4.7% system, 0.0% interrupt, 95.3% idle CPU 28: 0.0% user, 0.0% nice, 0.8% system, 0.0% interrupt, 99.2% idle CPU 29: 0.4% user, 0.0% nice, 0.8% system, 0.0% interrupt, 98.8% idle CPU 30: 0.0% user, 0.0% nice, 2.7% system, 0.0% interrupt, 97.3% idle CPU 31: 0.0% user, 0.0% nice, 1.2% system, 0.0% interrupt, 98.8% idle CPU 32: 0.0% user, 0.0% nice, 0.8% system, 0.0% interrupt, 99.2% idle CPU 33: 0.0% user, 0.0% nice, 3.5% system, 0.0% interrupt, 96.5% idle CPU 34: 0.0% user, 0.0% nice, 0.4% system, 0.0% interrupt, 99.6% idle CPU 35: 0.0% user, 0.0% nice, 0.4% system, 0.0% interrupt, 99.6% idle CPU 36: 1.2% user, 0.0% nice, 1.6% system, 0.0% interrupt, 97.3% idle CPU 37: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle CPU 38: 0.4% user, 0.0% nice, 1.2% system, 0.4% interrupt, 98.1% idle CPU 39: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle CPU 40: 0.0% user, 0.0% nice, 1.9% system, 0.0% interrupt, 98.1% idle CPU 41: 0.0% user, 0.0% nice, 1.2% system, 0.0% interrupt, 98.8% idle CPU 42: 0.4% user, 0.0% nice, 1.9% system, 0.0% interrupt, 97.7% idle CPU 43: 0.0% user, 0.0% nice, 4.7% system, 0.0% interrupt, 95.3% idle CPU 44: 0.0% user, 0.0% nice, 2.3% system, 0.0% interrupt, 97.7% idle CPU 45: 0.4% user, 0.0% nice, 2.7% system, 0.0% interrupt, 96.9% idle CPU 46: 0.4% user, 0.0% nice, 3.5% system, 0.0% interrupt, 96.1% idle CPU 47: 0.4% user, 0.0% nice, 1.6% system, 0.0% interrupt, 98.1% idle Mem: 82G Active, 23G Inact, 15G Wired, 3340K Cache, 1655M Buf, 4858M Free ARC: 12G Total, 527M MFU, 11G MRU, 4375K Anon, 377M Header, 89M Other Swap: 4096M Total, 12M Used, 4084M Free PID USERNAME PRI NICE SIZE RES STATE C TIME WCPU COMMAND 12461 root 31 0 12268K 2552K zio->i 30 0:07 18.16% cp 3151 mysql 24 0 92309M 92073M uwait 3 22:06 7.47% mysqld{mysqld} 3151 mysql 22 0 92309M 92073M select 33 15:30 4.79% mysqld{mysqld} 3151 mysql 20 0 92309M 92073M uwait 46 895:41 0.49% mysqld{mysqld} 12175 wfaulk 20 0 23864K 6404K CPU25 25 0:03 0.29% top 6074 root 20 0 84348K 40372K kqread 25 0:11 0.20% vc-aggregator{vc-aggregator} 

(其余的进程显示0.00%的CPU利用率。)

你尝试重新启动机器吗? 有没有区别?

如果重新启动没有帮助,你面临的问题可能是过度分散,这是旋转媒体的头号敌人(读取:硬盘驱动器)。 大量的快照可能加剧这种情况。

要确认问题,请尝试以下操作:

  1. 使用命令fallocate testfile.raw -l <size>创build一个新的类似大小的文件
  2. 尝试读取新分配的文件。 如果读取得很快,那么旧文件的碎片可能是罪魁祸首。

如果您确认这是一个碎片问题,请按照下列步骤操作:

  1. 停止MySQL
  2. 采取您的table.ibd文件的备份
  3. 将其重命名为table.ibd.old( mv table.ibd table.ibd.old
  4. 将其复制到以前的文件名( cp -a table.ibd.old table.ibd
  5. 重新启动MySQL

iostat更新后编辑

感谢您的iostat号码。

您在大约67秒内将一个15 GB文件移动到ZFSarrays,这意味着每个磁盘(不包括镜像的)的吞吐速率为223 MB / s或55 MB / s。 另一方面,你的iostat似乎报告了这个(大约25 MB / s),所以我把这个差异归因于压缩比约为2:1。

好的,这很好。 然而,在阅读奇怪的事情发生…

放弃cat结果( cat默认使用一个非常小的缓冲区,禁用prefetcher肯定会比cp慢), cp命令是慢的:你在1530s复制了一个15GB的文件,这意味着一个提取率只有10 MB / s。 这已经体现了压缩优势。 另一方面,您的iostat数字显示每个磁盘读取超过5 MB / s,每个磁盘arrays总计约为40 MB / s。 考虑2:1的压缩比率,它应该给你一个80 MB / s以北的传输速率。 这意味着你的阅读潜力约为你的1/8。

问题是:为什么? 看起来好像在传输过程中CPU已经被刷新了。 你可以在读取受影响的文件期间运行topdstat会话吗? 如果可能的话,configurationtop以显示每个CPU的负载。

MFI控制器昨天完全失败。 我猜这种缓慢只是即将发生硬件故障的一个早期症状。