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性能 调度 内存分 ...
随机推荐
- Android ConstraintLayout 说明和例子
快速说明 当我们点击一个按钮时,显示效果如下 Baseline的显示需要右键该控件,然后 约束类型 尺寸约束 实心方块,用来调整组件的大小 边界约束 空心圆圈,建立组件之间,组件和parent的约束关 ...
- pramfs理论
一.文件系统 1.百度百科: http://baike.baidu.com/link?url=WE3aLsszfbZZIPK-Vz8yPd799_RMqyfQZ4D-ETS5yd1nI8XzPK660 ...
- [转帖]国内拉取google kubernetes镜像
国内拉取google kubernetes镜像 2019年04月19日 01:19:03 willblog 阅读数 4231 标签: kubernetes 更多 个人分类: kubernetes ...
- php 简单的 单例模式
php单例模式简单说明 使用注意事项: 1.使用时不能用反射模式创建单例,否则会实例化一个新的对象 2.使用懒单例模式时注意线程安全问题 3.饿单例模式和懒单例模式构造方法都是 ...
- less的引用及公共变量的抽离
一.什么是less? less是什么自然不用多言,乃一个css预编译器,可以扩展css语言,添加功能如如允许变量(variables),混合(mixins),函数(functions) 和许多其他的技 ...
- 搞懂Dubbo服务发布与服务注册
一.前言 本文讲服务发布与服务注册,服务提供者本地发布服务,然后向注册中心注册服务,将服务实现类以服务接口的形式提供出去,以便服务消费者从注册中心查阅并调用服务. 本文源码分析基于org.apache ...
- tensorflow零起点快速入门(1)
导入: 其中的TF_CPP_MIN_LOG_LEVEL据说是为了忽略警告,但是我这里没有意义(numpy的一些警告) import tensorflow as tf import os os.envi ...
- 命名规范 camel case, pascal case, hyphen
2019-11-08 refer : https://ux.stackexchange.com/questions/43174/update-vs-modify-vs-change-create-v ...
- Datetime 在C#中的用法 获取当前时间的各种格式
DateTime 获得当前系统时间: DateTime dt = DateTime.Now; Environment.TickCount可以得到“系统启动到现在”的毫秒值 DateTime now = ...
- c# 是如何对一个可遍历对象实现遍历的
public class Persons:IEnumerable { public Persons(string[] people) { this.people = people; } public ...