Too many open file handles

前端 未结 12 1476
误落风尘
误落风尘 2020-12-16 03:00

I\'m working on a huge legacy Java application, with a lot of handwritten stuff, which nowadays you\'d let a framework handle.

The problem I\'m facing right now is

12条回答
  •  粉色の甜心
    2020-12-16 03:27

    This little script help me to keep eye on count of opened files when I need test ic count. If was used on Linux, so for Solaris you should patch it (may be :) )

    #!/bin/bash
    COUNTER=0
    HOW_MANY=0
    MAX=0
    # do not take care about COUNTER - just flag, shown should we continie or not
    while [ $COUNTER -lt 10 ]; do
        #run until process with passed pid alive
        if [ -r "/proc/$1" ]; then
            # count, how many files we have
            HOW_MANY=`/usr/sbin/lsof -p $1 | wc -l`
            #output for live monitoring
            echo `date +%H:%M:%S` $HOW_MANY
            # uncomment, if you want to save statistics
            #/usr/sbin/lsof -p $1 > ~/autocount/config_lsof_`echo $HOW_MANY`_`date +%H_%M_%S`.txt
    
            # look for max value
            if [ $MAX -lt $HOW_MANY ]; then
                let MAX=$HOW_MANY
                echo new max is $MAX
            fi 
            # test every second. if you don`t need so frequenlty test - increase this value
            sleep 1
        else
            echo max count is $MAX
            echo Process was finished
            let COUNTER=11
        fi
    done
    

    Also you can try to play with jvm ontion -Xverify:none - it should disable jar verification (if most of opened files is jars...). For leaks through not closed FileOutputStream you can use findbug (mentored above) or try to find article how to patch standard java FileOutputStream/FileInputStream , where you can see, who open files, and forgot close them. Unfortunatly, can not find this article right now, but this is existing :) Also think about increasing of filelimit - for up-to-date *nix kernels is not a problem handle more than 1024 fd.

提交回复
热议问题