Recommended LXD mariadb container configuration?

Is there a recommended way to configure a mariadb container on LXD, in order to avoid disk i/o bottlenecks? What do you do?

I have a host with a mariadb zfs container which runs various mariadb databases that other containers are using (web applications). I have two disks with mirrored zpool configuration. Lately, the load on the host goes sky high (~ 30 or more) with high wait times. iostats shows 100% disk utilization and iotop shows mysqld is responsible. I read about tuning mariadb on ZFS, and I already setup these mariadb configuration parameters:
skip-innodb_doublewrite
innodb_use_native_aio=0
innodb_use_atomic_writes=0

These seem to help, but I occasionally still get 100% disk usage and high uptime load times.

I also read that it’s best to use separate zfs datasets for the Innodb table data, with recordsize=16K and for the Innodb log files, with recordsize=128K. How would I set these record sizes with LXD? Is it worth it to attach and configure two additional zfs devices to the container (for data and logfiles) with these recordsizes? Could I just set recordsize=16K for the whole container?

Should I move the mariadb container to an ext4 filesystem (with dir LXD storage)? If I did that, I would lose snapshots.

This is how I ended up setting a mariadb container, for use by other containers:
Create two zfs filesystems on the host, with record sizes 16K and 128K, as recommended.
Assuming that these two filesystems are z/mysql/data and z/mysql/log, I created a mariadb profile:

config:
  raw.idmap: |
    uid 111 111
    gid 115 115
description: ""
devices:
  data:
    path: /var/share/mysql/data
    source: /z/mysql/data
    type: disk
  log:
    path: /var/share/mysql/log
    source: /z/mysql/log
    type: disk
name: mariadb
used_by: []

The uid/gid is the mysql uid/gid in a Ubuntu 18.04 container with mariadb installed.

  • Attach this profile to the mariadb container.
    Prepare the mariadb container:

  • service mysql stop

  • verify that the owner:group of /var/share/mysql/data and /var/share/mysql/log are mysql:mysql

  • rsync -av /var/lib/mysql/ /var/share/mysql/data/

  • mv /var/share/mysql/data/ib_logfile* /var/share/mysql/log/

  • Append this to /etc/mysql/my.cnf:

    [mysqld]
    skip-innodb_doublewrite
    innodb_use_native_aio=0
    innodb_use_atomic_writes=0

    datadir = /var/share/mysql/data
    innodb_log_group_home_dir = /var/share/mysql/log
    bind-address = 0.0.0.0

  • service mysql start

  • Verify that the correct filesystems are used by creating a database and checking that it is created in /var/share/mysql/data/

For snapshots, use zfs snapshots of the two filesystems (which can be done recursively on their parent filesystem). To make sure the snapshots have consistent data, use something like this:
echo "flush tables with read lock;" | ssh mariadb.lxd sudo mysql | sudo zfs snapshot -r z/mysql@{name}

I suspect the issue is due to MariaDB tuning (or lack thereof). Suggest you download and run the MySQL tuner perl script and make sure the DB is properly tuned. https://github.com/major/MySQLTuner-perl