0

We have a ruby application that started throwing lot of "unable to create new socket: Too many open files" errors recently I have updated "etc/security/limits.conf" as below

root soft  nofile 6553600
root hard  nofile 6553600
nobody soft nofile 655360
nobody soft nofile 655360
mysql hard nofile 655360
mysql hard nofile 655360
*      soft nofile 81920
*      hard nofile 65000
* - nofile 102400    

also updated fs.file-max = 90000 in /etc/sysctl.conf

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) 62459
 max locked memory       (kbytes, -l) 64
 max memory size         (kbytes, -m) unlimited
 open files                      (-n) 10240
 pipe size            (512 bytes, -p) 8
 POSIX message queues     (bytes, -q) 819200
 real-time priority              (-r) 0
 stack size              (kbytes, -s) 8192
 cpu time               (seconds, -t) unlimited
 max user processes              (-u) 62459
 virtual memory          (kbytes, -v) unlimited
 file locks                      (-x) unlimited

ulimit -n

10240

but still open file limit for ruby process is 1024

cat /proc/13765/limits (pid of ruby app)
 Limit                     Soft Limit           Hard Limit           Units     
 Max cpu time              unlimited            unlimited            seconds   
 Max file size             unlimited            unlimited            bytes     
 Max data size             unlimited            unlimited            bytes     
 Max stack size            8388608              unlimited            bytes     
 Max core file size        0                    unlimited            bytes     
 Max resident set          unlimited            unlimited            bytes     
 Max processes             62459                62459                processes 
 Max open files            1024                 4096                 files     
 Max locked memory         65536                65536                bytes     
 Max address space         unlimited            unlimited            bytes     
 Max file locks            unlimited            unlimited            locks     
 Max pending signals       62459                62459                signals   
 Max msgqueue size         819200               819200               bytes     
 Max nice priority         0                    0                    
 Max realtime priority     0                    0                    
 Max realtime timeout      unlimited            unlimited            us

ruby process is using more than 1024 files

lsof -p 13765 | wc -l

1070

How can I increase "Max open files" value for this ruby process/app ?

0

I have updated /etc/security/limits.conf as below

That's read by pam_limits.so, so it only takes effect for anything that goes through PAM, as in a user login.

updated /etc/sysctl.conf

That's likely read by some boot scripts, so the changes only take effect after a reboot... (There's systemd-sysctl.service and an old-style /etc/init.d/procps script on my Debian.)

The point is, that neither of those files is read instantly, and changes in ulimits never apply to running processes.

How can I increase "Max open files" value for this ruby process/app ?

Find out whatever starts it, change the ulimit there, and restart the process. If you start it from the command line, changing the limits on the shell and restarting it should do, if you run it from init/systemd/whatever, then you may need to find the correct configuration.

  • #upstart script for ruby app start on runlevel[234] start on (net-device-up and local-filesystems) stop on runlevel[0156] chdir /home/rubyuser/deploy/app ulimit -c 65000 && exec sudo -u rubyuser LANG=en_US.UTF-8 /usr/local/rvm/bin/ruby_app_bundle exec /usr/local/rvm/bin/ruby_app -e production -p 8001 /usr/local/ruby-app/ >> /var/log/app.log 2>&1 respawn Is this correct ? – Shyam Jos Mar 15 '17 at 3:27
  • I was able to increase the 1024 limit to 50000 by Adding the line 'limit nofile 50000 50000' to the upstart file, Thanks – Shyam Jos Mar 15 '17 at 6:02
  • @ShyamJos, I've no idea about upstart – ilkkachu Mar 15 '17 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.