buffer pool mysql_MySQL 5.7版本新特性(修改buffer pool,无需重启服务)
優(yōu)化online操作,例如修改buffer pool、修改索引名(非主鍵)、修改REPLICATION FILTER、修改MASTER而無需關閉SLAVE線程等眾多特性。
如果是加大buffer pool,其過程大致是:
1、以innodb_buffer_pool_chunk_size為單位,分配新的內存pages;
2、擴展buffer pool的AHI(adaptive hash index)鏈表,將新分配的pages包含進來;
3、將新分配的pages添加到free list中;
如果是縮減buffer pool,其過程則大致是:
1、重整buffer pool,準備回收pages;
2、以innodb_buffer_pool_chunk_size為單位,釋放刪除這些pages(這個過程會有一點點耗時);
3、調整AHI鏈表,使用新的內存地址。
實際測試時,發(fā)現在線修改 buffer poo 的代價并不大,SQL命令提交完畢后都是瞬間完成,而后臺進程的耗時也并不太久。在一個并發(fā)128線程跑tpcc壓測的環(huán)境中,將 buffer pool 從32G擴展到48G,后臺線程耗時 3秒,而從 48G 縮減回 32G 則耗時 18秒,期間壓測的事務未發(fā)生任何鎖等待。
-- 演示1:從 1G 擴大到 16G
[yejr@imysql.com]> SET GLOBAL innodb_buffer_pool_size = 51539607552;
Query OK, 0 rows affected (0.00 sec)
-- 看看日志記錄
09:21:19.460543Z 0 [Note] InnoDB: Resizing buffer pool from 1073741824 to 17179869184. (unit=134217728)
09:21:19.468069Z 0 [Note] InnoDB: disabled adaptive hash index.
09:21:20.760724Z 0 [Note] InnoDB: buffer pool 0 : 60 chunks (491511 blocks) were added.
09:21:21.922869Z 0 [Note] InnoDB: buffer pool 1 : 60 chunks (491520 blocks) were added.
09:21:21.935114Z 0 [Note] InnoDB: buffer pool 0 : hash tables were resized.
09:21:21.947264Z 0 [Note] InnoDB: buffer pool 1 : hash tables were resized.
09:21:22.203031Z 0 [Note] InnoDB: Resized hash tables at lock_sys, adaptive hash index, dictionary.
09:21:22.203062Z 0 [Note] InnoDB: Completed to resize buffer pool from 1073741824 to 17179869184.
09:21:22.203075Z 0 [Note] InnoDB: Re-enabled adaptive hash index.
-- 演示2:從 16G 縮減到 1G
[yejr@imysql.com]> SET GLOBAL innodb_buffer_pool_size = 1073741824;
Query OK, 0 rows affected (0.00 sec)
-- 看看日志記錄
09:22:55.591669Z 0 [Note] InnoDB: Resizing buffer pool from 17179869184 to 1073741824. (unit=134217728)
09:22:55.680836Z 0 [Note] InnoDB: disabled adaptive hash index.
09:22:55.680864Z 0 [Note] InnoDB: buffer pool 0 : start to withdraw the last 491511 blocks.
09:22:55.765778Z 0 [Note] InnoDB: buffer pool 0 : withdrew 489812 blocks from free list. Tried to relocate 1698 pages (491510/491511).
09:22:55.774492Z 0 [Note] InnoDB: buffer pool 0 : withdrew 0 blocks from free list. Tried to relocate 1 pages (491511/491511).
09:22:55.782745Z 0 [Note] InnoDB: buffer pool 0 : withdrawn target 491511 blocks.
09:22:55.782786Z 0 [Note] InnoDB: buffer pool 1 : start to withdraw the last 491520 blocks.
09:22:55.892068Z 0 [Note] InnoDB: buffer pool 1 : withdrew 489350 blocks from free list. Tried to relocate 2166 pages (491517/491520).
09:22:55.900743Z 0 [Note] InnoDB: buffer pool 1 : withdrew 0 blocks from free list. Tried to relocate 2 pages (491519/491520).
09:22:55.908257Z 0 [Note] InnoDB: buffer pool 1 : withdrew 0 blocks from free list. Tried to relocate 0 pages (491519/491520).
09:22:55.915778Z 0 [Note] InnoDB: buffer pool 1 : withdrew 0 blocks from free list. Tried to relocate 1 pages (491520/491520).
09:22:55.923836Z 0 [Note] InnoDB: buffer pool 1 : withdrawn target 491520 blocks.
09:22:56.149172Z 0 [Note] InnoDB: buffer pool 0 : 60 chunks (491511 blocks) were freed.
09:22:56.308997Z 0 [Note] InnoDB: buffer pool 1 : 60 chunks (491520 blocks) were freed.
09:22:56.316258Z 0 [Note] InnoDB: buffer pool 0 : hash tables were resized.
09:22:56.324027Z 0 [Note] InnoDB: buffer pool 1 : hash tables were resized.
09:22:56.393589Z 0 [Note] InnoDB: Resized hash tables at lock_sys, adaptive hash index, dictionary.
09:22:56.393616Z 0 [Note] InnoDB: Completed to resize buffer pool from 17179869184 to 1073741824.
09:22:56.393628Z 0 [Note] InnoDB: Re-enabled adaptive hash index.
再來看下在線修改非主鍵索引名,直接用?ALTER TABLE RENAME INDEX?語法即可。
【新特性實踐】
例如下面的SQL語法:
[yejr@imysql.com]> ALTER TABLE orders RENAME INDEX idx1 TO idxxx1;
Query OK, 0 rows affected (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 0
可以看到,幾乎瞬間完成,盡管我在執(zhí)行這個SQL時正跑著64個并發(fā)tpcc壓測。
總結
以上是生活随笔為你收集整理的buffer pool mysql_MySQL 5.7版本新特性(修改buffer pool,无需重启服务)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: qt设置文本背景透明_Qt修改图片的背景
- 下一篇: 溢流井阀门井做什么资料