Thin - A fast and simple web server

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 !

54 Responses to “Thin - A fast and simple web server”


  1. 1 Frank Lamontagne January 3, 2008 at 11:06 pm

    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!

  2. 2 Dan Simard January 4, 2008 at 1:42 am

    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!

  3. 3 James Golick January 4, 2008 at 8:48 am

    Woohoo! I can finally blog about this!

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

  4. 4 macournoyer January 4, 2008 at 8:52 am

    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!

  5. 5 Adam January 4, 2008 at 10:19 am

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

  6. 6 macournoyer January 4, 2008 at 10:39 am

    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

  7. 7 bobmccormick January 4, 2008 at 11:52 am

    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/)

  8. 8 Fernando Correia January 4, 2008 at 11:52 am

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

  9. 9 Adrian Madrid January 4, 2008 at 2:07 pm

    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!

  10. 10 Dan Simard January 4, 2008 at 2:10 pm

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

  11. 11 mehdi January 4, 2008 at 4:22 pm

    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

  12. 12 Yugurta January 4, 2008 at 4:30 pm

    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

  13. 13 NetManiac January 4, 2008 at 4:53 pm

    @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

  14. 14 Fred Brunel January 4, 2008 at 5:25 pm

    Hi Marc-Andre,

    Congrats for Thin!

    I’ll definitely try it!

  15. 15 Zed A. Shaw January 4, 2008 at 6:38 pm

    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.

  16. 16 macournoyer January 4, 2008 at 8:19 pm

    @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

  17. 17 free4re January 4, 2008 at 9:57 pm

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

  18. 18 macournoyer January 4, 2008 at 10:00 pm

    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.

  19. 19 Denis Canuel January 4, 2008 at 10:43 pm

    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! :)

  20. 20 macournoyer January 4, 2008 at 11:27 pm

    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.

  21. 21 danielharan January 4, 2008 at 11:28 pm

    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. :)

  22. 22 Seth January 4, 2008 at 11:29 pm

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

    Someone get to work :>

  23. 23 khelll January 5, 2008 at 11:53 am

    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

  24. 24 Josh January 5, 2008 at 3:05 pm

    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.

  25. 25 Josh January 5, 2008 at 3:07 pm

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

  26. 26 macournoyer January 5, 2008 at 3:14 pm

    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=

  27. 27 macournoyer January 5, 2008 at 3:16 pm

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

    You can try installing the latest version:

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

  28. 28 Stephen January 5, 2008 at 5:19 pm

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

  29. 29 khelll January 6, 2008 at 6:14 am

    @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

  30. 30 macournoyer January 6, 2008 at 7:19 pm

    @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

  31. 31 Yugurta January 8, 2008 at 12:39 pm

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

  32. 32 macournoyer January 8, 2008 at 12:56 pm

    @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 ^

  33. 33 Yugurta January 8, 2008 at 2:11 pm

    @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

  34. 34 Yugurta January 8, 2008 at 3:28 pm

    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.

  35. 35 macournoyer January 8, 2008 at 4:48 pm

    @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!

  36. 36 Carlos Aquino January 9, 2008 at 3:06 am

    Error on Debian :

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

  37. 37 Yugurta January 9, 2008 at 9:40 am

    @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)

  38. 38 Wyatt January 11, 2008 at 8:21 am

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

  39. 39 macournoyer January 11, 2008 at 1:00 pm

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

  40. 40 Heera January 12, 2008 at 10:44 am

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

    Salute !

  41. 41 chetanM February 15, 2008 at 5:10 am

    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

  42. 42 chetanM February 24, 2008 at 5:37 am

    #! /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

  43. 43 Tomas March 3, 2008 at 8:54 am

    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

  44. 44 Dedicated Hosting Provider March 24, 2008 at 12:32 pm

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

  1. 1 Montreal on Rails » Blog Archive » Thin web server, made in Montreal! Trackback on January 4, 2008 at 2:37 pm
  2. 2 Jerry Seinfeld on Ruby Trackback on January 4, 2008 at 5:51 pm
  3. 3 links for 2008-01-05 « Bloggitation Trackback on January 4, 2008 at 7:22 pm
  4. 4 web1979 » Blog Archive » Thin: A New (made-in-montreal) Webserver Trackback on January 4, 2008 at 7:41 pm
  5. 5 New Rails-based Webserver-Aptly Named "Thin" Trackback on January 5, 2008 at 8:08 pm
  6. 6 Controle de versões com Git — Learning on Rails Trackback on January 5, 2008 at 10:48 pm
  7. 7 Rails Magnet Trackback on January 10, 2008 at 5:14 am
  8. 8 Thin : A Followup! « Marc-André Cournoyer’s blog Trackback on January 10, 2008 at 10:07 am
  9. 9 Head On » Blog Archive » links for 2008-01-13 Trackback on January 12, 2008 at 9:19 pm
  10. 10 :: 2web :: » Blog Archive » Zed + Rant = Exôdo Railer? Trackback on January 15, 2008 at 8:31 pm

Leave a Reply




RefactorMyCode.comrefactorer Recommend Me

Top Clicks

  • None
Top Blogues page counter Add to Technorati Favorites

Blog Stats

  • 83,805 hits