Our Blog. We have some things we'd like to share.

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….

Tagged:

3 Responses to “Mongrel vs. WEBrick”

  1. 1

    April 4th, 2007 @ 12:21 am Max Lapshin Hollered:

    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. 2

    April 4th, 2007 @ 5:27 pm Keith Fahlgren Hollered:

    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. 3

    April 4th, 2007 @ 6:07 pm steveny Hollered:

    Done!

Leave a Response


Cincinnati 513.298.1865

Virginia 7875 Promontory Court Dunn Loring, VA 22027

Kentucky 12910 Shelbyville Road Suite 310 Louisville, KY 40243 502.245.6756

© 2010 Mission Data twitter