Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails can';无法创建线程:资源暂时不可用_Ruby On Rails_Ruby_Multithreading_Debian - Fatal编程技术网

Ruby on rails can';无法创建线程:资源暂时不可用

Ruby on rails can';无法创建线程:资源暂时不可用,ruby-on-rails,ruby,multithreading,debian,Ruby On Rails,Ruby,Multithreading,Debian,我正在一台功能强大的服务器(16核、32线程、70GB内存)上运行Debian10下的RubyonRails5.2.x项目的并行测试,我一直收到这个错误 #<Thread:0x000000000b9667d8@/usr/local/rbenv/versions/2.6.6/lib/ruby/2.6.0/webrick/utils.rb:163 run> terminated with exception (report_on_exception is true): Traceback

我正在一台功能强大的服务器(16核、32线程、70GB内存)上运行Debian10下的RubyonRails5.2.x项目的并行测试,我一直收到这个错误

#<Thread:0x000000000b9667d8@/usr/local/rbenv/versions/2.6.6/lib/ruby/2.6.0/webrick/utils.rb:163 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
    1: from /usr/local/rbenv/versions/2.6.6/lib/ruby/2.6.0/webrick/utils.rb:187:in `watch'
/usr/local/rbenv/versions/2.6.6/lib/ruby/2.6.0/webrick/utils.rb:187:in `start': can't create Thread: Resource temporarily unavailable (ThreadError)
用户最大线程数

% cat /proc/sys/kernel/threads-max
628996
ulimit -a

-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-m: resident set size (kbytes)      unlimited
-u: processes                       314498
-n: file descriptors                1024
-l: locked-in-memory size (kbytes)  64
-v: address space (kbytes)          unlimited
-x: file locks                      unlimited
-i: pending signals                 314498
-q: bytes in POSIX msg queues       819200
-e: max nice                        0
-r: max rt priority                 0
-N 15:                              unlimited
更新:通过一个简单的示例重新执行错误

我创建了这个小脚本并不断调整线程,直到它出现同样的错误

#!/usr/bin/env ruby
THREADS = 600
threads = []
pids = []

THREADS.times do
  t= Thread.new do 
    pid = spawn("echo 'hi';sleep 10;echo 'bye'")
    pids.push(pid)
    sleep 10
  end
  threads.push(t)
end

threads.each do |thread|
  thread.join
end

pids.each do |pid|
  `kill #{pid}`
end
这台计算机上有很多进程,我认为在正常操作中,我已经接近极限,所以当我运行测试时,它通常无法创建线程

以不同的用户身份运行此脚本将返回不同的结果


作为我的用户,当我将线程设置为600时,它会失败,但是如果我登录到一个没有打开任何线程的用户,那么我可以运行5000个线程,没有问题。

发现了问题,因为我的所有会话都是通过ssh(通过x2go)运行的,因为我在2020年像所有人一样远程工作,我必须设置以下内容才能使ulimit工作:

/etc/ssh/sshd\u配置

UsePAM yes

注销并重新登录后,我现在可以毫无问题地运行我的线程测试,我甚至尝试了9000个线程,结果成功了。

可能是因为您的计算机内存不足或处理器已达到最大值或其他原因。我在HTOP中观察了计算机以及负载,计算机没有那么紧张。它仍然有50GB的可用内存和大量的处理能力。它是一个双CPU Xeon,具有大量RAM。如果我对firefox做同样的测试,它会占用更多的资源。这看起来像是Chrome在我的设置上达到了极限。