14.6.3.8 Saving and Restoring the Buffer Pool Stat

To reduce the warmup period after restarting the server, InnoDB saves a percentage of the most recently used pages for each buffer pool at server shutdown and restores these pages at server startup. The percentage of recently used pages that is stored is defined by the innodb_buffer_pool_dump_pct configuration option.
爲了減少重新啓動服務器後的預熱時間,InnoDB在服務器關閉時爲每個緩衝池保存一定比例的最近使用的頁面,並在服務器啓動時恢復這些頁面.最近使用的頁面的百分比由innodb_buffer_pool_dump_pct配置選項定義。
After restarting a busy server, there is typically a warmup period with steadily increasing throughput, as disk pages that were in the buffer pool are brought back into memory (as the same data is queried, updated, and so on). The ability to restore the buffer pool at startup shortens the warmup period by reloading disk pages that were in the buffer pool before the restart rather than waiting for DML operations to access corresponding rows. Also, I/O requests can be performed in large batches, making the overall I/O faster. Page loading happens in the background, and does not delay database startup.
在重新啓動一個繁忙的服務器之後,通常會有一個不斷增加吞吐量的預熱期,因爲緩衝池中的磁盤頁將被帶回內存(同樣的數據將被查詢、更新,等等)。在啓動時恢復緩衝池的能力縮短了預熱週期,方法是在重啓之前重新加載緩衝池中的磁盤頁,而不是等待DML操作訪問相應的行。此外,I/O請求可以大批量執行,從而加快總體I/O的速度。頁面加載發生在後臺,不會延遲數據庫啓動。
In addition to saving the buffer pool state at shutdown and restoring it at startup, you can save and restore the buffer pool state at any time, while the server is running. For example, you can save the state of the buffer pool after reaching a stable throughput under a steady workload. You could also restore the previous buffer pool state after running reports or maintenance jobs that bring data pages into the buffer pool that are only requited for those operations, or after running some other non-typical workload.
除了在關機時保存緩衝池狀態並在啓動時恢復緩衝池狀態外,您還可以在服務器運行時隨時保存和恢復緩衝池狀態,例如,您可以在穩定的工作負載下達到穩定的吞吐量後保存緩衝池的狀態。您還可以在運行報告或維護jobs之後恢復前面的緩衝池狀態,這些jobs將數據頁帶入僅爲這些操作請求的緩衝池中,或者在運行其他一些非典型工作負載之後。
Even though a buffer pool can be many gigabytes in size, the buffer pool data that InnoDB saves to disk is tiny by comparison. Only tablespace IDs and page IDs necessary to locate the appropriate pages are saved to disk. This information is derived from the INNODB_BUFFER_PAGE_LRU INFORMATION_SCHEMA table. By default, tablespace ID and page ID data is saved in a file named ib_buffer_pool, which is saved to the InnoDB data directory. The file name and location can be modified using the innodb_buffer_pool_filename configuration parameter.
儘管一個緩衝池的大小可能是數GB,但InnoDB保存到磁盤的緩衝池數據相比之下卻很小。只有找到相應頁面所需的表空間IDs和頁面IDs纔會保存到磁盤。 此信息來自INNODB_BUFFER_PAGE_LRU INFORMATION_SCHEMA表。默認情況下,表空間ID和頁面ID數據保存在名爲ib_buffer_pool的文件中,該文件保存在InnoDB數據目錄中。 文件名和位置可以使用innodb_buffer_pool_filename配置參數進行修改。
Because data is cached in and aged out of the buffer pool as it is with regular database operations, there is no problem if the disk pages are recently updated, or if a DML operation involves data that has not yet been loaded. The loading mechanism skips requested pages that no longer exist.
因爲數據緩存在緩衝池中並且在緩衝池中老化,因爲它與常規數據庫操作一樣,所以如果磁盤頁最近被更新,或者DML操作涉及到尚未加載的數據,那麼就沒有問題。加載機制跳過不存在的請求頁面。
The underlying mechanism involves a background thread that is dispatched to perform the dump and load operations.
底層機制涉及一個後臺線程,它被分派來執行轉儲和加載操作。
Disk pages from compressed tables are loaded into the buffer pool in their compressed form. Pages are uncompressed as usual when page contents are accessed during DML operations. Because uncompressing pages is a CPU-intensive process, it is more efficient for concurrency to perform the operation in a connection thread rather than in the single thread that performs the buffer pool restore operation.
壓縮表中的磁盤頁以壓縮格式加載到緩衝池中,在DML操作期間訪問頁面內容時,頁面像往常一樣解壓縮。因爲解壓縮頁面是cpu密集型的過程,所以在併發在連接線程中執行操作比在執行緩衝池恢復操作的單個線程中更有效。
Operations related to saving and restoring the buffer pool state are described in the following topics:
以下主題描述了保存和恢復緩衝池狀態相關的操作:

  • Configuring the Dump Percentage for Buffer Pool Pages
  • Saving the Buffer Pool State at Shutdown and Restoring it at Startup
  • Saving and Restoring the Buffer Pool State Online
  • Displaying Buffer Pool Dump Progress
  • Displaying Buffer Pool Load Progress
  • Aborting a Buffer Pool Load Operation
  • Monitoring Buffer Pool Load Progress Using Performance Schema

