[英]Laravel MySql Connection problem too many connections
Neither 54K connections since startup, nor a max of 32 connections simultaneously doing something, is "too many".自启动以来的 54K 连接,或同时做某事的最多 32 个连接,都不是“太多”。
What is the real problem?真正的问题是什么? Sluggishness?
迟钝? Find the slowest queries and let's work on speeding them up.
找到最慢的查询,让我们努力加快它们的速度。 Run
SHOW FULL PROCESSLIST
to see if any queries have been running for more than a few seconds;运行
SHOW FULL PROCESSLIST
以查看是否有任何查询已运行超过几秒钟; they are a prime candidate for optimizing.它们是优化的主要候选者。 Or use the slowlog.
或者使用slowlog。
Connection is just a "count" of attempted connections.连接只是尝试连接的“计数”。 It does not relate to active connections nor max_used_connections.
它与活动连接和 max_used_connections 无关。
Run the following commands simultaneously:同时运行以下命令:
SHOW VARIABLES LIKE 'max_connections'
SET GLOBAL max_connections = 1000000;
Connection is just a "count" of attempted connections.连接只是尝试连接的“计数”。 It does not relate to active connections nor
max_used_connections
.它与活动连接或
max_used_connections
无关。
See MySQL show status - active or total connections?请参阅MySQL 显示状态 - 活动连接数还是总连接数?
If you really are having many current open connections, you should look into what these connections are.如果您确实有许多当前打开的连接,您应该查看这些连接是什么。 You might have a sub-optimal query in your code or a bot is spamming an open endpoint.
您的代码中可能存在次优查询,或者机器人正在向开放端点发送垃圾邮件。
You can see process list by running the query您可以通过运行查询来查看进程列表
show processlist;
You can then kill connections for the short term solution or take care of whatever problem was causing the connections in the first place.然后,您可以为短期解决方案终止连接,或者首先处理导致连接的任何问题。
If you really do need that many connections (doubt it), you should look into scaling your database instance, eg by adding read replicas.如果您确实需要那么多连接(对此表示怀疑),您应该考虑扩展您的数据库实例,例如通过添加只读副本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.