Open File Limit


Tomcat Log 出現 “Too many open files”

Log catalina.err 出現類似以下的 exception, 然後 application 就掛了 …

1
2
3
4
5
6
7
8
9
10
11
12
INFO: Deployment of web application archive /usr/tomcat/webapps/app.war has finished in 378,373 ms
Sep 2, 2014 10:46:54 AM org.apache.tomcat.util.net.JIoEndpoint$Acceptor run
SEVERE: Socket accept failed
java.net.SocketException: Too many open files
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:375)
at java.net.ServerSocket.implAccept(ServerSocket.java:478)
at java.net.ServerSocket.accept(ServerSocket.java:446)
at org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:60)
at org.apache.tomcat.util.net.JIoEndpoint$Acceptor.run(JIoEndpoint.java:220)
at java.lang.Thread.run(Thread.java:701)
Sep 2, 2014 10:46:55 AM org.apache.tomcat.util.net.JIoEndpoint$Acceptor run

Open File Limit in User Level

調整使用者的 Open File Limit, 修改 /etc/security/limits.conf 設定 (AWS AMI Linux), 這是針對每個 user 調整 open file 上限:

1
2
3
4
5
6
7
# <domain> <type> <item>  <value>
* soft nofile 65535
* hard nofile 65535

# 登出登入後, 取得使用者開檔限制
$ ulimit -n
65535

取得相關資訊

1
2
3
4
5
# 取的目前已開檔的數目
lsof | wc -l

# 取得最大可以開啟的檔案數
cat /proc/sys/fs/file-max

Open File Limit in OS Level

1
2
3
4
5
6
7
8
# 在 /etc/rc.local 加入以下這段
echo 65536 > /proc/sys/fs/file-max

# 或是修改 sysctl.conf, 加入以下:
fs.file-max=65536

# 重開機
reboot

AWS Instance Open File Limit

1
2
3
4
5
6
7
8
9
10
11
# m3.large
$ cat /proc/sys/fs/file-max
759830

# t2.medium
$ cat /proc/sys/fs/file-max
400716

# t2.medium
$ cat /proc/sys/fs/file-max
65535

延伸閱讀

參考資料


Comments