Mysql – How MySQL use the InnoDB Buffer

innodbMySQLperformanceperformance-tuningquery-performance

For example, when using mysqltuner.pl, it told me to increase the InnoDB Buffer Size to > 5GB as my data is 5.6GB

Does it mean: if I allocate enough for the InnoDB Buffer, data will be loaded from the memory instead of disk, and will greatly improve QPS for my database?

Best Answer

Short Answer: Rule of Thumb: If you have more than 4GB of RAM, then set innodb_buffer_pool_size to about 70% of available RAM. Set and forget.

Long Answer:

"Greatly improve QPS?" -- It depends.

The buffer_pool is a "cache", maintained roughly as "least-recently-used".

If your data + indexes are bigger than the buffer_pool, there may be some slowdown. Either live with the speed or get more RAM.

I have seen terabyte datasets run just fine on 32GB servers. It depends on the "working set". If the application only rummages through a portion of the rows (eg, "recent" rows), then a small buffer_pool works just as good as a big one.

If you have UUIDs, you are hosed. These lead to random access that leads to slow-due-to-IO versus buy-more-RAM.

mysqltuner has some good points and some bad points. Don't increase your buffer_pool to "big enough" unless you have 8GB or more of RAM. Swapping is much worse for performance than shrinking the buffer_pool.

With a big enough buffer_pool, no it won't automatically load everything. As a "cache", things (16KB blocks) are loaded as needed, then left there. If it is not big enough and your "working set size" is big, those blocks will be bumped out to make room for other blocks. Automatically. The only cost is speed.