技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> 算法 --> 深入浅出Flashcache(五)

深入浅出Flashcache(五)

浏览:1858次  出处信息

    前几天因为测试新版的Flashcache,为了便于监控性能指标,用Perl写了个秒级的监控程序Flashstat,一开始是通过定期获取dmsetup status的信息做解析,后来在flashcache-dev邮件列表中讨论时,Flashcache的作者Mohan Srinivasan说他已经将dmsetup status的信息暴露在/proc/flashcache_stats中,可以更加方便的解析。

    实际上,不同版本的Flashcache,输出的性能指标有一些变化。较老的stable_v1版本的性能指标暴露在/proc/flashcache_stats,但是有些重要的指标没有包含进来,例如metadata ssd writes。而新版本支持一个系统中创建多个flashcache设备,因此位置修改成了/proc/flashcache/ssddev+diskdev/flashcache_stats,其中ssddev+diskdev根据实际的设备名不同而不同,例如在上一篇我们创建的模拟设备就应该是loop0+loop1,同时sysctl参数也根据设备名可以设置多组。为了兼容,flashstat针对老版本的flashcache还是解析dmsetup status的信息,而针对新版本则解析/proc中的flashcache_stats。

    Flashstat的项目地址为:https://github.com/NinGoo/flashstat,和Mohan讨论过后,他已经将这个小工具接纳并merge到了主干代码,因此现在下载Flashcache的源码,已经在utils目录中包含了这个小工具,希望对Flashcache的用户有点用处。

    Flashstat的用法很简单,指定监控时间间隔(-i 默认1s),监控次数(-c 默认0表示一直监控),flashcache设备(-d 默认/dev/mapper/cachedev)即可。如果需要将结果重定向到文件,则建议关闭ANSI颜色显示,使用-n或者-nocolor选项即可。

    

    输出结果:

  read/s                reads per second for cachedev
  write/s               writes per second for cachedev
  diskr/s               disk reads per second
  diskw/s               disk writes per second
  ssdr/s                ssd reads per second
  ssdw/s                ssd writes per second
  uread/s               uncached reads per second
  uwrit/s               uncached writes per second
  metaw/s               metadata ssd writes per second
  clean/s               cleanings per second
  repl/s                replacement per second
  wrepl/s               write replacement per second
  hit%                  read hit percent(current hit%|total hit%)
  whit%                 write hit percent(current whit%|total whit%)
  dwhit%                dirty write hit percent(current dwhit%|total dwhit%)

    在前两天的一次测试过程中,发现iostat中disk device的svctm的波动比较大,当时利用flashstat很快定位了波动的原因。测试场景是MySQL的纯读场景,disk device的svctm一般都小于1ms,偶尔会波动到2ms,4ms甚至6ms以上,但没有超过8ms。

    首先查看raid卡的cache策略

$sudo /opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -LALL -aALL
Adapter 0-VD 0(target id: 0): Cache Policy:WriteBack, ReadAheadNone, Direct, Write Cache OK if bad BBU

    所有Raid卡不会缓存读操作,如果读IO透过flashcache落到了disk,那响应时间应该在6ms左右是正常的。而Raid卡会缓存写操作,写的响应时间就会短很多,一般在1ms以内。所以iostat显示的小于1ms的svctm,应该是混合了读写的平均响应时间的结果。但MySQL测试的场景是纯读,只有select,哪里来的写呢?通过flashstat发现clean/s和diskw/s一直持续有较大的值,原来是新版本的flashcache增加了根据脏块的过期时间后台刷出的特性,于是尝试关闭该特性

$sudo sh -c "echo 0 > /proc/sys/dev/flashcache/fioa+sdb1/fallow_delay"

    再观察flashstat的结果,发现clean/s, diskw/s变为0,同时iostat -x显示sdb的svctm时间稳定在5ms左右了。也就是说,之前看到的svctm时间不稳定,是由于flashcache后台刷出过期脏块的波动导致的,当刷出写入disk的力度较大时,由于写的响应时间较短(一般在100~200微妙),iostat的读写混合平均响应时间较低,而当写出较少时,iostat的读写混合平均响应时间反而较高了。用数据说话,但如果数据是平均值,则很容易掩盖掉一些瞬间的波动的珍视情况,尽信数据,不如无数据

    另外,利用blkiomon,也可以很好的验证上面的结论。blkiomon可以看到不同大小的io的响应时间的分布,根据blkiomon的输出结果,可以比较方便的分析io的行为,帮助追踪和确认很多的io工具,一大神器。

    下面是一个输出的示例,可以看到,1369次读io的平均大小是13k,平均响应时间约5.5ms,而245次写io的平均大小约20k,平均响应时间约203微秒。响应时间分布中,1毫秒以内的io次数有244次(差不多都是写),最快的响应时间只有26微妙。2毫秒以上的有1370次(差不读多都是读),响应最慢的有一次达到35毫秒。

$sudo  mount -t debugfs none /sys/kernel/debug/

$sudo  blktrace /dev/sdb -a issue -a complete -w 3600 -o - | blkiomon -I 5 -h -

time: Fri Jan 13 23:50:43 2012
device: 8,16
sizes read (bytes): num 1369, min 4096, max 16384, sum 18919424, squ 286236082176, avg 13819.9, var 18094812.6
sizes write (bytes): num 245, min 4096, max 131072, sum 5124096, squ 317106159616, avg 20914.7, var 856887118.5
d2c read (usec): num 1369, min 154, max 35396, sum 7526791, squ 51513446469, avg 5498.0, var 7400285.0
d2c write (usec): num 245, min 26, max 9605, sum 49959, squ 238326529, avg 203.9, var 931180.3
throughput read (bytes/msec): num 1369, min 298, max 106389, sum 4275218, squ 28512922538, avg 3122.9, var 11075196.9
throughput write (bytes/msec): num 245, min 2287, max 970903, sum 54430349, squ 24934376050407, avg 222164.7, var 52415814078.9
sizes histogram (bytes):
            0:     0         1024:     0         2048:     0         4096:   217
         8192:   212        16384:  1129        32768:    25        65536:    11
       131072:    20       262144:     0       524288:     0      1048576:     0
      2097152:     0      4194304:     0      8388608:     0    > 8388608:     0
d2c histogram (usec):
            0:     0            8:     0           16:     0           32:     8
           64:    99          128:    61          256:    73          512:     1
         1024:     2         2048:    52         4096:   350         8192:   809
        16384:   151        32768:     7        65536:     1       131072:     0
       262144:     0       524288:     0      1048576:     0      2097152:     0
      4194304:     0      8388608:     0     16777216:     0     33554432:     0
    >33554432:     0
bidirectional requests: 0

    参考文章:

     [1] Flashcache README

     [2] IO模式调查利器blkiomon介绍

建议继续学习:

  1. Ubuntu工作机使用FlashCache技术加速    (阅读:5067)
  2. 深入浅出Flashcache(一)    (阅读:2368)
  3. 深入浅出Flashcache(三)    (阅读:1971)
  4. 深入浅出Flashcache(四)    (阅读:1829)
  5. 深入浅出Flashcache(二)    (阅读:1802)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1