一、关于DB的写
1、数据库是一个写频繁的系统
2、后台写、写缓存
3、commit需要写入
4、写缓存失效或者写满-->写压力陡增-->写占读的带宽
1、BBU失效
2、写入突然增加、cache满
5、日志写入、脏缓冲区写入
二、写压力性能监控
全面剖析写压力:多维度的对写性能进行监控。
1、OS层面的监控:iostat -x
[root@localhost mydata]# iostat -x
Linux 2.6.32-642.el6.x86_64 (localhost.chinaitsoft.com) 07/05/2017 _x86_64_ (8 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.03 0.00 0.00 99.97
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await r_await w_await svctm %util
scd0 0.00 0.00 0.00 0.00 0.01 0.00 7.72 0.00 1.25 1.25 0.00 1.25 0.00
sdc 0.02 0.00 0.01 0.00 0.07 0.00 7.93 0.00 0.89 0.89 0.00 0.72 0.00
sda 0.18 0.13 0.13 0.05 5.38 1.43 37.95 0.00 6.63 3.99 13.77 2.23 0.04
sdb 0.03 0.00 0.01 0.00 0.12 0.00 8.72 0.00 1.14 0.80 35.89 0.71 0.00
1、写入的吞吐量:wsec/s sec=512字节=0.5K、写入的响应时间:await
2、我们需要确认我们的系统是写入还是读取的系统,如果是写入为主的系统,写压力自然就大,相关状态值也就大些。
3、监控系统的io状况,主要查看%util、r/s、w/s,一般繁忙度在70%,每秒写也在理想值了;但如果系统目前繁忙度低,每秒写很低,可以增加写入。
2、DB层面监控,有没有写异常:监控各种pending(挂起)
mysql> show global status like '%pend%';
+------------------------------+-------+
| Variable_name | Value |
+------------------------------+-------+
| Innodb_data_pending_fsyncs | 0 | #被挂起的fsync
| Innodb_data_pending_reads | 0 | #被挂起的物理读
| Innodb_data_pending_writes | 0 | #被挂起的写
| Innodb_os_log_pending_fsyncs | 0 | #被挂起的日志fsync
| Innodb_os_log_pending_writes | 0 | #被挂起的日志写
+------------------------------+-------+
5 rows in set (0.01 sec)
写挂起次数值大于0,甭管是什么写挂起,出现挂起的话就说明出现写压力,所以值最好的是保持为0。监控“挂起”状态值,出现大于0且持续增加,报警处理。
3、写入速度监控:日志写、脏页写
1、日志写入速度监控
mysql> show global status like '%log%written';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| Innodb_os_log_written | 5120 |
+----------------