0

I have set the

kern.maxfiles=65536
kern.maxfilesperproc=65536

After this, I put the following command in my .zshrc file

ulimit -n 30000

However, if I try to run a netty based application from eclipse, only 10k sockets open and then java IO exception "too many open files" occurs. Folowing is the stacktrace.

java.io.IOException: Too many open files
    at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
    at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:422)
    at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:250)
    at io.netty.channel.socket.nio.NioServerSocketChannel.doReadMessages(NioServerSocketChannel.java:135)
    at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:68)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:510)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:467)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:381)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:834)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
    at java.lang.Thread.run(Thread.java:745) 

I use the following command to check the number of open files/sockets being used by my server and it always shows a value slightly more that 10k when the exception occurs.

lsof -p <pid> | wc -l 
Sachin Malhotra
  • 1,211
  • 2
  • 11
  • 24
  • What does `ulimit -a` show? also, `lsof -p ` will show handles onlyl for are you opening sockets/handles via some other process or something left behind from previous runs? – ring bearer May 12 '15 at 12:04
  • @ringbearer ulimit -a shows the following --t: cpu time (seconds) **unlimited** -f: file size (blocks) **65536** -d: data seg size (kbytes) **unlimited** -s: stack size (kbytes) **8192** -c: core file size (blocks) **0** -u: processes **709** -n: file descriptors **65536** And no, all the sockets are being opened by my application itself. That I have checked. No other process is left behind. – Sachin Malhotra May 12 '15 at 12:07

1 Answers1

0

Increase your file descriptor value to achieve. You are setting values to "65536" but invoking only 30000 by adding in your shell

Please change the values then reload the bash, either by su - in current session or open the new terminal/session, then restart your application. It must work

You can set the ulimit with the help of following link.

https://vasnlinux.wordpress.com/2015/05/01/linux-server-hardening/

Abhishek
  • 1
  • 3
  • I am invoking 30000 because I am making sure that for the current session of my application, at max 20k sockets can be opened. So I don't need 65k. However, I set 65k as value because I need to load test my application for values as high as 60k. – Sachin Malhotra May 12 '15 at 13:09
  • have you restarted your application post value change and i believe you are running your application from root user. If not then some more modification need to be done for that user profile. – Abhishek May 12 '15 at 13:15
  • I am running my application from Eclipse GUI and yes I have restarted the system post the changes. – Sachin Malhotra May 12 '15 at 13:38
  • How many "thread" do you configure in the boss pool for the bootstrap (EventLoopGroup or equivalent) ? For me, reducing this number reduces the "virtual" need of open files (seems that Netty allocates one open files per boss thread). Generally a number close to the number of CPU (or a multiple of it) is a good choice. – Frederic Brégier May 13 '15 at 18:00