MySQL 101: Linux Tuning for MySQL

Linux Tuning for MySQL

Linux Tuning for MySQLWhen trying to do some Linux tuning for MySQL, there are a few options that will greatly influence the speed of MySQL.  Below are some of the most important of these settings to help you get started.


The first thing to look at is what swappiness is set to.  This will determine the tendency of the kernel to swap out memory pages.  In may cases, you will want to set this to “1” to keep the swapping to a minimum.  A value of “0” will disable it entirely.

You can determine the current value with the following command:

cat /proc/sys/vm/swappiness

If this is not set to “1”, you should consider making the change by using one of the following options:

# Make sure you are root and set swappiness to 1 
echo 1 > /proc/sys/vm/swappiness

# Or, you can use sysctl to do the same sysctl 
vm.swappiness vm.swappiness = 1

If the change helps, you will want to make it permanent by making the change in /etc/sysctl.conf:

vm.swappiness = 1

I/O Scheduler

The default for many systems is either “noop” or “deadline”.  In almost all cases, “noop” is more efficient than “deadline”, “cfq”, or “anticipatory”.  To check the current value of the I/O Scheduler, issue the following command:

cat /sys/block/sdb/queue/scheduler

If you want to test performance with “noop”, try the following command:

sudo echo noop > /sys/block/sdb/queue/scheduler

If you want to make the change permanent, you will need to do the following in the GRUB configuration file:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash elevator=noop"

CPU Governor

Most modern processors are capable of operating with a number of different clock frequency and voltage configurations.  These are referred to as Operating Performance Points or P-states.  Generally, the higher the clock frequency and the higher the voltage, the more instructions can be executed by the CPU over time.  Likewise, the higher the clock frequency and the voltage, the more energy is consumed. As such, there is a trade-off between CPU capacity and power draw by the processor.

You can check what driver and governor are in use with the following command:

cpupower frequency-info
driver: acpi-cpufreq
available cpufreq governors: conservative, ondemand, userspace, powersave, performance
The governor "ondemand" may decide which speed to use within this range.

In the above, you can see that the driver is “acpi-cpufreq” and the governor is set to “ondemand”.

You can also check the governor setting by issuing the following:

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

If “performance” is an option, you can make the change by issuing the command:

echo "performance" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

Of course, you will want to decide if this has helped performance, so testing is essential.


NUMA stands for “Non-uniform memory access.” With NUMA, an SMP’s system processor can access its own local memory faster than non-local memory.  This may result in swapping and thus negatively impact database performance.  When the memory allocated to the InnoDB Buffer Pool is larger than the amount of the RAM available and the default memory allocation policy is selected, swapping will likely occur.  A server with NUMA enabled will report different node distances between CPU nodes.

You can determine your setting with the following:

numactl --hardware

Whenever numactl shows different distances across nodes, the MySQL variable innodb_numa_interleave should be enabled to ensure memory interleaving. With Percona Server, you can improve NUMA support by using the flush_caches variable.  This will help with allocation fairness across nodes.  To determine whether the allocation is equal across nodes, you can check numa_maps with the script:


As is normally the case, you should always test any changes you make in a lower environment before making them in production.  Workloads are so different, and you must see how any changes impact your system.

by Michael Patrick via Percona Database Performance Blog


Popular posts from this blog