Thin and blocking calls - sticky situation

Skip to first unread message

Martin Konecny

Jan 28, 2015, 11:01:52 PM1/28/15

I chose Ruby for a side project some time ago, and used Thin as my primary server. At the time EventMachine and "evented web-server" didn't mean much to me so I ignored it - I just knew Thin was fast

Recently I've come back to understand these terms and have realized I've written my server code completely wrong. I have many blocking operations such as calls to the database, calls to redis, calls the third party API's all of which must be blocking the single reactor thread in EventMachine. None of the drivers I'm using have support enabled for EventMachine.

It seems that I have two options at the moment

  1. Switch to a threaded server
  2. Stay with an evented server such as Thin, but change all my blocking network calls to non-blocking.

I've noticed that thin provides a --threaded option as well, so perhaps this is a good short-term solution, since theoretically any blocking network calls will only affect that particular thread, and not the threads of other requests. Is this correct?

As a side question, does Thin benefit from using a threaded mode, as well as using non-blocking calls in each thread? Can I still use database drivers designed for EventMachine in this threaded mode, and is there an advantage for doing so?

Marc-André Cournoyer

Jan 29, 2015, 10:06:20 AM1/29/15
Usually, under any type of server, making calls to 3rd party APIs in your web app is a bad idea. Use a background worker to do it asynchronously.

For the DB and Redis, for most requests those should be pretty fast. If there is no IO wait (waiting for data to arrive), there will be no difference between blocking and non-blocking. If one is too slow, perhaps move it to a background worker too.

That being said, the best way to use Thin is with only non-blocking calls, which is not an easy thing to do in Ruby...

You received this message because you are subscribed to the Google Groups "thin-ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

Reply all
Reply to author
0 new messages