我已经使用 编写了一个“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