Yes it is. Believe it or not, ActiveRecord is thread fucken’ safe. Probably since Fri, 23 Jul 2004
But before you start your crazy thread shit, you should set :ActiveRecord::Base.allow_concurrency = true |
ActiveRecord::Base.verify_active_connections! |
The latter is useful to close stale open db connections, as each thread sets up it’s own connection when you have allow_concurrency set to true.
DISCLAIMER : The above post contains expletives that may not be suitable for children and the disclaimer is at the wrong end.





Whoa, whoa. You can’t take away the one thing people always complain about when talking about ActiveRecord! That’s like taking…something away from something else. It’s absurd!
My understanding was that if the ruby VM has parallel threads running and dynamic class definition/alteration is occurring, that is VM-wide and therefore the threads can collide and screw each other up.
Zed Shaw wrote the following in “Katana Suicide Concurrency” on Jun 5 2006.
“I resisted doing this, but it’s going to come down sooner or later now that François SIMOND figured it out. Mongrel was protecting the world from the allow_concurrency “feature” but now it lets you kill yourself in obscenely horrible ways. If you set ActionController::Base.allow_concurrency=true in your config/environments/* then Mongrel will NOT guard the Rails Dispatcher. This means that you’ll get full threaded madness thrashing your Rails controllers until they die horribly slicing themselves into tiny little bits leaving you breathless with the destruction. Mongrel will obnoxiously warn you about this, and people who try it will NOT get support from me without mad amounts of dough. If you turn this on, and your world comes crashing around your head, then I warned you. Otherwise, go ahead and give it a try and see if that improves things for you. “
So, is the behavior of ActiveRecord different here?.
Are there any guidelines on when to use (or not use) this?
@Jeremy : Oh no! Did I just do that !!? Damn. But hey, now they can finally talk about performance ;-) AR is slow, ruby is not™
@Mike : AR is certainly different here. This little pastie will give you a rough idea why ActionController::Base.allow_concurrency is pretty much a place holder as we talk. But I don’t think Actionpack is very far from being thread safe. It’s just a matter of time. Guidelines..umm..just try to piss off some people in #rubyonrails when you have some problem :-)