Recently, with the increase in website traffic to move the Web server to Linux, on the second day of the migration server, Tomcat frequently reported
Java.net.SocketException:Too Many open files error, error log reached more than 100 trillion, depressed, Windows ran a very long
The time did not appear this error, later learned that Linux on the process of open file number is limited.
View with Command ulimit-a
[Root@test security]# Ulimit-a
Core file size (blocks,-c) 0
Data seg Size (Kbytes,-D) Unlimited
File size (blocks,-f) Unlimited
Max locked Memory (Kbytes,-L) Unlimited
Max memory Size (Kbytes,-m) unlimited
OpenFiles(-N) 1024
Pipe Size (bytes,-p) 8
Stack size (Kbytes,-s) 8192
CPU time (seconds,-t) unlimited
MAX User Processes (-u) 7168
Virtual Memory (Kbytes,-V) Unlimited
[Root@test security]#
With the above command, we can seeOpenFilesThe maximum number is 1024
This limit is somewhat stretched for sites with large concurrent volumes, so I pass this command
Ulimit-n 4096
Set the limit on the number of open files to 4096, this is good, the project is stable again
Did not expect to two days later again to make this mistake, depressed, two hours to report once, the newspaper then hung off
After re-using ulimit-a, I found open files (-N) 1024 turned back to 1024.
Reported this error in my landing after the update and reported that the original ulimit-n 4096 command can only temporarily change the value of open files , when
After re-landing will be restored, so you need to permanently set the value of open files is OK,
modifying open files with Ulimit-n can never be maintained. So it's better to use one of the following simple ways.
Modify/etc/security/limits.conf Add the following line:
*-Nofile 1006154
Modify/etc/pam.d/login Add the following line
Session required/lib/security/pam_limits.so
This permanent modification after the program will not have that problem, has been stable operation.
In addition to this problem, we also need to check whether our program is closed after the operation of the IO, which is the most correct solution.
JAVA.NET.SOCKETEXCEPTION:TOO Many OPEN files workaround