如何分析 Rails 应用程序的启动?
问题很简单,我有一个遗留的 Rails 2.3 应用程序,做任何事情都需要很长时间。 rake
花费了超过 25 秒,但看起来并没有真正发生任何事情。
有没有什么简单的方法可以从应用程序加载时获取某种探查器转储,以查看哪些方法花费最长的时间?
针对 Rails 2.3 和 3.1 的解决方案会更有帮助。
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
分析需要 Rails 环境的 rake 任务,如下所示:
然后使用 ruby-prof 进行分析
它应该可以与 Rails 2.3 一起使用,只在 3.x 上进行了测试,但我看不出为什么应该这样做不工作。
Profile a rake task that requires the rails environment, something like this:
then profile with ruby-prof
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.
您可以使用连接的分析器来启动应用程序,例如 ruby-prof 或 perftools.rb。当它仍在启动时,对其启动 HTTP 查询,该查询将在应用程序启动后立即尝试
GET
/kill_me
路由。/kill_me
可能会通过调用exit
导致您的应用程序正常终止。这样您就获得了您的初创公司的简介。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 callingexit
. As a result you've got a profile of your startup.