Solve the problem of Too many open files appearing in high concurrency __too

Source: Internet
Author: User
Tags finally block

1. Main direction: In the source project to find all references to InputStream or other streams, to see if it is used up, normal close off, it is recommended here to put the flow close to the finally block, so the exception will also go to the close stream.

2. Secondary direction: Session or other useful to the socket code, carefully check to see if there is no resources to release the place

Also attached:

The following 2 instructions in Linux show that 1024 of the system default open files is not sufficient to support the test, adjust to 4096 accordingly .

The following script is executed at the peak time of system access as root user, and the possible results are as follows:

# Lsof-n|awk ' {print$2} ' |sort|uniq-c |sort-nr|more

1170 32229
57 24244
57 24231
56 24264

The first column is the number of open file handles and the second column is the process number.

# Ps-aef|grep 32229

Root 32229 1 10:58 pts/0 00:09:17/usr/java/jdk1.6.0_32/bin/java-djava.util.logging.config.file=/kmsapp/apache -tomcat-6.0.35_engine/conf/logging.properties-xms512m-xmx2048m-djava.util.logging.manager= Org.apache.juli.classloaderlogmanager-djava.endorsed.dirs=/kmsapp/apache-tomcat-6.0.35_engine/endorsed- Classpath/kmsapp/apache-tomcat-6.0.35_engine/bin/bootstrap.jar-dcatalina.base=/kmsapp/apache-tomcat-6.0.35_ engine-dcatalina.home=/kmsapp/apache-tomcat-6.0.35_engine-djava.io.tmpdir=/kmsapp/apache-tomcat-6.0.35_engine/ Temporg.apache.catalina.startup.Bootstrap start

found that the Tomcat process opened up to a maximum number of file handles, and it opened the number of 1170 file handles, exceeding the default value of 1024.

so you should set the value to 4096, so if you want to make a permanent adjustment, follow these 2 steps:

1. Modify/etc/security/limits.conf

modify its content through vi/etc/security/limits.conf, and add it at the end of the file (values can be defined yourself):

* Soft nofile = 4096

* Hard nofile = 4096


2. Modify/etc/profile

through Vi/etc/profile modifications, add the following at the end:

ulimit-n4096


and then log back in to take effect.

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.