[英]AWS RDS performance is very very low
有兩個數據庫,AWS RDS 和 Digitalocean 5 美元 VPS。 我將相同的.sql文件導入到兩個數據庫中,它們之間的性能差異幾乎是66000%
select count(special_cargo_id) from special_cargos;
AWS RDS 運行時間 = 35.681 秒
Mysql 上的 DO 5$ VPS 經過時間 = 0.086 秒
細節:
桌長
1.85GB 行 ~260k
MySQL 版本 8
表引擎 InnoDB
RDS OUTPUT
CREATE TABLE `special_cargos` (
`special_cargo_id` int(11) NOT NULL AUTO_INCREMENT,
`barcode` varchar(20) DEFAULT '',
`salesCode` varchar(15) NOT NULL,
`price` varchar(15) NOT NULL,
`para` varchar(3) DEFAULT NULL,
`postaceki` varchar(25) DEFAULT '',
`iban` varchar(30) DEFAULT NULL,
`send_type` tinyint(1) unsigned NOT NULL,
`customer_id` int(11) NOT NULL,
`address_id` int(11) NOT NULL,
`height` varchar(5) DEFAULT '',
`weight` varchar(5) DEFAULT '',
`width` varchar(5) NOT NULL DEFAULT '',
`desi` varchar(5) DEFAULT '',
`length` varchar(255) DEFAULT '',
`customer_firstname` varchar(32) NOT NULL,
`customer_lastname` varchar(32) NOT NULL,
`customer_company` varchar(40) NOT NULL,
`customer_address` varchar(255) NOT NULL,
`customer_city` int(11) NOT NULL DEFAULT '0',
`customer_city_name` varchar(55) DEFAULT '',
`customer_zone_id` int(11) NOT NULL DEFAULT '0',
`customer_zone_name` varchar(55) DEFAULT '',
`customer_postcode` varchar(10) NOT NULL,
`firstname` varchar(32) NOT NULL,
`lastname` varchar(32) NOT NULL,
`company` varchar(40) DEFAULT '',
`address` varchar(255) NOT NULL,
`country_id` int(5) DEFAULT NULL,
`country_name` varchar(64) DEFAULT NULL,
`city_id` int(11) NOT NULL,
`city_name` varchar(55) NOT NULL,
`district_id` int(11) NOT NULL,
`district_name` varchar(64) NOT NULL,
`email` varchar(96) NOT NULL,
`phone` varchar(55) NOT NULL,
`postcode` varchar(10) DEFAULT '',
`product` text,
`sendText` text,
`returnText` text,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL,
`cargo_firm` tinyint(1) NOT NULL DEFAULT '0',
`ups_barcode_link` text,
`status` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`special_cargo_id`),
KEY `customer_id` (`customer_id`),
KEY `special_cargo_id` (`special_cargo_id`),
KEY `barcode` (`barcode`),
KEY `salesCode` (`salesCode`),
KEY `price` (`price`),
KEY `postaceki` (`postaceki`),
KEY `customer_firstname` (`customer_firstname`),
KEY `customer_lastname` (`customer_lastname`),
KEY `firstname` (`firstname`),
KEY `lastname` (`lastname`),
KEY `customer_company` (`customer_company`),
KEY `customer_address` (`customer_address`),
KEY `customer_city_name` (`customer_city_name`),
KEY `customer_zone_name` (`customer_zone_name`),
KEY `company` (`company`),
KEY `address` (`address`),
KEY `city_name` (`city_name`),
KEY `district_name` (`district_name`),
KEY `email` (`email`),
KEY `phone` (`phone`),
KEY `postcode` (`postcode`),
KEY `index_special_cargos` (`special_cargo_id`)
) ENGINE=InnoDB AUTO_INCREMENT=497539 DEFAULT CHARSET=utf8
+-----------------------+----------+
|Variable_name |Value |
+-----------------------+----------+
|innodb_buffer_pool_size|1073741824|
+-----------------------+----------+
+--+-----------+--------------+----------+-----+-------------+-----------+-------+----+------+--------+-----------+
|id|select_type|table |partitions|type |possible_keys|key |key_len|ref |rows |filtered|Extra |
+--+-----------+--------------+----------+-----+-------------+-----------+-------+----+------+--------+-----------+
|1 |SIMPLE |special_cargos|NULL |index|NULL |customer_id|4 |NULL|146973|100 |Using index|
+--+-----------+--------------+----------+-----+-------------+-----------+-------+----+------+--------+-----------+
MYSQL OUTPUT 上的簡單 VPS
CREATE TABLE `special_cargos` (
`special_cargo_id` int(11) NOT NULL AUTO_INCREMENT,
`barcode` varchar(20) NOT NULL,
`salesCode` varchar(15) NOT NULL,
`price` varchar(15) NOT NULL,
`para` varchar(3) DEFAULT NULL,
`postaceki` varchar(25) NOT NULL,
`iban` varchar(30) DEFAULT NULL,
`send_type` tinyint(1) unsigned NOT NULL,
`customer_id` int(11) NOT NULL,
`address_id` int(11) NOT NULL,
`height` varchar(5) NOT NULL,
`weight` varchar(5) NOT NULL,
`width` varchar(5) NOT NULL,
`desi` varchar(5) NOT NULL,
`length` varchar(255) NOT NULL,
`customer_firstname` varchar(32) NOT NULL,
`customer_lastname` varchar(32) NOT NULL,
`customer_company` varchar(40) NOT NULL,
`customer_address` varchar(255) NOT NULL,
`customer_city` int(11) NOT NULL,
`customer_city_name` varchar(55) NOT NULL,
`customer_zone_id` int(11) NOT NULL,
`customer_zone_name` varchar(55) NOT NULL,
`customer_postcode` varchar(10) NOT NULL,
`firstname` varchar(32) NOT NULL,
`lastname` varchar(32) NOT NULL,
`company` varchar(40) NOT NULL,
`address` varchar(255) NOT NULL,
`country_id` int(5) DEFAULT NULL,
`country_name` varchar(64) DEFAULT NULL,
`city_id` int(11) NOT NULL,
`city_name` varchar(55) NOT NULL,
`district_id` int(11) NOT NULL,
`district_name` varchar(64) NOT NULL,
`email` varchar(96) NOT NULL,
`phone` varchar(55) NOT NULL,
`postcode` varchar(10) NOT NULL,
`product` text,
`sendText` text NOT NULL,
`returnText` text NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
`deleted_at` datetime DEFAULT NULL,
`cargo_firm` int(1) NOT NULL DEFAULT '0',
`ups_barcode_link` text,
`status` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`special_cargo_id`),
KEY `customer_id` (`customer_id`),
KEY `special_cargo_id` (`special_cargo_id`),
KEY `barcode` (`barcode`),
KEY `salesCode` (`salesCode`),
KEY `price` (`price`),
KEY `postaceki` (`postaceki`),
KEY `customer_firstname` (`customer_firstname`),
KEY `customer_lastname` (`customer_lastname`),
KEY `firstname` (`firstname`),
KEY `lastname` (`lastname`),
KEY `customer_company` (`customer_company`),
KEY `customer_address` (`customer_address`),
KEY `customer_city_name` (`customer_city_name`),
KEY `customer_zone_name` (`customer_zone_name`),
KEY `company` (`company`),
KEY `address` (`address`),
KEY `city_name` (`city_name`),
KEY `district_name` (`district_name`),
KEY `email` (`email`),
KEY `phone` (`phone`),
KEY `postcode` (`postcode`)
) ENGINE=InnoDB AUTO_INCREMENT=497037 DEFAULT CHARSET=utf8
+-----------------------+---------+
|Variable_name |Value |
+-----------------------+---------+
|innodb_buffer_pool_size|134217728|
+-----------------------+---------+
+--+-----------+--------------+----------+-----+-------------+-----------+-------+----+------+--------+-----------+
|id|select_type|table |partitions|type |possible_keys|key |key_len|ref |rows |filtered|Extra |
+--+-----------+--------------+----------+-----+-------------+-----------+-------+----+------+--------+-----------+
|1 |SIMPLE |special_cargos|NULL |index|NULL |customer_id|4 |NULL|133967|100 |Using index|
+--+-----------+--------------+----------+-----+-------------+-----------+-------+----+------+--------+-----------+
能否提供output的:
SHOW CREATE TABLE special_cargos;
SHOW GLOBAL VARIABLES LIKE 'innodb_buffer_pool_size';
EXPLAIN select count(special_cargo_id) from special_cargos;
在 RDS 和您的非 RDS 實例上?
假設special_cargo_id
是主鍵,它適合 RAM,並且 innodb_buffer_pool_size 配置合理(在具有 2GB RAM 的服務器上,1GB 是一個合理的數量,盡管 RDS 應該預先配置為一個合理的值),它應該在兩個節點上類似地運行。
我想到了兩種可能的解釋:
1) 在 RDS 上,您沒有將special_cargo_id
定義為 PK。
2)RDS由於某種原因選擇不使用索引(比較EXPLAIN
output將確認是否發生這種情況)。
編輯:
實際上 - 你確定你的 5 美元 VPS 正在使用 InnoDB 嗎? 如果您在 0.08 秒內得到答案,那聽起來它實際上並沒有掃描索引。 您很有可能在 VPS 上使用 MyISAM,它會在每次寫入后更新表 header 中的行數,特別是使SELECT COUNT(*) FROM table_name;
查詢立即返回 - 就像您觀察到的那樣。
編輯2:
哇 - 所以 VPS 只配置了 128MB 的 innodb_buffer_pool_size 並且它仍然比配置了 1GB 的 innodb_buffer_pool_size 的 RDS 更快,而且兩者的執行計划是一樣的?
好的,試試這個:
select count(1) from special_cargos FORCE INDEX (PRIMARY);
這里的問題有兩個方面。 IMO 的一個和更重要的方面是查詢 - 這很糟糕。 它進行全索引掃描(是的,PRIMARY 也是一個索引)。 它的性能與更好的線性比例呈線性關系,並且需要 B+tree 的 nlog(n)。
方面二。 為什么執行時間不同。 它可能與緩存有關(在 DO 的情況下,查詢是從緩沖池中提供的,而在 RDS 中來自磁盤(=EBS))。 它可以與 MySQL 優化器相關(DO 和 RDS 可以選擇不同的索引來服務於查詢 PRIMARY 與較小的二級索引)。 但是由於查詢本身的問題,所有這些都無關緊要。
當您只有 2GB 的 RAM 時,buffer_pool 的 1GB 非常危險。 可能那個系統正在瘋狂地交換。
把它降低到200M,看看它跑得有多快。
看看他們是否有某種方法來監控交換使用情況。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.