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:

  1. 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.
  2. manually check out connection pool activerecord::base.connection_pool.checkout. responsible returning connection pool when finished calling activerecord::base.connection_pool.checkin(connection).
  3. 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

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -