Thin and blocking calls - sticky situation

103 views
Skip to first unread message

Martin Konecny

unread,
Jan 28, 2015, 11:01:52 PM1/28/15
to thin...@googlegroups.com

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

unread,
Jan 29, 2015, 10:06:20 AM1/29/15
to thin...@googlegroups.com
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 thin-ruby+...@googlegroups.com.
To post to this group, send email to thin...@googlegroups.com.
Visit this group at http://groups.google.com/group/thin-ruby.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages