Skip to content

Instantly share code, notes, and snippets.

@yohangdev
Last active November 14, 2020 15:23
Show Gist options
  • Save yohangdev/fe4202e72c844de1a0e2fab38cfb13bb to your computer and use it in GitHub Desktop.
Save yohangdev/fe4202e72c844de1a0e2fab38cfb13bb to your computer and use it in GitHub Desktop.
MacOS Set Limit Open/Max Files

macOS has only 16K ports available that won't be released until socket TIME_WAIT is passed. The default timeout for TIME_WAIT is 15 seconds. Consider reducing in case of available port bottleneck.

You can check whether this is a problem with netstat:

$ sysctl net.inet.tcp.msl
net.inet.tcp.msl: 15000

$ sudo sysctl -w net.inet.tcp.msl=1000
net.inet.tcp.msl: 15000 -> 1000
launchctl limit maxfiles
sudo launchctl limit maxfiles 65536 200000
$ sysctl kern.maxfiles
kern.maxfiles: 12288
$ sysctl kern.maxfilesperproc
kern.maxfilesperproc: 10240
$ sudo sysctl -w kern.maxfiles=1048600
kern.maxfiles: 12288 -> 1048600
$ sudo sysctl -w kern.maxfilesperproc=1048576
kern.maxfilesperproc: 10240 -> 1048576
$ ulimit -S -n
256
$ ulimit -S -n 1048576
$ ulimit -S -n
1048576
# https://wilsonmar.github.io/maximum-limits/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment