Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
---
title: Learn how to Tune MySQL
title: Tune MySQL performance on Arm-based platforms
description: Learn how to tune MySQL configuration, Linux memory settings, and storage options to improve database performance on Arm-based platforms.

minutes_to_complete: 30

who_is_this_for: This is an advanced topic for software developers and DevOps professionals interested in optimizing MySQL performance on Arm-based VMs in the cloud.
who_is_this_for: This Learning Path is for database administrators (DBAs) and software developers who want to optimize MySQL performance on Arm-based platforms.

learning_objectives:
- Tune MySQL to increase performance
- Configure MySQL settings that affect connection handling, memory usage, disk flush behavior, and concurrency.
- Enable huge pages for MySQL and size them based on the InnoDB buffer pool.
- Evaluate storage, kernel, compiler, and library choices that can affect MySQL performance.

prerequisites:
- Bare-metal or cloud [installation of MySQL](/learning-paths/servers-and-cloud-computing/mysql/)
- On-prem or cloud [installation of MySQL](https://dev.mysql.com/doc/refman/en/)
- A repeatable MySQL workload or benchmark that you can run before and after tuning

author: Julio Suarez

Expand Down Expand Up @@ -41,18 +45,29 @@ test_maintenance: true

further_reading:
- resource:
title: MySQL documentation
link: https://www.mysql.com/
title: MySQL Reference Manual
link: https://dev.mysql.com/doc/refman/en/
type: documentation
- resource:
title: Running MySQL on ARM
link: https://mysqlonarm.github.io/Running-MySQL-on-ARM/
title: InnoDB configuration parameters
link: https://dev.mysql.com/doc/refman/en/innodb-parameters.html
type: documentation
- resource:
title: Optimizing InnoDB disk I/O
link: https://dev.mysql.com/doc/refman/en/optimizing-innodb-diskio.html
type: documentation
- resource:
title: Linux HugeTLBpage documentation
link: https://docs.kernel.org/admin-guide/mm/hugetlbpage.html
type: documentation
- resource:
title: Migrating applications to Arm servers
link: /learning-paths/servers-and-cloud-computing/migration/
type: learning-path

### FIXED, DO NOT MODIFY
# ================================================================================
weight: 1
layout: learningpathall
learning_path_main_page: 'yes'
---

Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
---
title: "About MySQL performance tuning"
title: "Measure MySQL tuning impact"
description: Learn how to approach MySQL performance tuning as a measurement-driven process and compare baseline results with tuned results.
weight: 2
layout: "learningpathall"
---

## About database performance tuning
## About performance tuning

The configuration of a database and the types of requests made by clients to it will differ from use case to use case. This means there is no one size fits all set of tuning parameters for `MySQL`. Use the information in this learning path as general guidance to help with tuning `MySQL`.
Performance tuning is most useful when you treat it as a measurement process, not a fixed checklist. You can tune by changing one parameter at a time, running a designed experiment, comparing profiles, or using automation and AI-assisted tools to explore a larger configuration space.

## Importance of tuning
There isn't a universal set of tuning parameters that works best for every application. The right settings depend on the workload, data size, memory capacity, storage performance, network behavior, software version, system architecture, operating system, and other application-specific factors.

Application tuning allows you to gain performance without scaling a deployment up (bigger machines) or out (more machines). This gives the option to use the gained performance, or to trade it for cost savings by reducing the total compute resources provisioned.
Whatever method you use, keep the measurements repeatable. Record the system configuration, workload, software versions, and tuning parameters so you can identify which changes improved performance and which changes had little effect.

## Note on MySQL Documentation
## Why tune MySQL

All links to [MySQL documentation](https://dev.mysql.com/doc/refman/en/) in this learning path point to the latest version of the documentation. If you are using an older version of MySQL, be sure to change the documentation version after clicking the links.
MySQL performance can be limited by memory usage, disk I/O, connection handling, concurrency, or synchronization overhead. Tuning helps you use the available compute, memory, and storage resources more efficiently.

Improved performance can give you higher throughput, lower latency, or better cost efficiency. A tuned configuration can increase capacity on the same system, or help you meet the same performance target with fewer compute resources.

## Example benchmark result

The following example shows MySQL throughput with HammerDB TPROC-C before and after tuning on an Arm Neoverse V3 system.

![Bar chart comparing MySQL HammerDB TPROC-C normalized NOPM throughput before and after tuning on an Arm Neoverse V3 system. At 128 clients, the out-of-box configuration is 1.00 and the tuned configuration is 15.37.#center](oobvstuned.png "MySQL HammerDB TPROC-C throughput before and after tuning")

This benchmark result is an example, not a guaranteed improvement for every workload. Your results depend on the MySQL version, database size, storage device, memory capacity, client thread count, and the queries used in the test.

{{% notice Note %}}
Links to MySQL documentation in this Learning Path point to the latest version of the documentation. If you use an older version of MySQL, select the matching documentation version after opening the links.
{{% /notice %}}
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
---
# User change
title: "System, Kernel, Compiler, and Libraries"
title: "Tune system, kernel, compiler, and library settings"
description: Learn how storage, kernel page size, Linux huge pages, compiler settings, and OpenSSL choices can affect MySQL performance on Arm-based systems.

weight: 3 # 1 is first, 2 is second, etc.

# Do not modify these elements
layout: "learningpathall"
---

## Storage technology, file system format, and disk scheduling
## Tune the system around MySQL

The underlying storage technology and the file system format can impact performance. In general, locally attached SSD storage will perform best. However, network based storage systems can perform well. You should spend some time studying and experimenting with different storage technologies and configuration options.
MySQL configuration is only one part of performance tuning. Operating system settings, storage behavior, kernel memory management, compiler choices, and library versions can also affect throughput and latency. This section highlights system-level areas to check before or alongside MySQL-specific tuning.

Aside from the storage technology, the file system format used with `MySQL` can impact performance. The `xfs` file system is a good starting point. The `ext4` file system is another good alternative. Last, it is recommended to use storage drives that are dedicated to the database (i.e. not shared with the OS or other applications).
## Storage technology, file systems, and disk scheduling

When running in the cloud, the disk scheduling algorithm is typically set to `noop` or a similar "dumb" algorithm. This is typically optimal for `MySQL` in the cloud, so no adjustment is needed. However, if running `MySQL` on an on-prem server, it's a good idea to double check what the disk scheduling algorithm is, and possibly change it. According to the [Optimizing InnoDB Disk I/O documentation](https://dev.mysql.com/doc/refman/en/optimizing-innodb-diskio.html), `noop` or `deadline` might be better options. It's worth testing this with on-prem systems.
Storage technology and file system choices can affect performance. In general, locally attached SSD storage performs best, but network-based storage systems can also perform well. Test the storage technologies and configuration options available in your environment.

## MySQL storage engines
The file system used with MySQL can also affect performance. The `xfs` file system is a good starting point, and `ext4` is another good option. For production systems, use storage volumes dedicated to the database instead of sharing them with the operating system or other applications.

There are different storage engines available for `MySQL`. The default storage engine is `InnoDB`. `InnoDB` is the default storage engine because it performs the best in the broadest set of use cases.
When running in the cloud, the disk scheduling algorithm is typically set to `noop` or a similar minimal scheduler. This is usually a good setting for MySQL in cloud environments, so no adjustment is needed. If you run MySQL on an on-premises server, double-check the disk scheduling algorithm and test alternatives. According to the [Optimizing InnoDB Disk I/O documentation](https://dev.mysql.com/doc/refman/en/optimizing-innodb-diskio.html), `noop` or `deadline` might be better options for some systems.

## MySQL storage engines

MySQL supports different storage engines. The default storage engine is `InnoDB`, which performs best across the broadest set of use cases.

Information on alternative storage engines can be found in the [MySQL documentation](https://dev.mysql.com/doc/refman/en/storage-engines.html).

## Kernel configuration
## Kernel configuration

`MySQL` can benefit from adjustments to kernel parameters. Below is a list of kernel related settings that can have a positive impact on performance.
MySQL can benefit from adjustments to kernel parameters. The following kernel-related settings can have a positive impact on performance.

### Linux virtual memory subsystem

Making changes to the Linux Virtual Memory subsystem can improve performance.
Making changes to the Linux virtual memory subsystem can improve performance.

These settings can be changed in the `/etc/sysctl.conf` file, or by using the `sysctl` command.
You can change these settings by using the `sysctl` command or by adding configuration files under `/etc/sysctl.d/`.

Documentation on the virtual memory subsystem parameters can be found in the [admin-guide for sysctl in the Linux source code](https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/sysctl/vm.rst).

Expand All @@ -42,14 +47,35 @@ sudo sysctl -a

See the `sysctl` command documentation for more.

### Consider 64 KB kernel pages on Arm

Some Arm Linux distributions provide kernels built with `64 KB` base pages instead of `4 KB` base pages. This is a kernel selection or build-time choice, not a `sysctl` setting you can change on a running system.

A `64 KB` base page can improve some memory-intensive workloads because each base page maps more memory. This can reduce Memory Management Unit (MMU) translation overhead, reduce page-table walk depth, and relieve Translation Lookaside Buffer (TLB) pressure, including instruction-side TLB pressure in the CPU front end.

The tradeoff is memory efficiency. Larger base pages can increase internal fragmentation for workloads with many small or sparsely touched mappings, which can reduce the effective amount of memory available to the application and operating system.

The benefit is workload dependent, so compare a `4 KB` kernel and a `64 KB` kernel with the same MySQL & storage configuration.

Base page size also affects the huge page sizes available on Arm. The common PMD-level huge page sizes are:

| Kernel base page size | PMD-level huge page size |
|-----------------------|--------------------------|
| `4 KB` | `2 MiB` |
| `64 KB` | `512 MiB` |

For more information, see the Linux kernel documentation for [Memory Layout on AArch64 Linux](https://docs.kernel.org/next/arm64/memory.html) and [HugeTLBpage on ARM64](https://docs.kernel.org/next/arm64/hugetlbpage.html).

### Huge memory pages

`MySQL` benefits from using huge memory pages. Huge pages reduce how often virtual memory pages are mapped to physical memory.

MySQL can benefit from using huge memory pages, especially when the InnoDB buffer pool is large. Huge memory pages have a similar performance goal to `64 KB` base pages: they map more memory per translation entry, which can reduce page-table walks and TLB pressure.

The tradeoff is also similar. Huge pages reserve memory in larger chunks, so over-allocating them can reduce the memory available for other uses. Under-allocating them can prevent MySQL from using huge pages at all. The performance impact depends on your workload and system configuration.

To see the current huge memory page configuration, run the following command on the host:

```bash
cat /proc/meminfo | grep ^Huge
grep '^Huge' /proc/meminfo
```

The output should be similar to:
Expand All @@ -63,44 +89,51 @@ Hugepagesize: 2048 kB
Hugetlb: 0 kB
```

Huge pages are not being used if `HugePages_Total` is 0 (this is typically the default).
Huge pages are not being used if `HugePages_Total` is `0` (this is typically the default).

Also note that `Hugepagesize` is 2MiB which is the typical default for huge pages on Linux.
The `Hugepagesize` value depends on the kernel base page size and platform configuration. Use the value reported by `/proc/meminfo` when calculating `vm.nr_hugepages`.

The sysctl parameter that enables huge pages is shown below:

```output
vm.nr_hugepages
```

This parameter sets the number of huge pages you want the kernel to make available to applications.
This parameter sets the number of huge pages you want the kernel to make available to applications.

The total amount of memory that will be used for huge pages will be this number (defaulted to 0) times the `Hugepagesize`.
The total amount of memory used for huge pages is this number, which defaults to 0, multiplied by the `Hugepagesize` value.

As an example, if you want a total of 1GB of huge page space, then you should set `vm.nr_hugepages` to 500 (500x2MB=1GB).
For example, if you want `1 GiB` of huge page space and `Hugepagesize` is `2 MiB`, set `vm.nr_hugepages` to `512`.

```bash
sudo sysctl -w vm.nr_hugepages=500
sudo sysctl -w vm.nr_hugepages=512
```

To make the change permanent:

```bash
sudo sh -c 'echo "vm.nr_hugepages=500" >> /etc/sysctl.conf'
echo "vm.nr_hugepages=512" | sudo tee /etc/sysctl.d/99-mysql-hugepages.conf
sudo sysctl --system
```

### Selecting the number of huge pages to use

You should set `vm.nr_hugepages` to a value that gives a total huge page space equal to or slightly larger than the `MySQL` buffer pool size. Selecting the buffer pool size is discussed in the [Tuning MySQL](/learning-paths/servers-and-cloud-computing/mysql_tune/tuning/) section.
If huge pages improve your workload, set `vm.nr_hugepages` to a value that gives a total huge page space equal to or slightly larger than the InnoDB buffer pool size, which is controlled by `innodb_buffer_pool_size`.

{{% notice Important %}}
After restarting MySQL with `large-pages=ON`, check both `/proc/meminfo` and the MySQL error log. If the huge page pool is too small, or MySQL cannot allocate huge pages for another reason, InnoDB can fall back to traditional memory and write `Warning: Using conventional memory pool.` to the MySQL error log. You might also see an allocation warning similar to `large_page_aligned_alloc mmap(... bytes) failed; errno 12`.
{{% /notice %}}

Selecting the buffer pool size is discussed in the [Tuning MySQL](/learning-paths/servers-and-cloud-computing/mysql_tune/tuning/) section.

Typically, only the number of huge pages needs to be configured. However, for more information on the different parameters that affect the configuration of huge pages, review the [admin-guide for hugetlbpage in the Linux source code](https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/mm/hugetlbpage.rst).

## Compiler Considerations
## Compiler considerations

The easiest way to gain performance is to use the latest version of GCC. Aside from that, the flags `-mcpu` and `-flto` can be used to potentially gain additional performance. Usage of these flags is explained in the [Migrating C/C++ applications](/learning-paths/servers-and-cloud-computing/migration/c/) section of the [Migrating applications to Arm servers](/learning-paths/servers-and-cloud-computing/migration/) learning path.
If you build MySQL from source, the compiler version and optimization flags can affect performance. Use a recent version of GCC, and consider flags such as `-mcpu` and `-flto` for additional optimization. These flags are explained in the [Migrating C/C++ applications](/learning-paths/servers-and-cloud-computing/migration/c/) section of the [Migrating applications to Arm servers](/learning-paths/servers-and-cloud-computing/migration/) Learning Path.

## OpenSSL Considerations
## OpenSSL considerations

MySQL relies on [OpenSSL](https://www.openssl.org/) for cryptographic operations. Thus, the version of OpenSSL used with MySQL (and the GCC version and switches used to compile it) can impact performance. Typically using the Linux distribution default version of OpenSSL is sufficient.
MySQL relies on [OpenSSL](https://www.openssl.org/) for cryptographic operations. The OpenSSL version used with MySQL, and the compiler version and switches used to build it, can affect performance. The default OpenSSL version provided by your Linux distribution is typically sufficient.

However, it is possible to use newer versions of OpenSSL which could yield performance improvements. This is achieved by building and installing OpenSSL before building MySQL.
If you build MySQL from source, you can also build and install a newer version of OpenSSL before building MySQL. This might improve performance for workloads that spend significant time in cryptographic operations.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading