我正在使用 tomcat 7 和 java 1.7 的 debian 服务器。这是一个接收多个 TCP 连接的应用程序,每个 TCP 连接都是 java 进程打开的文件。
看着/proc/pid of java/fd
我发现,有时打开的文件数超过 1024,当这种情况发生时,我在catalina.out
日志中找到了堆栈跟踪_SocketException: Too many open files_
我发现有关此错误的所有内容,人们都指的是 ulimit,我已经更改了此内容并且错误一直在发生。这是配置:
在/etc/security/limits.conf
root soft nofile 8192
root hard nofile 8192
在/etc/sysctl.conf
fs.file-max = 300000
命令ulimit -a
返回:
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 16382
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 8192
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) unlimited
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
但是,当我检查 java 进程的限制时,它只有 1024
在/proc/pid of java/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 32339 32339 processes
Max open files 1024 1024 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 32339 32339 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
如何增加Max open files
java进程的数量?