Sinatra 如何使用 ruby-prof 对 sinatra 进行性能测试

neverlandxy_naix · 2013年04月27日 · 最后由 luikore 回复于 2013年04月27日 · 3263 次阅读

请问各位是如何对 sinatra app 做性能测试呢?

我用了一个 ruby-prof 的 gem

新建了一个文件,在里面写入下列代码,本意是想在 每一个 get 请求上都调用 RubyProf ,可是实际执行后输出的是 Ruby 内部 define_method 的性能,并没有输入我每一次 get 请求的性能。
请问这样该如何去做?thanks

class Sinatra::Base

  class << self
    alias :oldget :get

    def get path, opts={}, &block
      RubyProf.start
      oldget(path, opts, &block)
      result = RubyProf.stop
      output_result(result)
    end

    private

    def output_result(result, filepath = "./config/ruby_prof.txt")
      File.open(filepath, 'a+') do |f|
        RubyProf::GraphPrinter.new(result).print(f)
      end
    end
  end

@luikore 有空能帮忙看一下吗?

#1 楼 @neverlandxy_naix prof 是找瓶颈用的,如果只想简单的看看平均一个请求要多久,用 ab 或者 siege 就可以吧...

需要 登录 后方可回复, 如果你还没有账号请 注册新账号