views:

43

answers:

1

So I am new to Rails, so pardon the basic question.

I see rails spits this out (in the console) for every request I make to my controller. Why? I'm not even doing any DB operation, I just started writing a HelloWorld rails app. I did pick mysql as the db when creating this rails project (rails -d mysql helloworld)

SQL (0.1ms)   SET NAMES 'utf8'
SQL (0.1ms)   SET SQL_AUTO_IS_NULL=0

So I noticed, that rails attempts to establish a DB connection for every request, irrespective whether you do a DB/ActiveRecord operation. It does this right after it does action_controller/dispatch. This seems like a waste of DB resource to me, why establish a connection to DB when I may not even do a ActiveRecord operation??

+1  A: 

You're seeing this on every request because you're in development mode. In production mode (or with class caching turned on), this only happens once, when the connection is added to the connection pool.

daryn
It is certainly a design-decision, which some will support and some will call a flaw :)Note: if you don't need activerecord at all in your app, you can disable it in the environment.rb file, but otherwise, I *think* you're stuck with this. It is a pretty trivial amount of overhead, but yes, it is potentially pointless on any given request.
daryn
I agree, thanks for your inputs