Hey Guys, I''m using ActiveRecord in a threaded application and getting the "MSQL lost its database connection...etc." error message. Searching through the forum I see the issue is basically related to the fact that Rails is not thread safe. In several posting I''ve seen suggestions about using backgrounDRb to mitigate this issue. I''ve gone to the backgrounDRb home page and read through the project description. I''m still not sure what advantage this plugin provides over using DRb ... (though I''m not really familiar with the advantages of plugins). The fact that backgrounDRb is in alpha release is also making me a little skittish about using it.... Sonny. -- Posted via http://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hey Guys, As a follow-up question, I presume that within each backgrounDrb/DRb call, ActiveRecord is still not thread-safe. In other words, if I attempted to create threads inside *Drb, I would still run into the same ''MSQL lost database connection .." error with ActiveRecords right? Sonny. -- Posted via http://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
BackgroundDRb makes it easier to leverage DRb and takes care of a lot of details for you (assuming you''re not on win32). You can use DRb directly, but you''ll have to figure out ways to connect it up to your Rails controllers, daemonize a ruby process and keep tabs on currently running tasks. All of that isn''t hard, it just takes time away from what you really want to accomplish. It''s still in alpha, but so far it has been solid for me. YMMV On Apr 18, 3:57 am, Sonny Chee <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hey Guys, > > I''m using ActiveRecord in a threaded application and getting the "MSQL > lost its database connection...etc." error message. Searching through > the forum I see the issue is basically related to the fact that Rails is > not thread safe. > > In several posting I''ve seen suggestions about using backgrounDRb to > mitigate this issue. I''ve gone to the backgrounDRb home page and read > through the project description. I''m still not sure what advantage this > plugin provides over using DRb ... (though I''m not really familiar with > the advantages of plugins). > > The fact that backgrounDRb is in alpha release is also making me a > little skittish about using it.... > > Sonny. > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Actually, ActiveRecord is thread safe. Set ActiveRecord::Base.allow_concurrency to true in your Backgroun/DRb processes. On Apr 18, 4:20 am, Sonny Chee <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hey Guys, > > As a follow-up question, I presume that within each backgrounDrb/DRb > call, ActiveRecord is still not thread-safe. In other words, if I > attempted to create threads inside *Drb, I would still run into the same > ''MSQL lost database connection .." error with ActiveRecords right? > > Sonny. > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 17, 2007, at 7:23 PM, eden li wrote:> > Actually, ActiveRecord is thread safe. Set > ActiveRecord::Base.allow_concurrency to true in your Backgroun/DRb > processes.Actually if you set allow_concurreny to true then you must *always* remember to call ActiveRecord::Base.verify_active_connections! at the end of each worker. Otherwise AR in multi threaded mode uses a database connection *per thread* and never releases them unless you call verify_active_connections! . If you don''t release the connections then you will rapidly use all the database handles your database will allow. Cheers- -- Ezra Zygmuntowicz -- Lead Rails Evangelist -- ez-NLltGlunAUd/unjJdyJNww@public.gmane.org -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273) --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the good info guys. I didn''t know ActiveRecord was thread-safe. What could be the cause of "MSQL lost its database connection...etc." error message then? This error only occurs in the parent thread after I''ve made an ActiveRecord call in the child thread.... Any idea how I can further diagnose the issue would also be appreciated. Sonny.>> Actually, ActiveRecord is thread safe. Set >> ActiveRecord::Base.allow_concurrency to true in your Backgroun/DRb >> processes. > > Actually if you set allow_concurreny to true then you must *always* > remember to call ActiveRecord::Base.verify_active_connections! at > the end of each worker. Otherwise AR in multi threaded mode uses a > database connection *per thread* and never releases them unless you > call verify_active_connections! . If you don''t release the > connections then you will rapidly use all the database handles your > database will allow. >-- Posted via http://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---