Forum: Ruby on Rails backgrounDRb versus DRb...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sonny C. (Guest)
on 2007-04-17 23:57
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.
Sonny C. (Guest)
on 2007-04-18 00:20
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.
Eden L. (Guest)
on 2007-04-18 06:22
(Received via mailing list)
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 C. <removed_email_address@domain.invalid>
Eden L. (Guest)
on 2007-04-18 06:24
(Received via mailing list)
Actually, ActiveRecord is thread safe.  Set
ActiveRecord::Base.allow_concurrency to true in your Backgroun/DRb
processes.

On Apr 18, 4:20 am, Sonny C. <removed_email_address@domain.invalid>
Ezra Z. (Guest)
on 2007-04-18 06:33
(Received via mailing list)
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 Z.
-- Lead Rails Evangelist
-- removed_email_address@domain.invalid
-- Engine Y., Serious Rails Hosting
-- (866) 518-YARD (9273)
Sonny C. (Guest)
on 2007-04-18 09:43
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.
>
This topic is locked and can not be replied to.