DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Observability Architecture: Financial Payments Introduction
  • VPN Architecture for Internal Networks
  • What Is Istio Service Mesh?
  • File Upload Security and Malware Protection

Trending

  • Observability Architecture: Financial Payments Introduction
  • VPN Architecture for Internal Networks
  • What Is Istio Service Mesh?
  • File Upload Security and Malware Protection
  1. DZone
  2. Data Engineering
  3. Databases
  4. MySQL 101: Linux Tuning for MySQL

MySQL 101: Linux Tuning for MySQL

When trying to do some Linux tuning for MySQL, there are a few options that will greatly influence the speed of MySQL.

Michael Patrick user avatar by
Michael Patrick
·
Jul. 16, 20 · Tutorial
Like (2)
Save
Tweet
Share
6.95K Views

Join the DZone community and get the full member experience.

Join For Free

When 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: 

Java
 




x


 
1
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:

Shell
 




x


 
1
# Make sure you are root and set swappiness to 1 
2
echo 1 > /proc/sys/vm/swappiness
3
 
4
# Or, you can use sysctl to do the same sysctl 
5
vm.swappiness vm.swappiness = 1



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

Java
 




xxxxxxxxxx
1


 
1
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: 

Java
 




xxxxxxxxxx
1


 
1
cat /sys/block/sdb/queue/scheduler



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

Java
 




xxxxxxxxxx
1


 
1
 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: 

Java
 




xxxxxxxxxx
1


 
1
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:

Shell
 




xxxxxxxxxx
1


 
1
cpupower frequency-info
2
...
3
driver: acpi-cpufreq
4
...
5
available cpufreq governors: conservative, ondemand, userspace, powersave, performance
6
...
7
The governor "ondemand" may decide which speed to use within this range.
8
...



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: 

Shell
 




xxxxxxxxxx
1


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



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

Shell
 




xxxxxxxxxx
1


 
1
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

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: 

Java
 




xxxxxxxxxx
1


 
1
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: 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.

MySQL Linux (operating system)

Published at DZone with permission of Michael Patrick. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Observability Architecture: Financial Payments Introduction
  • VPN Architecture for Internal Networks
  • What Is Istio Service Mesh?
  • File Upload Security and Malware Protection

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: