MySQL 8.0 Reference Manual(讀書筆記70節--InnoDB Buffer Pool Configuration (1))

东山絮柳仔發表於2024-03-24

1.InnoDB Buffer Pool Size 配置

When increasing or decreasing innodb_buffer_pool_size, the operation is performed in chunks. Chunk size is defined by the innodb_buffer_pool_chunk_size configuration option, which has a default of 128M.-----innodb_buffer_pool_size的擴容和縮容,都是以innodb_buffer_pool_chunk_size為單位進行的,其預設為128M 。

Buffer pool size must always be equal to or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances. If you configure innodb_buffer_pool_size to a value that is not equal to or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances, buffer pool size is automatically adjusted to a value that is equal to or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances.----- innodb_buffer_pool_size必須是 innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances乘積的整數倍

舉個例子:

假如 innodb_buffer_pool_instances 為16;innodb_buffer_pool_chunk_size預設的為128M。

innodb_buffer_pool_instances * innodb_buffer_pool_chunk_size =2G;

innodb_buffer_pool_size 應該設定為2G的倍數

如果你設定成了8G,透過 SELECT @@innodb_buffer_pool_size/1024/1024/1024; 命令檢視,確實為8G;

如果你設定成了9G,透過SELECT @@innodb_buffer_pool_size/1024/1024/1024;命令檢視,實際上變成了10G。【向上擴充套件】

2.InnoDB Buffer Pool Chunk Size 配置

innodb_buffer_pool_chunk_size can be increased or decreased in 1MB (1048576 byte) units but can only be modified at startup, in a command line string or in a MySQL configuration file.

---調整的最小單位為1M,並且需重啟。

The following conditions apply when altering innodb_buffer_pool_chunk_size:

• If the new innodb_buffer_pool_chunk_size value * innodb_buffer_pool_instances is larger than the current buffer pool size when the buffer pool is initialized,

innodb_buffer_pool_chunk_size is truncated to innodb_buffer_pool_size / innodb_buffer_pool_instances.

• Buffer pool size must always be equal to or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances.

If you alter innodb_buffer_pool_chunk_size, innodb_buffer_pool_size is automatically adjusted to a value that is equal to or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances.

The adjustment occurs when the buffer pool is initialized.

注意事項

(1)Care should be taken when changing innodb_buffer_pool_chunk_size, as changing this value can increase the size of the buffer pool, as shown in the examples above.

Before you change innodb_buffer_pool_chunk_size, calculate the effect on innodb_buffer_pool_size to ensure that the resulting buffer pool size is acceptable. --謹慎調整

(2)To avoid potential performance issues, the number of chunks (innodb_buffer_pool_size / innodb_buffer_pool_chunk_size) should not exceed 1000. ---換句話說,當innodb_buffer_pool_size>128G時,

可以考慮修改innodb_buffer_pool_chunk_size的預設值了。

3. InnoDB Buffer Pool Size 線上調整

是支援線上調整的。

Active transactions and operations performed through InnoDB APIs should be completed before resizing the buffer pool【當前的事務需要執行完畢】. When initiating a resizing operation, the operation does not start until all active transactions are completed.【新的事務請求,會被阻塞住,等待調整的命令執行完】 Once the resizing operation is in progress, new transactions and operations that require access to the buffer pool must wait until the resizing operation finishes.【調整時,buffer 也不允許新的事務或請求,去訪問】 The exception to the rule is that concurrent【同時發生的】 access to the buffer pool is permitted while the buffer pool is defragmented 【去碎片化】and pages are withdrawn when buffer pool size is decreased. A drawback【ˈdrɔːbæk 缺點】 of allowing concurrent access is that it could result in a temporary shortage of available pages while pages are being withdrawn【撤回、撤離、不再提供】.

-----三種事務: 發出調整命令前的事務;發出命令後事務;同時發出的事務。

需要注意的是:Nested transactions could fail if initiated after the buffer pool resizing operation begins.

4.視覺化Online Buffer Pool Resizing Progress

The Innodb_buffer_pool_resize_status variable reports a string value indicating buffer pool resizing progress;執行的命令為:

SHOW STATUS WHERE Variable_name='InnoDB_buffer_pool_resize_status';

From MyQL 8.0.31, you can also monitor an online buffer pool resizing operation using the Innodb_buffer_pool_resize_status_code and Innodb_buffer_pool_resize_status_progress status variables, which report numeric values, preferable for programmatic monitoring.--新版本的MySQL,有更多的監控指標

The Innodb_buffer_pool_resize_status_code status variable reports a status code indicating the stage of an online buffer pool resizing operation. Status codes include:

• 0: No Resize operation in progress

• 1: Starting Resize

• 2: Disabling AHI (Adaptive Hash Index)

• 3: Withdrawing Blocks

• 4: Acquiring Global Lock

• 5: Resizing Pool

• 6: Resizing Hash

• 7: Resizing Failed

The Innodb_buffer_pool_resize_status_progress status variable reports a percentage value indicating the progress of each stage. The percentage value is updated after each buffer pool instance is processed. As the status (reported by Innodb_buffer_pool_resize_status_code) changes from one status to another, the percentage value is reset to 0.

The following query returns a string value indicating the buffer pool resizing progress, a code indicating the current stage of the operation, and the current progress of that stage, expressed as a percentage value:

SELECT variable_name, variable_value 
 FROM performance_schema.global_status 
 WHERE LOWER(variable_name) LIKE "innodb_buffer_pool_resize%";

Buffer pool resizing progress is also visible in the server error log. ---調整過程也可以在error log 檢視。

From MySQL 8.0.31, starting the server with --log-error-verbosity=3 logs additional information to the error log during an online buffer pool resizing operation.Additional information includes the status codes reported by Innodb_buffer_pool_resize_status_code and the percentage progress value reported by Innodb_buffer_pool_resize_status_progress.

5.Online Buffer Pool Resizing Internals

The resizing operation is performed by a background thread.

增加記憶體分配

When increasing the size of the buffer pool, the resizing operation:

• Adds pages in chunks (chunk size is defined by innodb_buffer_pool_chunk_size)

• Converts hash tables, lists, and pointers to use new addresses in memory

• Adds new pages to the free list

While these operations are in progress, other threads are blocked from accessing the buffer pool.

減少記憶體分配

When decreasing the size of the buffer pool, the resizing operation:

• Defragments the buffer pool and withdraws (frees) pages

• Removes pages in chunks (chunk size is defined by innodb_buffer_pool_chunk_size)

• Converts hash tables, lists, and pointers to use new addresses in memory

Of these operations, only defragmenting the buffer pool and withdrawing pages allow other threads to access to the buffer pool concurrently.

---《17.8.3.1 Configuring InnoDB Buffer Pool Size》

https://dev.mysql.com/doc/refman/8.0/en/innodb-buffer-pool-resize.html

相關文章