openSUSE:Appliances events workshop Nuremberg 2010 projects WebYaST Performance
WebYast Performance
团队
负责人: Michal Žugec
成员: Jozef Uhliarik
目标
这里的目标是找到改进 WebYaST 性能的可能方法。
原因
- 重新加载单个页面需要几秒钟
- 有一些关于改进性能的请求
- 我们甚至不知道性能瓶颈在哪里
任务
替换 XML 解析器
- 我们使用的 rexml 解析器与其他解析器(nokogiri、libxml-ruby、hpricot)相比非常慢
- 唯一的原因是它内置于标准 rails 中
- 根据我们的测试,使用另一个解析器(nokogiri 或 libxml-ruby)可以提高大约 15% 的性能
- 也许我们可以从用 JSON 替换 XML 中受益
查找并修复性能瓶颈
- 我们使用 RubyProf 创建 webclient 的性能分析报告,并使用 kcachegrind 来可视化它
- 它花费大部分时间等待后端响应
- 我们也需要分析后端
结果
XML 解析器
rexml
- 这是我们现在正在使用的
- test/functional/groups_controller_test.rb
完成于 4.307689 秒。完成于 4.31859 秒。完成于 4.2826 秒。
- Firefox https://:54984/groups
8.55s, 8.75s, 8.67s
libxml
- test/functional/groups_controller_test.rb
完成于 3.218182 秒。完成于 2.951006 秒。完成于 3.040806 秒。
- Firefox https://:54984/groups
7.4s, 7.61s, 7.4s
nokogiri
- test/functional/groups_controller_test.rb
完成于 2.967758 秒。完成于 3.04099 秒。完成于 2.992017 秒。
- Firefox https://:54984/groups
7.66s, 7.43s, 7.11s
性能分析图
require 'ruby-prof'
RubyProf.start
# code we want to profile
all_groups=Group.find :all
result = RubyProf.stop
printer = RubyProf::CallTreePrinter.new(result)
printer.print(File.new ('/tmp/profiling.prof', 'w+'), :min_percent=>00)
然后您可以在查看器中看到性能分析图
kcachegrind /tmp/profiling.prof