遅いサイトをなんとかする必要があったので、まずは計測する。
最初に使ったrack-mini-profilerは大して役に立たないので無駄だった。
qcachegrindのインストール
% brew install qcachegrind graphviz
graphvizはqcachegrindでコールグラフの生成に使う
手順
Gemfileに
ruby-profを追加group :profile do gem 'ruby-prof' endconfig.ruにprofの設定追加
if Rails.env.profile? use Rack::RubyProf, :path => 'tmp/profile', :printers => { ::RubyProf::FlatPrinter => 'flat.txt', ::RubyProf::GraphPrinter => 'graph.txt', ::RubyProf::GraphHtmlPrinter => 'graph.html', ::RubyProf::CallStackPrinter => 'call_stack.html', ::RubyProf::CallTreePrinter => 'call_grind.txt', } endRAILS_ENV=profileの設定は適宜developmentあたりをコピーして作成。サーバを起動して、問題のページにアクセスする。
./bundle/bin/spring rails s -p 3001 -e profiletmp/profile/-call_grind.txtが生成されているのでqcachegrindに読み込ませる。
Incl.やSelfの値の大きいところを目安にして、実際に遅い処理の部分を探す
0 件のコメント:
コメントを投稿