Rechercher dans le manuel MySQL

15.8.3.1 Configuring InnoDB Buffer Pool Size

You can configure InnoDB buffer pool size offline (at startup) or online, while the server is running. Behavior described in this section applies to both methods. For additional information about configuring buffer pool size online, see Configuring InnoDB Buffer Pool Size Online.

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. For more information, see Configuring InnoDB Buffer Pool Chunk Size.

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.

In the following example, innodb_buffer_pool_size is set to 8G, and innodb_buffer_pool_instances is set to 16. innodb_buffer_pool_chunk_size is 128M, which is the default value.

8G is a valid innodb_buffer_pool_size value because 8G is a multiple of innodb_buffer_pool_instances=16 * innodb_buffer_pool_chunk_size=128M, which is 2G.

shell> mysqld --innodb-buffer-pool-size=8G --innodb-buffer-pool-instances=16
  1. mysql> SELECT @@innodb_buffer_pool_size/1024/1024/1024;
  2. +------------------------------------------+
  3. | @@innodb_buffer_pool_size/1024/1024/1024 |
  4. +------------------------------------------+
  5. |                           8.000000000000 |
  6. +------------------------------------------+

In this example, innodb_buffer_pool_size is set to 9G, and innodb_buffer_pool_instances is set to 16. innodb_buffer_pool_chunk_size is 128M, which is the default value. In this case, 9G is not a multiple of innodb_buffer_pool_instances=16 * innodb_buffer_pool_chunk_size=128M, so innodb_buffer_pool_size is adjusted to 10G, which is a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances.

shell> mysqld --innodb-buffer-pool-size=9G --innodb-buffer-pool-instances=16
  1. mysql> SELECT @@innodb_buffer_pool_size/1024/1024/1024;
  2. +------------------------------------------+
  3. | @@innodb_buffer_pool_size/1024/1024/1024 |
  4. +------------------------------------------+
  5. |                          10.000000000000 |
  6. +------------------------------------------+
Configuring 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.

Command line:

shell> mysqld --innodb-buffer-pool-chunk-size=134217728

Configuration file:

[mysqld]
innodb_buffer_pool_chunk_size=134217728

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.

    For example, if the buffer pool is initialized with a size of 2GB (2147483648 bytes), 4 buffer pool instances, and a chunk size of 1GB (1073741824 bytes), chunk size is truncated to a value equal to innodb_buffer_pool_size / innodb_buffer_pool_instances, as shown below:

    shell> mysqld --innodb-buffer-pool-size=2147483648 --innodb-buffer-pool-instances=4
    --innodb-buffer-pool-chunk-size=1073741824;
    1. mysql> SELECT @@innodb_buffer_pool_size;
    2. +---------------------------+
    3. | @@innodb_buffer_pool_size |
    4. +---------------------------+
    5. |                2147483648 |
    6. +---------------------------+
    7.  
    8. mysql> SELECT @@innodb_buffer_pool_instances;
    9. +--------------------------------+
    10. | @@innodb_buffer_pool_instances |
    11. +--------------------------------+
    12. |                              4 |
    13. +--------------------------------+
    14.  
    15. # Chunk size was set to 1GB (1073741824 bytes) on startup but was
    16. # truncated to innodb_buffer_pool_size / innodb_buffer_pool_instances
    17.  
    18. mysql> SELECT @@innodb_buffer_pool_chunk_size;
    19. +---------------------------------+
    20. | @@innodb_buffer_pool_chunk_size |
    21. +---------------------------------+
    22. |                       536870912 |
    23. +---------------------------------+
  • 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. This behavior is demonstrated in the following example:

    1. # The buffer pool has a default size of 128MB (134217728 bytes)
    2.  
    3. mysql> SELECT @@innodb_buffer_pool_size;
    4. +---------------------------+
    5. | @@innodb_buffer_pool_size |
    6. +---------------------------+
    7. |                 134217728 |
    8. +---------------------------+
    9.  
    10. # The chunk size is also 128MB (134217728 bytes)
    11.  
    12. mysql> SELECT @@innodb_buffer_pool_chunk_size;
    13. +---------------------------------+
    14. | @@innodb_buffer_pool_chunk_size |
    15. +---------------------------------+
    16. |                       134217728 |
    17. +---------------------------------+
    18.  
    19. # There is a single buffer pool instance
    20.  
    21. mysql> SELECT @@innodb_buffer_pool_instances;
    22. +--------------------------------+
    23. | @@innodb_buffer_pool_instances |
    24. +--------------------------------+
    25. |                              1 |
    26. +--------------------------------+
    27.  
    28. # Chunk size is decreased by 1MB (1048576 bytes) at startup
    29. # (134217728 - 1048576 = 133169152):
    30.  
    31. shell> mysqld --innodb-buffer-pool-chunk-size=133169152
    32.  
    33. mysql> SELECT @@innodb_buffer_pool_chunk_size;
    34. +---------------------------------+
    35. | @@innodb_buffer_pool_chunk_size |
    36. +---------------------------------+
    37. |                       133169152 |
    38. +---------------------------------+
    39.  
    40. # Buffer pool size increases from 134217728 to 266338304
    41. # Buffer pool size is automatically adjusted to a value that is equal to
    42. # or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances
    43.  
    44. mysql> SELECT @@innodb_buffer_pool_size;
    45. +---------------------------+
    46. | @@innodb_buffer_pool_size |
    47. +---------------------------+
    48. |                 266338304 |
    49. +---------------------------+

    This example demonstrates the same behavior but with multiple buffer pool instances:

    1. # The buffer pool has a default size of 2GB (2147483648 bytes)
    2.  
    3. mysql> SELECT @@innodb_buffer_pool_size;
    4. +---------------------------+
    5. | @@innodb_buffer_pool_size |
    6. +---------------------------+
    7. |                2147483648 |
    8. +---------------------------+
    9.  
    10. # The chunk size is .5 GB (536870912 bytes)
    11.  
    12. mysql> SELECT @@innodb_buffer_pool_chunk_size;
    13. +---------------------------------+
    14. | @@innodb_buffer_pool_chunk_size |
    15. +---------------------------------+
    16. |                       536870912 |
    17. +---------------------------------+
    18.  
    19. # There are 4 buffer pool instances
    20.  
    21. mysql> SELECT @@innodb_buffer_pool_instances;
    22. +--------------------------------+
    23. | @@innodb_buffer_pool_instances |
    24. +--------------------------------+
    25. |                              4 |
    26. +--------------------------------+
    27.  
    28. # Chunk size is decreased by 1MB (1048576 bytes) at startup
    29. # (536870912 - 1048576 = 535822336):
    30.  
    31. shell> mysqld --innodb-buffer-pool-chunk-size=535822336
    32.  
    33. mysql> SELECT @@innodb_buffer_pool_chunk_size;
    34. +---------------------------------+
    35. | @@innodb_buffer_pool_chunk_size |
    36. +---------------------------------+
    37. |                       535822336 |
    38. +---------------------------------+
    39.  
    40. # Buffer pool size increases from 2147483648 to 4286578688
    41. # Buffer pool size is automatically adjusted to a value that is equal to
    42. # or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances
    43.  
    44. mysql> SELECT @@innodb_buffer_pool_size;
    45. +---------------------------+
    46. | @@innodb_buffer_pool_size |
    47. +---------------------------+
    48. |                4286578688 |
    49. +---------------------------+

    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.

