Calculating InnoDB Buffer Pool Size for your MySQL Server
Tags: mysql, innodb, bufferpool, memory
Published: 2018-03-28 17:45:04

---
title: Calculating InnoDB Buffer Pool Size for your MySQL Server
published: true
description: In this ScaleGrid post, you'll learn 2 methods of calculating MySQL InnoDB buffer pool size, pros/cons, and how to compute a optimum value based on system RAM size.
tags: MySQL, InnoDB, Buffer Pool, Memory,
canonical_url: https://scalegrid.io/blog/calculating-innodb-buffer-pool-size-for-your-mysql-server/
---
<link rel="canonical" href="https://scalegrid.io/blog/calculating-innodb-buffer-pool-size-for-your-mysql-server/" />

<img class="alignnone wp-image-2946 size-full" src="https://mongodb.scalegrid.io/hubfs/Calculating-InnoDB-Buffer-Pool-Size-for-your-MySQL-Server-ScaleGrid-TW.jpg" alt="chart" width="831" height="514" />
<h2>What is an InnoDB Buffer Pool?</h2>
<p style="text-align: justify;"><a href="https://dev.mysql.com/doc/refman/5.5/en/innodb-buffer-pool.html" target="_blank">InnoDB buffer pool</a> is the memory space that holds many in-memory data structures of InnoDB, buffers, caches, indexes and even row-data. <a href="https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_buffer_pool_size" target="_blank">innodb_buffer_pool_size</a> is the <a href="https://www.mysql.com/" target="_blank">MySQL </a>configuration parameter that specifies the amount of memory allocated to the InnoDB buffer pool by MySQL. This is one of the most important settings in the MySQL configuration and should be configured based on the available system RAM.</p>
<p style="text-align: justify;">In this post, we’ll walk you through two approaches of setting your InnoDB buffer pool size value, examine the pros and cons of those practices, and also propose a unique method to arrive at an optimum value based on the size of your system RAM.</p>

<h2>Approach 1. Rule of Thumb Method</h2>
<p style="text-align: justify;">The most commonly followed practice is to set this value at <a href="https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html" target="_blank">70% - 80%</a> of the system RAM. Though it works well in most cases, this method may not be optimal in all configurations. Let’s take the example of a system with 192GB of RAM. Based on the above method, we arrive at about 150GB for the buffer pool size. However, this isn’t really an optimal number as it does not fully leverage the large RAM size that’s available in the system, and leaves behind about 40GB of memory. This difference can be even more significant as we move to systems with larger configurations where we should be utilizing the available RAM to a greater extent.</p>

<h2>Approach 2. A More Nuanced Approach</h2>
<p style="text-align: justify;">This approach is based on a more detailed understanding of the internals of the InnoDB buffer pool and its interactions, which is described very well in the book <a href="http://www.highperfmysql.com/" target="_blank">High Performance MySQL</a>.</p>
<p style="text-align: justify;">Let’s look at the following method to compute the InnoDB buffer pool size.</p>

<ol>
	<li>Start with total RAM available.</li>
	<li>Subtract suitable amount for the OS needs.</li>
	<li>Subtract suitable amount for all MySQL needs (like various MySQL buffers, temporary tables, connection pools, and replication related buffers).</li>
	<li>Divide the result by 105%, which is an approximation of the overhead required to manage the buffer pool itself.</li>
</ol>
<p style="text-align: justify;">For example, let's look at a system with 192GB RAM using only InnoDB and having a total log file size of about 4GB. We can use a rule like ‘maximum of 2GB or 5% of total RAM’ for OS needs allocation as recommended in the above book, which comes to about 9.6GB. Then, we'll also allocate about 4GB for other MySQL needs, mainly taking into account the log file size. This method results in about 170GB for our InnoDB buffer pool size, which is about 88.5% utilization of the available RAM size.</p>
<p style="text-align: justify;">Though we used the ‘maximum of 2GB or 5% of total RAM’ rule to compute our memory allocation for OS needs above, the same rule does not work very well in all cases, specifically for systems with medium-sized RAMs between 2GB and 32GB. For instance, in a system with 3GB RAM, allocating 2GB for OS needs does not leave much for the InnoDB buffer pool, while allocating 5% of RAM is just too little for our OS needs.</p>
<p style="text-align: justify;">So, let’s fine-tune the above OS allocation rule and examine the InnoDB computation method across various RAM configurations:</p>

<h3 style="padding-left: 30px;">For Systems with Small-Sized RAM (&lt;= 1GB)</h3>
<p style="text-align: justify; padding-left: 30px;">For systems running with less than 1GB of RAM, it is better to go with the <a href="https://dev.mysql.com/doc/refman/5.7/en/innodb-buffer-pool-resize.html" target="_blank">MySQL default configuration value</a> of 128MB for InnoDB buffer pool size.</p>

<h3 style="padding-left: 30px;">For Systems with Medium-Sized RAM (1GB – 32GB)</h3>
<p style="text-align: justify; padding-left: 30px;">Considering the case of systems with a RAM size of 1GB - 32GB, we can compute OS needs using this rough heuristics:</p>
<p style="padding-left: 30px;"><i>256MB + 256 * log2(RAM size in GB)</i></p>
<p style="text-align: justify; padding-left: 30px;">The rationalization here is that, for low RAM configurations, we start with a base value of 256MB for OS needs and increase this allocation in a logarithmic scale as the amount of RAM increases. This way, we can come up with a deterministic formula to allocate RAM for our OS needs. We'll also allocate the same amount of memory for our MySQL other needs. For example, in a system with 3GB of RAM, we would make a fair allocation of 660MB for OS needs, and another 660MB for MySQL other needs, resulting in a value of about 1.6GB for our InnoDB buffer pool size.</p>

<h3 style="padding-left: 30px;">For Systems with Higher-Sized RAM (&gt; 32GB)</h3>
<p style="text-align: justify; padding-left: 30px;">For systems with RAM sizes greater than 32GB, we would revert back to calculating OS needs as 5% of our system RAM size, and the same amount for MySQL other needs. So, for a system with a RAM size of 192GB, our method will land at about 165GB for InnoDB buffer pool size, which is again, an optimal value to be used.</p>


<h2 style="margin-bottom: 10px; text-align: center;"><span style="font-weight: 400;">InnoDB Buffer Pool Size Calculator</span></h2>

<p style="text-align: justify;">Calculate the optimal value for any-sized RAM: <a href="https://scalegrid.io/blog/calculating-innodb-buffer-pool-size-for-your-mysql-server/" target="_blank">Try the calculator on original post</a></p>

<h2 style="padding-top: 25px;">Plot of InnoDB Buffer Pool Size for Various RAM Sizes</h2>
<img class="alignnone wp-image-2946 size-full" src="https://scalegrid.io/blog/wp-content/uploads/2018/01/chart.png" alt="chart" width="831" height="514" />
<h2>Word of Caution for InnoDB Buffer Pool Size Calculations</h2>
<p style="text-align: justify;">The considerations in this blog post are for Linux systems that are dedicated for MySQL. For Windows systems or systems that run multiple applications along with MySQL, these observations can be inaccurate. It’s also important to note that, though we can use these tools as references, it really takes good experience, experimentation, continuous monitoring, and fine-tuning to get the right sizing for your innodb_buffer_pool_size.</p>