Simple problem, I have a legacy Rails 2.3 application and it takes quite long to do anything. rake
takes over 25 seconds, but it doesn't look like anything is really happening.
简单的问题,我有一个传统的Rails 2.3应用程序,它需要很长时间才能做任何事情。耙子需要超过25秒,但看起来并没有真正发生任何事情。
Is there any simple way I can just get some kind of profiler dump from the time when the app is loading, to see which methods take the longest time?
有没有简单的方法,我可以从应用程序加载时获得某种分析器转储,看看哪些方法花费最长的时间?
A solution for both Rails 2.3 and 3.1 would be even more helpful.
Rails 2.3和3.1的解决方案将更有帮助。
2 个解决方案
#1
10
Profile a rake task that requires the rails environment, something like this:
描述需要rails环境的rake任务,如下所示:
desc "Load it"
task :loadit => :environment do
end
then profile with ruby-prof
然后用ruby-prof描述
ruby -Ilib -S ruby-prof -p graph_html `which rake` loadit > profile.html
It ought to work with rails 2.3 have only tested it on 3.x but I see no reason why it should not work.
它应该使用rails 2.3仅在3.x上测试它但我认为没有理由它不应该工作。
#2
1
You could start your application with a profiler hooked in, e.g. ruby-prof or perftools.rb. While it's still starting up, launch a HTTP query against it, which would try go GET
a /kill_me
route as soon as the application starts. /kill_me
could cause your application to gracefully die by calling exit
. As a result you've got a profile of your startup.
您可以使用挂钩的分析器启动您的应用程序,例如ruby-prof或perftools.rb。虽然它仍在启动,但是针对它启动HTTP查询,一旦应用程序启动,它将尝试GET a / kill_me路由。 / kill_me可能会通过调用exit使您的应用程序正常死亡。结果你得到了你的创业公司简介。
#1
10
Profile a rake task that requires the rails environment, something like this:
描述需要rails环境的rake任务,如下所示:
desc "Load it"
task :loadit => :environment do
end
then profile with ruby-prof
然后用ruby-prof描述
ruby -Ilib -S ruby-prof -p graph_html `which rake` loadit > profile.html
It ought to work with rails 2.3 have only tested it on 3.x but I see no reason why it should not work.
它应该使用rails 2.3仅在3.x上测试它但我认为没有理由它不应该工作。
#2
1
You could start your application with a profiler hooked in, e.g. ruby-prof or perftools.rb. While it's still starting up, launch a HTTP query against it, which would try go GET
a /kill_me
route as soon as the application starts. /kill_me
could cause your application to gracefully die by calling exit
. As a result you've got a profile of your startup.
您可以使用挂钩的分析器启动您的应用程序,例如ruby-prof或perftools.rb。虽然它仍在启动,但是针对它启动HTTP查询,一旦应用程序启动,它将尝试GET a / kill_me路由。 / kill_me可能会通过调用exit使您的应用程序正常死亡。结果你得到了你的创业公司简介。