8

When executing gatling (load test tools) from shell on Mac iOS (El Capitan) on my Macbook Pro 15 ' (16 Giga of RAM, 4 physical cores), i've the error "Too many open files".

I spend days to fix this problem, without any success :

  • I created a file in /Library/LaunchDaemons/limit.maxfiles.plist with a XML file content copied from the web, no result.

  • sudo ulimit -n 15000 doesn't work.

  • I created a file /etc/sysctl.conf with the following content

kern.maxfiles=20480
kern.maxfilesperproc=20480

  • I tried the command "sudo launchctl limit maxfiles 20480 20480" without any result.

I think that the xml file in "/Library/LaunchDaemons/" seem have some effect, because when i change the value of the maxfiles, the command "sudo launchctl limit" display to me the value i entered in the XML file, and when calling "ulimit -n" with some value, it accept every values less than this value, but when i call "ulimit -n", the result is everytime the same "4096".

I saw that in Java, the limit is 10240, so i tried the VM option (-XX:-MaxFDLimit) without any effect.

On strange thing, when i executed Gatling from Intellij (IDE), i ca go until 10 200 sockets. The same thing, give differents effects, even after executing all commands in all combinaisons (ulimit, sysctl, launchctl, ...).

Best regards

bsh
  • 205
  • 2
  • 10
  • and tried exactly what the doccu says at http://gatling.io/docs/2.0.0-RC2/general/operations.html ? e.g. instead of 20k set 300k to kerm.*? – clt60 Nov 20 '15 at 22:51
  • Thank you for your answer. I found the answer to my question.my problem with gatling come from the fact that i can't execute the ulimit with my user (permission denied), and "sudo ulimit" has not effect to the current shell for my user. So, my solution is to execute my gatling stress test under a root user (sudo -s), why i can' t execute ulimit without sudo ? The problem remain when executing java program from Intellij (10 240 limit). I understand that it does not make sens to execute a program like this in Intellij, just curiosity :) – bsh Nov 21 '15 at 00:20
  • For intellij, the answer is to modify the vmoptions of intellij in the Info.plist file to add in the VMOptions key at the end of the file the "-XX:-MaxFDLimit". changing the file idea.vmoptions has no effect. For the ulimit, the answer is to add "ulimit -n 23000" in my /etc/profile. – bsh Nov 21 '15 at 01:01

2 Answers2

13

Just in case any one else lands here from google, here are the steps required to change the open files limit on the latest versions of OS X:

1. In /Library/LaunchDaemons create a file named limit.maxfiles.plist and paste the following in (feel free to change the two numbers (which are the soft and hard limits, respectively):

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"  
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">  
  <dict>
    <key>Label</key>
    <string>limit.maxfiles</string>
    <key>ProgramArguments</key>
    <array>
      <string>launchctl</string>
      <string>limit</string>
      <string>maxfiles</string>
      <string>64000</string>
      <string>524288</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist> 

2. Change the owner of your new file:

sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist

3. Check current settings launchctl limit maxfiles

4. Load these new settings:

sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist

5. Finally, check that the limits are correct:

launchctl limit maxfiles
Ashutosh Jindal
  • 18,501
  • 4
  • 62
  • 91
ninjaPixel
  • 6,122
  • 3
  • 36
  • 47
  • 1
    A very helpful answer! – Konstantin Dec 07 '18 at 10:28
  • 2
    This limit.maxfiles.plist config does not work for me on Mac OS 10.15 / Java 1.8... has anyone else hit this issue? – Felix GV Feb 23 '21 at 18:21
  • 1
    A little hint: NEVER use phrases like "latest version of macOS". If it's written and recorded to database this statement(technically) will be out of date as soon as next version comes out. It's 2022 now and I'm wondering if this is still the way to go for increasing files limit. – Aleksandr Kravets Mar 26 '22 at 08:08
6

I found the answer to my question.

Ulimit and Shell

My problem with gatling come from the fact that i can't execute the ulimit with my user (permission denied), and "sudo ulimit" has not effect to the current shell for my user. So, my solution is to

Execute my gatling stress test under a root user (sudo -s). Add a line "ulimit -n 23000" in the /etc/profile file.

Intellij

For intellij, the answer is to modify the vmoptions of intellij in the Info.plist file to add in the VMOptions key at the end of the file the "-XX:-MaxFDLimit".

Changing the file bin/idea.vmoptions has no effect.

Global value of maxfiles should be changed by adding a file "limit.maxfiles.plist" in the /Library/LaunchDaemons directory.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
    <dict>
      <key>Label</key>
        <string>limit.maxfiles</string>
      <key>ProgramArguments</key>
        <array>
          <string>launchctl</string>
          <string>limit</string>
          <string>maxfiles</string>
          <string>66111</string>
          <string>66111</string>
        </array>
      <key>RunAtLoad</key>
        <true/>
      <key>ServiceIPC</key>
        <false/>
    </dict>
  </plist>

Thank you

Community
  • 1
  • 1
bsh
  • 205
  • 2
  • 10
  • This limit.maxfiles.plist config does not work for me on Mac OS 10.15 / Java 1.8... has anyone else hit this issue? – Felix GV Feb 23 '21 at 18:21