您的位置:首页 > 数据库 > MySQL

性能调优之mysql通过status性能优化 2

2016-02-29 17:18 756 查看
四、临时表mysql> show global status like 'created_tmp%';
+-------------------------+---------+
| variable_name            | value    |
+-------------------------+---------+
| created_tmp_disk_tables | 21197    |
| created_tmp_files        | 58       |
| created_tmp_tables       | 1771587 |
+-------------------------+---------+每次创建临时表,created_tmp_tables增加,如果是在磁盘上创建临时表,created_tmp_disk_tables也增加,created_tmp_files表示mysql服务创建的临时文件文件数,比较理想的配置是:  created_tmp_disk_tables / created_tmp_tables * 100%< = 25%比如上面的服务器created_tmp_disk_tables / created_tmp_tables * 100% = 1.20%,应该相当好了。我们再看一下mysql服务器对临时表的配置:mysql> show variables where variable_name in ('tmp_table_size', 'max_heap_table_size');
+---------------------+-----------+
| variable_name        | value      |
+---------------------+-----------+
| max_heap_table_size | 268435456 |
| tmp_table_size       | 536870912 |
+---------------------+-----------+只有256mb以下的临时表才能全部放内存,超过的就会用到硬盘临时表。五、open table情况mysql> show global status like 'open%tables%';
+---------------+-------+
| variable_name | value |
+---------------+-------+
| open_tables    | 919    |
| opened_tables | 1951  |
+---------------+-------+open_tables表示打开表的数量,opened_tables表示打开过的表数量,如果opened_tables数量过大,说明配置中 table_cache(5.1.3之后这个值叫做table_open_cache)值可能太小,我们查询一下服务器table_cache值:mysql> show variables like 'table_cache';
+---------------+-------+
| variable_name | value |
+---------------+-------+
| table_cache    | 2048  |
+---------------+-------+比较合适的值为:open_tables / opened_tables * 100% >= 85%open_tables / table_cache * 100%< = 95%六、进程使用情况mysql> show global status like 'thread%';
+-------------------+-------+
| variable_name      | value |
+-------------------+-------+
| threads_cached     | 46     |
| threads_connected | 2      |
| threads_created    | 570    |
| threads_running    | 1      |
+-------------------+-------+如果我们在mysql服务器配置文件中设置了thread_cache_size,当客户端断开之后,服务器处理此客户的线程将会缓存起来以响应下一个客户而不是销毁(前提是缓存数未达上限)。threads_created表示创建过的线程数,如果发现threads_created值过大的话,表明 mysql服务器一直在创建线程,这也是比较耗资源,可以适当增加配置文件中thread_cache_size值,查询服务器 thread_cache_size配置:mysql> show variables like 'thread_cache_size';
+-------------------+-------+
| variable_name      | value |
+-------------------+-------+
| thread_cache_size | 64     |
+-------------------+-------+示例中的服务器还是挺健康的。七、查询缓存(query cache)mysql> show global status like 'qcache%';
+-------------------------+-----------+
| variable_name            | value      |
+-------------------------+-----------+
| qcache_free_blocks       | 22756      |
| qcache_free_memory       | 76764704  |
| qcache_hits              | 213028692 |
| qcache_inserts           | 208894227 |
| qcache_lowmem_prunes     | 4010916    |
| qcache_not_cached        | 13385031  |
| qcache_queries_in_cache | 43560      |
| qcache_total_blocks      | 111212     |
+-------------------------+-----------+mysql查询缓存变量解释:qcache_free_blocks:缓存中相邻内存块的个数。数目大说明可能有碎片。flush query cache会对缓存中的碎片进行整理,从而得到一个空闲块。qcache_free_memory:缓存中的空闲内存。qcache_hits:每次查询在缓存中命中时就增大qcache_inserts:每次插入一个查询时就增大。命中次数除以插入次数就是不中比率。qcache_lowmem_prunes:缓存出现内存不足并且必须要进行清理以便为更多查询提供空间的次数。这个数字最好长时间来看;如果这个数字在不断增长,就表示可能碎片非常严重,或者内存很少。(上面的 free_blocks和free_memory可以告诉您属于哪种情况)qcache_not_cached:不适合进行缓存的查询的数量,通常是由于这些查询不是 select 语句或者用了now()之类的函数。qcache_queries_in_cache:当前缓存的查询(和响应)的数量。qcache_total_blocks:缓存中块的数量。我们再查询一下服务器关于query_cache的配置:mysql> show variables like 'query_cache%';
+------------------------------+-----------+
| variable_name                 | value      |
+------------------------------+-----------+
| query_cache_limit             | 2097152    |
| query_cache_min_res_unit      | 4096       |
| query_cache_size              | 203423744 |
| query_cache_type              | on         |
| query_cache_wlock_invalidate | off        |
+------------------------------+-----------+各字段的解释:query_cache_limit:超过此大小的查询将不缓存query_cache_min_res_unit:缓存块的最小大小query_cache_size:查询缓存大小query_cache_type:缓存类型,决定缓存什么样的查询,示例中表示不缓存 select sql_no_cache 查询query_cache_wlock_invalidate:当有其他客户端正在对myisam表进行写操作时,如果查询在query cache中,是否返回cache结果还是等写操作完成再读表获取结果。query_cache_min_res_unit的配置是一柄”双刃剑”,默认是4kb,设置值大对大数据查询有好处,但如果你的查询都是小数据查询,就容易造成内存碎片和浪费。查询缓存碎片率 = qcache_free_blocks / qcache_total_blocks * 100%如果查询缓存碎片率超过20%,可以用flush query cache整理缓存碎片,或者试试减小query_cache_min_res_unit,如果你的查询都是小数据量的话。查询缓存利用率 = (query_cache_size - qcache_free_memory) / query_cache_size * 100%查询缓存利用率在25%以下的话说明query_cache_size设置的过大,可适当减小;查询缓存利用率在80%以上而且qcache_lowmem_prunes > 50的话说明query_cache_size可能有点小,要不就是碎片太多。查询缓存命中率 = (qcache_hits - qcache_inserts) / qcache_hits * 100%示例服务器 查询缓存碎片率 = 20.46%,查询缓存利用率 = 62.26%,查询缓存命中率 = 1.94%,命中率很差,可能写操作比较频繁吧,而且可能有些碎片。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  软件测试