How do I resolve this error while increasing eager loading? "ERROR ThreadError: Attempt to unlock a mutex which is locked by another thread"
How do I resolve this error while increasing eager loading? "ERROR ThreadError: Attempt to unlock a mutex which is locked by another thread"
我的 Rails 应用程序使用 inherited_resources
gem。我目前正在尝试加快它的速度,以便能够处理更大的数据集。因此,我继续(在 Bullet gem 的帮助下)在证明有用的地方使用预加载。在 inherited_resources 中,它看起来像这样:
def collection
my_widgets ||= end_of_association_chain.includes(:association_one, :association_two, :association_three, :association_four)
@widgets = case params[:filter]
when nil then my_widgets.all
when 'old' then my_widgets.old
when 'new' then my_widgets.new
end
@final_collection
end
新密码是.includes(:association_one, :association_two, :association_three, :association_four)
对于我的测试大型数据库,这个简单的更改使我在日志中的加载时间加快了大约 5 倍。然而,浏览器只会坐在那里,一片空白。没有什么。 chrome 正在加载图标。
当我在终端中终止服务器时,我得到了这个相当独特的错误:
ERROR ThreadError: Attempt to unlock a mutex which is locked by another thread
回溯在底部。
我已经尝试过在这个问题的最佳答案中讨论的解决方案:How can I serve requests concurrently with Rails 4?,具有以下内容:
#config/environments/development.rb
config.cache_classes = false
config.eager_load = true
config.allow_concurrency=true
我在这里错过了什么?为什么简单地将这些关联添加到预先加载中,这会显着加快幕后的速度,却借给我一个无响应的浏览器并出现此 ThreadError?
/Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/lock.rb:22:in `unlock'
/Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/lock.rb:22:in `ensure in call'
/Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/lock.rb:23:in `call'
/Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call'
/Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service'
/Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
/Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/handler/webrick.rb:48:in `shutdown': undefined method `shutdown' for nil:NilClass (NoMethodError)
from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/server.rb:280:in `block in start'
from /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:206:in `call'
from /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:206:in `join'
from /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:206:in `block (2 levels) in start'
from /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:206:in `each'
from /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:206:in `block in start'
from /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:32:in `start'
from /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:162:in `start'
from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/handler/webrick.rb:34:in `run'
from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/server.rb:286:in `start'
from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/railties-4.2.6/lib/rails/commands/server.rb:80:in `start'
from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `server'
from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/railties-4.2.6/lib/rails/commands.rb:17:in `'
from bin/rails:4:in `require'
from bin/rails:4:in `'
编辑:我开始怀疑这是不是一个线程错误,因为我的数据集太大而无法预先加载,是否存在一个阈值,您可以在其中快速加载如此多的对象,虽然它在终端,浏览器就永远坐在那里?
是否可以从 WEBrick 切换到 Puma?我有一个需要并发请求的应用程序。我收到了您描述的错误:
ERROR ThreadError: Attempt to unlock a mutex which is locked by another thread
改用 Puma 立即解决了这个问题。
我的 Rails 应用程序使用 inherited_resources
gem。我目前正在尝试加快它的速度,以便能够处理更大的数据集。因此,我继续(在 Bullet gem 的帮助下)在证明有用的地方使用预加载。在 inherited_resources 中,它看起来像这样:
def collection
my_widgets ||= end_of_association_chain.includes(:association_one, :association_two, :association_three, :association_four)
@widgets = case params[:filter]
when nil then my_widgets.all
when 'old' then my_widgets.old
when 'new' then my_widgets.new
end
@final_collection
end
新密码是.includes(:association_one, :association_two, :association_three, :association_four)
对于我的测试大型数据库,这个简单的更改使我在日志中的加载时间加快了大约 5 倍。然而,浏览器只会坐在那里,一片空白。没有什么。 chrome 正在加载图标。
当我在终端中终止服务器时,我得到了这个相当独特的错误:
ERROR ThreadError: Attempt to unlock a mutex which is locked by another thread
回溯在底部。
我已经尝试过在这个问题的最佳答案中讨论的解决方案:How can I serve requests concurrently with Rails 4?,具有以下内容:
#config/environments/development.rb
config.cache_classes = false
config.eager_load = true
config.allow_concurrency=true
我在这里错过了什么?为什么简单地将这些关联添加到预先加载中,这会显着加快幕后的速度,却借给我一个无响应的浏览器并出现此 ThreadError?
/Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/lock.rb:22:in `unlock' /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/lock.rb:22:in `ensure in call' /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/lock.rb:23:in `call' /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call' /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service' /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service' /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run' /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread' /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/handler/webrick.rb:48:in `shutdown': undefined method `shutdown' for nil:NilClass (NoMethodError) from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/server.rb:280:in `block in start' from /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:206:in `call' from /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:206:in `join' from /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:206:in `block (2 levels) in start' from /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:206:in `each' from /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:206:in `block in start' from /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:32:in `start' from /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:162:in `start' from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/handler/webrick.rb:34:in `run' from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/server.rb:286:in `start' from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/railties-4.2.6/lib/rails/commands/server.rb:80:in `start' from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:80:in `block in server' from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `tap' from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `server' from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!' from /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/railties-4.2.6/lib/rails/commands.rb:17:in `' from bin/rails:4:in `require' from bin/rails:4:in `'
编辑:我开始怀疑这是不是一个线程错误,因为我的数据集太大而无法预先加载,是否存在一个阈值,您可以在其中快速加载如此多的对象,虽然它在终端,浏览器就永远坐在那里?
是否可以从 WEBrick 切换到 Puma?我有一个需要并发请求的应用程序。我收到了您描述的错误:
ERROR ThreadError: Attempt to unlock a mutex which is locked by another thread
改用 Puma 立即解决了这个问题。