em-synchrony icon indicating copy to clipboard operation
em-synchrony copied to clipboard

Is the pool setting in the ActiveRecord tests a mistake?

Open kswope opened this issue 12 years ago • 3 comments
trafficstars

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 avatar Jun 10 '13 05:06 kswope

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

kswope avatar Jun 12 '13 22:06 kswope

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?

igrigorik avatar Jun 14 '13 05:06 igrigorik

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.

kswope avatar Jun 14 '13 07:06 kswope