igrigorik / em-synchrony

Fiber aware EventMachine clients and convenience classes
http://www.igvita.com/2010/03/22/untangling-evented-code-with-ruby-fibers
MIT License
1.04k stars 151 forks source link

Is the pool setting in the ActiveRecord tests a mistake? #160

Open kswope opened 11 years ago

kswope commented 11 years ago

In the activerecord spec

https://github.com/igrigorik/em-synchrony/blob/master/spec/activerecord_spec.rb

There is a pool of 10 specified.

def establish_connection
    ActiveRecord::Base.establish_connection(
      :adapter => 'em_mysql2',
      :database => 'widgets',
      :username => 'root',
      :pool => 10
    )

But in the docs it says "If you need to control the connection pool size, use rack/fiber_pool."

Is this

:pool => 10

actually doing anything?

I'm also getting the impression from the spec and docs that this pooling happens automagically but I have a feeling it isn't

Is this construct still the proper way to utilize a pool, outside of rails, even when using em-synchrony?

ActiveRecord::Base.connection_pool.with_connection do
  User.find(1)
end
kswope commented 11 years ago

After a lot of stress testing I've determined that

:pool => X,      
:adapter => 'em_mysql2',

seems to be all you need for mysql connection pooling and it performs perfectly. I tested it by wrapping the relevant code in a bogus http server and blasting it with the likes of ab, httperf, and weighttp. You can clearly see the connection pool at work in the mysql processlist.

I think this might be only the case if you use em-syncrony's ActiveRecord's client and ActiveRecord calls only, no cheating by grabbing a database connection from ActiveRecord and running raw queries.

This statement in the docs completely threw me off, and I'm not sure why its there - "If you need to control the connection pool size, use rack/fiber_pool."

I put my code here in case anybody could use it https://github.com/kswope/em-synchrony-ar-pool-stress

igrigorik commented 11 years ago

I think this might be only the case if you use em-syncrony's ActiveRecord's client and ActiveRecord calls only, no cheating by grabbing a database connection from ActiveRecord and running raw queries.

Correct.

Anything else to resolve on this one? Have you resolved #159?

kswope commented 11 years ago

I haven't resolved 159 yet. If nobody else is having this problem, and there's nothing obvious to the experts that I'm doing something wrong, then I'll take another crack at it, it must be something unique to my situation.