Tuesday, March 5, 2013

java.net.SocketException: Too many open files

I've recently experienced this bad exception in my linux machine, during load test I've launched
java.net.SocketException: Too many open files

After some google search + consultation with my colleague in production, I've learned the following:

Type
ulimit -a

[root@tlvcib7 ~]# ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 62827
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 256pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

This means that I'm allowed to open up to 256 file descriptors.

In order to modify it, in your own shell, do the following
ulimit -n  65536  
from then, in your own shell, you'll have the limit set to 65536 (64*1024)

You can also define it in
/etc/security/limits.conf


For everyone
*       hard    nproc           65536
*        soft    nproc           65536

or more specifically for a given user

@student        hard    nproc           20
@faculty        soft    nproc           20

or as implemented in Shark @ LP (somehow, the above lines didn't do what I expected )

root hard nofile 32768
web hard nofile 32768

root soft nofile 32768
root soft nproc 32768
web soft nproc 32768
web soft nofile 32768
web          -    nofile          32768




The file descriptor being used are in
/proc/<pid>/fd/

For ex, if your java process is 13336


 ls /proc/13336/fd0    105  112  12   127  134  141  149  156  163  170  178  185  192  2    206  213  220  228  235  242  25   259  27  34  41  49  56  63  70  78  85  921    106  113  120  128  135  142  15   157  164  171  179  186  193  20   207  214  221  229  236  243  250  26   28  35  42  5   57  64  71  79  86  9310   107  114  121  129  136  143  150  158  165  172  18   187  194  200  208  215  222  23   237  244  251  260  29  36  43  50  58  65  72  8   87  94100  108  115  122  13   137  144  151  159  166  173  180  188  195  201  209  216  223  230  238  245  252  261  3   37  44  51  59  66  73  80  88  95101  109  116  123  130  138  145  152  16   167  174  181  189  196  202  21   217  224  231  239  246  253  262  30  38  45  52  6   67  74  81  89  96102  11   117  124  131  139  146  153  160  168  175  182  19   197  203  210  218  225  232  24   247  254  263  31  39  46  53  60  68  75  82  9   97103  110  118  125  132  14   147  154  161  169  176  183  190  198  204  211  219  226  233  240  248  255  264  32  4   47  54  61  69  76  83  90  98104  111  119  126  133  140  148  155  162  17   177  184  191  199  205  212  22   227  234  241  249  258  266  33  40  48  55  62  7   77  84  91  99


4 comments:

Anonymous said...

I loved as much as you will receive carried out right here.
The sketch is tasteful, your authored material stylish.
nonetheless, you command get got an shakiness over that you wish be
delivering the following. unwell unquestionably
come further formerly again as exactly the same nearly a lot often inside case you shield this hike.


Also visit my webpage: thinning hair men

Anonymous said...

Hello, after reading this amazing article i am too cheerful to
share my familiarity here with friends.

my homepage - tips for fat loss

Anonymous said...

Keep on writing, great job!

my site - dumbbells sets target

Anonymous said...

you're actually a just right webmaster. The website loading velocity is amazing. It seems that you're doing any unique trick.

Also, The contents are masterpiece. you have done a magnificent task on this topic!


My website muscle building protein