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

本文通过使用sysbench工具在Percona Server 5.6.37上进行了在线事务处理(OLTP)测试,对比了开启与未开启Performance Schema(PS)时的数据库性能表现。结果显示,在开启PS情况下,数据库性能存在约10%的损耗。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

测试环境:

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

image

测试步骤:
一:数据库及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)是默认不开启定况下的测试
image

image

五:结论
当前环境下三轮测试结果可以看出,数据库性能随并发量的变化而变化
(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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值