views:

207

answers:

2

Is there a ruby gem or such for MySQL connection pooling that isn't part of rails? I simply have a ruby script (again, I don't do anything with rails).

A: 

Seamless Database Pool is supposed to work "with any ActiveRecord application", and ActiveRecord is easy to use without Rails. I've used ActiveRecord in a plain Ruby app, and it was just a matter of configuring the logger and the database connection, something like

ActiveRecord::Base.logger = App.logger
dbconfig = YAML::load(File.open("#{APP_ROOT}/config/database.yml"))
ActiveRecord::Base.establish_connection(dbconfig[ENV["APP_ENV"]])

I haven't used Seamless Database Pool outside of Rails, but I couldn't find any connection poolers aimed at plain Ruby apps after a quick search so it might be your best bet.

Alex - Aotea Studios
A: 

If you use JRuby (with ActiveRecord and JDBC adapter) you can configure a J2EE container to handle DB connection pool and pass the pool in database.yml via jndi similar to here (example with oracle).

Also, some slides for MYSQL pools via ActiveRecord

ActiveRecord::Base.establish_connection(
  :adapter => 'mysql',
  :username => 'root',
  :password => '123456',
  :database => 'database',
  :pool => 5 # <- CONN POOL
)
clyfe