2006-01-31 00:36:30 -05:00
|
|
|
= Mongrel: Simple Fast Mostly Ruby Web Server
|
2006-01-28 14:03:53 -05:00
|
|
|
|
|
|
|
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
|
2006-01-31 00:36:30 -05:00
|
|
|
scream without too many portability issues.
|
2006-01-28 14:03:53 -05:00
|
|
|
|
|
|
|
== Status
|
|
|
|
|
2006-02-14 07:19:02 -05:00
|
|
|
The 0.3.2 release supports Ruby On Rails much better than previously, and also
|
2006-02-11 22:37:38 -05:00
|
|
|
sports the beginning of a command and plugin infrastructure. This last part
|
|
|
|
isn't documented yet.
|
2006-02-11 14:35:06 -05:00
|
|
|
|
2006-02-11 22:37:38 -05:00
|
|
|
After you've installed (either with gem install mongrel or via source) you should
|
|
|
|
have the mongrel_rails command available in your PATH. Then you just do the following:
|
2006-02-11 14:35:06 -05:00
|
|
|
|
2006-02-11 22:37:38 -05:00
|
|
|
> cd myrailsapp
|
|
|
|
> mongrel_rails start
|
2006-02-11 14:35:06 -05:00
|
|
|
|
2006-02-11 22:37:38 -05:00
|
|
|
This will start it in the foreground so you can play with it. It runs your application
|
|
|
|
in production mode. To get help do:
|
2006-02-11 14:35:06 -05:00
|
|
|
|
2006-02-11 22:37:38 -05:00
|
|
|
> mongrel_rails start -h
|
2006-02-11 14:35:06 -05:00
|
|
|
|
2006-02-11 22:37:38 -05:00
|
|
|
Finally, you can then start in background mode (probably won't work in win32):
|
2006-02-11 14:35:06 -05:00
|
|
|
|
2006-02-11 22:37:38 -05:00
|
|
|
> mongrel_rails start -d
|
2006-02-11 14:35:06 -05:00
|
|
|
|
2006-02-11 22:37:38 -05:00
|
|
|
And you can stop it whenever you like with:
|
|
|
|
|
|
|
|
> mongrel_rails stop
|
|
|
|
|
|
|
|
All of which should be done from your application's directory. It writes the
|
|
|
|
PID of the process you ran into log/mongrel.pid.
|
2006-02-11 14:35:06 -05:00
|
|
|
|
2006-02-14 07:19:02 -05:00
|
|
|
There are also many more new options for configuring the rails runner including
|
|
|
|
changing to a different directory, adding more MIME types, and setting processor
|
|
|
|
threads and timeouts.
|
2006-01-28 14:03:53 -05:00
|
|
|
|
2006-01-31 00:36:30 -05:00
|
|
|
== Install
|
2006-01-28 14:03:53 -05:00
|
|
|
|
2006-01-31 00:36:30 -05:00
|
|
|
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).
|
2006-01-28 14:03:53 -05:00
|
|
|
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.
|
|
|
|
|
2006-01-31 00:36:30 -05:00
|
|
|
Finally, the source includes a setup.rb for those who hate RubyGems.
|
2006-01-28 14:03:53 -05:00
|
|
|
|
2006-02-11 14:35:06 -05:00
|
|
|
|
2006-01-28 14:03:53 -05:00
|
|
|
== Usage
|
|
|
|
|
2006-01-31 00:36:30 -05:00
|
|
|
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)
|
2006-02-15 08:00:04 -05:00
|
|
|
h.register("/files", Mongrel::DirHandler.new("."))
|
2006-01-31 00:36:30 -05:00
|
|
|
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.
|
2006-01-28 14:03:53 -05:00
|
|
|
|
2006-02-08 07:48:41 -05:00
|
|
|
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.*
|
|
|
|
|
|
|
|
|
2006-01-28 14:03:53 -05:00
|
|
|
== Speed
|
|
|
|
|
2006-02-11 22:37:38 -05:00
|
|
|
Like previous releases 0.3.1 continues the trend of making things
|
|
|
|
as fast as possible. It currently might be a little slower than
|
|
|
|
other releases but should hold up pretty good against at least
|
|
|
|
WEBrick (especially when running Rails).
|
2006-01-31 00:36:30 -05:00
|
|
|
|
2006-02-11 22:37:38 -05:00
|
|
|
As before you can control the number of processor threads (and thus
|
|
|
|
ActiveRecord database connections) with:
|
2006-01-31 00:36:30 -05:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
== 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.
|
2006-02-11 14:35:06 -05:00
|
|
|
* Nitro -- Nitro folks have already hooked this up and started using it. Nice.
|
2006-01-31 00:36:30 -05:00
|
|
|
* ????? -- Others people might be interested in.
|
2006-01-28 14:03:53 -05:00
|
|
|
|
|
|
|
== Contact
|
|
|
|
|
|
|
|
E-mail zedshaw at zedshaw.com and I'll help. Comments about the API are welcome.
|