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表进行更新) 数 ...
- Fabric Raft机制理解
为了不被无缘无故甩锅锅,这个我要好好理解下.
- Mac 每次重启终端后配置的不生效.需要重新source
Mac 每次都要执行source ~/.bash_profile 配置的环境变量才生效 自己在 ~/.bash_profile 中配置环境变量, 可是每次重启终端后配置的不生效.需要重新执行 : $s ...
- 判断屏幕宽度px大小鉴别是移动设备或者PC
if(window.matchMedia("(max-width: 767px)").matches){ alert("这是一个移动设备.");}else { ...
- 外边距margin的叠加问题
下午在看<css禅意花园>,书中提到了外边距重叠,于是去网上搜索了一下资料. 写了一个小例子做测试.发现网上的有些总结与我的测试不符,索性就自己总结了╮(╯▽╰)╭ <!DOCTYP ...
- XXLJOB2.1.0数据源配置踩坑记录
最近在看XXLJOB,因为截至到发文时间最新的版本是2.1.0而且需要建立的数据库与Quartz解耦了,所以就用了最新的版本. 首先说一下踩坑过程: 代码开发完成之后,在定时跑的时候第一次跑的多数失败 ...
- shell 选择打印部分输出内容
1. 根据进程pid查端口: lsof -i | grep pid 2. 根据端口port查进程(某次面试还考过): lsof -i:port 3. 根据进程pid查端口: netstat -n ...
- 【hash表】图书管理
[哈希和哈希表]图书管理 题目描述 图书管理是一件十分繁杂的工作,在一个图书馆中每天都会有许多新书加入.为了更方便的管理图书(以便于帮助想要借书的客人快速查找他们是否有他们所需要的书),我们需要设计一 ...
- Codeforces 1244D. Paint the Tree
传送门 首先如果某个点的度数大于 $2$ 那么显然无解 然后考虑点的度数小于等于 $2$ 的情况 发现其实是一条链 一旦确定了链开头的两个点,后面的点的颜色都可以通过之前的点推出 所以直接枚举即可 # ...
- eclipse 创建Java web项目 Cannot change version of project facet Dynamic web module to xxx
问题描述: 用Eclipse创建Java web项目时选择的Artifact Id为maven-artchetype-webapp,由于这个archetype比较老,用的servlet还是2.3的. ...