Skip to main content

"Too many open files" error in Linux

10 replies [Last post]
boraldo
Offline
Joined: 2010-02-01

My Glassfish works on Linux.
I have 3 simultaneous domains.

Often when I start domain it throws
>> java.io.IOException: Too many open files

What should I do to get rid of it ?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Mark Mielke

Linux, like many other UNIX systems, defaults to a maximum of 1024 file
descriptors. For the most part, this is to provide compatibility with
"legacy" applications, although MANY applications fall into this category.

Any application that uses select() and "fd_set *", with the standard
macros FD_CLR(), FD_ISSET(), FD_SET(), and FD_ZERO(), is using an
interface that normally uses a predefined bitmask size of 1024. As only
1024 bits are allocated, then if the system returned a file descriptor
greater than 1024, then the program would start scribbling over memory
outside the bit mask and cause problems. Applications that uses poll()
or epoll are safe from this problem. Java is safe from this problem.

On my servers, I set the "hard" limit to 8192 and leave the "soft" limit
at 1024. This means that programs are restricted to 1024 unless they
specifically know how to raise the "soft" limit up to the "hard" limit
themselves. Java knows how to do this and does it automatically in my
experience.

On Fedora 11, I raise the "hard" limit using the following lines in
/etc/security/limits.d/99-max-files.conf:

* soft nofile 1024
* hard nofile 8192

You may need to logout and login for this to take effect. A full reboot
will ensure that all processes benefit from this change.

From the command line, before starting Glassfish, you can execute the
following:

ulimit -Hn 8192

Note that "ulimit -Hn" probably requires root to run. Therefore, you
would have to run this command in startup scripts *before* switching to
become the Glassfish user. I prefer
/etc/security/limits.d/99-max-files.conf as this avoids the need for
wrapper startup scripts.

Cheers,
mark

On 06/03/2010 04:12 AM, Haluk Durmus wrote:
> Are you running glassfish on a virtual server ?
>
>
> ----- Ursprüngliche Mail ----
> Von: "glassfish@javadesktop.org"
> An: users@glassfish.dev.java.net
> Gesendet: Donnerstag, den 3. Juni 2010, 11:18:07 Uhr
> Betreff: "Too many open files" error in Linux
>
> My Glassfish works on Linux.
> I have 3 simultaneous domains.
>
> Often when I start domain it throws
>
>>> java.io.IOException: Too many open files
>>>
> What should I do to get rid of it ?
> [Message sent by forum member 'boraldo']
>
> http://forums.java.net/jive/thread.jspa?messageID=472515
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>
>

--
Mark Mielke

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

boraldo
Offline
Joined: 2010-02-01

How can I ensure that at this moment number of opened files is less than I set up though etc/security/limit ?

rjdkolb
Offline
Joined: 2006-07-20

> What should I do to get rid of it ?

Perhaps you should check what is causing it.
Do a lsof (ls open files)

My GlassFish is installed in a directory glassfishv3

So I : lsof |grep glassfishv3 | wc -l

My output is 563, so GlassFish 3 has opened 563 files for a newly started GlassFish.

Perhaps you can monitor this value and see if GlassFish is gradually leaking file descriptors. (Which is possible even in Java)
If you could prove this, and if I ever meet you, I will buy you a cold beer :)

regards
Richard.

boraldo
Offline
Joined: 2010-02-01

Sometimes when I meet this problem I do even [b]lsof | wc -l[/b]. It shows much less than [b]ulimit -n[/b]. How could error happen?

boraldo
Offline
Joined: 2010-02-01

How can I ensure that at this moment number of opened files is less than I set up though etc/security/limit or etc/profile ?

Glenn Holmer

On Thu, 2010-06-03 at 01:18 -0700, glassfish@javadesktop.org wrote:
> My Glassfish works on Linux.
> I have 3 simultaneous domains.
>
> Often when I start domain it throws
> >> java.io.IOException: Too many open files
>
> What should I do to get rid of it ?

This is what we did (assuming GlassFish runs as user "glassfish"):

Add the following lines to /etc/security/limits.conf to increase the
maximum number of open files for the user that Glassfish runs as:

glassfish soft nofile 32768
glassfish hard nofile 65536

You will also need to add this line in /etc/pam.d/su:

session required pam_limits.so

--
____________________________________________________________
Glenn Holmer gholmer@weycogroup.com
Software Engineer phone: 414-908-1809
Weyco Group, Inc. fax: 414-908-1601

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

hammoud
Offline
Joined: 2005-06-20

On OpenSuse system fixed the "Too many open files" problem by increasing the limits in "/etc/security/limits.conf":
http://www.i-coding.de/www/en/glassfish/configuration/too-many-open-file...

This did not work on Debian5 (think was a bug)
Set ulimit in /root/bashrc additionally.

Haluk Durmus

Are you running glassfish on a virtual server ?

----- Ursprüngliche Mail ----
Von: "glassfish@javadesktop.org"
An: users@glassfish.dev.java.net
Gesendet: Donnerstag, den 3. Juni 2010, 11:18:07 Uhr
Betreff: "Too many open files" error in Linux

My Glassfish works on Linux.
I have 3 simultaneous domains.

Often when I start domain it throws
>> java.io.IOException: Too many open files

What should I do to get rid of it ?
[Message sent by forum member 'boraldo']

http://forums.java.net/jive/thread.jspa?messageID=472515

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

boraldo
Offline
Joined: 2010-02-01

No. It is a usual machine with Linux OS.

Brij Mohan Negi \(India\)

Plz increase the file limit on linux box using ulimit i guess.

Brij

-----Original Message-----
From: glassfish@javadesktop.org [mailto:glassfish@javadesktop.org]
Sent: Thursday, June 03, 2010 2:37 PM
To: users@glassfish.dev.java.net
Subject: Re: AW: "Too many open files" error in Linux

No. It is a usual machine with Linux OS.
[Message sent by forum member 'boraldo']

http://forums.java.net/jive/thread.jspa?messageID=472524

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net