InnoDB 缓冲池大小调整

开发者福利!热门AI工具限时免费用 购周边即赠Coding Plan Lite,Claude Code、Cursor等20+工具畅享,效率翻倍! 阅读详情

导读

翻译者:魏新平

译文校稿:叶师傅

原文出处:《Chunk Change: InnoDB Buffer Pool Resizing

https://www.percona.com/blog/2018/06/19/chunk-change-innodb-buffer-pool-resizing/

原文作者:David Ducos

关键词:InnoDB, Insight for DBAs, MySQL, open source databases, Percona Server for MySQL  buffer pool, InnoDB buffer pool, InnoDB buffer pool size, InnoDB Performance, memory, Memory 

从MySQL 5.7.5开始,我们可以动态修改InnoDB Buffer Pool的大小。这个新特性同时也引入了一个参数--innodb_buffer_pool_chunk_size,buffer pool会根据这个参数值的整数倍增加或减小。这个参数不是动态修改的,如果配置错误,可能会导致不想看到的结果。

Since MySQL 5.7.5, we have been able to resize dynamically the InnoDB Buffer Pool. This new feature also introduced a new variable — innodb_buffer_pool_chunk_size — which defines the chunk size by which the buffer pool is enlarged or reduced. This variable is not dynamic and if it is incorrectly configured, could lead to undesired situations.

首先我们观察一下innodb_buffer_pool_size , innodb_buffer_pool_instances and innodb_buffer_pool_chunk_size如何相互影响。buffer pool可以存放多个instance,每个instance由多个chunk组成。instance的数量范围和chunk的总数量范围分别为1-64,1-1000。

Let’s see first how innodb_buffer_pool_size , innodb_buffer_pool_instances and innodb_buffer_pool_chunk_size interact: 640?wx_fmt=jpeg

The buffer pool can hold several instances and each instance is divided into chunks. There is some information that we need to take into account: the number of instances can go from 1 to 64 and the total amount of chunks should not exceed 1000.

一个3G内存的服务器,128MB的chunk值,2GB的buffer pool,8个instance,那么每个instance就有2个chunk。

So, for a server with 3GB RAM, a buffer pool of 2GB with 8 instances and chunks at default value (128MB) we are going to get 2 chunks per instance: 640?wx_fmt=png 这意味着一共有16个chunks。 This means that there will be 16 chunks.

本文只关注修改buffer pool大小的影响,所以不会阐述多个instance的好处。那为什么要修改buffer pool的大小呢?有多个理由,比如:

I’m not going to explain the benefits of having multiple instances, I will focus on resizing operations. Why would you want to resize the buffer pool? Well, there are several reasons, such as:

如果数据库主机是虚拟机,可以根据需求动态的修改主机内存;

如果数据库主机是物理机,可能会想减少数据库所占用的内存,让其他进程使用;

一开始数据库的大小比可用内存小,根据规划,数据量会有巨大增长,这时,会需要增大buffer pool的大小。

on a virtual server you can add more memory dynamically

for a physical server, you might want to reduce database memory usage to make way for other processes

on systems where the database size is smaller than available RAM if you expect a huge growth and want to increase the buffer pool on demand

缩小buffer pool 

让我们开始减小buffer pool

Reducing the buffer pool

Let’s start reducing the buffer pool:

| innodb_buffer_pool_size | 2147483648 |
| innodb_buffer_pool_instances | 8     |
| innodb_buffer_pool_chunk_size | 134217728 |

mysql> set global innodb_buffer_pool_size=1073741824;
Query OK, 0 rows affected (0.00 sec)
mysql> show global variables like 'innodb_buffer_pool_size';
+-------------------------+------------+
| Variable_name           | Value      |
+-------------------------+------------+
| innodb_buffer_pool_size | 1073741824 |
+-------------------------+------------+
1 row in set (0.00 sec)

假如我们缩小buffer pool到1.5GB,buffer pool的大小不会改变并且会出现一个告警:

If we try to decrease it to 1.5GB, the buffer pool will not change and a warning will be showed:


640?wx_fmt=png

增加buffer pool

Increasing the buffer pool

当我们把buffer pool从1GB增加到1.5GB时,1.5GB的值被认为是不合适,并且会被mysql调整为其他的值。

When we try to increase the value from 1GB to 1.5GB, the buffer pool is resized but the requested innodb_buffer_pool_size is considered to be incorrect and is truncated:

640?wx_fmt=png

