ruby-on-rails – 如何在增加急切加载的同时解决此错误? “错误ThreadError:尝试解锁由另一个线程锁定的互斥锁”

ruby-on-rails – 如何在增加急切加载的同时解决此错误? “错误ThreadError:尝试解锁由另一个线程锁定的互斥锁”,第1张

概述My Rails应用程序使用inherited_resources gem.我目前正在努力加快速度,以便能够处理更大的数据集.所以我继续前进(在Bullet宝石的帮助下)使用渴望加载,这将证明是有用的.在inherited_resources中,它看起来像这样: def collection my_widgets ||= end_of_association_chain.includes(:a My Rails应用程序使用inherited_resources gem.我目前正在努力加快速度,以便能够处理更大的数据集.所以我继续前进(在Bullet宝石的帮助下)使用渴望加载,这将证明是有用的.在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_collectionend

新代码是.includes(:association_one,:association_two,:association_three,:association_four)

对于我的测试庞大的数据库,这个简单的更改加快了我在日志中的加载时间约5倍.但是,浏览器只会坐在那里,空白.没有.随着Chrome加载图标去.

当我终止终端中的服务器时,我得到了这个相当独特的错误

ERROR ThreadError: Attempt to unlock a mutex which is locked by another thread

Backtrace在底部.

我已经尝试过在这个问题的最佳答案中讨论的解决方案:How can I serve requests concurrently with Rails 4?,具有以下内容:

#config/environments/development.rbconfig.cache_classes = falseconfig.eager_load = trueconfig.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是一个选项吗?我有一个需要并发请求的应用程序.我收到你描述的错误:

错误ThreadError:尝试解锁由另一个线程锁定的互斥锁

切换到Puma解决了这个问题的开箱即用.

总结

以上是内存溢出为你收集整理的ruby-on-rails – 如何在增加急切加载的同时解决此错误? “错误ThreadError:尝试解锁由另一个线程锁定的互斥锁”全部内容,希望文章能够帮你解决ruby-on-rails – 如何在增加急切加载的同时解决此错误? “错误ThreadError:尝试解锁由另一个线程锁定的互斥锁”所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1271188.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存