Home > Linux > java.net.SocketException Too many files open

java.net.SocketException Too many files open

JavaAl poner en produccion un portal corporativo y pese a haber realizado pruebas de carga, aparece el siguiente mensaje:

java.net.SocketException Too many files open

El problema se solventó subiendo el parámetro nofiles, parámetro que gestiona el número máximo de ficheros abiertos. Este parámetro se cambia en el fichero /etc/security/limits.conf

# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#<domain> <type> <item> <value>
#
#Where:
#<domain> can be:
# – an user name
# – a group name, with @group syntax
# – the wildcard *, for default entry
# – the wildcard %, can be also used with %group syntax,
# for maxlogin limit
#
#<type> can have the two values:
# – “soft” for enforcing the soft limits
# – “hard” for enforcing hard limits
#
#<item> can be one of the following:
# – core – limits the core file size (KB)
# – data – max data size (KB)
# – fsize – maximum filesize (KB)
# – memlock – max locked-in-memory address space (KB)
# – nofile – max number of open files
# – rss – max resident set size (KB)
# – stack – max stack size (KB)
# – cpu – max CPU time (MIN)
# – nproc – max number of processes
# – as – address space limit
# – maxlogins – max number of logins for this user
# – maxsyslogins – max number of logins on the system
# – priority – the priority to run user process with
# – locks – max number of file locks the user can hold
# – sigpending – max number of pending signals
# – msgqueue – max memory used by POSIX message queues (bytes)
#
#<domain> <type> <item> <value>
#

#* soft core 0
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#@student – maxlogins 4

# End of file
# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#<domain> <type> <item> <value>
#
#Where:
#<domain> can be:
# – an user name
# – a group name, with @group syntax
# – the wildcard *, for default entry
# – the wildcard %, can be also used with %group syntax,
# for maxlogin limit
#
#<type> can have the two values:
# – “soft” for enforcing the soft limits
# – “hard” for enforcing hard limits
#
#<item> can be one of the following:
# – core – limits the core file size (KB)
# – data – max data size (KB)
# – fsize – maximum filesize (KB)
# – memlock – max locked-in-memory address space (KB)
# – nofile – max number of open files
# – rss – max resident set size (KB)
# – stack – max stack size (KB)
# – cpu – max CPU time (MIN)
# – nproc – max number of processes
# – as – address space limit
# – maxlogins – max number of logins for this user
# – maxsyslogins – max number of logins on the system
# – priority – the priority to run user process with
# – locks – max number of file locks the user can hold
# – sigpending – max number of pending signals
# – msgqueue – max memory used by POSIX message queues (bytes)
#
#<domain> <type> <item> <value>
#

#* soft core 0
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#@student – maxlogins 4

# End of file

Deberemos de añadir la siguiente linea:

U

suario hard nofile valor

Donde Usuario es el usuario para el que queremos cambiar los valores, o * para todos los usuarios/grupos del sistema. Hard indica el valor máximo que puede alcanzar el sistema operativo mientras que si ponemos soft, sería como una especie de warning.

Una vez que está establecido a nivel de sistema operativo, el usuario deberia de añadir en su .profile .bash_profile, dependiendo de la shell que use.

La linea a añadir sería:

ulimit -n valor

Ahora el usuario deberia de salir de la sesión y hacer un logon de nuevo. El usuario ya tiene los nuevos valores, pero habría que reiniciar la aplicación para que los nuevos procesos tengan ese límite cambiado.

Categories: Linux Tags: ,
  1. mauricio gaueca
    April 17th, 2009 at 23:18 | #1

    Excelente ayuda! muchas gracias

  2. April 18th, 2009 at 11:52 | #2

    Me alegro que te haya servido de ayuda, espero verte aquí de nuevo ;)

  1. No trackbacks yet.