buffer pool最后的值为2GB。1.5GB的值被调整为了2GB,即使你多设置了1byte,比如设置成:1073741825,你还是会得到2GB大小的buffer pool。

And the final size is 2GB. Yes! you intended to set the value to 1.5GB and you succeeded in setting it to 2GB. Even if you set 1 byte higher, like setting: 1073741825, you will end up with a buffer pool of 2GB.

mysql> set global innodb_buffer_pool_size=1073741825;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show global variables like 'innodb_buffer_pool_%size' ;
+-------------------------------+------------+
| Variable_name                 | Value      |
+-------------------------------+------------+
| innodb_buffer_pool_chunk_size | 134217728  |
| innodb_buffer_pool_size       | 2147483648 |
+-------------------------------+------------+
2 rows in set (0.01 sec)

有趣的情景—增加配置文件当中的值 

Interesting scenarios-Increasing size in the config file

假如有一天,你突然想优化mysql的一些参数。由于服务器还有空闲内存,你想增加buffer pool的大小。在这个例子当中,我们将会在一台16个innodb_buffer_pool_instances,2GB buffer pool的mysql上面做实验。我们会把buffer pool的大小增加到2.5GB。

Let’s suppose one day you get up willing to change or tune some variables in your server, and you decide that as you have free memory you will increase the buffer pool. In this example, we are going to use a server with innodb_buffer_pool_instances = 16 and 2GB of buffer pool size which will be increased to 2.5GB

我们在配置文件当中配置如下参数值

So, we set in the configuration file:

innodb_buffer_pool_size = 2684354560

重启后我们发现

But then after restart, we found:

mysql> show global variables like 'innodb_buffer_pool_%size' ;
+-------------------------------+------------+
| Variable_name                 | Value      |
+-------------------------------+------------+
| innodb_buffer_pool_chunk_size | 134217728  |
| innodb_buffer_pool_size       | 4294967296 |
+-------------------------------+------------+
2 rows in set (0.00 sec)

错误日志发现如下报错

And the error log says:

2018-05-02T21:52:43.568054Z 0 [Note] InnoDB: Initializing buffer pool, 
total size = 4G, instances = 16, chunk size = 128M

由于instance和chunk的影响,配置文档当中的2.5GB没有生效,重启后buffer pool变成了4GB。日志信息并没有告诉我们chunk的数量,但是这个数量值对于理解为何会出现这种现象有很大的帮助。

So, after we have set innodb_buffer_pool_size in the config file to 2.5GB, the database gives us a 4GB buffer pool, because of the number of instances and the chunk size. What the message doesn’t tell us is the number of chunks, and this would be useful to understand why such a huge difference.

让我们观察一下4GB是如何被算出来的

Let’s take a look at how that’s calculated.

增加instance和chunk的值

修改instance或者chunk size需要重启数据库并且需要考虑buffer pool的上限。比如配置成如下的值

Increasing instances and chunk size

Changing the number of instances or the chunk size will require a restart and will take into consideration the buffer pool size as an upper limit to set the chunk size. For instance, with this configuration:

innodb_buffer_pool_size = 2147483648
innodb_buffer_pool_instances = 32
innodb_buffer_pool_chunk_size = 134217728

我们得到如下的chunk大小

We get this chunk size:

mysql> show global variables like 'innodb_buffer_pool_%size' ;
+-------------------------------+------------+
| Variable_name                 | Value      |
+-------------------------------+------------+
| innodb_buffer_pool_chunk_size | 67108864   |
| innodb_buffer_pool_size       | 2147483648 |
+-------------------------------+------------+
2 rows in set (0.00 sec)

那么,如何计算innodb_buffer_pool_chunk_size的大小呢。innodb_buffer_pool_size除以innodb_buffer_pool_instances,得到的值再根据1MB的整数倍四舍五入。

However, we need to understand how this is really working. To get the innodb_buffer_pool_chunk_size it will make this calculation: innodb_buffer_pool_size / innodb_buffer_pool_instances with the result rounded to a multiple of 1MB.

在上述例子当中,计算方式为2147483648 / 32 = 67108864,而67108864除以1048576等于0,刚好是1MB的整数倍。每个instance刚好一个chunk。

In our example, the calculation will be 2147483648 / 32 = 67108864 which 67108864%1048576=0, no rounding needed. The number of chunks will be one chunk per instance.

那什么情况下instance会有多个chunk呢?当想要的innodb_buffer_pool_size的大小和配置文件当中配置的值相差比1MB大或者等于1MB的时候。

