TDengine too many open files

发布于:2024-04-14 ⋅ 阅读:(143) ⋅ 点赞:(0)

too many open files 是比较常见的报错,尤其使用TDengine 3.0 集群时,大概率会遇到。这个报错很简单,但要想顺利解决,却涉及到很多知识点。

知识点:fs.nr_open

官方说明:This denotes the maximum number of file-handles a process can allocate. Default value is 1024*1024 (1048576) which should be enough for most machines. Actual limit depends on RLIMIT_NOFILE resource limit.

单个进程能够打开的最大句柄数量,大部分同学看到too many open files 时想到的参数。这个参数时操作系统全局变量,天花板级的参数,决定了进程能够打开最大句柄数量。可动态修改,最大值:2147483584(x64环境)

sysctl -w fs.nr_open=2147483584

知识点:file-max & fs.file-nr

官方说明: The value in file-max denotes the maximum number of file- handles that the Linux kernel will allocate. When you get lots of error messages about running out of file handles, you might want to increase this limit.

Historically,the kernel was able to allocate file handles dynamically,
but not to free them again. The three values in file-nr denote the
number of allocated file handles, the number of allocated but unused
file handles, and the maximum number of file handles. Linux 2.6 and
later always reports 0 as the number of free file handles – this is
not an error, it just means that the number of allocated file handles
exactly matches the number of used file handles.

我们可用通过查询fs.file-nr,来获得当前系统已打开的句柄数量和支持的最大数量。当我们修改fs.nr_open 时会发现 fs.file-nr中的最大值并没有变化,因为最大值是有 fs.file-max 控制的。如果我们单独修改 fs.nr_open 并不能获得想要的效果。
在这里插入图片描述
在这里插入图片描述
对于fs.file-max 的最大值不同的操作系统限制也不同。

操作系统版本 file-max最大值
RHEL4/5 2147483647
RHEL6 18446744073709551615
RHEL7.7- 18446744073709551615
RHEL7.8+ 9223372036854775807
RHEL8 9223372036854775807
RHEL9 9223372036854775807

知识点:limits.conf

通过limits.conf 可设置用户初始化参数

root soft nproc  65536
root soft nofile 65536
root soft stack  65536
root hard nproc  65536
root hard nofile 65536
root hard stack  65536

注意:RHEL7/CentOS7 以后的系统limits.conf文件只影响通过pam登录的用户。

知识点:LimitNOFILE

以上提到了limits.conf 只影响用户,对于服务进程,需要通过配置启动文件中LimitNOFILE参数来限制。
如果LimitNOFILE没有配置或配置为infilty,则默认取fs.nr_open 数值。

在这里插入图片描述

注意:systemd 234版本以下不支持infinity参数,而CentOS 7 的systemd 版本是219。

知识点:ulimit

用户的最大打开句柄数会在操作系统启动时通过limits.conf 中数值进行初始化。操作系统启动后,可通过ulimit 进行动态修改。

ulimit -n 1048576

在这里插入图片描述

知识点:prlimit

ulimit 只能动态修改用户相关参数,如果想动态修改进程参数,则需要使用prlimit

prlimit --nofile=2147483584 -p `pidof taosd`

在这里插入图片描述

引用:
[1] Documentation for /proc/sys/fs/
[2]What is the default value and the max value range for fs.file-max in Red Hat Enterprise Linux?
[3]What is the maximum value and default value for fs.nr_open in Red Hat Enterprise Linux?


网站公告

今日签到

点亮在社区的每一天
去签到