Quantcast
Channel: Percona Database Performance Blog
Viewing all articles
Browse latest Browse all 1786

How to Monitor Online InnoDB Buffer Pool Resizing

$
0
0
Monitor Online InnoDB Buffer Pool Resizing

The InnoDB buffer pool acts as a powerhouse for MySQL, caching frequently accessed data and index pages in memory to accelerate query performance. In this blog post, we will go through the process of InnoDB buffer pool resizing online, covering why it is important to monitor its progress and how to monitor it.

Importance of monitoring the InnoDB buffer pool resize

Since MySQL 5.7.5, we have been able to resize the InnoDB buffer pool online, which allows administrators to adjust the buffer pool size dynamically without requiring a server restart, offering a flexible solution for optimizing system resources.

You can dynamically change the buffer pool using the following command:

SET GLOBAL innodb_buffer_pool_size = XYZ;

In short, we will review what major steps are taken while doing the buffer pool resize. InnoDB’s background threads take care of making this change.

When the buffer pool size is increased, the following steps are considered:

  •   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 and queries will be paused.

When the buffer pool size is reduced:

  •   Defragment 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 the buffer pool concurrently.

Since the operation is not causing 100% downtime but is a blocking type, it becomes important for us to know the status of the operation.

Monitoring buffer pool size changes

Prior to MySQL 8.0.31, we can do this by checking the innodb_buffer_pool_resize_status after modifying the innodb_buffer_pool_size. This status variable reports a string value indicating buffer pool resizing progress.

mysql> SHOW STATUS WHERE Variable_name='InnoDB_buffer_pool_resize_status';
+----------------------------------+----------------------------------+
| Variable_name                    | Value                            |
+----------------------------------+----------------------------------+
| Innodb_buffer_pool_resize_status | Resizing also other hash tables. |
+----------------------------------+----------------------------------+

Starting from MySQL 8.0.31 monitoring the online innodb_buffer_pool resize operation is even better and introduces exciting improvements, particularly in monitoring the progress of online buffer pool resizing operations.

Starting from 8.0.31, two new variables were added, which are innodb_buffer_pool_resize_status_code and innodb_buffer_pool_resize_status_progress. These variables report the numeric values, making it easier for administrators to keep a close eye on the progress of buffer pool resizing operations.

Query to monitor InnoDB buffer pool resize status:

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

Using PMM to track the InnoDB buffer pool resize status:

The Percona Monitoring and Management tool also collects and tracks the related configuration variables which enable us to visualize the same. The following is a sample PMM dashboard that shows the multiple buffer pool resize operations during my tests.

PMM Buffer Pool

Buffer pool resizing operation status codes

Buffer pool resize monitoring in action

Let’s dive into a practical example to demonstrate how to leverage these variables. Consider a scenario where you want to resize the InnoDB buffer pool to accommodate a growing dataset.

Step 1: Check current status

Before initiating any changes, let’s understand the current status of the buffer pool resizing operation by executing the following query:

mysql> SELECT variable_name, variable_value
    ->  FROM performance_schema.global_status
    ->  WHERE LOWER(variable_name) LIKE "innodb_buffer_pool_resize%";
+-------------------------------------------+----------------+
| variable_name                             | variable_value |
+-------------------------------------------+----------------+
| Innodb_buffer_pool_resize_status          |                |
| Innodb_buffer_pool_resize_status_code     | 0              |
| Innodb_buffer_pool_resize_status_progress | 0              |
+-------------------------------------------+----------------+
3 rows in set (0.03 sec)

This query provides a snapshot of the current status and progress of the buffer pool resizing operation. From the above output, we can confirm that there is no buffer pool resize operation in progress.

Step 2: Initiate resizing

Let’s change the InnoDB buffer pool from default 128MB to 1G.

mysql> SELECT @@GLOBAL.innodb_buffer_pool_size/pow(1024,2) buffer_pool_mb;
+----------------+
| buffer_pool_mb |
+----------------+
|            128 |
+----------------+
1 row in set (0.00 sec)

