mac修改open files数目

来源:互联网 发布:c语言 原版书 编辑:程序博客网 时间:2024/05/22 11:31

上午在进行压力测试的时候,因为开启线程爬虫太多,所以在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即可设置最大进程数。



0 0
原创粉丝点击