1

Recently I have switched my Rails apps from using WEBrick to THIN because I was told that THIN can thread the app to handle more requests concurrently.

However, what I am confused about is the different documentations showing different way to using THIN: With gem 'thin' installed, 'rails s' will automatically use THIN. Does this also enable multithreading on THIN? Running with 'bundle exec thin start --threaded', if I don't specify that I want threading, will it just be single threaded like WEBrick?

Khanetor
  • 11,595
  • 8
  • 40
  • 76
  • Can you not test this quite easily? I suppose you could make a controller action that just loops forever, and then request another page from your app to see if it executes that requests simultaneously in a different thread. That is, in a controller make `def busy;sleep(1) while 1;end`, then request `localhost/controller/busy` and additionally request another page. In WEBrick on my machine that would not load since the only thread is processing the first request (forever). I suppose with proper multithreading the second page would still load. – Daniël Knippers Jul 01 '14 at 09:19
  • So I did as you said, and having Thin web server does not help with multithreading. With the --threaded option, Thin does not serve anything, and all my requests are in pending indefinitely. I also tried pushing the code to heroku if the production environment is any different, and unfortunately it is not. – Khanetor Jul 01 '14 at 17:30
  • That's strange. I cannot test with Thin myself, it fails to install. Anyway, you could try [this +1 answer](http://stackoverflow.com/questions/14027151/how-rails-resolve-multi-requests-at-the-same-time#answer-20940926) to modify WEBrick to become multithreaded. I found it after commenting and it did work for me (i.e., the second page was served after requesting `/busy` first). Note that as it says, you need `config.cache_classes = true` and `config.eager_load = true` in your `config/environment/*.rb` – Daniël Knippers Jul 01 '14 at 17:33

0 Answers0