Configuring the Dump Percentage for Buffer Pool Pages

配置緩衝池頁面的轉儲百分比

Before dumping pages from the buffer pool, you can configure the percentage of most-recently-used buffer pool pages that you want to dump by setting the innodb_buffer_pool_dump_pct option. If you plan to dump buffer pool pages while the server is running, you can configure the option dynamically:
在從緩衝池中轉儲頁面之前,通過設置innodb_buffer_pool_dump_pct選項,可以配置要轉儲的最近使用的緩衝池頁面的百分比。 如果您計劃在服務器運行時轉儲緩衝池頁面,則可以動態配置該選項:
SET GLOBAL innodb_buffer_pool_dump_pct=40;
If you plan to dump buffer pool pages at server shutdown, set innodb_buffer_pool_dump_pct in your configuration file.
如果您計劃在服務器關閉時轉儲緩衝池頁面,請在您的配置文件中設置innodb_buffer_pool_dump_pct
[mysqld]
innodb_buffer_pool_dump_pct=40
The innodb_buffer_pool_dump_pct default value was changed from 100 (dump all pages) to 25 (dump 25% of most-recently-used pages) in MySQL 5.7 when innodb_buffer_pool_dump_at_shutdown andinnodb_buffer_pool_load_at_startup were enabled by default.
在MySQL 5.7中,當innodb_buffer_pool_dump_at_shutdown 和innodb_buffer_pool_dump_pct默認啓用時,innodb_buffer_pool_dump_pct從100(轉儲所有頁面)更改爲25(轉儲最近使用的頁面的25%)。

Saving the Buffer Pool State at Shutdown and Restoring it at Startup

在關閉時保存緩衝池狀態,在啓動時恢復緩衝池狀態
To save the state of the buffer pool at server shutdown, issue the following statement prior to shutting down the server:
爲了在服務器關閉時保存緩衝池的狀態,在關閉服務器之前發出以下語句:
SET GLOBAL innodb_buffer_pool_dump_at_shutdown=ON;
innodb_buffer_pool_dump_at_shutdown is enabled by default.
默認情況下,innodb_buffer_pool_dump_at_shutdown是啓用的。
To restore the buffer pool state at server startup, specify the --innodb_buffer_pool_load_at_startup option when starting the server:
要在服務器啓動時恢復緩衝池狀態,請在啓動服務器時指定--innodb_buffer_pool_load_at_startup選項:
mysqld --innodb_buffer_pool_load_at_startup=ON;
innodb_buffer_pool_load_at_startup is enabled by default.
默認情況下,innodb_buffer_pool_load_at_startup是啓用的。

Saving and Restoring the Buffer Pool State Online
在線保存和恢復緩衝池狀態

To save the state of the buffer pool while MySQL server is running, issue the following statement:
要在MySQL服務器運行時保存緩衝池的狀態,請發出以下語句:
SET GLOBAL innodb_buffer_pool_dump_now=ON;
To restore the buffer pool state while MySQL is running, issue the following statement:
要在MySQL運行時恢復緩衝池狀態,請發出以下語句:
SET GLOBAL innodb_buffer_pool_load_now=ON;

Displaying Buffer Pool Dump Progress
顯示緩衝池轉儲進度
To display progress when saving the buffer pool state to disk, issue the following statement:
若要在將緩衝池狀態保存到磁盤時顯示進度,請發出以下語句:
SHOW STATUS LIKE 'Innodb_buffer_pool_dump_status';
If the operation has not yet started, “not started” is returned. If the operation is complete, the completion time is printed (e.g. Finished at 110505 12:18:02). If the operation is in progress, status information is provided (e.g. Dumping buffer pool 5/7, page 237/2873).
如果操作尚未啓動,則返回“not started”。如果操作完成,則打印完成時間(例如,完成時間爲110505 12:18:02)。如果操作正在進行,則提供狀態信息(例如Dumping buffer pool 5/7, page 237/2873)。

Displaying Buffer Pool Load Progress
顯示緩衝池加載進度
To display progress when loading the buffer pool, issue the following statement:
要顯示加載緩衝池時的進度,請發出以下語句:
SHOW STATUS LIKE 'Innodb_buffer_pool_load_status';
If the operation has not yet started, “not started” is returned. If the operation is complete, the completion time is printed (e.g. Finished at 110505 12:23:24). If the operation is in progress, status information is provided (e.g. Loaded 123/22301 pages).
如果操作尚未啓動,則返回“not started”。如果操作完成,打印完成時間(如:110505 12:23:24)。如果操作正在進行,則提供狀態信息(例如,Loaded 123/22301 pages)。

Aborting a Buffer Pool Load Operation
中止緩衝池加載操作
To abort a buffer pool load operation, issue the following statement:
若要中止緩衝池加載操作,請發出以下語句:
SET GLOBAL innodb_buffer_pool_load_abort=ON;

