免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1469 | 回复: 4
打印 上一主题 下一主题

请教mysql的几个参数配置 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-05-29 10:04 |只看该作者 |倒序浏览
本帖最后由 biyexp 于 2013-05-29 10:09 编辑

服务器的内存是32G的。64位linux centos6.3

show global status like 'open%tables%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Open_tables   | 3072  |
| Opened_tables | 13759 |
+---------------+-------+
2 rows in set (0.00 sec)

table_cache = 3072  最初设置512,然后逐渐加大到3072了, 还要加大吗? 再大的话有没有副作用?
---------------------------------------------------------------------------------------------------

show global status like 'qcache%';
+-------------------------+-----------+
| Variable_name           | Value     |
+-------------------------+-----------+
| Qcache_free_blocks      | 61169     |
| Qcache_free_memory      | 104067104 |
| Qcache_hits             | 21234797  |
| Qcache_inserts          | 24009021  |
| Qcache_lowmem_prunes    | 2659629   |
| Qcache_not_cached       | 234441    |
| Qcache_queries_in_cache | 110267    |
| Qcache_total_blocks     | 282960    |
+-------------------------+-----------+
8 rows in set (0.00 sec)

query_cache_size = 256M
query_cache_limit = 2M
query_cache_min_res_unit = 2k

剩余内存足够多了, 为什么 Qcache_lowmem_prunes  还是很高呀


------------------------------------------------------------------------------------------------------
mysql>  show global status like 'Thread%';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_cached    | 497   |
| Threads_connected | 16    |
| Threads_created   | 1068  |
| Threads_running   | 3     |
+-------------------+-------+
4 rows in set (0.00 sec)

thread_cache_size = 512
是否需要调整?

论坛徽章:
0
2 [报告]
发表于 2013-05-29 11:22 |只看该作者
mysql>  show global status like 'Thread%';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_cached    | 497   |
| Threads_connected | 16    |
| Threads_created   | 1068  |
| Threads_running   | 3     |
+-------------------+-------+
4 rows in set (0.00 sec)

thread_cache_size = 512
是否需要调整?


是否要调整thread_cache_size,要看以下几个variables
- max_connections (show variables)
- Max_used_connections (show status)
如果Max_used_connections接近max_connections,则需要提高max_connections,然后让你的thread_cache_size的值接近max_connections,但不要超过1024

论坛徽章:
0
3 [报告]
发表于 2013-05-29 11:32 |只看该作者
max_connections | 2000   我设置的应该是高了
Max_used_connections | 607         

如果我把max_connections 和thread_cache_size 都改成800, 是否会好一些?

论坛徽章:
0
4 [报告]
发表于 2013-05-29 13:56 |只看该作者
1。max_connections是根据你的app最大并发量设置的,如果你的最大并发不超过N,你把max_connections设成N即可,这样不会出现“too much connection”的错误
2。把thread_cache_size设成800,好处是mysql不会在create-thread上花费时间(这在高并发时很有效);但是,如果你的并发量只是偶尔很大,这样你在平时就会有很多内存资源浪费了。如果你的内存足够大,就没事了

PS. mysql的manual说thread_cache_size不会在很大程度上影响性能
Normally, this does not provide a notable performance improvement if you have a good thread implementation.

论坛徽章:
0
5 [报告]
发表于 2013-05-29 16:01 |只看该作者
show global status like 'open%tables%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Open_tables   | 3072  |
| Opened_tables | 13759 |
+---------------+-------+
2 rows in set (0.00 sec)

table_cache = 3072  最初设置512,然后逐渐加大到3072了, 还要加大吗? 再大的话有没有副作用?


1。首先需要加大table_cache,因为open_tables都已经等于table_cache,说明当前的并发查询需要的表多余table_cache了;
2。加大是有副作用的,因为更多的open_tables消耗更多的file-descriptors,而OS中允许打开的的file-descriptiots是一定的,所有可能会出现“too many open files“导致mysql不公作了
3。可以设置"open_files_limit"来避免上述的问题,公式:
   table_open_cache = max_connection * N + temp, 其中,N是每个查询需要打开的表的数目,if是myisam的表,需要再多加一个,temp是一些而外的开销。
   把open_files_limit 设置成比这个还要大的数
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP