-
Notifications
You must be signed in to change notification settings - Fork 253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why is it necessary to reconnect each iteration for parallelizing ActiveRecord? #36
Comments
Try and see if it works, I had lots of issues without this, maybe it's better in AR3, You can reconnect once per fork, but thats also tricky :) |
I am also having a lot of issues using the Parallel gem and ActiveRecord, and without a decent explanation from you as to why reconnection for every iteration is necessary, I'm forced to conclude that this gem is unsafe with ActiveRecord. |
conclude what you want, I don't have any sla's :D afaik you have to reconnect affter forking, not sure about threading, but I saw a lot of weird issues so far, so I always use forking + reconnect |
whoops wrong button |
if you can digg down and find any issue let me know, or add it to the readme |
http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html seems to indicate that though ActiveRecord is thread safe, you have to manage the connection pool manually. This seems like something that this gem could/should support. |
This gem should ideally not have to worry about issues of other gems, |
I found one possible solution using Parallel.each(Message.where(some_condition).all, :in_threads => 8) do |message|
ActiveRecord::Base.connection_pool.with_connection do
message.update_attribute(:some_attribute, some_value)
end
end |
Added it to the readme, let's see if it works :) |
It works well for me with mongoid. |
Why is it necessary to run
ActiveRecord::Base.connection.reconnect!
in order to parallelize the processing of ActiveRecord::Base objects? ActiveRecord::Base is thread safe, so what is this actually fixing? Reconnecting every iteration is extremely wasteful.The text was updated successfully, but these errors were encountered: