Ruby, MySQL: Connection pool outside the rails framework?
3 answers
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 pooling outside of Rails, but after a quick search, I couldn't find connection pools targeting simple Ruby applications, so you might be better off.
0
source to share
If you are using JRuby (with an ActiveRecord adapter and JDBC), you can configure a J2EE container to manage the DB connection pool and pass the pool to database.yml via jndi, similar here (oracle example) .
Also, a few slides for MYSQL pools via ActiveRecord
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:username => 'root',
:password => '123456',
:database => 'database',
:pool => 5 # <- CONN POOL
)
0
source to share
You can wrap the connection_pool gem around a pair of separate connections.
Examples from doc (redis):
Usage example with block (faster):
@pool = ConnectionPool.new { Redis.new } @pool.with do |redis| redis.lpop('my-list') if redis.llen('my-list') > 0 end
Example using replace existing connection (slower):
$redis = ConnectionPool.wrap { Redis.new } def do_work $redis.lpop('my-list') if $redis.llen('my-list') > 0 end
0
source to share