# How to use connection pool in Rails2.3.5 with WEBrick and MySQL?

**URL:** <https://www.ruby-forum.com/t/how-to-use-connection-pool-in-rails2-3-5-with-webrick-and-mysql/184102>\
**Category:** Rails\
**Created:** [February 25, 2010, 2:13am UTC](https://www.ruby-forum.com/t/how-to-use-connection-pool-in-rails2-3-5-with-webrick-and-mysql/184102 "2010-02-25T02:13:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sheile](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecae2f/32.png) [@Sheile](https://www.ruby-forum.com/u/Sheile)\
**Post date:** [February 25, 2010, 2:13am UTC](https://www.ruby-forum.com/t/how-to-use-connection-pool-in-rails2-3-5-with-webrick-and-mysql/184102/1 "2010-02-25T02:13:53Z")

</div>

We use Rails 2.3.5, MySQL, and WEBrick.

ActiveRecord call ConnectionPool#checkout and create new connection to  
MySQL when receive a first HTTP request.  
At this time, register to connection pool its connection in  
ConnectionPool#checkout\_new\_connection.

# 

> <https://github.com/rails/rails/blob/v2.3.5/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L181>

# 

> <https://github.com/rails/rails/blob/v2.3.5/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L246>

but, Rack::Handler::WEBrick#service call body.close in ensure section  
when return the HTTP response.  
It call another method. after some call, it call  
ConnectionPool#clear\_reloadable\_connections and clear its connection  
pool.

# 

> <https://github.com/rails/rails/blob/v2.3.5/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L145>

As a result, the connection was created by every request and spend  
time for connection.

How to use connection pool?
