January 3, 2008...9:46 pm

Thin – A fast and simple web server

Jump to Comments

ThinThin is a web server that glues together 3 of the best Ruby libraries in web history:

  • the Mongrel parser: the root of Mongrel speed and security
  • Event Machine: a network I/O library with extremely high scalability, performance and stability
  • Rack: a minimal interface between web servers and Ruby frameworks

Which makes it, with all humble humility, the most secure, stable, fast and extensible Ruby web server ever built, bundled in an easy to use gem for your own pleasure.

Why another web server ?

Thin started as an experiment to build an 100% Ruby singled threaded server which ended up being as fast as Mongrel on some cases (like handling Rails request). But that was not enough. Using the EventMachine library the performance and stability are now more impressive then a 500 pounds guy standing on one hand and juggling with the other.

It’s less then 500 lines of clean and fully tested Ruby code plus the customized Mongrel parser (written in C).

Faster then Mongrel ? Yeah right !

Yes it is! It’s even faster then the patched version of Mongrel that uses EventMachine (aka Evented Mongrel).
Request / seconds comparison

Try it

sudo gem install thin

Then in your Rails application directory:

thin start

You can also use it with any framework that support Rack. More info on the usage page.

More alpha then the Greek letter

This is the first experimental release. If you use this on your production server right now you are stupid, looking for extreme sensations or trying to find a way to get fired.

If you’d like to help, have fun or report a bug, join me in the project Google Group and get the code:

git clone http://code.macournoyer.com/git/thin.git

Stay tuned for updates and releases!

If you care, Digg it or Reddit it !

