Lionel Bouton a écrit, le 11/20/2009 01:27 PM : > jhaagmans a écrit, le 11/20/2009 12:41 PM : > >> I haven't had a chance to test Conrad's suggestion, but I've also seen >> that I reach the connection limit for ActiveRecord. Is there a way to >> do, for example: >> >> hosts.each do |host| >> #Do all kinds of stuff to host >> end >> hosts.save >> >> So I don't have alot of concurrent connections to my database? >> >> > > Are you using threads in the block ? If not, even if you use host.save > in the block and not a single commit at the end, there's only one > connection to the database. > > Lionel > >
BTW, if you use threads, you should join each thread (or try to) to have at least some control over the number of threads running concurrently. If not, each time you loop over such code you create new threads (which probably will use new DB connections, I'm not sure how the ActiveRecord DB connection pool is used when ActiveRecord is used in a threaded environment) without any guarantee that previous ones finish. Lionel -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=.

