在过去的几天里,我们遇到了 MySQL(旧版本 5.1.69)的一些奇怪的性能问题。 慢日志显示如下内容:
# User@Host: jboss[jboss] @ localhost [127.0.0.1]
# Query_time: 46.595796 Lock_time: 0.000022 Rows_sent: 0 Rows_examined: 0
SET timestamp=1496127084;
insert into ACTIVE_RENT (LINE_ID, CHARGED_UP_TO, EVENT_ID, NUMBER, RENT_START, TYPE) values (149914, '2017-05-02 00:00:00', 625751, 'ABCD1234567', '2013-08-02 00:00:00', 'DETENTION');
# User@Host: jboss[jboss] @ localhost [127.0.0.1]
# Query_time: 19.401896 Lock_time: 0.000041 Rows_sent: 0 Rows_examined: 0
SET timestamp=1496127084;
delete from ACTIVE_RENT where ACTIVE_RENT_ID=463965;
在删除或更新时没有指定级联,它只有一个到另一个表的外键,并且该表没有触发器。 table 真的很基本。而且只有大约 14k 行。 通常这些插入或删除非常快,但最近几天在高峰期它们可能非常非常慢。
我们已将 innodb_buffer_size 增加到 20G,但变化不大(关于这个问题,其他东西更快)。目前数据库大小约为 40GB。 下面是 my.conf。知道瓶颈从何而来以及如何应对吗?我们计划将 MySQL 升级到 5.5,但这几周内不会发生。
[client]
default-character-set=utf8
socket=/home/mysql-data/mysql/mysql.sock
[mysql]
default-character-set=utf8
max_allowed_packet=32M
[mysqld]
# these are the install settings
local-infile=0
open_files_limit=8192
query_cache_size = 256M
query_cache_type = 1
query_cache_limit = 6M
query_prealloc_size = 16384
query_alloc_block_size = 2048
tmp_table_size = 128M
max_heap_table_size = 256M
table_cache = 1024
thread_cache_size = 512
key_buffer = 256M
join_buffer_size = 8M
read_buffer_size = 8M
sort_buffer_size = 8M
innodb_lock_wait_timeout = 120
binlog_format=row
max_allowed_packet=32M
log-bin=mysql-bin
server-id=1
#Allow group_concat to return longer data types
group_concat_max_len=16384
default-character-set = utf8
skip-character-set-client-handshake
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
innodb_buffer_pool_size = 20GB
最佳答案
query_cache_size = 256M
-- 太大了。每当发生写入时,必须清除该表的 QC 中的所有 条目。这样的时间大致与大小成正比。降低到 50M
。
你的表是 InnoDB 吗?如果服务器有 64GB 并且主要用于 MySQL,则将 buffer_pool 设置为其 70%。
ACTIVE_RENT_ID
是 PRIMARY KEY
吗?
InnoDB 中的一行 INSERT
不会花费 46 秒,除非正在进行长时间运行的 ALTER
。环视四周;还涉及其他事情。或者可能是一个最终在 50 秒时超时的长时间运行的事务?您使用的是 autocommit=0
吗? (我希望不会。)你在使用 BEGIN...COMMIT
吗?
ACTIVE_RENT
表有多大?
关于mysql - 在 MySQL 的重负载下插入/删除行需要几秒钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44281740/