12
返回列表 发新帖
楼主: mchdba

[笔记] 给一个朋友优化My.cnf参数

[复制链接]
论坛徽章:
27
优秀写手
日期:2013-12-18 09:29:09ITPUB季度 技术新星
日期:2012-08-15 14:50:13嫦娥
日期:2013-03-04 09:47:05数据库板块每日发贴之星
日期:2011-09-08 01:01:01数据库板块每日发贴之星
日期:2011-09-11 01:01:01数据库板块每日发贴之星
日期:2011-09-10 01:01:02数据库板块每日发贴之星
日期:2011-09-09 01:01:01ITPUB十周年纪念徽章
日期:2011-11-01 16:26:59ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:422013年新春福章
日期:2013-03-04 09:50:49
11#
 楼主| 发表于 2013-8-15 15:04 | 只看该作者
tom_fans 发表于 2013-8-15 15:43
我没有说你的参数有问题, 另外你的TMP_TABLE_SIZE给2G, tmp_table_size是属于per-thread的,如果你有2个 ...

分析这个 show status  挺好的,我们这边也经常看这些数据。

使用道具 举报

回复
论坛徽章:
9
2009新春纪念徽章
日期:2009-01-04 14:52:28祖国60周年纪念徽章
日期:2009-10-09 08:28:00ITPUB9周年纪念徽章
日期:2010-10-08 09:28:51蛋疼蛋
日期:2011-08-09 14:26:55ITPUB十周年纪念徽章
日期:2011-11-01 16:24:51ITPUB 11周年纪念徽章
日期:2012-10-09 18:09:19奥迪
日期:2013-09-12 15:57:042014年新春福章
日期:2014-02-18 16:43:09马上有钱
日期:2014-02-18 16:43:09
12#
发表于 2013-8-15 15:09 | 只看该作者
mchdba 发表于 2013-8-15 15:04
分析这个 show status  挺好的,我们这边也经常看这些数据。

你什么版本的MySQL?

使用道具 举报

回复
论坛徽章:
27
优秀写手
日期:2013-12-18 09:29:09ITPUB季度 技术新星
日期:2012-08-15 14:50:13嫦娥
日期:2013-03-04 09:47:05数据库板块每日发贴之星
日期:2011-09-08 01:01:01数据库板块每日发贴之星
日期:2011-09-11 01:01:01数据库板块每日发贴之星
日期:2011-09-10 01:01:02数据库板块每日发贴之星
日期:2011-09-09 01:01:01ITPUB十周年纪念徽章
日期:2011-11-01 16:26:59ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:422013年新春福章
日期:2013-03-04 09:50:49
13#
 楼主| 发表于 2013-8-15 16:28 | 只看该作者
jinguanding 发表于 2013-8-14 21:25
innodb_buffer_pool_size = 3000M
  小了,改成db服务器总内存的60% 到80%

再次阅读了官方文档:
确实没有说具体的配置上限和下限,60%到80%是自己以前刚做dba的时候,一些前辈给的建议,然后就一直沿用了下来,目前为止没有出现过重大的失误。老金见多识广,你们现在对这配置在互联网应用中有自己大概设置的范围值吗?


8.6.2. The InnoDB Buffer Pool


         InnoDB maintains a buffer pool for        caching data and indexes in memory.         InnoDB manages the pool as a list,        using a least recently used (LRU) algorithm incorporating a        midpoint insertion strategy. When room is needed to add a new        block to the pool, InnoDB evicts        the least recently used block and adds the new block to the        middle of the list. The midpoint insertion strategy in effect        causes the list to be treated as two sublists:      
  •             At the head, a sublist of “new” (or             “young”) blocks that have been recently used.           
  •             At the tail, a sublist of “old” blocks that are            less recently used.           


        As a result of the algorithm, the new sublist contains blocks        that are heavily used by queries. The old sublist contains        less-used blocks, and candidates for eviction are taken from        this sublist.      
        The LRU algorithm operates as follows by default:      
  •             3/8 of the buffer pool is devoted to the old sublist.           
  •             The midpoint of the list is the boundary where the tail of            the new sublist meets the head of the old sublist.           
  •             When InnoDB reads a block into            the buffer pool, it initially inserts it at the midpoint            (the head of the old sublist). A block can be read in as a            result of two types of read requests: Because it is required            (for example, to satisfy query execution), or as part of            read-ahead performed in anticipation that it will be            required.           
  •             The first access to a block in the old sublist makes it             “young”, causing it to move to the head of the            buffer pool (the head of the new sublist). If the block was            read in because it was required, the first access occurs            immediately and the block is made young. If the block was            read in due to read-ahead, the first access does not occur            immediately (and might not occur at all before the block is            evicted).           
  •             As long as no accesses occur for a block in the pool, it             “ages” by moving toward the tail of the list.            Blocks in both the new and old sublists age as other blocks            are made new. Blocks in the old sublist also age as blocks            are inserted at the midpoint. Eventually, a block that            remains unused for long enough reaches the tail of the old            sublist and is evicted.           


        In the default operation of the buffer pool, a block when read        in is loaded at the midpoint and then moved immediately to the        head of the new sublist as soon as an access occurs. In the case        of a table scan (such as performed for a         mysqldump operation), each block read by the        scan ends up moving to the head of the new sublist because        multiple rows are accessed from each block. This occurs even for        a one-time scan, where the blocks are not otherwise used by        other queries. Blocks may also be loaded by the read-ahead        background thread and then moved to the head of the new sublist        by a single access. These effects can be disadvantageous because        they push blocks that are in heavy use by other queries out of        the new sublist to the old sublist where they become subject to        eviction.      
        The innodb_buffer_pool_size        system variable specifies the size of the buffer pool. If your        buffer pool is small and you have sufficient memory, making the        pool larger can improve performance by reducing the amount of        disk I/O needed as queries access         InnoDB tables.




使用道具 举报

回复
论坛徽章:
27
优秀写手
日期:2013-12-18 09:29:09ITPUB季度 技术新星
日期:2012-08-15 14:50:13嫦娥
日期:2013-03-04 09:47:05数据库板块每日发贴之星
日期:2011-09-08 01:01:01数据库板块每日发贴之星
日期:2011-09-11 01:01:01数据库板块每日发贴之星
日期:2011-09-10 01:01:02数据库板块每日发贴之星
日期:2011-09-09 01:01:01ITPUB十周年纪念徽章
日期:2011-11-01 16:26:59ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:422013年新春福章
日期:2013-03-04 09:50:49
14#
 楼主| 发表于 2013-8-15 16:30 | 只看该作者
tom_fans 发表于 2013-8-15 16:09
你什么版本的MySQL?

我朋友的版本是 5.5.25a。

使用道具 举报

回复
论坛徽章:
9
2009新春纪念徽章
日期:2009-01-04 14:52:28祖国60周年纪念徽章
日期:2009-10-09 08:28:00ITPUB9周年纪念徽章
日期:2010-10-08 09:28:51蛋疼蛋
日期:2011-08-09 14:26:55ITPUB十周年纪念徽章
日期:2011-11-01 16:24:51ITPUB 11周年纪念徽章
日期:2012-10-09 18:09:19奥迪
日期:2013-09-12 15:57:042014年新春福章
日期:2014-02-18 16:43:09马上有钱
日期:2014-02-18 16:43:09
15#
发表于 2013-8-15 18:52 | 只看该作者
mchdba 发表于 2013-8-15 16:30
我朋友的版本是 5.5.25a。

60-80%是在你内存规划好的情况下,认为内存是够的,这个是前提。 如果你只有1G内存,你给个60%或者80%,那肯定不行啊。

其实确认内存够不够,光看命中率很多时候不准,因为即使命中率99.9%,有时候并不表示内存是否的,当然OLTP基本能显示出来。从系统来看vmstat, iostat都是监视工具

使用道具 举报

回复
论坛徽章:
52
2015年新春福章
日期:2015-03-06 11:57:312012新春纪念徽章
日期:2012-02-13 15:12:252012新春纪念徽章
日期:2012-02-13 15:12:25生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:32:552012新春纪念徽章
日期:2012-02-07 09:59:35
16#
发表于 2013-8-16 15:29 | 只看该作者
mchdba 发表于 2013-8-15 16:28
再次阅读了官方文档:
确实没有说具体的配置上限和下限,60%到80%是自己以前刚做dba的时候,一些前辈给的 ...

