Ruby 测试 Ruby 能跑多少个线程

hooopo · September 05, 2012 · Last by chaosong replied at September 21, 2012 · 3038 hits

ruby -v -e 'i=0;loop do; Thread.new { sleep 1 while 1 } rescue raise(i.to_s); print i+=1, "\r"; end'

我机器上 ree -> 5546 但是最终程序卡死了。 1.9.2 -> 2969 1.9.3 -> 2978 2.0.dev -> 3012

refs: https://twitter.com/hellolucky123/status/243180278825222146

ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] 4G 内存 跑到 2 万几了 http://ww2.sinaimg.cn/large/65a79f0cgw1dwlk0s4pdyj.jpg

到 3 万几就出错了,不知道碰到了什么限制,内存是没满的 http://ww3.sinaimg.cn/large/65a79f0cgw1dwlk31v1x8j.jpg

ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin10.8.0]下是 9998,然后就出现了RuntimeError

各种句柄限制,各种 ulimit

这个的限制不是 ruby 本身的,是系统的,我用 http://people.redhat.com/alikins/tuning_utils/thread-limit.c 来测试是 30961 linux 的话,内核有个值是 /proc/sys/kernel/threads-max,默认是6万几,设高了也不能突破3万几的限制,貌似还有个每用户的限制

ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] 31994 内存 800M 左右 虚拟内存 40 多 G 吧

ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] -e:1: warning: literal in condition -e:1:in `rescue in block in ': 32005 (RuntimeError)

You need to Sign in before reply, if you don't have an account, please Sign up first.