where to set @@allow_concurrency= true

Hi all, I would like to have a connection-per-thread in my rails app. According to the base.rb file, @@allow_concurrency parameter mustbe set to true. I tried setting it both in environment.rb and ApplicationController but did not work. Where should I change that parameter so that it can work?

Thanks.

Ayhan

That kind of configuration should go in config/environment.rb, though you can’t just do ‘@@allow_concurrency = true’ in the Initializer block. I’m not sure where this var is, I think ActiveRecord, so this would be the line you add (I’m pretty sure):

Rails::Initializer do … config.active_record.allow_concurency = true … end

Jason

Can you explain what you mean by “I would like to have a connection-per-thread in my rails app” ? Rails doesn’t work that way as th framework as a whole is not thread safe> So when it is served by mongrel , webrick or fcgi, requests are serialized when they are dispatched to rails so that only one runs at a time. So setting allow_concurrency= true in a normal rails app will not get you anything. If you explain what you are trying to do I amy be able to shed some more light on it for you.;

-Ezra

Thanks for your replies. In my tests in webrick server I found that all the threads are sharing a single database conenction. But I would like each thread to have its own connection.

I solved that with Jason's advice by doing the the following in environment.rb

Rails::Initializer.run do |config|   config.active_record.allow_concurrency = true end

Thanks.