mysql> SET GLOBAL innodb_buffer_pool_size=1*1024*1024*1024;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @@GLOBAL.innodb_buffer_pool_size/pow(1024,2) buffer_pool_mb;
+----------------+
| buffer_pool_mb |
+----------------+
|           1024 |
+----------------+
1 row in set (0.00 sec)

Step 3: Monitor progress

After resizing the InnoDB buffer pool online, execute the monitoring query periodically to track the progress of the resizing operation. Keep an eye on the innodb_buffer_pool_resize_status_code and innodb_buffer_pool_resize_status_progress values. The status code provides insights into the current state of the resizing operation, while the progress value indicates the completion percentage.

mysql> SELECT variable_name, variable_value   FROM performance_schema.global_status   WHERE LOWER(variable_name) LIKE "innodb_buffer_pool_resize%";
+-------------------------------------------+--------------------------------+
| variable_name                             | variable_value                 |
+-------------------------------------------+--------------------------------+
| Innodb_buffer_pool_resize_status          | Disabling adaptive hash index. |
| Innodb_buffer_pool_resize_status_code     | 2                              |
| Innodb_buffer_pool_resize_status_progress | 0                              |
+-------------------------------------------+--------------------------------+
3 rows in set (6.29 sec)

mysql> SELECT variable_name, variable_value FROM performance_schema.global_status WHERE LOWER(variable_name) LIKE "innodb_buffer_pool_resize%";
+-------------------------------------------+----------------------------------+
| variable_name                             | variable_value                   |
+-------------------------------------------+----------------------------------+
| Innodb_buffer_pool_resize_status          | Resizing also other hash tables. |
| Innodb_buffer_pool_resize_status_code     | 6                                |
| Innodb_buffer_pool_resize_status_progress | 100                              |
+-------------------------------------------+----------------------------------+
3 rows in set (1.47 sec)

mysql> SELECT variable_name, variable_value   FROM performance_schema.global_status   WHERE LOWER(variable_name) LIKE "innodb_buffer_pool_resize%";
+-------------------------------------------+----------------------------------------------------+
| variable_name                             | variable_value                                     |
+-------------------------------------------+----------------------------------------------------+
| Innodb_buffer_pool_resize_status          | Completed resizing buffer pool at 231205 10:24:24. |
| Innodb_buffer_pool_resize_status_code     | 0                                                  |
| Innodb_buffer_pool_resize_status_progress | 100                                                |
+-------------------------------------------+----------------------------------------------------+
3 rows in set (1.46 sec)

Important: MySQL error log provides additional information which includes the percentage progress value of each status code. This is available only for the log_error_verbosity=3.

