mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
A Ruby/Rack web server built for parallelism
![]() git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@29 19e92222-5c0b-0410-8929-a290d50e31e9 |
||
---|---|---|
bin | ||
examples | ||
ext/http11 | ||
lib | ||
test | ||
tools | ||
COPYING | ||
LICENSE | ||
Rakefile | ||
README | ||
setup.rb |
= Mongrel: Simple Fast Mostly Ruby Web Server Mongrel is a small library that provides a very fast HTTP 1.1 server for Ruby web applications. It is not particular to any framework, and is intended to be just enough to get a web application running behind a more complete and robust web server. What makes Mongrel so fast is the careful use of a C extension to provide fast HTTP 1.1 protocol parsing and fast URI lookup. This combination makes the server scream without too many portability issues. == Status The 0.3 release is the first official release to start supporting Ruby on Rails and to have a more complete DirHandler for serving directories of files. This release is actually closer to a full functioning web server than the previous releases. The Rails support is pretty rough right now, but check out the bin/mongrel_rails file, which should be installed into your PATH if you use a gem. You should be able to do the following to run your Rails applications: > cd myrailsapp > mongrel_rails 0.0.0.0 3000 And then hit http://localhost:3000/ to see your app. One thing is that if you have a public/index.html file then you'll get that served instead of your Rails application. People with the daemons gem installed will see that mongrel_rails will go into the background. You can kill it with: > kill -TERM `cat log/mongrel-3000.pid` Where "3000" is whatever port you told it to listen on when you ran it. The file serving is still a little rough and the redirects might not work well, but try it out and tell me about any weird errors. File uploads will definitely have some problems. == Install It doesn't explicitly require Camping, but if you want to run the examples/camping/ examples then you'll need to install Camping 1.2 at least (and redcloth I think). These are all available from RubyGems. The library consists of a C extension so you'll need a C compiler or at least a friend who can build it for you. Finally, the source includes a setup.rb for those who hate RubyGems. == Usage The examples/simpletest.rb file has the following code as the simplest example: require 'mongrel' class SimpleHandler < Mongrel::HttpHandler def process(request, response) response.start(200) do |head,out| head["Content-Type"] = "text/plain" out.write("hello!\n") end end end h = Mongrel::HttpServer.new("0.0.0.0", "3000") h.register("/test", SimpleHandler.new) h.register("/files", DirHandler.new(".")) h.run.join If you run this and access port 3000 with a browser it will say "hello!". If you access it with any url other than "/test" it will give a simple 404. Check out the Mongrel::Error404Handler for a basic way to give a more complex 404 message. This also shows the DirHandler with directory listings. This is still rough but it should work for basic hosting. *File extension to mime type mapping is missing though.* == Speed The 0.2.1 release probably consists of the most effort I've ever put into tuning a Ruby library for speed. It consists of nearly everything I could think of to make Mongrel the fastest Ruby HTTP library possible. I've tried about seven different architectures and IO processing methods and none of them make it any faster. In short: Mongrel is amazingly fast considering Ruby's speed limitations. This release also brings in controllable threads that you can scale to meet your needs to do your processing. Simple pass in the HttpServer.new third optional parameter: h = Mongrel::HttpServer.new("0.0.0.0", "3000", 40) Which will make 40 thread processors. Right now the optimal setting is up in the air, but 20 seemed to be about the sweet spot on my systems. The limited processors also means that you can use ActiveRecord as-is and it will create a matching database connection for each processor thread. More on this in future releases. With this release I'm hoping that I've created a nice solid fast as hell core upon which I can build the remaining features I want in Mongrel. == The Future With the core of Mongrel completed I'm now turning to the next set of features to make Mongrel useful for hosting web applications in a heavily utilized production environment. Right now I'm looking at: * An idea I've had for an insane caching handler which could speed up quite a few deployments. Overall though the goal of Mongrel is to be just enough HTTP to serve a Ruby web application that sits behind a more complete web server. Everything in the next will focus on actually hosting the major web frameworks for Ruby: * Camping -- because it's already done (thanks Why). * Ruby on Rails -- that's where my bread is buttered right now. * Nitro -- Nitro folks have already hooked this up and started using it. Nice. * ????? -- Others people might be interested in. == Contact E-mail zedshaw at zedshaw.com and I'll help. Comments about the API are welcome.