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

neverlandxy_naix · April 27, 2013 · Last by luikore replied at April 27, 2013 · 3265 hits

请问各位是如何对 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 就可以吧...

You need to Sign in before reply, if you don't have an account, please Sign up first.