sysbench0.4.12测试query_cache_size和query_cache_type
建议:
query_cache_size和query_cache_type生产环境中关闭。
(1)软件包下载地址:
https://dev.mysql.com/downloads/benchmarks.html
(2)安装
tar xzvf sysbench-0.4.12.14.tar.gz
cd sysbench-0.4.12.14
./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib
make && make install
sysbench -v
which sysbench
sysbench --version
(3)测试query_cache=0关闭还是其它值和query_cache_type=off或开启。
以下是第一种情况:
mysql> show variables like "query_cache_size%";
+------------------+---------+
| Variable_name | Value |
+------------------+---------+
| query_cache_size | 1048576 |
+------------------+---------+
1 row in set (0.00 sec)
mysql> show variables like "query_cache_type%";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| query_cache_type | OFF |
+------------------+-------+
1 row in set (0.00 sec)
(a)测试三过程prepare(创建sbtest表等环境)、run(正式测试)、clean(清除);
[root@zstedu lib]# /usr/local/bin/sysbench --test=oltp --mysql-table-engine=innodb --mysql-db=andyhsi --oltp-table-size=10000 --db-driver=mysql --num-threads=16 --mysql-socket=/tmp/mysql3306.sock --mysql-user=root --mysql-password="andyxi" prepare
sysbench 0.4.12.10: multi-threaded system evaluation benchmark
Creating table 'sbtest'...
Creating 10000 records in table 'sbtest'...
[root@zstedu lib]# /usr/local/bin/sysbench --test=oltp --mysql-table-engine=innodb --mysql-db=andyhsi --oltp-table-size=10000 --db-driver=mysql --num-threads=16 --mysql-socket=/tmp/mysql3306.sock --mysql-user=root --mysql-password="andyxi" run
sysbench 0.4.12.10: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 16
Random number generator seed is 0 and will be ignored
Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 10000
Using 1 test tables
Threads started!
Done.
OLTP test statistics:
queries performed:
read: 144102
write: 50592
other: 20293
total: 214987
transactions: 10000 (158.16 per sec.)
deadlocks: 293 (4.63 per sec.)
read/write requests: 194694 (3079.30 per sec.)
other operations: 20293 (320.96 per sec.)
General statistics:
total time: 63.2267s
total number of events: 10000
total time taken by event execution: 1008.7897
response time:
min: 9.51ms
avg: 100.88ms
max: 1134.90ms
approx. 95 percentile: 277.95ms
Threads fairness:
events (avg/stddev): 625.0000/5.72
execution time (avg/stddev): 63.0494/0.09
(2)
mysql> show variables like "query_cache_size%";
+------------------+---------+
| Variable_name | Value |
+------------------+---------+
| query_cache_size | 0 |
+------------------+---------+
1 row in set (0.00 sec)
mysql> show variables like "query_cache_type%";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| query_cache_type | OFF |
+------------------+-------+
1 row in set (0.00 sec)
[root@zstedu lib]# /usr/local/bin/sysbench --test=oltp --mysql-table-engine=innodb --mysql-db=andyhsi --oltp-table-size=10000 --db-driver=mysql --num-threads=16 --mysql-socket=/tmp/mysql3306.sock --mysql-user=root --mysql-password="andyxi" run
sysbench 0.4.12.10: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 16
Random number generator seed is 0 and will be ignored
Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 10000
Using 1 test tables
Threads started!
Done.
OLTP test statistics:
queries performed:
read: 143892
write: 50550
other: 20278
total: 214720
transactions: 10000 (162.17 per sec.)
deadlocks: 278 (4.51 per sec.)
read/write requests: 194442 (3153.32 per sec.)
other operations: 20278 (328.85 per sec.)
General statistics:
total time: 61.6626s
total number of events: 10000
total time taken by event execution: 986.1886
response time:
min: 9.31ms
avg: 98.62ms
max: 1305.78ms
approx. 95 percentile: 214.48ms
Threads fairness:
events (avg/stddev): 625.0000/6.88
execution time (avg/stddev): 61.6368/0.01
(3)
mysql> show variables like "query_cache_type%";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| query_cache_type | ON |
+------------------+-------+
mysql> show variables like "query_cache_size";
+------------------+---------+
| Variable_name | Value |
+------------------+---------+
| query_cache_size | 0 |
+------------------+---------+
Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 10000
Using 1 test tables
Threads started!
Done.
OLTP test statistics:
queries performed:
read: 143304
write: 50479
other: 20236
total: 214019
transactions: 10000 (202.88 per sec.)
deadlocks: 236 (4.79 per sec.)
read/write requests: 193783 (3931.51 per sec.)
other operations: 20236 (410.55 per sec.)
General statistics:
total time: 49.2897s
total number of events: 10000
total time taken by event execution: 788.1897
response time:
min: 9.04ms
avg: 78.82ms
max: 227.10ms
approx. 95 percentile: 111.58ms
Threads fairness:
events (avg/stddev): 625.0000/3.74
execution time (avg/stddev): 49.2619/0.02
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
发现 query_cache_type 是off问 是否有必要打开 query_cache_type , 他的好处或者是否适合搞并发的oltp系统?
- 看你的查询是否会有许多相同的。如果经常有 select name from department; 这样,有cache当然会快。 但如果你的应用中相同的查询很少则意义不大。
- select name from department where name ='???';
这样的很多 , 基本name名字都不同 这个可以用有cache???MySQL query_cache_type 详解
MySQL设置查询缓存的用意:
把查询到的结果缓存起来,下次再执行相同查询时就可以直接从结果集中取;这样就比重新查一遍要快的多。
查询缓存的最终结果是事与愿违:
之所以查询缓存并没有能起到提升性能的做用,客观上有如下两点原因
1、把SQL语句的hash值作为键,SQL语句的结果集作为值;这样就引起了一个问题如 select user from mysql.user 和 SELECT user FROM mysql.user
这两个将会被当成不同的SQL语句,这个时候就算结果集已经有了,但是一然用不到。
2、当查询所基于的低层表有改动时与这个表有关的查询缓存都会作废、如果对于并发度比较大的系统这个开销是可观的;对于作废结果集这个操作也是要用并发
访问控制的,就是说也会有锁。并发大的时候就会有Waiting for query cache lock 产生。
3、至于用不用还是要看业务模型的。
如果何配置查询缓存:
query_cache_type 这个系统变量控制着查询缓存工能的开启的关闭。
query_cache_type=0时表示关闭,1时表示打开,2表示只要select 中明确指定SQL_CACHE才缓存。
这个参数的设置有点奇怪,1、如果事先查询缓存是关闭的然而用 set @@global.query_cache_type=1; 会报错
ERROR 1651 (HY000): Query cache is disabled; restart the server with query_cache_type=1 to enable it
2、如果事先是打开着的尝试去闭关它,那么这个关闭也是不完全的,这种情况下查询还是会去尝试查找缓存。
最好的关闭查询缓存的办法就是把my.cnf 中的query_cache_type=0然后再重启mysql。
查询缓存相关的系统变量:
have_query_cache 表示这个mysql版本是否支持查询缓存。
query_cache_limit 表示单个结果集所被允许缓存的最大值。
query_cache_min_res_unit 每个被缓存的结果集要占用的最小内存。
query_cache_size 用于查询缓存的内存大小。
如何监控查询缓存的命中率:
Qcache_free_memory 查询缓存目前剩余空间大小。
Qcache_hits 查询缓存的命中次数。
Qcache_inserts 查询缓存插入的次数。
也就是说缓存的命中率为 Qcache_hits/(Qcache_hits+Qcache_inserts)
sysbench0.4.12测试query_cache_size和query_cache_type的更多相关文章
- mysql之 sysbench0.4.12数据库性能测试
1. 常用选项 在Shell中运行以下命令便可得到sysbench的常用选项信息: sysbench --help 上述命令的输出信息如下图所示: 1.1 使用语法 使用sysbench时,可以通过以 ...
- openstack controller ha测试环境搭建记录(四)——配置mysql数据库集群
内容正式开始前,我已经在集群中添加了新的节点controller1(IP地址为10.0.0.14). 在所有节点上安装软件:# yum install -y mariadb-galera-server ...
- 使用 sysbench对mysql进行压力测试介绍之一
sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试.数据库目前支持MySQL/Oracle/PostgreSQL.本文只是简单演示一下几种测试的用 ...
- sysbench压力测试工具简介和使用(一)
sysbench压力测试工具安装和参数介绍 一.sysbench压力测试工具简介: sysbench是一个开源的.模块化的.跨平台的多线程性能测试工具,可以用来进行CPU.内存.磁盘I/O.线程.数据 ...
- MySQL MHA 搭建&测试(环境:CentOS7 + MySQL5.7.23)
MySQL MHA架构介绍: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Face ...
- sysbench压力测试工具安装和参数介绍
一.sysbench压力测试工具简介: sysbench是一个开源的.模块化的.跨平台的多线程性能测试工具,可以用来进行CPU.内存.磁盘I/O.线程.数据库的性能测试.目前支持的数据库有MySQL. ...
- sysbench 压力测试工具
一.sysbench压力测试工具简介: sysbench是一个开源的.模块化的.跨平台的多线程性能测试工具,可以用来进行CPU.内存.磁盘I/O.线程.数据库的性能测试.目前支持的数据库有MySQL. ...
- sysbench 0.4.12安装
前提:mysql已安装完成,请参考http://www.cnblogs.com/lizhi221/p/6813907.html 安装依赖环境包: yum install -y bzr yum in ...
- 压力测试工具sysbench
sysbench是一个模块化.跨平台.多线程基准测试工具,主要用于测试不同系统参数下的数据库负载情况,本文主要介绍0.4版本的使用.sysbench主要用于以下性能测试: 文件I/O性能 调度 内存分 ...
随机推荐
- merge效率
测试merge效率 测试说明: MERGE是oracle提供的一种特殊的sql语法,非常适用于数据同步场景,即: (把A表数据插到B表,如果B表存在相同主键的记录则使用A表数据对B表进行更新) 数 ...
- Git提交本地项目文件到GitHub的详细操作
因最近在使用git命令提交代码到github的操作,网上找了下教程,记录下过程,便于查看 添加整个文件夹及内容 git add 文件夹/ 添加目录中所有某种类型的文件 git add *.文件类型 `
- PYTHON 100days学习笔记006:函数和模块的使用
目录 Day006:函数和模块的使用 1.函数的作用 2.定义函数 2.1 语法 2.2 实例 2.3 函数的调用 4.函数的参数 4.1 必须参数 4.2 关键字参数 4.3 默认参数 4.4 不定 ...
- ULB
https://docs.ucloud.cn/network/ulb/intro/whatisulb 创建ulb ulb里创建vserver, 设置监听端口 配置后端转发节点(服务节点) 在服务节点上 ...
- Windows冷门快捷键
Win+Shift+>或者+<光标键,可以使一个程序,在双屏显示器上左右切换. alt+space快捷键相当于在窗口的标题栏上面右键单击,弹出菜单,选择M键,就可以使用光标键上下左右移动来 ...
- SQL server 维护计划中 “清除维护任务” 执行报错
SQL server 维护计划中 “清除维护任务” 执行报错,错误如下: 执行查询“EXECUTE master.dbo.xp_delete_file 0,N'',N'',N'2019...”失败,错 ...
- 【Life】 今天的思考
今天一个实习生来问我问题,他要用python操作outlook发送邮件,代码是从网上找的. 在其他人的电脑上可以成功运行,但在他的电脑上就失败. 处理过程 (1)我查看了他method里的代码, 发现 ...
- 在react项目当中做导航守卫
距离上一篇文章,似乎已经过去好久了. 确实是最近相对忙了一点,本身是用vue重构之前一个传统的项目,就自己一个人写.而且,在稍微闲暇之余,想着同时用react也重构一遍,也算是对react的学习吧!毕 ...
- pycharm问题
Pycharm 出现Unresolved reference '' 错误的解决方法:http://www.mamicode.com/info-detail-2190842.html
- qt tableview使用
Qt::CheckState checkSibling(QStandardItem * item); void treeItem_checkAllChild(QStandardItem * item, ...