关于mysql-配置:技术分享-MySQL-复制重试参数配置

13次阅读

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

作者:code0

爱可生 DMP 团队一位不出名的 coder,充斥神秘的气味 …

本文起源:原创投稿

* 爱可生开源社区出品,原创内容未经受权不得随便应用,转载请分割小编并注明起源。


一、起因

非 root 用户运行 MySQL,当 MySQL 配置比拟高时,MySQL 运行中失效的参数值与配置的值不一样,所以具体分析一下 MySQL 是怎么调整这些参数值的。

所以这篇文章的目标是为了阐明在系统资源不够的状况下,MySQL 是怎么调整者三个参数的。

二、阐明

此文波及到 3 个参数:

  • open_files_limit
  • max_connections
  • table_open_cache

这 3 个参数与零碎相干的资源是最多能同时关上的文件(ulimit -n 查看)理论即文件描述符(fd)。

零碎参数与文件描述符的关系 – max_connection & fd : 每一个 MySQL connection 都须要一个文件描述符 – table_open_cache & fd 关上一张表至多须要一个文件描述符,如关上 MyISAM 须要两个 fd

三、MySQL 调整参数的形式

  1. 依据配置(配置的 3 个参数值或默认值)计算 request_open_files(须要的文件描述符)
  2. 获取无效的零碎的限度值 effective_open_files
  3. 依据 effective_open_files 调整 request_open_files
  4. 依据调整后的 request_open_files,计算理论失效的参数值(show variables 查看到的 3 个参数值)

1、计算 request_open_files

request_open_files 有三个计算公式:

# 最大连接数 + 同时关上的表的最大数量 + 其余(各种日志等等)limit_1= max_connections + table_cache_size * 2 + 10;

# 假如均匀每个连贯关上的表的数量(2-4)# 源码中是这么写的:# We are trying to allocate no less than  
# max_connections*5 file handles 
limit_2= max_connections * 5;

# MySQL 默认的最低值是 5000
limit_3= open_files_limit ? open_files_limit : 5000;

# 所以 open_files_limit 期待的最低 
request_open_files= max(limit_1, limit_2,limit_3);

2、计算 effective_open_files

MySQL 的思路:在无限值的的范畴内 MySQL 尽量将 effective_open_files 的值设大

3、修改 request_open_files

requested_open_files= min(effective_open_files, request_open_files);

从新计算参数值

1、修改 open_files_limit

open_files_limit = effective_open_files

2、修改 max_connections

max_connections 依据 request_open_files 来做修改。

limit = requested_open_files - 10 - TABLE_OPEN_CACHE_MIN * 2;
  • 如果配置的 max_connections 值大于 limit,则将 max_connections 的值修改为 limit
  • 其余状况下 max_connections 保留配置值

3、修改 table_cache_size

table_cache_size 会依据 request_open_files 来做修改。

# MySQL table_cache_size 最小值,400
limit1 = TABLE_OPEN_CACHE_MIN 

# 依据 requested_open_files 计算
limit2 = (requested_open_files - 10 - max_connections) / 2
limit = max(limit1,limt2);
  • 如果配置的 table_cache_size 值大于 limit,则将 table_cache_size 的值修改为 limit
  • 其余状况下 table_cache_size 保留配置值

四、举例

以下用例全副在非 root 用户下运行

- 系统资源不够且无奈调整
# 参数设置
mysql max_connections = 1000 //ulimit -n 1024

# 失效的值
open_files_limit = 1024 max_connections = 1024 - 10 - 800 = 214 table_open_cache = (1024 - 10 - 214) / 2 = 400

---
- 系统资源不够能够调整
# 参数设置
mysql max_connections = 1000 //ulimit -S -n 1000 //ulimit -H -n 65535

# 失效的值
open_files_limit = 65535 max_connections = 1000 table_open_cache = (1024 - 10 - 214) / 2 = 400

---
- mysql 批改 open_files_limit
# 参数设置
//mysql max_connections = 1000 max_connections = 1000 //ulimit -n 65535

# 失效的值
open_files_limit = 65535 max_connections = 1000 table_open_cache = 2000 ```

五、其它

淘宝数据库内核月报中说道的相干内容:《MySQL·答疑解惑·open file limits》这篇次要讲的是,MySQL 在执行哪些操作时会执行关上文件的操作。

《MySQL·答疑解惑·open file limits》:http://mysql.taobao.org//mont…

正文完
 0