Why is thread-safe disabled by default under production?

One of the things I love in Rails are the good defaults. Now that jQuery is the default Javascript framework it got even better! :smiley: Maybe sometime Rspec will get there too :wink: (Just kidding - although I prefer Rspec, I don't want to start this discussion)

But one thing that has always bothered me is why config.threadsafe! is disabled by default in production.rb.

This seems really odd to me.

Could someone explain me the reasons behind this decision?

Or, is it time for changing this default?

Best regards,

Rodrigo.

I think it is off by default implicitly in all environments and the line in production.rb is a hint to turn it on. IIRC, it hints or warns that you would have to write thread-safe code to begin with and to use this carefully. Since most people do not write thread-safe code and doing so is the exception vs the rule, then this setting makes sense to most I have talked to. My opinion.

- Ken

Hi Ken, could you think in some concrete example of what you consider a common non-thread-safe code to justify not enabling it by default?

I guess most people, with background in other frameworks and languages, will indeed expect their web application to be multi-thread.

It was actually a surprise for me when I first realized Rails wasn't multi-thread the first time I used, when it didn't support the threaded model yet.

So, maybe Rails still doesn't enable multi-thread by default for historical reasons, like MRI Ruby 1.8 poor performance in threaded environments due to a lack of support of system threads (only green threads supported) and the lack of support of Rails itself in its first versions.

But JRuby has always support great concurrency and now that MRI 1.9 has better thread support too, maybe the only reason for not enabling the "config.threadsafe!" under production by default is just a historical consequence.

Actually, I've seen some people working to make "autoload" thread-safe in MRI so that it could also be enabled for development mode after a while...

Maybe Rails 3.1 would provide a great opportunity to change this default.

I am no expert and can only defer to a few old articles.

http://m.onkey.org/thread-safety-for-your-rails

- Ken