Ruby on Rails Friday, October 28, 2011

On Oct 28, 10:02 am, AWD Switzerland <li...@ruby-forum.com> wrote:
> Hi There
>
> Is active record 3.1.1 supposed to be threadsafe?
> In other words, should the following (concurrent access to a model)
> work?
>
> Thread.new do MyModel.where(some_condition).first end
> Thread.new do MyModel.where(some_condition).first end
>
> I ask because upon the answer, it depends which component should handle
> synchronization, and in consequence, which component to patch/fix.
>
Rails added thread safety back in 2.1 or 2.2 so current versions
should be threadsafe.

> A bit of background: We stumbled over a concurrency issue when using
> capybara-webkit with rails3.1. We traced the issue down to one thread
> querying and trying to accessing the cache while another thread cleared
> the same cache.
> Assuming active record 3.1.1 is supposed to be threadsafe, then the
> culprit for the issue would be
> ActiveRecord::ConnectionAdapters::QueryCache, which doesn't synchronize
> access to its @query_cache. Seehttps://github.com/awd-switzerland/rails/commit/22aeda0f0553fdcabca15...
> for a possible way to resolve that. However, I'm not sure in which layer
> the rails team wants to handle synchronisation.

In theory I don't think this is needed because different threads
should be using different connection objects (there's supposed to be a
pool of connection objections, and any member of the pool is only ever
used by one thread at a time. You might also want to ask on the rails-
core list

Fred
> Also notice that the patch is naive in that it simply assumes thread
> support in ruby to be enabled.
>


> Best regards
> Stefan Rusterholz
>
> --
> Posted viahttp://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment