简体   繁体   English

mysql(aws 强制更新)从 5.6 到 5.7 导致查询变慢

[英]mysql (aws forced update) from 5.6 to 5.7 causing slower queries

Premise: I have a db (was running well on mysql 5.6) that got upgraded to 5.7 and is causing performance issues.前提:我有一个数据库(在 mysql 5.6 上运行良好)升级到 5.7 并导致性能问题。 The front end gets aroun 20k requests per minute (consistent).前端每分钟收到大约 20k 个请求(一致)。 Each request generates an IODKU into one of the tables.每个请求都会在其中一个表中生成一个 IODKU。

RDS hardware: db.m5.large RDS 硬件:db.m5.large

On 5.6, CPU: 30%, Avg DB Connections: 20 On 5.7, CPU: 75%, Avg DB Connections: 255.在 5.6 上,CPU:30%,平均数据库连接数:20 在 5.7 上,CPU:75%,平均数据库连接数:255。

For the following query:对于以下查询:

show global status like 'threads%';显示全局状态,如“threads%”;

I keep refreshing, and For the most part I can see我一直在刷新,大部分时间我都能看到

Threads_cached 0 Threads_cached 0
Threads_connected 257 Threads_created 203899 Threads_connected 257 Threads_created 203899
Threads_running 255 Threads_running 255

But In between, for a short bit, it will also go to但在这之间,有一小段时间,它也会 go 到

Threads_cached 30 Threads_cached 30
Threads_connected 3 Threads_connected 3
Threads_created 206709线程创建 206709
Threads_running 1 Threads_running 1

I have spend around 3 days, reading, and changing different parameter group values.我花了大约 3 天的时间阅读和更改不同的参数组值。 See below my changes, links I based my actions on, results, etc.在下面查看我的更改、我基于我的操作的链接、结果等。

============= =============

optimizer_switch优化器开关

https://dba.stackexchange.com/questions/193262/after-mysql-upgrade-to-5-7-optimizer-not-using-index-on-large-in-clause https://dba.stackexchange.com/questions/193262/after-mysql-upgrade-to-5-7-optimizer-not-using-index-on-large-in-clause

https://support-acquia.force.com/s/article/360061350614-Resolving-unexpected-slow-database-queries-after-MySQL-5-7-upgrade https://support-acquia.force.com/s/article/360061350614-Resolving-unexpected-slow-database-queries-after-MySQL-5-7-upgrade

changes mentioned in this link did not make much difference.此链接中提到的更改没有太大区别。

========= =========

innodb_flush_log_at_trx_commit innodb_flush_log_at_trx_commit

https://dba.stackexchange.com/questions/174527/poor-mysql-5-7-performance-compared-to-mysql-5-6 https://dba.stackexchange.com/questions/174527/poor-mysql-5-7-performance-compared-to-mysql-5-6

originally set to 1. Changing to 2 did not make any difference最初设置为 1。更改为 2 没有任何区别

======= =======

query_cache_size查询缓存大小

original: 1048576. Changing to 67108864 Did not make any difference.原来:1048576,改成67108864也没啥区别。

======= =======

query_cache_type查询缓存类型

shows as OFF.显示为 OFF。 Changing to 1.Seemed to worsen.变为 1。似乎恶化了。 So put it back to OFF.所以把它放回OFF。 Had to restart.不得不重新启动。

======== ========

innodb_io_capacity default: 200. Changing to 400 and even 800. Did not make any difference. innodb_io_capacity 默认值:200。更改为 400 甚至 800。没有任何区别。

====== innodb_flush_neighbors default: 1. changing to 0. Did not make any difference. ====== innodb_flush_neighbors 默认值:1。更改为 0。没有任何区别。

====== ======

thread_cache_size线程缓存大小

https://aws.amazon.com/blogs/database/best-practices-for-configuring-parameters-for-amazon-rds-for-mysql-part-1-parameters-related-to-performance/ default: 14. Changing to 32. Did not make any difference. https://aws.amazon.com/blogs/database/best-practices-for-configuring-parameters-for-amazon-rds-for-mysql-part-1-parameters-related-to-performance/默认值:14。更改为 32。没有任何区别。

======= =======

tmp_table_size default: 16777216. Changing to 33554432. Did not make any difference. tmp_table_size 默认值:16777216。更改为 33554432。没有任何区别。

====== innodb_read_io_threads, innodb_write_io_threads default: 4. changing to 8. Needs reboot. ====== innodb_read_io_threads,innodb_write_io_threads 默认值:4。更改为 8。需要重启。 Made things worse.让事情变得更糟。 Putting back to 4.回到4。

=========== Pretty much all links from google search on this regard are now "pink" on my browser (meaning already visited), and I am kinda at a loss. =========== 几乎所有来自谷歌搜索的关于这方面的链接现在在我的浏览器上都是“粉红色”(意味着已经访问过),我有点不知所措。 Any help is appreciated.任何帮助表示赞赏。

UPDATE#1:更新#1:

Enabled Slow_query_log.启用 Slow_query_log。 Waited for a while, and this is what is in the log.等了一会儿,这是日志中的内容。

/rdsdbbin/mysql/bin/mysqld, Version: 5.7.38-log (Source distribution). /rdsdbbin/mysql/bin/mysqld,版本:5.7.38-log(源分发)。 started with: Tcp port: 3306 Unix socket: /tmp/mysql.sock Time Id Command Argument /rdsdbbin/mysql/bin/mysqld, Version: 5.7.38-log (Source distribution).开始于:Tcp 端口:3306 Unix 套接字:/tmp/mysql.sock 时间 ID 命令参数 /rdsdbbin/mysql/bin/mysqld,版本:5.7.38-log(源分发)。 started with: Tcp port: 3306 Unix socket: /tmp/mysql.sock Time Id Command Argument ----------------------- END OF LOG ----------------------开始于:Tcp 端口:3306 Unix 套接字:/tmp/mysql.sock 时间 ID 命令参数 ---------------------- 日志结束 ---- ------------------

UPDATE 2更新 2

For each Request The following happens.对于每个请求,都会发生以下情况。

Query#1查询#1

SELECT m.id AS uID,m.tkn,m.email FROM memberTable m WHERE m.tkn='$subTkn' SELECT m.id AS uID,m.tkn,m.email 来自 memberTable m WHERE m.tkn='$subTkn'

For memberTable, id (primary) and tkn(indexed) have indexes.对于 memberTable,id (primary) 和 tkn(indexed) 都有索引。

Then after some processing, the following Query#2 happens.然后经过一些处理,发生以下查询#2。

INSERT into dataTable (memberID,status,packetTime ) VALUES ('76418','1','2022-12-25 22:10:33') ON DUPLICATE KEY UPDATE memberID='76418',status='1',packetTime='2022-12-25 22:10:33' INSERT into dataTable (memberID,status,packetTime) VALUES ('76418','1','2022-12-25 22:10:33') ON DUPLICATE KEY UPDATE memberID='76418',status='1',packetTime ='2022-12-25 22:10:33'

For dataTable, memberID(primary) is indexed.对于dataTable,memberID(primary) 是有索引的。

UPDATE#3更新#3

EXPLAIN SELECT m.id AS uID,m.tkn,m.email FROM memberTable m WHERE m.tkn='$subTkn'

id      select_type table   partitions  type    possible_keys   key     key_len ref     rows    filtered    Extra
76418   SIMPLE      m       NULL        const   tkn             tkn     42      const   1       100.00      NULL    



EXPLAIN INSERT into dataTable (memberID,status,packetTime ) VALUES ('76418','1','2022-12-25 22:10:33') ON DUPLICATE KEY UPDATE memberID='76418',status='1',packetTime='2022-12-25 22:10:33'

id  select_type table       partitions  type    possible_keys   key     key_len ref     rows    filtered    Extra
1   INSERT  dataTable   NULL        ALL     NULL            NULL    NULL    NULL    NULL    NULL        NULL

UPDATE 4更新 4

show variables like "transact%";显示变量,如“transact%”;

transaction_alloc_block_size    8192    
transaction_allow_batching  OFF 
transaction_isolation   REPEATABLE-READ 
transaction_prealloc_size   4096    
transaction_read_only   OFF 
transaction_write_set_extraction    OFF 

optimizer_switch优化器开关

index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=on,block_nested_loop=on,batched_key_access=off,materialization=on,semijoin=on,loosescan=on,firstmatch=on,duplicateweedout=off,subquery_materialization_cost_based=on,use_index_extensions=on,condition_fanout_filter=on,derived_merge=off,prefer_ordering_index=on

For those who reach this part of the island, here is how my issue was resolved.对于那些到达岛上这一部分的人,我的问题是这样解决的。 I had a continuous barrage of queries that were IODKU.我连续不断地收到 IODKU 的查询。 Apparently, this is causing row locks in innoDB.显然,这导致了 innoDB 中的行锁。 Had to change the code, and query to UPDATE (unless insert is required), and all seems back to normal.不得不更改代码,并查询更新(除非需要插入),一切似乎恢复正常。

Thanks, Bill, DimitryC for asking insightful questions.感谢 Bill、DimitryC 提出了富有洞察力的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 CloudFormation 将 Aurora 无服务器从 MySQL 5.6 更新到 5.7 而不会丢失 - Updating an Aurora serverless from MySQL 5.6 to 5.7 with CloudFormation without loss CSV 使用 DataGrip 删除连接导入 AWS Aurora MySQL(5.6) - CSV import to AWS Aurora MySQL(5.6) with DataGrip dropping connection 从 AWS Lambda 创建复杂的参数驱动查询? - Create complex argument-driven queries from AWS Lambda? AWS Lambda - 访问公共 AWS RDS MySQL - AWS Lambda - Access Public AWS RDS MySQL 使用 bq 命令在 GCP Bigquery 和 Cloud SQL (Mysql 5.7) 之间创建连接时出现错误 - Error emitted when creating a connection between GCP Bigquery and Cloud SQL (Mysql 5.7) using bq command nodemailer 在 Aws Ec2 上的生产环境中导致错误 - nodemailer is causing an error in production environment on Aws Ec2 AWS PowerShell 更新 CloudFront 分布 - AWS PowerShell update CloudFront distribution AWS 根据条件更新所有资源标签 - AWS Update all resource Tags based on a condition 使用 CLI 克隆 AWS Aurora MySQL 数据库 - AWS Aurora MySQL Database cloning using CLI 通过键从数据存储中加载实体与查询实体相比是否更慢? - Is it slower to load an entity from the Datastore by key versus querying for it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM