I've written a 'Hello World' app using Goliath
, and I decided to mount Grape
on top of it:
#!/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
I benchmarked it:
ab -n 1000 -c 100 http://localhost:9000/
It shows that about 250 requests can be handled per second. But when I comment out the line require 'grape'
, this value suddenly increased to about 700. Can anybody answer why the simple require
can bring such a huge difference?
P.S. I use MRI 2.2.2
Are you running Goliath in production mode? You have to set -e prod of it will do code re-loading on each request.