60 Comments

  • I don’t know what to say… you’re a real “machine”, aren’t you?? haha it’s great I can’t wait to try it out!

  • I don’t know what to say! When I first read this post, I thought that it was a server that you were only talking about and that it was written by somebody else. I will surely try it out. Congrats!

  • Woohoo! I can finally blog about this!

    Congrats on the launch, MA – this is an awesome piece of software.

  • If I haven’t met you both I’d be sure you’re the same person, starting with the same sentence, posting at the same time all the time!

    Thx to you 2 (or 1 ?!)! Let me know if you got any problem or suggestion to make my project better!

  • Awesome. As a point of curiosity, how does this compare to using Merb? Or is it too different to compare?

  • Hi Adam,

    Merb is a framework. Thin is a web server.

    Merb is built around Mongrel but has a Rack adapter which allows it to be used w/ any Rack handler, so with Thin.

    In other words: Thin can run Merb apps but I’m not sure it’s gonna be faster in this case since Merb was build specially for Mongrel (Merb = Mongrel + ERB), I’ll have to run some benchmarks.

    Check this thread on the mailing list for instructions and more info: http://groups.google.com/group/thin-ruby/browse_thread/thread/e9e5de36bba536e5

  • Does Thin run multiple Rails processes? Or do you still need to put it behind a load balancing proxy like you do with Mongrel? (like this config: http://blog.codahale.com/2006/06/19/time-for-a-grown-up-server-rails-mongrel-apache-capistrano-and-you/)

  • Fernando Correia

    Congratulations! This is great news. I’ll wait for the stable version…

  • This is great! You put together exactly what I was looking for. I’ve been getting into EM lately and was into building an EM handler when Chuck Remes at the EM list mentioned your project. This is heaven! Mixing up Mongrel’s parser, EM and Rack is just a touch of genius. I’ll be playing with this and benchmarking it. I will let you know how I do.

    Thanks!

  • Oops! I guess I was as amazed as Frank Lamontagne. I didn’t read his comment but maybe I was unconsciously influenced by it…

  • [...] fellow MoRer, Marc-Andre Cournoyer, has outdone himself again!  He just released a Ruby web server named Thin that will give Mongrel a run for its money.  Congrats and thanks! [...]

  • Awesome !!

    Congratulation for you ! and long life for Thin ;-)

    Couldn’t resist to test it …. I’m putting it on my list for the next few days.

    Mehdi

  • That’s waht I got on windows:

    C:\ruby\bin>gem install thin
    Bulk updating Gem source index for: http://gems.rubyforge.org
    Install required dependency eventmachine? [Yn] Y
    Building native extensions. This could take a while…
    ERROR: While executing gem … (Gem::Installer::ExtensionBuildError)
    ERROR: Failed to build gem native extension.

    ruby extconf.rb install thin
    checking for windows.h… no
    *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of
    necessary libraries and/or headers. Check the mkmf.log file for more
    details. You may need configuration options.

    Provided configuration options:
    –with-opt-dir
    –without-opt-dir
    –with-opt-include
    –without-opt-include=${opt-dir}/include
    –with-opt-lib
    –without-opt-lib=${opt-dir}/lib
    –with-make-prog
    –srcdir=.
    –curdir
    –ruby=c:/ruby/bin/ruby

    Gem files will remain installed in C:/ruby/lib/ruby/gems/1.8/gems/eventmachine-0
    .10.0 for inspection.
    Results logged to C:/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.10.0/ext/gem_mak
    e.out

  • @Yugurta
    You have probably new and shine EventMachine gem installed on Your windows box, despite of those compilation errors. EM tries to compile C library and it fails since You have no compiler. EM 0.10 has pure ruby version, which is usable in Your case. In other words – Thin should work for You! I’m saying it as EM user – I have not tested Thin yet, so maybe there some other problems with Windows env

    You can try to install Event Machine version 0.8.1 which has binary package for Windows, but I don;t know if Thin depends on any later EM feature.

    http://rubyforge.org/frs/download.php/23665/eventmachine-win32-0.8.1.gem

  • Hi Marc-Andre,

    Congrats for Thin!

    I’ll definitely try it!

  • [...] From mhd commenting about the new ruby web server Thin [...]

  • Awesome job man. You should probably also check out Rev (http://rev.rubyforge.org) which is a light simple binding around libev (not libevent) and works only in Ruby 1.9. Tony is building a very nice API for it that you can use, and libev is very fast and small.

    Enjoy.

  • [...] Thin – A fast and simple web server Faster than Evented Mongrel. Less than 500 lines of Ruby (and a little C). (tags: ruby rails web sysadmin mongrel) [...]

  • [...] Marc-Andre Cournoyer released Thin, his very own Ruby Web server that is faster than even the fastest alternatives, (according to his [...]

  • @bobmccormick: Thin is exacly like Mongrel on that side, you’ll need multiple Rails processes for a web site with some traffic.

    @Adrian: glad you like my idea. I’m really interested to see you benchmarking results!

    @Yugurta: haven’t tried it on windows yet, but like NetManiac mentioned, it looks like a required lib is not building. Try running: “gem install eventmachine” before installing thin.

    @zed: thx a lot, I didn’t know about libev, I looked for libevent Ruby bindings but only found your dead Ruby/Event project. I’ll definitely benchmark it!

    Thx all for the nice comments, it’s very appreciated!

    Stay tuned for the next release

  • Awesome? How long, you think, before it can be used on a production server?

  • 3 year + or – 1095.75 days

    rough estimate

    :)

    A better reply would be: you tell me! If you feel like it, deploy an app using it and let me know if it works for you.

  • I’m curious… there’s some talk about how Ruby is not (or was not) fully scalable. How will this change the picture?

    Very cool though! :)

  • Denis, Ruby had some problems in the past with threads, Mongrel helped fixing those bugs in Ruby’s core but still, Ruby threads are not native (don’t use OS processes, so can’t take advantage of multicore processors). And threading is not the most scalable way of handle huge loads. Event-driven I/O can handle more requests and uses only one thread.

    Thin is more stable cause it can handle more requests without loosing any or crashing mainly because it’s running in a single thread.

  • Denis – I’m not sure there’s anything that can change the fact that there’s *talk* about scalability. It only took a couple days to have Twitter’s problems solved, but some VC’s still ask about it. :)

  • Cool, now where’s the info on how to replace my mongrel clusters with thin clusters?

    Someone get to work :>

  • usining kubuntt i installed the gem…

    and navigated to my rails app and
    tried to start thin but i keep getting

    bash: thin: command not found

  • Looks very cool – I find Mongrel fast, so I can’t wait to get it up and running. Unfortunately I’ve had exactly the same problem as Yugurta. I’m running Windows XP Home. I’ve tried doing gem install eventmachine, gem install eventmachine -0.10, and gem install eventmachine -0.8.1, but it doesn’t work. Hopefully I’ll get it running soon. Thanks for sharing.

  • To correct my previous post, when I ran the commands, I did include v, i.e. I actually did gem install -v0.10 not gem install -0.10 (so basically it should have worked).

  • hasn’t gem install eventmachine -v0.8.1 offered you a mswin version of the gem? This one should be precompiled for windows so you shouldn’t have any build error.

    If you’d like more support, you can ask a question on the google group: http://groups.google.com/group/thin-ruby/topics?start=

  • @khelll: you probably had errors during the build process.

    You can try installing the latest version:

    gem install thin –source http://code.macournoyer.com

  • @Seth, here’s a rake task to start and stop a cluster:

    http://groups.google.com/group/thin-ruby/browse_thread/thread/a639d1e20a1b0d75

    If you’re using Capistrano, adjust your deploy.rb accordingly.

  • [...] If you’d like to help, have fun or report a bug, join me in the project Google Group and get the code: Source: Thin – A fast and simple web server « Marc-André Cournoyer’s blog [...]

  • [...] seu último post, Fábio Akita falou sobre Git (e sobre o Thin, que também foi assunto mais cedo no Ruby Inside) e apontou um link com um guia que mostra como [...]

  • @macournoyer , did it , got

    Building native extensions. This could take a while…
    Successfully installed thin-0.5.0

    then

    khelll@khelll:~/d1g$ thin start
    bash: thin: command not found

  • @khell: run: ruby -rrubygems -e “puts require(‘thin’)”

    if that doesn’t raise any error, the gem script dir is probably not in your path. Make sure /usr/local/bin is in your path if you installed ruby in /usr/local

  • @marc
    very glad to know that we have ruby hackers in Montreal (I am in west-island) I hope more Ruby/Rails shops will open in the city so I can escape my java typing job :-)
    I cloudn’t try ‘thin’ because of EventMachine not installing on windows, I went to the weird (under construction) web site http://rubyeventmachine.com/ and got no tips.
    Anyway congralatuation for ‘thin’, I wonder what Zed ‘le fou’ is going to react to your server.

  • @Yugurta: you should come to the next MontrealOnRails : http://montrealonrails.com

    You can try installing Thin latest version, it should work on Windows.

    Zed wrote a nice comment up there ^

  • @marc: I saw Zed comment, I think he is a very nice guy (a gentleman).
    For ‘thin’ on windows it still doesn’t install properly (but pass eventMachine install) but don’t bother no serious hacker is using windows anyway…
    For MontrealOnRails I’ll try even if a tuesday is a bit hard for me (5h Garderie, 5h30 traffic 40-est, 6h30 stationnement sur st-laurent)
    But now I have the Montreal Rails community on my bookmarks and I will follow future events

  • Finally got it working on windows XP :-)

    The problem is the C/C++ compiler version test in ruby C:\ruby\lib\ruby\1.8\i386-mswin32\config.h, there is these 3 lines:

    #if _MSC_VER != 1200
    #error MSC version unmatch
    #endif

    I have Visual Studio 2003 and _MSC_VER should be 1310 I guess, so when building native windows extension update the test to #if _MSC_VER >= 1200 or remove the 3 lines test (that’s what I did)

    so native thin_parser was built and thin server started serving rails application fine on windows XP.

  • @Yugurta: very nice!!! I think you’re the first person to install it successfully on win :)

    I’d like to provide a precompiled version for windows users, can you send me your compiled files so I can package them up (or just send me the whole thin gem dir, should be in C:\ruby\lib\ruby\gem\1.8\gems\thin-0.5.1)

    thx a lot!

  • Error on Debian :

    aquino@adagas:~$ sudo gem install thin
    ERROR: While executing gem … (Gem::GemNotFoundException)
    Could not find thin (> 0) in any repository

  • @marc: No problem, I sent you zipped Thin gem folder to the address
    macournoyer at yahoo.ca (hope it’s the correct adress !)
    check spam folder may be yahoo will filter me (na…@gmail.com)

  • A new web server for rails – and it is Thin

    I’m looking forward to trying out Thin, a new web server for rails that’s built on Rack, Event Machine, and the Mongrel parser. The one downside of mongrel is that it does consume more memory that I would prefer and Thin may use somewhat less and de…

  • [...] Scratchpad « Thin – A fast and simple web server [...]

  • Nice work! I am very interested in a precompiled version for Windows users, too.

  • @Wyatt win32 gem should be part of the next release if all goes well

  • Heera is feeling anxious, surely it’s a great new platform am looking forward to its gr8 services.

    Salute !

  • [...] Thin – A fast and simple web server (tags: ruby server mongrel merb) These icons link to social bookmarking sites where readers can share and discover new web pages. [...]

  • [...] estiveram em tanta evidência. Alternativas ao Mongrel, vem também ganhando atenção, tal como o Thin – já que o Mongrel era desenvolvido pelo ex-ruby-guy Zed Shaw. A própria implementação da VM do [...]

  • Really its rocking

    I used thin cluster with apache mod_proxy

    meanwhile apache serving static & thin cluster having 3 port on dynamics

    is there any tricky setting for thin too boost performance

    congrats :wq

    chetanM

  • #! /bin/bash

    cd /app/home/current/

    if [ "$1" == "start" ] ;then
    echo “starting this cluster:”
    thin start -d -p44556 -Ptmp/pids/thin-44556.pid -l log/thin.44556.log
    thin start -d -p44557 -Ptmp/pids/thin-44557.pid -l log/thin.44557.log
    thin start -d -p44558 -Ptmp/pids/thin-44558.pid -l log/thin.44558.log

    elif [ "$1" == "stop" ] ;then
    echo “stoping the cluster:”
    thin stop -Ptmp/pids/thin-44556.pid
    thin stop -Ptmp/pids/thin-44557.pid
    thin stop -Ptmp/pids/thin-44558.pid
    else
    echo “usage chthin start OORR chthin stop”
    fi

    echo “done”

    this is safe to run with mod_proxy balancers

  • After numerous trials, I could install thin on Windows, the crucial part was to install the binary build of eventmachine, which is not the latest build, and to install think from source:

    gem install eventmachine -v0.8.1
    gem install thin –source http://code.macournoyer.com

  • Thin sounds like a pretty reliable and secure system. If the statistical analysis is accurate, Thin is provides a pretty awesome infrastructure.

  • I’ve this error too bash: thin: command not found, if you see in /var/lib/gems/1.8/bin there’s thin and it starts. Do you have to set this in the $PATH? when using ruby do i have to set this paths?

    Thanks a lot

  • For the previous post… do:
    sudo ln -s /var/lib/gems/1.8/* /usr/local/bin

    Thats it!

  • I need a little help, I could install it on windows:
    > thin-1.0.0-i386-mswin32
    > rack-0.9.1
    > eventmachine-0-12-0-i386-mswin32

    But when running ‘thin start’ I get the following error: (…)/eventmachine.rb:500:in ’start_tcp_server’: no acceptor

    I’ve read that this could be because the port is already in use, but this is not the case since I tried different ports using the -p option.

    Thanks!

  • Hello team ,

    We getting stuck with thin frequently showing mod_proxy balancer error with Apache .

    proxy: error reading status line from remote server 127.0.0.1
    proxy: Error reading from remote server

    Is there any solution on it .

    Regards

    chetanM

  • Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.


Leave a Reply