官方只是建议,没有一定可以~~~~这个是有场景的建议~~

官方文档不等于就是一定任何场合都适用的,学会辩证看问题,和怀疑精神~~

若是你只有 8G内存,你会考虑80%?

若是你只有4G,你会考虑60-80%?



使用道具 举报

回复
论坛徽章:
27
优秀写手
日期:2013-12-18 09:29:09ITPUB季度 技术新星
日期:2012-08-15 14:50:13嫦娥
日期:2013-03-04 09:47:05数据库板块每日发贴之星
日期:2011-09-08 01:01:01数据库板块每日发贴之星
日期:2011-09-11 01:01:01数据库板块每日发贴之星
日期:2011-09-10 01:01:02数据库板块每日发贴之星
日期:2011-09-09 01:01:01ITPUB十周年纪念徽章
日期:2011-11-01 16:26:59ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:422013年新春福章
日期:2013-03-04 09:50:49
17#
 楼主| 发表于 2013-8-17 09:30 | 只看该作者
jinguanding 发表于 2013-8-16 16:29
官方只是建议,没有一定可以~~~~这个是有场景的建议~~

官方文档不等于就是一定任何场合都适用的 ...

嗯,辩证看问题,怀疑精神。

刚做DBA的时候,公司比较小,机器配置不好:
系统一期的时候,db服务器恰好是总共4G内存,我设置了1G,正好够用。
系统二期的时候,db服务器恰好是总共8G内存,我设置了4G,运行还比较好。
这个场景是普通的小金融站点系统,qps,tps都很少。

后来公司有钱了,32G内存了(18G),64G内存了(32G),128G内存(60G),我就按照50%到60%的比例进行设置这个参数。这个是电商系统,tps 峰值是800(双十一记忆特别清楚)。qps好像是10W吧(也许不是)以及其他的数据都记不起来了,人老了,记忆不好了,离开的时候所有的资料都交出去了。
这个是电商系统

使用道具 举报

回复
论坛徽章:
19
季节之章:冬
日期:2009-01-13 11:30:57季节之章:春
日期:2009-02-09 13:40:00季节之章:夏
日期:2009-06-08 13:44:20季节之章:秋
日期:2009-08-18 20:27:35
18#
发表于 2013-8-17 13:38 | 只看该作者
mchdba 发表于 2013-8-15 15:00
再次去查阅了文档,
tmp_table_size Yes Yes Yes  Both Yes

应该在脚本里设置session级的tmp_table_size,而不是写在my.cnf文件做为全局设置

使用道具 举报

回复
论坛徽章:
27
优秀写手
日期:2013-12-18 09:29:09ITPUB季度 技术新星
日期:2012-08-15 14:50:13嫦娥
日期:2013-03-04 09:47:05数据库板块每日发贴之星
日期:2011-09-08 01:01:01数据库板块每日发贴之星
日期:2011-09-11 01:01:01数据库板块每日发贴之星
日期:2011-09-10 01:01:02数据库板块每日发贴之星
日期:2011-09-09 01:01:01ITPUB十周年纪念徽章
日期:2011-11-01 16:26:59ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:422013年新春福章
日期:2013-03-04 09:50:49
19#
 楼主| 发表于 2013-8-18 10:43 | 只看该作者
TomLeng 发表于 2013-8-17 14:38
应该在脚本里设置session级的tmp_table_size,而不是写在my.cnf文件做为全局设置

你们的production上面都是如此处理的吗?

使用道具 举报

回复
论坛徽章:
32
ITPUB十周年纪念徽章
日期:2011-11-01 16:25:22马上加薪
日期:2014-12-08 22:53:43马上有房
日期:2014-12-09 01:05:19美羊羊
日期:2015-03-04 14:52:282015年新春福章
日期:2015-03-06 11:58:18巨蟹座
日期:2015-11-17 11:02:55双子座
日期:2015-11-17 12:21:47白羊座
日期:2015-12-10 17:27:08狮子座
日期:2016-02-23 10:11:01双子座
日期:2016-02-23 10:17:05
20#
发表于 2013-10-16 14:14 | 只看该作者
多进行测试,通过测评达到什么一个指标值。

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表