Mongrel vs. WEBrick

We had the need to hook up a simple ruby web process (non-rails) to our production apache server. As Leslie Hensley pointed out, fcgi and scgi are on the way out, and mongrel + mod_proxy_balancer is the new way to go. We use mongrel extensively in our rails deploys, but always just used WEBrick to do simple serving. To make a long story short, we had to ask ourselves….is mongrel that much better (and in this case better == faster) than WEBrick?

At first I decided my test would just respond with the yamlized request (just like the mongrel sample did). This worked fine but there was a significant size difference in the two documents (WEBrick’s was much bigger). In the end, I just decided to respond with a few bytes of text.

The Code

mongrel_service.rb:

require 'rubygems'
require 'mongrel'
require 'yaml'

class SimpleHandler < Mongrel::HttpHandler
  def process(request, response)
    response.start do |head,out|
      head["Content-Type"] = "text/html"
      out << "I am mongrel, hear me roar"
    end
  end
end

config = Mongrel::Configurator.new :host => "localhost", :port => 4000 do
  listener {uri "/", :handler => SimpleHandler.new}
  trap("INT") { stop }
  run
end

config.join

webrick_service.rb:

require 'webrick'
require 'yaml'
include WEBrick

class SimpleServlet < HTTPServlet::AbstractServlet
  def do_GET(request, response)
    response["Content-Type"] = "text/html"
    response.body = "I am WEBrick, hear me roar"
  end
end

s = HTTPServer.new( :Port => 4001 )
s.mount("/", SimpleServlet)
trap('INT'){ s.shutdown }
s.start

The Test

There are serveral good benchmarking tools available, but I had apache bench (ab) handy, so that is what I used. I just used the stock gem install of mongrel and the WEBrick that comes with ruby 1.8.4 (the one non-stock change I made was to comment out access logging for WEBrick since mongrel doesn’t log by default).

The Results

Total Requests Concurrent Connections WEBrick (seconds) Mongrel (seconds)
1000 1 1.889523 0.365838
10000 10 19.443034 4.411788
10000 100 20.906522 4.174591

The Conclusion

Looks like mongrel it is….

del.icio.us:Mongrel vs. WEBrick digg:Mongrel vs. WEBrick spurl:Mongrel vs. WEBrick wists:Mongrel vs. WEBrick simpy:Mongrel vs. WEBrick newsvine:Mongrel vs. WEBrick blinklist:Mongrel vs. WEBrick furl:Mongrel vs. WEBrick reddit:Mongrel vs. WEBrick fark:Mongrel vs. WEBrick blogmarks:Mongrel vs. WEBrick Y!:Mongrel vs. WEBrick smarking:Mongrel vs. WEBrick magnolia:Mongrel vs. WEBrick segnalo:Mongrel vs. WEBrick gifttagging:Mongrel vs. WEBrick

3 Responses to “Mongrel vs. WEBrick”

  1. Max Lapshin Says:

    I’m now thinking about refusing from mod_proxy_balancer to HAProxy, because of it’s flag connection_count=1.
    mod_proxy_balancer doesn’t know, that mongrel can serve only one request per second

  2. Keith Fahlgren Says:

    Hey,

    You probably want to link to the regular Mongrel docs rather than my copy: http://mongrel.rubyforge.org/rdoc/index.html

    Thanks,
    Keith

  3. steveny Says:

    Done!

Leave a Reply