私の 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 倍高速化されました。ただし、ブラウザは何も表示されず、ただそこに座っているだけです。何もない。クロムの読み込みアイコンが表示されます。
ターミナルでサーバーを強制終了すると、次のかなりユニークなエラーが発生します。
ERROR ThreadError: Attempt to unlock a mutex which is locked by another thread
一番下にバックトレース。
この質問に対するトップの回答で説明されているソリューションを既に試しました: 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:「ロック解除」 /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:「サービス」内 /Users/johndoeuser/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:「サービス」 /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': 定義されていないメソッド `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 `ブロック (2 レベル) 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:`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 `サーバー内ブロック' 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 `サーバー' /Users/johndoeuser/.rvm/gems/ruby-2.2.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39: から `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 `'
編集:これは、私のデータセットが大きすぎて積極的に読み込むことができないよりも、スレッド エラーが少ないのではないかと考え始めています。ターミナルですばやく読み込まれている間、ブラウザーが永遠にそこに座っていますか?