RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

How Do I Know Whether My Rails App Is Thread-safe or Not?

Heroku now recommends using Puma as the app server for your Rails apps. It will help you get more juice out of a dyno, but comes with a caveat: your app needs to be thread-safe. But how can you make sure if that’s the case with your app? Let’s find out.

Comments

Here’s the recap of the article:

To make a Rails app thread-safe, you have to make sure the code is thread-safe on three different levels.

  • The Rails framework and its dependencies
  • Your app code
  • Any third party code you use

The first part is handled for you, unless you do stupid shit with it. The rest is your responsibility.

The main thing to keep in mind is to never mutate data that is shared across threads. Most often, this happens through class variables, class instance variables, or by accidentally mutating objects that are referenced by a constant.

There are, however, some pretty esoteric ways an app can end up thread-unsafe, so be sure to track down and fix the last remaining threading issues while running in production.

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in