When does it consider that it needs to use more chunks per instance? When the difference between the required size and the innodb_buffer_pool_size configured in the file is greater or equal to 1MB.

这就是为什么假如你设置innodb_buffer_pool_size为1GB+1MB-1B,你将会得到1GB的buffer pool。

That is why, for instance, if you try to set the innodb_buffer_pool_size equal to 1GB + 1MB – 1B you will get 1GB of buffer pool:

innodb_buffer_pool_size = 1074790399
innodb_buffer_pool_instances = 16
innodb_buffer_pool_chunk_size = 67141632
2018-05-07T09:26:43.328313Z 0 [Note] InnoDB: Initializing buffer pool,
total size = 1G, instances = 16, chunk size = 64M

但是假如你设置innodb_buffer_pool_size为1GB+1MB,你将会得到2GB的buffer pool。

But if you set the innodb_buffer_pool_size equals to 1GB + 1MB you will get 2GB of buffer pool:

innodb_buffer_pool_size = 1074790400
innodb_buffer_pool_instances = 16
innodb_buffer_pool_chunk_size = 67141632
2018-05-07T09:25:48.204032Z 0 [Note] InnoDB: Initializing buffer pool,
total size = 2G, instances = 16, chunk size = 64M

这是因为它认为两个chunk刚好。我们可以认为Innodb Buffer pool是这样计算的。

This is because it considers that two chunks will fit. We can say that this is how the InnoDB Buffer pool size is calculated:

determine_best_chunk_size{
  if innodb_buffer_pool_size / innodb_buffer_pool_instances < innodb_buffer_pool_chunk_size
  then
    innodb_buffer_pool_chunk_size = roundDownMB(innodb_buffer_pool_size / innodb_buffer_pool_instances)
  fi
}
determine_amount_of_chunks{
  innodb_buffer_amount_chunks_per_instance = roundDown(innodb_buffer_pool_size / innodb_buffer_pool_instances / innodb_buffer_pool_chunk_size)
  if innodb_buffer_amount_chunks_per_instance * innodb_buffer_pool_instances * innodb_buffer_pool_chunk_size - innodb_buffer_pool_size > 1024*1024
  then
    innodb_buffer_amount_chunks_per_instance++
  fi
}
determine_best_chunk_size
determine_amount_of_chunks
innodb_buffer_pool_size = innodb_buffer_pool_instances * innodb_buffer_pool_chunk_size * innodb_buffer_amount_chunks_per_instance

那什么才是最合适的配置呢? 为了分析最好的配置,你需要知道chunk有1000个数量限制。在我们的例子当中,每个instance不能超过62个chunk。

What is the best setting? In order to analyze the best setting you will need to know that there is a upper limit of 1000 chunks. In our example with 16 instances, we can have no more than 62 chunks per instance.

另一个需要考虑的事情是每个chunk占多大百分比。继续上面的例子,每个chunk每个instance代表了1.61%的大小,我们只能按照这个值的整数倍来修改innodb buffer pool的大小。

Another thing to consider is what each chunk represents in percentage terms. Continuing with the example, each chunk per instance represent 1.61%, which means that we can increase or decrease the complete buffer pool size in multiples of this percentage.

从管理的角度来说,我认为你可能想要考虑最少2%到%5来增加或者减少buffer。我做了一些测试来验证小chunk值对数据库的影响,但是没有找到任何重要的东西。

From a management point of view, I think that you might want to consider at least a range of 2% to 5% to increase or decrease the buffer. I performed some tests to see the impact of having small chunks and I found no issues but this is something that needs to be thoroughly tested.


  

640.gif?


加入知数堂

挑战40万+年薪!



640?640?640?640?


知数堂

叶金荣与吴炳锡联合打造

领跑IT精英培训

行业资深专家强强联合,倾心定制

MySQL实战/MySQL优化/MongoDB/

Python/ SQL优化/Hadoop+ELK

数门精品课程

“阅读原文”可获更多正课试听视频

密码:hg3h

紧随技术发展趋势,定期优化培训教案

融入大量生产案例,贴合企业一线需求

社群陪伴学习,一次报名,可学1年

DBA、开发工程师必修课

上千位学员已华丽转身,薪资翻番,职位提升

改变已悄然发生,你还在等什么?

640.png?



640?wx_fmt=gif扫码加入QQ技术交流群

MySQL 8.0|MGR研究院-ZST

(QQ群号:650149401)    

