mac修改open files數目
阿新 • • 發佈:2018-12-13
上午在進行壓力測試的時候,因為開啟執行緒爬蟲太多,所以在tcp連線的時候太多了,故一直出現tcp : too many open files的情況,查了一下,原來是系統開啟檔案數有限制。
樹黴派上面的同事已經設定好了,然後程式是在自己的mac上執行的,所以還得把自己的open files數目設定一下。
上網找了好多解決方案,都沒有有用的。最後快要放棄的時候找到一個:http://docs.basho.com/riak/latest/ops/tuning/open-files-limit/#Mac-OS-X
因為自己的mac是Mac OS X Yosemite,裡面正好有這個的解決方案,試了一下,可以修改open files數目成功!
解決方案如下:
輸入命令:launchctl limit
可以看到類似這樣:
maxproc表示的是開啟的最大程序數,第一個1064表示的是soft限制,第二個1064表示的是hard限制,即硬體最大的限制數,自己設定的不能高於hard限制。所以 我soft也改成了1064最大的。
maxfiles表示的是開啟的最大檔案數(控制代碼),意義同上……
如何設定呢?下面講重點:
開啟或者新建一個檔案:/Library/LaunchDaemons/limit.maxfiles.plist
輸入:
<?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>65536</string> <string>65536</string> </array> <key>RunAtLoad</key> <true/> <key>ServiceIPC</key> <false/> </dict> </plist>
儲存並重啟mac即可設定最大檔案數。
開啟或者新建一個檔案:/Library/LaunchDaemons/limit.maxproc.plist
輸入:
<?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.maxproc</string> <key>ProgramArguments</key> <array> <string>launchctl</string> <string>limit</string> <string>maxproc</string> <string>2048</string> <string>2048</string> </array> <key>RunAtLoad</key> <true /> <key>ServiceIPC</key> <false /> </dict> </plist>
儲存並重啟mac即可設定最大程序數。