ruby on rails - Is there any reason to use a database connection pool with ActiveRecord? -
what benefits using external connection pool?
i've heard other applications open connection each unit of work. in rails, example, i'd take mean each request open new connection. i'm assuming connection pool make possible.
the benefit can think of allows have 1,000 frontend processes without having 1,000 postgres processes running.
are there other benefits?
rails has connection pooling built in:
- simply use activerecord::base.connection active record 2.1 , earlier (pre-connection-pooling). eventually, when you’re done connection(s) , wish returned pool, call activerecord::base.clear_active_connections!. default behavior active record when used in conjunction action pack’s request handling cycle.
- manually check out connection pool activerecord::base.connection_pool.checkout. responsible returning connection pool when finished calling activerecord::base.connection_pool.checkin(connection).
- use activerecord::base.connection_pool.with_connection(&block), obtains connection, yields sole argument block, , returns pool after block completes.
this has been available since version 2.2. you'll see pool
parameter in database.yml
controlling it:
pool
: number indicating size of connection pool (default 5)
i don't think there point in layering pooling system underneath , confuse ar's pooling if tried it.
Comments
Post a Comment