技术分享-MySQL-主机该如何配置-fsaiomaxnr

5次阅读

共计 1017 个字符,预计需要花费 3 分钟才能阅读完成。

作者:洪斌
爱可生南区负责人兼技术服务总监,MySQL  ACE,擅长数据库架构规划、故障诊断、性能优化分析,实践经验丰富,帮助各行业客户解决 MySQL 技术问题,为金融、运营商、互联网等行业客户提供 MySQL 整体解决方案。
本文来源:转载自公众号 - 玩转 MySQL
* 爱可生开源社区出品,原创内容未经授权不得随意使用,转载请联系小编并注明来源。


MySQL 默认是启用 innodb_use_native_aio,使用异步 IO 操作,MySQL 启动时所需 aio slot 若超过系统当前 fs.aio-max-nr 设置,则无法启动报错 InnoDB: io_setup() failed with EAGAIN after 5 attempts.

通常在单机单实例环境下很少会遇到超出 aio-max-nr 的问题,若部署单机多实例,会大概率遇到此问题。我们来分析下该如何配置 fs.aio-max-nr 参数。关于 aio-nr 与 aio-max-nr

aio-nr is the running total of the number of events specified on the
io_setup system call for all currently active aio contexts. If aio-nr
reaches aio-max-nr then io_setup will fail with EAGAIN. Note that
raising aio-max-nr does not result in the pre-allocation or re-sizing
of any kernel data structures.

启动 MySQL 时会分配多少个 event slot?

使用 strace 观测 io_setup 调用情况,

strace -fe trace=io_setup  /path/to/mysqld --defaults-file=/etc/my.cnf --daemonize  2>&1 |grep io_setup

总共:4709 个 =  18 * 256 + 101

其分配 256 event 的也就是 InnoDB IO 线程。

结论

  • 实例申请的 fs.aio-nr = (innodb_read_io_threads  + innodb_write_io_threads  + log thread + insert buffer thread)  * 256  + 101
  • 若单实例部署,fs.aio-max-nr 至少大于单实例 fs.aio-nr
  • 若多实例部署,至少大于 本机实例数 * 每个实例的 fs.aio-nr
正文完
 0