【问题标题】:Mysql start dropping connection when peak hoursMysql在高峰时段开始断开连接
【发布时间】:2015-10-25 02:47:15
【问题描述】:

我们的数据库在高峰时段开始断开连接。大约有 3% 的连接断开,mysql 返回消息 "mysqli::mysqli(): (HY000/2003): Can't connect to MySQL server on '10.88.***' (99)" 。我已经调整了几个 mysql 和内核参数,但没有帮助: -/etc/sysctl.conf:

net.ipv4.tcp_max_tw_buckets = 524288 net.core.somaxconn = 2048 net.ipv4.ip_local_port_range = 1024 65000 net.ipv4.tcp_max_syn_backlog=30000 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_synack_retries = 2

-/etc/my.cnf:

open_files_limit = 65536 最大连接数=3600
连接超时=60
wait_timeout=2400
back_log=4096

-/etc/security/limits.conf

mysql 软文件 65536 mysql 硬文件 65536 mysql 软 nproc 65536 mysql 硬 nproc 65536

我们的数据库通过一台数据库机器每秒处理 >40000 个查询和 >8000 个连接,没有分片和连接池。 我错过了什么? 有谁知道可能导致这个瓶颈的原因是什么?谢谢。

这是my.cnf中的内容:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

skip_name_resolve = off
open_files_limit = 65536

max_allowed_packet = 1073741824
expire_logs_days = 2

binlog_format = row
innodb_file_per_table = 1
innodb_flush_method=O_DIRECT

innodb_buffer_pool_instances = 16
innodb_buffer_pool_size = 43G
innodb_thread_concurrency = 0

log-bin=mysql-bin
server-id=1
innodb_flush_log_at_trx_commit=1
slave-skip-errors = 1062,1032

max_connections=3600
connect_timeout=60
wait_timeout=2400

back_log=4096

thread_cache_size=48

symbolic-links=0

user=mysql

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
!includedir /etc/my.cnf.d

【问题讨论】:

  • 要问的一个明显问题是,当下降开始发生时,您打开了多少个会话?
  • 3600 个连接?您的服务器的 RAM 是多少...如果您共享 mysql 配置文件的所有参数,那么可能会得到一些线索...
  • 我们在数据库服务器上有 64GB RAM。我不确定问题发生时有多少会话
  • @ZafarMalik 没什么大不了的。在我们的时代,RAM 已经足够便宜了
  • 您不应该增加 max_connections 因为它会消耗每个连接的服务器资源,但是您必须检查服务器上的连接是否处于睡眠模式,并且您的应用程序正在正确使用连接...等待超时太高了,如果没有具体原因,你应该把它降低到120或240。

标签: mysql limits sysctl


【解决方案1】:

所以.. 尝试将您的 max_connections 增加到 > 8000 ?

在我的.cnf 中

max_connections=9000

【讨论】:

  • 感谢您的回复。一个问题,我们在非高峰时间有> 4000个连接,这已经超过了我设置的最大连接数,但是为什么mysql没有抛出错误?
  • 我相信你没有使用持久连接? php?
  • 我们正在使用 php mysqli 但没有使用持久连接
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-19
  • 1970-01-01
  • 2013-08-11
  • 2017-08-27
相关资源
最近更新 更多