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.

Swappiness

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:

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

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

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:

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

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

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:

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:

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

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

NUMA

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:

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: https://github.com/sonots/bin/blob/master/numa-maps-summary.pl

Conclusion

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.

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
fanderchan

how about disable numa?

Beau

Per Red Hat’s docs and numerous others, setting swappiness=0 does not actually disable it. It does change the way it functions, though swappiness=0 increases the likelihood of OOM killing during high memory and i/o pressure. Additionally, Red Hat used to recommend swappiness=10 for database servers without heavy levels of fine tuning, though I have not seen that recommendation recently.

src: https://access.redhat.com/solutions/3383811