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 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