MySQL 查询卡在队列中成为瓶颈
最近,有时我无法打开我的网站。
我使用 VPS 进行托管。
当我执行 mytop 时,
它向我显示:
User Host/IP DB Time Cmd Query or State
-- ---- ------- -- ---- --- ----------
12512 xxx localhost xxx 39 Query SELECT * FROM user WHERE no = '12341'
12513 xxx localhost xxx 39 Query SELECT name FROM user WHERE no = '2488'
12511 xxx localhost xxx 40 Query UPDATE `user` SET `exp` = exp+6, `vright` = vright+1, `correct` = correct+1 WHERE `name` = 'Amethys'
12465 xxx localhost xxx 48 Query SELECT * FROM user WHERE name = 'pinoysamurai'
12483 xxx localhost xxx 48 Query SELECT * FROM user WHERE name = 'pinoysamurai'
12501 xxx localhost xxx 52 Query UPDATE `user` SET `exp` = exp+7, `vright` = vright+1, `correct` = correct+1 WHERE `name` = 'yuya_sama'
12422 xxx localhost xxx 57 Query SELECT uo.name, ( SELECT COUNT(*) FROM user ui WHERE (ui.kright, ui.no) >= (uo.kright, uo.no) ) AS rank FROM user uo WHERE name = 0
最底层的查询花了 100 多秒才能完成。而还没完成,后面的队列也卡住了。您可以在 mytop 输出中看到它。
这有什么问题吗? 我很郁闷...
我正在使用 itk mpm 这是我的 my.cnf 文件:(我有 512-1GB 的 RAM,
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
old_passwords=1
interactive_timeout=27
wait_timeout=10
connect_timeout=10
skip-locking
skip-innodb
skip-bdb
max_connections=77
table_cache=2M
thread_cache_size=2M
query_cache_type=1
query_cache_limit=1M
query_cache_size=64M
key_buffer_size=64M
read_rnd_buffer_size=2M
read_buffer_size=2M
sort_buffer_size=2M
join_buffer_size=2M
thread_cache_size=128
thread_concurrency=12
thread_stack =256K
tmp_table_size=32M
谢谢,
Recently, sometimes I cannot open my site.
I'm using VPS for hosting.
and when I do mytop
it shows me:
User Host/IP DB Time Cmd Query or State
-- ---- ------- -- ---- --- ----------
12512 xxx localhost xxx 39 Query SELECT * FROM user WHERE no = '12341'
12513 xxx localhost xxx 39 Query SELECT name FROM user WHERE no = '2488'
12511 xxx localhost xxx 40 Query UPDATE `user` SET `exp` = exp+6, `vright` = vright+1, `correct` = correct+1 WHERE `name` = 'Amethys'
12465 xxx localhost xxx 48 Query SELECT * FROM user WHERE name = 'pinoysamurai'
12483 xxx localhost xxx 48 Query SELECT * FROM user WHERE name = 'pinoysamurai'
12501 xxx localhost xxx 52 Query UPDATE `user` SET `exp` = exp+7, `vright` = vright+1, `correct` = correct+1 WHERE `name` = 'yuya_sama'
12422 xxx localhost xxx 57 Query SELECT uo.name, ( SELECT COUNT(*) FROM user ui WHERE (ui.kright, ui.no) >= (uo.kright, uo.no) ) AS rank FROM user uo WHERE name = 0
the most bottom query took more than 100 seconds to complete. and before it is completed, the queue behind it got stuck as well. You can see it on the mytop output.
what is the problem of this?
I am so depressed...
I'm using itk mpm
and here is my my.cnf file: (I have 512-1GB of RAM
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
old_passwords=1
interactive_timeout=27
wait_timeout=10
connect_timeout=10
skip-locking
skip-innodb
skip-bdb
max_connections=77
table_cache=2M
thread_cache_size=2M
query_cache_type=1
query_cache_limit=1M
query_cache_size=64M
key_buffer_size=64M
read_rnd_buffer_size=2M
read_buffer_size=2M
sort_buffer_size=2M
join_buffer_size=2M
thread_cache_size=128
thread_concurrency=12
thread_stack =256K
tmp_table_size=32M
Thank You,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许它有助于在
kright, no
上添加组合索引,以便连接更快?但我不确定 MySQL 是否会遵守这一点。Maybe it helps adding a combined index on
kright, no
so the join is faster? But I am not sure if MySQL would honour that.