NAS 上的性能非常慢 MySQL

Very Slow MySQL Performance on NAS

刚刚给自己买了一台 Asustor NAS 来处理我的视频、图片、音乐等。 家里有台式机和笔记本电脑,我认为在 NAS 上设置我的数据库是个好主意(它已经预装了 MariaDB)。

设置:RAID 1,从磁盘读取的最大速度约为 110MB/s,通过 1.3 Mbps WiFi 和千兆连接进行连接。使用 BlackMagic Benchmark 获得大约 60MB/s。

查询:

    SELECT items.title, items.discount, items.qtd, items.price,  ((price * qtd) - discount) AS total, DATE_FORMAT(orders.created_at, '%m-%y')
    FROM items
    INNER JOIN orders ON orders.order_id = items.order_id
    ORDER BY created_at;

table orders 大约有 1.8k 行,table items 大约有 4.7k 行。该查询影响 5k 行,需要 4.8 到 7.0 秒才能达到 运行,这对于这样一个简单的查询来说似乎很荒谬。我曾经在我的本地主机中 运行 相同的查询(好吧,它是一个 NVMe SSD,我得到的速度快了很多),以毫秒为单位。 order_id 是一个包含大约 10 个字符的 VARCHAR。

在所有 table 中插入所有数据大约用了 7(上次 9)分钟:

`orders` - 1.7k rows, 11 columns
`items` - 4.8k rows, 12 columns
`customers` - 1.7k rows, 9 columns

我的问题:

  1. 性能真的有那么差吗,还是我在使用 NVMe SSD 后得到了错误的性能基准?
  2. 如果确实很糟糕,我可以做些什么来改进它(仍然在我的 NAS 上托管我的数据库)?
  3. 我对在线托管数据库的性能有何期待?

非常感谢。

**Tables:**
`CREATE TABLE `orders` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `order_id` varchar(15) DEFAULT NULL COMMENT 'VA',
  `created_at` datetime DEFAULT NULL,
  `gateway` varchar(25) DEFAULT NULL,
  `total` decimal(15,0) DEFAULT NULL,
  `subtotal` decimal(15,0) DEFAULT NULL,
  `status` varchar(20) DEFAULT NULL,
  `discounts` decimal(15,0) DEFAULT NULL,
  `total_price` decimal(15,0) DEFAULT NULL,
  `order_number` varchar(15) DEFAULT NULL,
  `processing` varchar(15) DEFAULT NULL,
  `customer_id` varchar(15) DEFAULT NULL,
  `number` varchar(15) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `number` (`number`),
  UNIQUE KEY `order_id` (`order_id`),
  KEY `customer_id` (`customer_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1712 DEFAULT CHARSET=utf8;`
  1. 性能真的有那么差吗,还是我在使用 NVMe SSD 后得到了错误的性能基准?

是的,这是一种糟糕的表现。查询的正确索引将在一定程度上解决查询的性能问题。要让 NAS 使用 innodb_buffer_pool 和可用内存作为磁盘缓存将很困难,因为板载只有 512M。

  1. 如果确实很糟糕,我可以做些什么来改进它(仍然在我的 NAS 上托管我的数据库)?

通过连接和顺序更正表的索引。设计更改以使用整数主键进行连接。作为第一步,如果 order_id 真的不是 utf8 并且只是对该列进行 latin1 更改会使键变小,也可以将其更改为主键。

由于这是查询中的整个两个表数据搜索,如果它可以全部保留在 RAM 中,它只会消除 IO 延迟。

  1. 我对在线托管数据库的性能有何期待?

托管数据库将提供更多 RAM,并且可能速度更快 CPU。

我的NASmysql版本是Mariadb 10.3.29,blow change work for me,你可以试试!

  • /volume1/@appstore/MariaDB10/usr/local/mariadb10/etc/mysql/my.cnf
  • 改变
    #innodb_flush_log_at_trx_commit = 1
    
    innodb_flush_log_at_trx_commit = 0
    
  • 重启MySQL

----或----

  • 登录MySQL
  • SET GLOBAL innodb_flush_log_at_trx_commit=0;
  • 您可以在运行时更改它并检查不同之处!