JAVA.NET.SOCKETEXCEPTION:TOO Many OPEN files workaround

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.