测试服务器(或虚拟机)的QPS峰值
利用sysbench压测工具模拟SELECT操作
# 已有test库的话先drop掉
drop database test;
create database test;
# prepare准备阶段,构建压测环境
sysbench /usr/local/share/sysbench/tests/include/oltp_legacy/select.lua \
--oltp-table-size=20000 --mysql-table-engine=innodb --db-driver=mysql \
--mysql-user=root --mysql-password=root123 --mysql-port=3306 \
--mysql-host=10.245.231.202 --mysql-db=test \
--events=0 --time=60 --oltp-tables-count=20 --report-interval=10 --threads=2 prepare
# 开始压测
sysbench /usr/local/share/sysbench/tests/include/oltp_legacy/select.lua \
--oltp-table-size=20000 --mysql-table-engine=innodb --db-driver=mysql \
--mysql-user=root --mysql-password=root123 --mysql-port=3306 \
--mysql-host=10.245.231.202 --mysql-db=test \
--events=0 --time=60 --oltp-tables-count=20 --report-interval=10 --threads=2 run
sysbench 1.0.5 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 2
Report intermediate results every 10 second(s)
Initializing random number generator from current time
Initializing worker threads...
Threads started!
[ 10s ] thds: 2 tps: 8087.29 qps: 8087.29 (r/w/o: 8087.29/0.00/0.00) lat (ms,95%): 0.34 err/ s: 0.00 reconn/s: 0.00
[ 20s ] thds: 2 tps: 6949.28 qps: 6949.28 (r/w/o: 6949.28/0.00/0.00) lat (ms,95%): 0.35 err/ s: 0.00 reconn/s: 0.00
[ 30s ] thds: 2 tps: 7251.71 qps: 7251.71 (r/w/o: 7251.71/0.00/0.00) lat (ms,95%): 0.34 err/ s: 0.00 reconn/s: 0.00
[ 40s ] thds: 2 tps: 6927.19 qps: 6927.19 (r/w/o: 6927.19/0.00/0.00) lat (ms,95%): 0.35 err/ s: 0.00 reconn/s: 0.00
[ 50s ] thds: 2 tps: 7387.64 qps: 7387.64 (r/w/o: 7387.64/0.00/0.00) lat (ms,95%): 0.32 err/ s: 0.00 reconn/s: 0.00
[ 60s ] thds: 2 tps: 10171.21 qps: 10171.21 (r/w/o: 10171.21/0.00/0.00) lat (ms,95%): 0.26 err/ s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 467780
write: 0
other: 0
total: 467780
transactions: 467780 (7795.29 per sec.)
queries: 467780 (7795.29 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0008s
total number of events: 467780
Latency (ms):
min: 0.11
avg: 0.25
max: 27.63
95th percentile: 0.34
sum: 119092.82
Threads fairness:
events (avg/stddev): 233890.0000/242.00
execution time (avg/stddev): 59.5464/0.00
|
使用orzdba工具实际查看
[mysql@mydb1 ~]$ ./orzdba -lazy
.=================================================.
| Welcome to use the orzdba tool ! |
| Yep...Chinese English~ |
'=============== Date : 2017-08-20 ==============='
HOST: mydb1 IP: 10.245.231.202
DB : lyj|performance_schema
Var : port[3306] read_only[OFF] version[5.6.35-log]
binlog_format[ROW] max_binlog_cache_size[4G] max_binlog_size[500M]
max_connect_errors[100] max_connections[214] max_user_connections[2800]
open_files_limit[1024] sync_binlog[100] table_definition_cache[600]
table_open_cache[400] thread_cache_size[10]
innodb_adaptive_flushing[ON] innodb_adaptive_hash_index[ON] innodb_buffer_pool_instances[8]
innodb_buffer_pool_size[4G] innodb_file_per_table[ON] innodb_flush_log_at_trx_commit[1]
innodb_flush_method[O_DIRECT] innodb_io_capacity[1000] innodb_lock_wait_timeout[10]
innodb_log_buffer_size[64M] innodb_log_file_size[1000M] innodb_log_files_in_group[4]
innodb_max_dirty_pages_pct[60] innodb_open_files[400] innodb_read_io_threads[4]
innodb_stats_on_metadata[OFF] innodb_thread_concurrency[0] innodb_write_io_threads[10]
-------- -----load-avg---- ---cpu-usage--- ---swap--- -QPS- -TPS- -Hit%- ------threads------
time | 1m 5m 15m |usr sys idl iow| si so| ins upd del sel iud| lor hit| run con cre cac|
15:51:25| 0.07 0.04 0.05| 0 0 100 0| 0 0| 0 0 0 0 0| 0 100.00| 0 0 0 0|
15:51:28| 0.14 0.06 0.05| 8 2 90 0| 0 0| 0 0 0 7178 0| 15417 100.00| 3 4 0 0|
15:51:31| 0.13 0.06 0.05| 6 3 91 0| 0 0| 0 0 0 6757 0| 14528 100.00| 4 4 0 0|
15:51:34| 0.13 0.06 0.05| 7 2 91 0| 0 0| 0 0 0 6679 0| 14342 100.00| 4 4 0 0|
15:51:37| 0.12 0.06 0.05| 7 3 90 0| 0 0| 0 0 0 7569 0| 16285 100.00| 2 4 0 0|
15:51:40| 0.12 0.06 0.05| 8 2 90 0| 0 0| 0 0 0 7298 0| 15707 100.00| 3 4 0 0|
15:51:43| 0.19 0.07 0.06| 8 2 90 0| 0 0| 0 0 0 7668 0| 16498 100.00| 2 4 0 0|
15:51:46| 0.18 0.07 0.06| 8 2 91 0| 0 0| 0 0 0 9787 0| 21050 100.00| 2 4 0 0|
15:51:49| 0.18 0.07 0.06| 8 2 91 0| 0 0| 0 0 0 11045 0| 23759 100.00| 2 4 0 0|
15:51:52| 0.24 0.09 0.06| 8 2 90 0| 0 0| 0 0 0 9709 0| 20881 100.00| 2 4 0 0|
# 从上面可以看出QPS峰值大约在1万
|
利用ZABBIX监控工具观察QPS
zabbix自带的mysql模板共可监测以下14项,图形化查看方法如下

点”MySQL queries per second”项的Graph”就可以图形化观察QPS了

重现MySQL主从复制延迟的场景
查看主从库状态
比较主库的Position和从库的Read_Master_Log_Pos和Exec_Master_Log_Pos是不是相同,以下相同说明没有延迟
# 主库状态
mysql> show master status\G;
*************************** 1. row ***************************
File: binlog.000031
Position: 458032215
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)
# 从库状态
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.245.231.202
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000031
Read_Master_Log_Pos: 458032215
Relay_Log_File: relaylog.000002
Relay_Log_Pos: 458032375
Relay_Master_Log_File: binlog.000031
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 458032215
Relay_Log_Space: 458032541
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 101
Master_UUID: 337aaf35-1b73-11e7-8b30-005056a01c3e
Master_Info_File: /u01/data/3306/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)
|
用sysbench工具做大批量的insert
# 创建数据库
mysql> drop database lyj;
mysql> create database lyj;
# 用sysbench工具准备测试环境
sysbench /usr/local/share/sysbench/tests/include/oltp_legacy/insert.lua \
--oltp-table-size=1000000 --mysql-table-engine=innodb --db-driver=mysql \
--mysql-user=root --mysql-password=root123 --mysql-port=3306 \
--mysql-host=10.245.231.202 --mysql-db=lyj \
--events=0 --time=60 --oltp-tables-count=2 --report-interval=10 --threads=2 prepare
|
查看从库状态
在insert过程中,从库的Read_Master_Log_Pos和Exec_Master_Log_Pos出现不相同现象,表明MySQL主从复制有延迟
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Queueing master event to the relay log
Master_Host: 10.245.231.202
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000031
Read_Master_Log_Pos: 524289249
Relay_Log_File: relaylog.000002
Relay_Log_Pos: 458032683
Relay_Master_Log_File: binlog.000031
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 458032523
Relay_Log_Space: 524289857
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 22
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 101
Master_UUID: 337aaf35-1b73-11e7-8b30-005056a01c3e
Master_Info_File: /u01/data/3306/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Reading event from the relay log
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
- MySQL性能优化最佳实践 - 01 MySQL优化方法论
MySQL优化方法的关键是? MySQL参数优化,innodb_buffer_pool_size/innodb_flush_log_at_trx_commit/sync_binlog SQL开发规范 ...
- MySQL性能优化最佳实践 - 05 MySQL核心参数优化
back_log参数的作用 指定MySQL可能的TCP/IP的连接数量(一个TCP/IP连接占256k),默认是50.当MySQL主线程在很短的时间内得到非常多的连接请求,该参数就起作用,之后主线程花 ...
- 【读书笔记】读《高性能网站建设指南》及《高性能网站建设进阶指南:Web开发者性能优化最佳实践》
这两本书就一块儿搞了,大多数已经理解,简单做个标记.主要对自己不太了解的地方,做一些记录. 一.读<高性能网站建设指南> 0> 黄金性能法则:只有10%~20%的最终用户响应时间 ...
- 经典的性能优化最佳实践 web性能权威指南 读书笔记
web性能权威指南 page 203 经典的性能优化最佳实践 无论什么网络,也不管所用网络协议是什么版本,所有应用都应该致力于消除或减 少不必要的网络延迟,将需要传输的数据压缩至最少.这两条标准是经典 ...
- MySQL性能优化最佳实践20条
今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数据 ...
- ASP.NET Core 性能优化最佳实践
本文提供了 ASP.NET Core 的性能最佳实践指南. 译文原文地址:https://docs.microsoft.com/en-us/aspnet/core/performance/perfor ...
- Google的网站性能优化最佳实践
网站性能最佳实践 当描述一个web页面的页面速度,评价的一致性遵循许多不同的规则.这些规则是任何阶段的web开发可以应用的前端最佳实践.这个文档的每个规则都陈述于此,无论你是否运行页面测速工具-- ...
- react性能优化最佳实践
1.PureComponent 的使用场景 PureComponent 和 Component 的区别是,PureComponent 自带 shouldComponentUpdate 生命周期函数,会 ...
- Unity3D性能优化最佳实践(四)资源审查
Asset auditing - 资源审查 许多项目发生效能问题的真正原因只是由于人员操作不当或是试东试西,而不小心改到导入设定影响到导入的资源.(例如最近的gitlab惨案) 对于较大规模的项目,最 ...
随机推荐
- 中小规模集群----Centos6部署wordpress及java程序
1 概述 1.1 业务需求 公司共有两个业务,网上图书馆和一个电商网站.现要求运维设计一个安全架构,本着高可用.廉价的原则. 具体情况如下: 网上图书馆是基于jsp开发: 电商系统是基于 ...
- 1 PHP 5.3中的新特性
1 PHP 5.3中的新特性 1.1 支持命名空间 (Namespace) 毫无疑问,命名空间是PHP5.3所带来的最重要的新特性. 在PHP5.3中,则只需要指定不同的命名空间即可,命名空间的分隔符 ...
- Java线程——线程习题(二)生成者消费者
生产者消费者问题是线程模型中的经典问题:生产者和消费者在同一时间段内共用同一存储空间,生产者向空间里生产数据,而消费者取走数据. 这里实现如下情况的生产--消费模型: 生产者不断交替地生产两组数据“姓 ...
- Ubuntu--- 安装VMware 报错 Build enviroment error!
今天从 Ubuntu 安装 VMware 下载并安装过程都很顺利,但是在启动过程中报错误,所以总结如下: 报错原因:VMware 第一次启动需要编译一些模块,但是刚开始并没有安装 gcc 所以便报无法 ...
- C++---类成员变量定义为引用
摘要:类成员变量是可以定义为引用类型的,但是我们需要注意一下用法 note1:在类中定义引用变量, 必须要在初始化列表中初始化该成员变量(const 类型数据成员也必须在初始化列表中进行初始化) #i ...
- python编程:从入门到实践----第四章>操作列表
一.遍历整个列表 1-1.假设有一个魔术师名单,需要将其中每个魔术师的名字都打印出来. # 用for循环来打印魔术师名单中的名字 magicians=['alice','david','carolin ...
- 新手学习Web前端的三个高效学习方法,基础要重视
作为新手,出于对风险的担心,不免在学习一项新技能或者转投一个新行业的时候,有所犹豫与徘徊.毕竟,在这场类似冒险的选择中,我们需要投入时间.精力以及承受相关的经济损失.但是,只有勇敢迈出第一步,才能为生 ...
- C++常用库函数 C函数库 cstdio
常用的C/C++函数库, cstdio(stdio.h) 标准输入输出库.C Standard Input and Output Library 1. 实例 #include <cstdio&g ...
- Maven--优化依赖
Maven 会自动解析所有项目的直接依赖和传递依赖,并且根据规则正确判断每个依赖的范围,对于一些依赖冲突,也能进行调节,以确保任何一个构件只有唯一的版本在依赖中存在.在这些工作之后,最后得到的那些依赖 ...
- Window RabbitMq安装
rabbitMQ是一个在AMQP协议标准基础上完整的,可服用的企业消息系统.它遵循Mozilla Public License开源协议,采用 Erlang 实现的工业级的消息队列(MQ)服务器,Rab ...