2023-12-05T16:51:29.610886Z 65 [Note] [MY-012398] [InnoDB] Requested to resize buffer pool. (new size: 1073741824 bytes)
2023-12-05T16:51:29.610907Z 0 [Note] [MY-013954] [InnoDB] Status code 1: Resizing buffer pool from 134217728 to 1073741824 (unit=134217728).
2023-12-05T16:51:29.620309Z 0 [Note] [MY-013953] [InnoDB] Status code 1: 100% complete
2023-12-05T16:51:29.620347Z 0 [Note] [MY-013952] [InnoDB] Status code 1: Completed
2023-12-05T16:51:29.620357Z 0 [Note] [MY-013954] [InnoDB] Status code 2: Disabling adaptive hash index.
2023-12-05T16:51:29.620707Z 0 [Note] [MY-011885] [InnoDB] disabled adaptive hash index.
2023-12-05T16:51:29.620754Z 0 [Note] [MY-013953] [InnoDB] Status code 2: 100% complete
2023-12-05T16:51:29.620766Z 0 [Note] [MY-013952] [InnoDB] Status code 2: Completed
2023-12-05T16:51:29.620783Z 0 [Note] [MY-013954] [InnoDB] Status code 3: Withdrawing blocks to be shrunken.
2023-12-05T16:51:29.620812Z 0 [Note] [MY-013953] [InnoDB] Status code 3: 100% complete
2023-12-05T16:51:29.620832Z 0 [Note] [MY-013952] [InnoDB] Status code 3: Completed
2023-12-05T16:51:29.620852Z 0 [Note] [MY-013954] [InnoDB] Status code 4: Latching whole of buffer pool.
2023-12-05T16:51:29.620863Z 0 [Note] [MY-013953] [InnoDB] Status code 4: 14% complete
2023-12-05T16:51:29.620882Z 0 [Note] [MY-013953] [InnoDB] Status code 4: 28% complete
2023-12-05T16:51:29.620977Z 0 [Note] [MY-013953] [InnoDB] Status code 4: 42% complete
2023-12-05T16:51:29.621007Z 0 [Note] [MY-013953] [InnoDB] Status code 4: 57% complete
2023-12-05T16:51:29.621027Z 0 [Note] [MY-013953] [InnoDB] Status code 4: 71% complete
2023-12-05T16:51:29.621035Z 0 [Note] [MY-013953] [InnoDB] Status code 4: 85% complete
2023-12-05T16:51:29.621054Z 0 [Note] [MY-013953] [InnoDB] Status code 4: 100% complete
2023-12-05T16:51:29.621064Z 0 [Note] [MY-013952] [InnoDB] Status code 4: Completed
2023-12-05T16:51:29.621072Z 0 [Note] [MY-013954] [InnoDB] Status code 5: Starting pool resize
2023-12-05T16:51:29.621079Z 0 [Note] [MY-013954] [InnoDB] Status code 5: buffer pool 0 : resizing with chunks 1 to 8.
2023-12-05T16:51:29.675427Z 0 [Note] [MY-011891] [InnoDB] buffer pool 0 : 7 chunks (57339 blocks) were added.
2023-12-05T16:51:29.675604Z 0 [Note] [MY-013953] [InnoDB] Status code 5: 100% complete
2023-12-05T16:51:29.675658Z 0 [Note] [MY-013952] [InnoDB] Status code 5: Completed
2023-12-05T16:51:29.675671Z 0 [Note] [MY-013954] [InnoDB] Status code 6: Resizing hash tables.
2023-12-05T16:51:29.676962Z 0 [Note] [MY-011892] [InnoDB] buffer pool 0 : hash tables were resized.
2023-12-05T16:51:29.677106Z 0 [Note] [MY-013953] [InnoDB] Status code 6: 100% complete
2023-12-05T16:51:29.677150Z 0 [Note] [MY-013954] [InnoDB] Status code 6: Resizing also other hash tables.
2023-12-05T16:51:29.681750Z 0 [Note] [MY-011893] [InnoDB] Resized hash tables at lock_sys, adaptive hash index, dictionary.
2023-12-05T16:51:29.682098Z 0 [Note] [MY-011894] [InnoDB] Completed to resize buffer pool from 134217728 to 1073741824.
2023-12-05T16:51:29.682143Z 0 [Note] [MY-011895] [InnoDB] Re-enabled adaptive hash index.
2023-12-05T16:51:29.682157Z 0 [Note] [MY-013952] [InnoDB] Status code 6: Completed
2023-12-05T16:51:29.682173Z 0 [Note] [MY-013954] [InnoDB] Status code 0: Completed resizing buffer pool at 231205 16:51:29.
2023-12-05T16:51:29.682191Z 0 [Note] [MY-013953] [InnoDB] Status code 0: 100% complete

Conclusion

With MySQL variables like innodb_buffer_pool_resize_status_code and innodb_buffer_pool_resize_status_progress from MySQL 8.0.31, administrators can effectively monitor online InnoDB buffer pool resizing and manage its online operations.

Percona Distribution for MySQL is the most complete, stable, scalable, and secure open source MySQL solution available, delivering enterprise-grade database environments for your most critical business applications… and it’s free to use!

 

Try Percona Distribution for MySQL today!


Viewing all articles
Browse latest Browse all 1786

Trending Articles