RSS

Category Archives: UNIX

Too many open files error and ulimit

I’ve been running some tests on my Mac where I was opening lots of connections from my virtual clients to my server and I suddenly ended up with this error:

java.io.IOException: Too many open files in system

As you guessed, there’s a limit to the number of open files in most of the operating systems. You can see the limit on your machine using ulimit -a. Note the open files limit is 256:

matamel-MacBookPro:etc matamel$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) 6144
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 256
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 266
virtual memory (kbytes, -v) unlimited

And, you can change the open files limit using ulimit -n. In this case, I increased my open files by 10:

matamel-MacBookPro:etc matamel$ ulimit -n 2560
matamel-MacBookPro:etc matamel$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) 6144
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 2560
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 266
virtual memory (kbytes, -v) unlimited

Note that this only applies to the shell you’re currently in although I’m sure there’s a way to make this permanent on Mac OS, just didn’t spend the time to look for it. I know that in Suse, you can make this change permanent by adding the following to /etc/security/limits.conf

* soft nofile 10240
* hard nofile 20480

In Windows, I seem to remember that this was controlled by a registry setting called MaxUserPort but might be wrong.

 
3 Comments

Posted by on January 19, 2010 in UNIX