Hoping someone could confirm a couple of things for me. I''m playing with activerecord/activerecord-jdbc inside jruby threads with allow_concurrency set to true. It''s creating a new connection for each thread and appears to be working fine. Transactions appear to be working ok also and I haven''t seen any queries going into the wrong transactions. Anything else that might be a problem? Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hmm found one problem already, database connections are still held open even after the thread is gone. Chris --~--~---------~--~----~------------~-------~--~----~ 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 Jul 8, 2007, at 2:19 PM, snacktime wrote:> > Hmm found one problem already, database connections are still held > open even after the thread is gone. > > ChrisYeah AR uses one connection per thread in multithreaded mode. You need to call ActiveRecord::Base.verify_active_connections! every 20 threads or so to clear out old connections. But be careful of AR in supposed thread safe mode, I''ve run into some really nasty issues where one thread gets its result set mixed up with results form another thread and data gets intertwined. Your best bet is to not use it in threaded mode and instead wrap a small mutex around anywhere you call AR. Perhaps something like this: def use_db @mutex ||= Mutex.new @mutex.synchronize { yield } end use_db do foo = Foo.find :all foo.bar = ''baz; foo.save end 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 -~----------~----~----~----~------~----~------~--~---
On 7/8/07, Ezra Zygmuntowicz <ezmobius-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Jul 8, 2007, at 2:19 PM, snacktime wrote: > > > > > Hmm found one problem already, database connections are still held > > open even after the thread is gone. > > > > Chris > > Yeah AR uses one connection per thread in multithreaded mode. You > need to call ActiveRecord::Base.verify_active_connections! every 20 > threads or so to clear out old connections. But be careful of AR in > supposed thread safe mode, I''ve run into some really nasty issues > where one thread gets its result set mixed up with results form > another thread and data gets intertwined.I''ve heard that. If you happen to have any test cases lying around that can produce that behavior I''d love to tests it against jruby to see if it''s ar that is the problem or ruby itself. Your best bet is to not use> it in threaded mode and instead wrap a small mutex around anywhere > you call AR. > > Perhaps something like this: > > def use_db > @mutex ||= Mutex.new > @mutex.synchronize { yield } > end > > use_db do > foo = Foo.find :all > foo.bar = ''baz; > foo.save > endYa that works fine, I have a connection pool module that does about the same thing. But then it blocks, and it''s actually worse then just processing each request synchronously. Instead of the requests getting processed in the order they are received, it''s too easy for some to ''race'' ahead of others to the blocking point. Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---