Note

To avoid potential performance issues, the number of chunks (innodb_buffer_pool_size / innodb_buffer_pool_chunk_size) should not exceed 1000.

Inhoudsopgave Haut

Configuring InnoDB Buffer Pool Size Online

The innodb_buffer_pool_size configuration option can be set dynamically using a SET statement, allowing you to resize the buffer pool without restarting the server. For example:

  1. mysql> SET GLOBAL innodb_buffer_pool_size=402653184;

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. 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 of allowing concurrent access is that it could result in a temporary shortage of available pages while pages are being withdrawn.

Note

Nested transactions could fail if initiated after the buffer pool resizing operation begins.

Inhoudsopgave Haut

Monitoring Online Buffer Pool Resizing Progress

The Innodb_buffer_pool_resize_status reports buffer pool resizing progress. For example:

  1. mysql> SHOW STATUS WHERE Variable_name='InnoDB_buffer_pool_resize_status';
  2. +----------------------------------+----------------------------------+
  3. | Variable_name                    | Value                            |
  4. +----------------------------------+----------------------------------+
  5. | Innodb_buffer_pool_resize_status | Resizing also other hash tables. |
  6. +----------------------------------+----------------------------------+

Buffer pool resizing progress is also logged in the server error log. This example shows notes that are logged when increasing the size of the buffer pool:

[Note] InnoDB: Resizing buffer pool from 134217728 to 4294967296. (unit=134217728)
[Note] InnoDB: disabled adaptive hash index.
[Note] InnoDB: buffer pool 0 : 31 chunks (253952 blocks) was added.
[Note] InnoDB: buffer pool 0 : hash tables were resized.
[Note] InnoDB: Resized hash tables at lock_sys, adaptive hash index, dictionary.
[Note] InnoDB: completed to resize buffer pool from 134217728 to 4294967296.
[Note] InnoDB: re-enabled adaptive hash index.

This example shows notes that are logged when decreasing the size of the buffer pool:

[Note] InnoDB: Resizing buffer pool from 4294967296 to 134217728. (unit=134217728)
[Note] InnoDB: disabled adaptive hash index.
[Note] InnoDB: buffer pool 0 : start to withdraw the last 253952 blocks.
[Note] InnoDB: buffer pool 0 : withdrew 253952 blocks from free list. tried to relocate 0 pages.
(253952/253952)
[Note] InnoDB: buffer pool 0 : withdrawn target 253952 blocks.
[Note] InnoDB: buffer pool 0 : 31 chunks (253952 blocks) was freed.
[Note] InnoDB: buffer pool 0 : hash tables were resized.
[Note] InnoDB: Resized hash tables at lock_sys, adaptive hash index, dictionary.
[Note] InnoDB: completed to resize buffer pool from 4294967296 to 134217728.
[Note] InnoDB: re-enabled adaptive hash index.

Inhoudsopgave Haut

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)

  • Coverts 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.


Zoek in de MySQL-handleiding

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 26/06/2006 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/mysql-rf-innodb-buffer-pool-resize.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:en Manuel MySQL : https://dev.mysql.com/

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut