且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

测试开启MySQL performance_schema后对性能的影响

更新时间:2022-10-09 20:19:30

在开启MySQL PerformanceSchema 性能收集功能的情况下,对数据库性能影响。

测试环境:

MySQL版本:percona5.6.37
压测工具:sysbench
基础数据量:100W
压测时长:1200S
压测类型:OLTP
线程数:10/25/40
是否开启PerformanceSchema:是/否/部分开启

测试开启MySQL performance_schema后对性能的影响

测试步骤:

一:数据库及sysbench部署(略)
二:压测脚本
# 准备数据
sysbench --mysql-port=3308 --mysql-user=tpcc --mysql-password=tpcc --test=tests/db/oltp.lua --oltp_tables_count=3 --oltp-table-size=1000000 --rand-init=on prepare --mysql-socket=/opt/mysql/run/mysql.sock

# 测试
sysbench --mysql-port=3308 --mysql-user=tpcc --mysql-password=tpcc --test=./tests/db/oltp.lua **--num-threads=10** --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=1200 --max-requests=0 --percentile=99 run --oltp_tables_count=3 --mysql-socket=/opt/mysql/run/mysql.sock

# 清理压测环境
sysbench --mysql-port=3308 --mysql-user=tpcc --mysql-password=tpcc --test=tests/db/oltp.lua --oltp_tables_count=3 --oltp-table-size=1000000 --rand-init=on cleanup --mysql-socket=/opt/mysql/run/mysql.sock 
三:PS开启方法
# 默认不开启
[mysqld]
performance_schema=OFF

# 开启
[mysqld]
performance_schema=ON
# 重启数据库

# The setup_instruments table lists classes of instrumented objects for which events can be collected
# 只开启线程事件监控功能

SELECT * FROM setup_instruments WHERE NAME LIKE 'statement/%';
update  setup_instruments set ENABLED='NO',TIMED ='NO' ;
update  setup_instruments set ENABLED='YES',TIMED ='YES' WHERE NAME LIKE 'statement/%';

#The setup_consumers table lists the types of consumers for which event information can be stored and which are enabled:
#开启需要监控的事件类型

update setup_consumers  set ENABLED ='NO'; 
update setup_consumers set ENABLED ='YES' WHERE NAME LIKE 'events_statements_current';
update setup_consumers set ENABLED ='YES' WHERE NAME LIKE 'statements_digest';
update setup_consumers set ENABLED = 'YES' where name like '%instrumentation';

#The setup_timers table shows the currently selected event timers
#多久收集一次事件信息

SELECT * FROM setup_timers WHERE NAME = 'statement';

四:压测结果收集
收集信息包括压测并发线程数thread,每秒平均事务数trx ,平均每秒读r,平均每秒写w
首先是在开启PS情况下的测试(01),(02)是默认不开启定况下的测试
测试开启MySQL performance_schema后对性能的影响

测试开启MySQL performance_schema后对性能的影响

五:结论
当前环境下三轮测试结果可以看出,数据库性能随并发量的变化而变化
(1)不开启PS的情况下,数据库性能还未到达瓶颈;
(2)开启PS的情况下,数据库过早地到达了性能瓶颈,且相对有10%左右的损耗
(3)当前只开启了PS的事件检测功能,性能就有了损耗,若想开启其他类型的监控,请以当前业务环境类型进行压测,决定是否开启PS。

参考资料:
https://dev.mysql.com/doc/refman/5.6/en/performance-schema-table-descriptions.html
https://dev.mysql.com/doc/refman/5.6/en/events-statements-current-table.html
https://dev.mysql.com/doc/refman/5.6/en/setup-instruments-table.html