macos 如何增加 osx 上的套接字限制以进行负载测试?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7578594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:28:53  来源:igfitidea点击:

How to increase limits on sockets on osx for load testing?

macossocketsfreebsdlibev

提问by Chris

I'm creating a load tester that uses libev to create lots of open tcp connections to an app i'm working on. Currently it bombs out at 256 connections, due to the nofiles limit:

我正在创建一个负载测试器,它使用 libev 创建大量与我正在处理的应用程序的开放 tcp 连接。目前,由于 nofiles 限制,它在 256 个连接处爆炸:

ulimit -n
256

I can increase this to 1024 by doing the below:

我可以通过执行以下操作将其增加到 1024:

ulimit -n 1024

But i cannot increase it further. Ideally i want to set it to 1048576. It gives the following error:

但我不能进一步增加它。理想情况下,我想将其设置为 1048576。它给出了以下错误:

ulimit: open files: cannot modify limit: Invalid argument

How can i increase the ulimit further on osx?

如何在 osx 上进一步增加 ulimit?

回答by Grrrr

(answer updated to use -S as several commenters suggested)

(答案更新为使用 -S 作为几个评论者的建议)

$ 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

回答by Juraj Antas

One more thing: Limit on ports is 65535. So you may not get as many as you want to.

还有一件事:端口的限制是 65535。所以你可能得不到你想要的那么多。

回答by Jeremy Friesner

Try running as root (e.g. do a "sudo -s" before running the ulimit command and your program).

尝试以 root 身份运行(例如,在运行 ulimit 命令和您的程序之前执行“sudo -s”)。

Note that I'm not sure that 1-million-plus TCP sockets at once is realistically achievable (although I'm interesting in hearing about what happens when you try it ;^))

请注意,我不确定一次 100 万个以上的 TCP 套接字是否真的可以实现(尽管我很高兴听到您尝试时会发生什么;^))

Also, check out this.

另外,看看这个