Monitoring Buffer Pool Load Progress Using Performance Schema
使用Performance Schema監視緩衝池加載進度
You can monitor buffer pool load progress using Performance Schema.
您可以使用Performance Schema.監控緩衝池加載進度。
The following example demonstrates how to enable the stage/innodb/buffer pool load stage event instrument and related consumer tables to monitor buffer pool load progress.
以下示例演示如何啓用 stage/innodb/buffer pool load階段事件工具和相關的使用者表以監視緩衝池加載進度。
For information about buffer pool dump and load procedures used in this example, see Section 14.6.3.8, “Saving and Restoring the Buffer Pool State”. For information about Performance Schema stage event instruments and related consumers, see Section 25.11.5, “Performance Schema Stage Event Tables”.
有關本例中使用的緩衝池轉儲和加載過程的信息,請參見Section 14.6.3.8, “Saving and Restoring the Buffer Pool State”.。有關性能模式階段事件工具和相關使用者的信息,請參閱Section 25.11.5, “Performance Schema Stage Event Tables”.。

  1. Enable the stage/innodb/buffer pool load instrument:
  2. 啓用stage/innodb/buffer pool load 工具
    mysql> UPDATE performance_schema.setup_instruments SET ENABLED = 'YES'
    WHERE NAME LIKE 'stage/innodb/buffer%';
  3. Enable the stage event consumer tables, which include events_stages_current, events_stages_history, andevents_stages_history_long.
  4. 啓用stage事件消費者表,其中包括events_stages_current、events_stages_history、andevents_stages_history_long。
    mysql> UPDATE performance_schema.setup_consumers SET ENABLED = 'YES'
    WHERE NAME LIKE '%stages%';
  5. Dump the current buffer pool state by enabling innodb_buffer_pool_dump_now.
  6. 通過啓用innodb_buffer_pool_dump_now,轉儲當前緩衝池狀態。
    mysql> SET GLOBAL innodb_buffer_pool_dump_now=ON;
  7. Check the buffer pool dump status to ensure that the operation has completed.
  8. 檢查緩衝池轉儲狀態,以確保操作已經完成。
    mysql> SHOW STATUS LIKE 'Innodb_buffer_pool_dump_status'\G
    1. row
    Variable_name: Innodb_buffer_pool_dump_status
    Value: Buffer pool(s) dump completed at 150202 16:38:58
  9. Load the buffer pool by enabling innodb_buffer_pool_load_now:
  10. 通過啓用innodb_buffer_pool_load_now加載緩衝池:
    mysql> SET GLOBAL innodb_buffer_pool_load_now=ON;
  11. Check the current status of the buffer pool load operation by querying the Performance Schema events_stages_current table. The WORK_COMPLETED column shows the number of buffer pool pages loaded. The WORK_ESTIMATED column provides an estimate of the remaining work, in pages.
  12. 通過查詢Performdeance Schemad的events_stages_current表檢查緩衝池負載操作的當前狀態。WORK_COMPLETED列顯示加載的緩衝池頁面的數量。WORK_ESTIMATED列提供了對剩餘工作的估計,在頁面中。
    mysql> SELECT EVENT_NAME, WORK_COMPLETED, WORK_ESTIMATED
    FROM performance_schema.events_stages_current;
    +-------------------------------+----------------+----------------+
    | EVENT_NAME | WORK_COMPLETED | WORK_ESTIMATED |
    +-------------------------------+----------------+----------------+
    | stage/innodb/buffer pool load | 5353 | 7167 |
    +-------------------------------+----------------+----------------+

The events_stages_current table returns an empty set if the buffer pool load operation has completed. In this case, you can check the events_stages_history table to view data for the completed event. For example:

  1. 如果緩衝池裝載操作已經完成,則events_stages_current表返回一個空集。在本例中,可以檢查events_stages_history表以查看已完成事件的數據。例如:
    mysql> SELECT EVENT_NAME, WORK_COMPLETED, WORK_ESTIMATED
    FROM performance_schema.events_stages_history;
    +-------------------------------+----------------+----------------+
    | EVENT_NAME | WORK_COMPLETED | WORK_ESTIMATED |
    +-------------------------------+----------------+----------------+
    | stage/innodb/buffer pool load | 7167 | 7167 |
    +-------------------------------+----------------+----------------+
    Note
    You can also monitor buffer pool load progress using Performance Schema when loading the buffer pool at startup using innodb_buffer_pool_load_at_startup. In this case, the stage/innodb/buffer pool load instrument and related consumers must be enabled at startup. For more information, see Section 25.3, “Performance Schema Startup Configuration”.
    在啓動時使用innodb_buffer_pool_load_at_startup加載緩衝池時,還可以使用Performance Schema監視緩衝池加載進度。在這種情況下,必須在啓動時啓用stage/innodb/buffer pool load工具和相關的使用者。

PREV: 14.6.3.7 Fine-tuning InnoDB Buffer Pool Flushing. https://blog.51cto.com/itzhoujun/2356985
NEXT: 14.6.3.9 Monitoring the Buffer Pool. https://blog.51cto.com/itzhoujun/2356992

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章