640?wx_fmt=jpeg

Mysql 8.0 之调整 innodb buffer innodb_buffer_pool_size是一个内存区域,用来缓存InnoDB存储引擎的表中的数据和索引数据,以便提高对InnoDB存储引擎表中数据的查询访问速度。 阅读详情

相关推荐

Mysql——》缓存池大小innodb_buffer_pool_size

在进行修改之前,需要根据服务器的内存大小和数据库负载情况确定合适的缓冲池大小。一般来说,建议将缓冲池设置为可用内存的 50% 到 80%。

小仙~ 2887

MySQL,全局变量innodb_buffer_pool_size

命令中值的单位为Bytes,3200*1024*1024即3200MB,约3.2GB.的默认值)的倍数,这个操作会四舍五入到下一个128MB的倍数并产生一个警告.如果新设置的缓冲池大小不是128MB(

m0_72787342的博客 622

调整MySQL InnoDB缓冲池大小的方法(无需重启MySQL进程)

在MySQL数据库中,InnoDB是一种常用的存储引擎,它使用缓冲池(Buffer Pool)来提高读取和写入性能。通过调整InnoDB缓冲池大小,我们可以优化系统的性能。至此,您已经成功地在线调整了MySQL InnoDB缓冲池大小,而无需重启MySQL进程。请注意,在高负载环境中进行缓冲池大小调整可能会对数据库性能产生一定影响。替换为您希望设置的新的缓冲池大小。在调整InnoDB缓冲池大小之前,我们需要获取当前的缓冲池大小。希望本文对您有所帮助!确保新的缓冲池大小与您在第2步中设置的值相匹配。

BjmmVue的博客 1011

mysql innodbuffer修改_mysql修改 innodb_buffer_pool 大小笔记

mysql> show global variables like 'innodb_buffer_pool_size';+-------------------------+-----------+| Variable_name | Value |+-------------------------+-----------+| innodb_buffer_pool...

weixin_39996739的博客 227

MySQL调优之innodb_buffer_pool_size大小设置

MySQL调优之innodb_buffer_pool_size大小设置 相关查看命令 sql> show global variables like 'innodb_buffer_pool_size'; sql> show global status like 'Innodb_buffer_pool_pages_data'; sql> show global status like 'In

sunny05296的博客 9万+

MySQL中调整InnoDB缓冲池大小

调整InnoDB缓冲池大小是优化MySQL性能的关键步骤之一。以下是如何调整InnoDB缓冲池大小的详细步骤

Demolist的博客 947

mysql缓冲池大小_InnoDB 缓冲池大小调整

原标题:InnoDB 缓冲池大小调整导读翻译者:魏新平译文校稿:叶师傅原文出处:《Chunk Change: InnoDB Buffer Pool Resizing》https://www.percona.com/blog/2018/06/19/chunk-change-innodb-buffer-pool-resizing/原文作者:David Ducos关键词:InnoDB, Insight ...

weixin_39976733的博客 1038

记录在线调整Mysql的InnoDB缓冲池大小

记录调整Mysql缓存池大小语句 (1)缓存池大小调整需要进行计算,set 语句请酌情执行。 (2)如果重启Mysql后,设置自动失效。 -- 查看MySQL版本信息 select VERSION(); show status like 'Innodb_buffer_pool_resize%'; -- 查看缓存池大小 show variables like 'innodb_buffer_pool_size'; -- 查看缓存池信息 show variables like 'innodb_buffer

知世故而不世故 869

mysql 内存缓冲池innodb_buffer_pool_sizes大小调整实现

是 MySQL 中 InnoDB 存储引擎的一个重要参数,它定义了 InnoDB 缓冲池大小缓冲池是一个内存区域,用于缓存数据库中的数据和索引,以加快数据库的读取操作。减少磁盘访问:通过增大缓冲池大小,可以将更多的数据和索引存放在内存中,减少对磁盘的访问次数,从而降低磁盘 I/O 的负载。提高查询性能:由于数据和索引在缓冲池中的存在,查询操作可以更快速地在内存中完成,而不需要频繁地读取磁盘上的数据。改善并发性能:缓冲池的存在可以减少对磁盘的并发访问,提高并发读取的性能,从而改善数据库的并发处理能力。

江江的博客 821

mysql 内存缓冲池innodb_buffer_pool_sizes大小调整

是 MySQL 中 InnoDB 存储引擎的一个重要参数,它定义了 InnoDB 缓冲池大小缓冲池是一个内存区域,用于缓存数据库中的数据和索引,以加快数据库的读取操作。以下是的作用:提高读取性能:将常用的数据和索引加载到内存缓冲池中,可以减少磁盘 I/O 操作,从而提高读取性能。因为内存的读取速度远远快于磁盘的读取速度。减少磁盘访问:通过增大缓冲池大小,可以将更多的数据和索引存放在内存中,减少对磁盘的访问次数,从而降低磁盘 I/O 的负载。

qq_42476938的博客 5250

MySQL 8.0 配置InnoDB缓冲池大小

Innodb_buffer_pool_resize_status 变量报告一个字符串值,指示缓冲池大小调整进度;删除中的页面chunks(块大小由 定义 innodb_buffer_pool_chunk_size)添加页面chunks(块大小由 定义 innodb_buffer_pool_chunk_size)其中,只有对缓冲池进行碎片整理和撤回页面才允许其他线程并发访问缓冲池调整大小操作由后台线程执行。当这些操作正在进行时,其他线程将被阻止访问缓冲池。转换哈希表、列表和指针以使用内存中的新地址。

扑火的小飞蛾 454

配置InnoDB缓冲池(Buffer Pool)大小

1.配置InnoDB缓冲池(Buffer Pool)大小 当服务器正运行时,用户可以离线(启动时)或在线配置InnoDB缓冲池大小。这部分描述的行为适用这两种方法。 当增加或减少innodb_buffer_pool_size时,该操作按照数据块(chunks)执行。数据块的大小通过innodb_buffer_pool_chunk_size配置选项进行定义,该选项默认为128M. 缓冲池大小必须总是等于innodb_buffer_pool_chunk_size* innodb_buffer_pool_inst

数据库生态圈(RDB & NoSQL & Bigdata)——专注于关系库应用与研究(Oracle & Mysql & Postgresql & SQL Server ) 1456

在线调整InnoDB Buffer Pool Size

InnoDB Buffer Pool主要是用来缓存数据表和索引数据的内存区域,它的默认值为134217728字节(128MB)。最大值取决于CPU架构;32位系统上的最大值为4294967295(232-1),64位系统上的最大值为18446744073709551615(264-1)。在32位系统上,CPU体系结构和操作系统的实际最大大小可能低于标准的最大大小。当缓冲池的...

weixin_30892763的博客 422

innodb_buffer_pool_size 配置文件设置的值和查询的值怎么不一致

您可以配置缓冲池大小 脱机或在服务器运行时。中描述的行为 本节适用于这两种方法。更多信息 关于在线配置缓冲池大小,请参阅在线配置 InnoDB 缓冲池大小InnoDB当增加或减少innodb_buffer_pool_size时, 操作以块的形式执行。块大小innodb_buffer_pool_chunk_size 配置选项定义,该选项的缺省值为。有关更多信息,请参阅配置 InnoDB 缓冲池区块大小。128M缓冲池大小必须始终等于 innodb_buffer_pool_chunk_size。

feifeigo123的博客 877

InnoDB缓存池介绍

InnoDB会在内存中维护一个缓冲池,用于缓存数据和索引。缓冲池分为两个区域,一个是sublist of new blocks区域(经常被访问的数据-热数据),一个是sublist of old blocks区域(不经常访问的数据)。当用户访问数据时,如果缓冲区里有相应的数据则直接返回,否则会从磁盘读数据到缓冲区的sublist of old blocks区域,然后在移动到sublist of

zuimei_forver的博客 2189

mysql设置bufferpool_设置MySQL的innodb_buffer_pool_size参数

In the earlier versions of MySQL ( < 5.7.5 ) the only way to set'innodb_buffer_pool_size'variable was by writing it to my.cnf (for linux) and my.ini (for windows) under [mysqld] section :[mysqld]in...

weixin_42413747的博客 874

InnoDB学习笔记二缓冲池(buffer pool)

本篇是mysql的InnoDB引擎学习笔记之二缓冲池,主要介绍了缓冲池的概念以及如何调整大小,接着介绍了其内存结构 如 free list、flush list、lru list的结构、实现方式使用场景。希望对学习innodb的同学有所帮助

liushangzaibeijing的博客 2万+
上一篇: 网易数据库中间件Cetus开源直播啦
下一篇: 沃趣微讲堂索引| PXC、MGC&amp;MGR原理与实践对比
老叶茶馆_
博客等级 码龄9年 1137粉丝 411原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值