0

我已经使用 编写了一个“Hello World”应用程序Goliath,我决定安装Grape在它上面:

#!/usr/bin/env ruby

require 'rubygems'
require 'bundler/setup'
Bundler.setup :default
require 'goliath'
require 'grape'   # <-- Comment out this line will hugely increase performance, but why?

class Server < Goliath::API
  def response(env)
    [200, {}, 'Hello, world!']
  end
end

我对其进行了基准测试:

ab -n 1000 -c 100 http://localhost:9000/

它表明每秒可以处理大约 250 个请求。但是当我注释掉这行时require 'grape',这个值突然增加到了 700 左右。有人可以回答为什么简单require可以带来如此巨大的差异吗?

PS我使用MRI 2.2.2

4

1 回答 1

0

您是否在生产模式下运行 Goliath?您必须设置 -e prod 它将在每个请求上重新加载代码。

于 2015-10-17T00:07:34.317 回答