backgrounDRb versus DRb

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.

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.

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. [email protected]

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. [email protected]

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
[email protected]
– Engine Y., Serious Rails Hosting
– (866) 518-YARD (9273)

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.