Rails 对过滤器链进行基准测试?
我正在对 Rails (2.3.5) 应用程序进行一些优化,但似乎找不到一种优雅的方法来对过滤器链进行基准测试。我正在使用以下内容测试该网站:
ab -n 200 -c 3 -i -k http://localtestingserver:80/test
/test 设置为控制器中没有任何内容,页面中也没有任何内容,因此它只是加载我们的默认过滤器链并渲染布局。每个请求平均需要 86 毫秒,很好。
当我禁用过滤器 (skip_filter filter_chain) 时,它会下降到 37ms,而如果没有布局 (render :layout => false),它会下降到 16ms。有没有一种方法可以在调用控制器之前(或者实际上是之后)进行基准测试,也许可以使用 Benchmark.realtime 将每个函数加载到过滤器链中?我可以输出请求中调用的所有过滤器的列表吗?
谢谢,
Dan
编辑
我正在使用 Hodel3000 记录器和 Oink,因此根据请求获取输出,例如:
Jan 27 17:56:55 testing rails[19611]: Memory usage: 98748 | PID: 19611
Jan 27 17:56:55 testing rails[19611]: Instantiation Breakdown: Total: 2 | Room: 1 | User: 1
Jan 27 17:56:55 testing rails[19611]: Completed in 240ms (View: 28, DB: 0) | 200 OK [/test]
我只是想更好地理解和分析调用控制器之前发生的情况 - 我可以分析控制器自己很好。就像上面请求中额外的 212 毫秒来自哪里。显然,我可以将代码放入我自己的每个 before_filters 中,但希望有一种方法可以一次性包装每个过滤器(例如来自包含的 gem 的过滤器等)。
I'm doing some optimisation on my Rails (2.3.5) app, and can't seem to find an elegant way of benchmarking the filter chain. I'm ab testing the site with something like:
ab -n 200 -c 3 -i -k http://localtestingserver:80/test
/test is setup with nothing in the controller and nothing in the page, so it's just loading our default filter chain plus rendering the layout. I get an average of 86ms per request, fine.
When I disable the filters (skip_filter filter_chain) it drops to 37ms, and without the layout (render :layout => false) it drops to 16ms. Is there a way I can benchmark, perhaps with Benchmark.realtime, each function being loaded in the filter chain, before the controller is called (or indeed after)? Can I output even a list of all filters being called on a request?
Thanks,
Dan
Edit
I'm using the Hodel3000 logger and Oink so get output per request like:
Jan 27 17:56:55 testing rails[19611]: Memory usage: 98748 | PID: 19611
Jan 27 17:56:55 testing rails[19611]: Instantiation Breakdown: Total: 2 | Room: 1 | User: 1
Jan 27 17:56:55 testing rails[19611]: Completed in 240ms (View: 28, DB: 0) | 200 OK [/test]
I'd just like to better understand and profile what happens before the controller is called - I can profile the controllers themselves fine. Like where the extra 212ms is from in the above request. Obviously I could drop code into each of my own before_filters, but hoped there was a way to wrap every filter in one go (like ones from included gems, etc.).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
性能测试 Rails 应用程序 指南看起来是一个不错的起点。
The Performance Testing Rails Applications guide looks like a good place to start.