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.
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.
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.
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.
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.
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.
Operations related to saving and restoring the buffer pool state are described in the following topics:
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:
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.
[mysqld]
innodb_buffer_pool_dump_pct=40
The
innodb_buffer_pool_dump_pct
default value is 25 (dump 25% of most-recently-used pages).
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.
To restore the buffer pool state at server startup, specify
the --innodb-buffer-pool-load-at-startup
option when starting the server:
mysqld --innodb-buffer-pool-load-at-startup=ON;
innodb_buffer_pool_load_at_startup
is enabled by default.
To save the state of the buffer pool while MySQL server is running, issue the following statement:
SET GLOBAL innodb_buffer_pool_dump_now=ON;
To restore the buffer pool state while MySQL is running, issue the following statement:
SET GLOBAL innodb_buffer_pool_load_now=ON;
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).
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).
To abort a buffer pool load operation, issue the following statement:
SET GLOBAL innodb_buffer_pool_load_abort=ON;
You can monitor buffer pool load progress using 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.
For information about buffer pool dump and load procedures used in this example, see Section 17.8.3.6, “Saving and Restoring the Buffer Pool State”. For information about Performance Schema stage event instruments and related consumers, see Section 29.12.5, “Performance Schema Stage Event Tables”.
Enable the
stage/innodb/buffer pool load
instrument:mysql> UPDATE performance_schema.setup_instruments SET ENABLED = 'YES' WHERE NAME LIKE 'stage/innodb/buffer%';
Enable the stage event consumer tables, which include
events_stages_current
,events_stages_history
, andevents_stages_history_long
.mysql> UPDATE performance_schema.setup_consumers SET ENABLED = 'YES' WHERE NAME LIKE '%stages%';
Dump the current buffer pool state by enabling
innodb_buffer_pool_dump_now
.mysql> SET GLOBAL innodb_buffer_pool_dump_now=ON;
Check the buffer pool dump status to ensure that the operation has completed.
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
Load the buffer pool by enabling
innodb_buffer_pool_load_now
:mysql> SET GLOBAL innodb_buffer_pool_load_now=ON;
Check the current status of the buffer pool load operation by querying the Performance Schema
events_stages_current
table. TheWORK_COMPLETED
column shows the number of buffer pool pages loaded. TheWORK_ESTIMATED
column provides an estimate of the remaining work, in pages.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 theevents_stages_history
table to view data for the completed event. For example: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 | +-------------------------------+----------------+----------------+
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 29.3, “Performance Schema Startup Configuration”.