Thin 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).
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!
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/)
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…
Pingback: Montreal on Rails » Blog Archive » Thin web server, made in Montreal!
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!
Pingback: Jerry Seinfeld on Ruby
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.
Pingback: links for 2008-01-05 « Bloggitation
Pingback: web1979 » Blog Archive » Thin: A New (made-in-montreal) Webserver
@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.
Pingback: New Rails-based Webserver-Aptly Named "Thin"
Pingback: Controle de versões com Git — Learning on Rails
@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)
Pingback: Rails Magnet
Pingback: Thin : A Followup! « Marc-André Cournoyer’s blog
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 !
Pingback: Head On » Blog Archive » links for 2008-01-13
Pingback: :: 2web :: » Blog Archive » Zed + Rant = Exôdo Railer?
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
please ask support questions on http://groups.google.com/group/thin-ruby/topics
Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.
Just got thin working. I needed to:
sudo ln -s /opt/ruby1.9.1/bin/thin /usr/bin/thin
to get it working (Ubuntu 9.04)
Question: How do I run it in a verbose manner to see what is happening with requests to the server, in a development mode, to debug, etc?
sanjaya@shala:~$ thin -h
Usage: thin [options] start|stop|restart|config|install
Server options:
-a, –address HOST bind to HOST address (default: 0.0.0.0)
-p, –port PORT use PORT (default: 3000)
-S, –socket FILE bind to unix domain socket
-y, –swiftiply [KEY] Run using swiftiply
-A, –adapter NAME Rack adapter to use (default: autodetect)
(rails, ramaze, halcyon, merb, mack, mack, file)
-R, –rackup FILE Load a Rack config file instead of Rack adapter
-c, –chdir DIR Change to dir before starting
–stats PATH Mount the Stats adapter under PATH
Adapter options:
-e, –environment ENV Framework environment (default: development)
–prefix PATH Mount the app under PATH (start with /)
Daemon options:
-d, –daemonize Run daemonized in the background
-l, –log FILE File to redirect output (default: log/thin.log)
-P, –pid FILE File to store PID (default: tmp/pids/thin.pid)
-u, –user NAME User to run daemon as (use with -g)
-g, –group NAME Group to run daemon as (use with -u)
–tag NAME Additional text to display in process listing
Cluster options:
-s, –servers NUM Number of servers to start
-o, –only NUM Send command to only one server of the cluster
-C, –config FILE Load options from config file
–all [DIR] Send command to each config files in DIR
-O, –onebyone Restart the cluster one by one (only works with restart command)
-w, –wait NUM Maximum wait time for server to be started in seconds (use with -O)
Tuning options:
-b, –backend CLASS Backend to use, full classname
-t, –timeout SEC Request or command timeout in sec (default: 30)
-f, –force Force the execution of the command
–max-conns NUM Maximum number of open file descriptors (default: 1024)
Might require sudo to set higher then 1024
–max-persistent-conns NUM Maximum number of persistent connections
(default: 512)
–threaded Call the Rack application in threads [experimental]
–no-epoll Disable the use of epoll
Common options:
-r, –require FILE require the library
-D, –debug Set debbuging on
-V, –trace Set tracing on (log raw request/response)
-h, –help Show this message
-v, –version Show version
The log output is setup by the code in script/server. You can specify which server to use:
script/server thin
Cool! I’ll wait for the stable version.
Thanks so much for this excellent information! I came across your site surfing on Google. Great info and I’m now addicted to your blog!
Pingback: Brian's Blog | Rails install on Win 7
Thin was literally TOO easy to setup.
I had planned taking the 1.5 hr bus ride in to enable it with my rails application. 2 minutes later I’m done installing, and wishing I had brought my microcontroller along with me, because now I’m doing nothing.
Hi, this weekend is nice in support of me, since this point in time i am reading this
wonderful educational article here at my home.
Hey there, You have done a fantastic job. I will definitely digg it and personally recommend to my friends. I’m sure they will be benefited from this site.
Very creatiive post