What's New in Edge Rails: Connection Pools

Posted by ryan
at 5:32 PM on Sunday, September 07, 2008

With the upcoming thread-safety of Rails comes the necessity of database connection pools. While less a feature and more a hidden implementation detail, you do have the ability to adjust the max size of these new pools (default is 5). In your database.yml configuration file just set the pool key:

  adapter: mysql
  username: root
  database: myapp_dev
  pool: 10

So there ya go – connection pools. That was easy…

tags: ruby, rubyonrails


Leave a response

  1. Andrew ZSeptember 07, 2008 @ 07:26 PM

    Rails 2.2 looks like it may be my favourite release yet.

  2. Dr NicSeptember 08, 2008 @ 07:05 AM

    What is the default size? 10?

  3. CarlSeptember 08, 2008 @ 01:15 PM

    Now some guidelines on what a reasonable setting for pools would be useful…

  4. andySeptember 08, 2008 @ 01:53 PM

    is there any practical reason I would want to do this?

  5. Ryan DaigleSeptember 09, 2008 @ 08:32 AM

    The default pool size is 5.

  6. StephaneSeptember 09, 2008 @ 11:17 AM

    I think it could be good to have as much connections as you have running servers. How do you think?

  7. Nick SiegerSeptember 10, 2008 @ 12:06 PM

    Carl: depends on how you plan to run Rails. If you continue to run with multiple Mongrels/Thins or Passenger in a situation where each request has a big mutex around it, the pool size won’t really matter because you’re still only using a single connection at a time.

    If you run in full MT mode, the number of connections you need depends on how much parallelism you need in that server. I’d probably do some load testing until I start getting pool timeout errors and then set the pool maximum size comfortably above that.

  8. Mike LaurenceSeptember 19, 2008 @ 12:22 PM

    Hey Ryan, thanks for all of the excellent info! Your blog has been responsible for countless improvements to the efficiency of my coding : )

    I do have a suggestion regarding the format of the site: sometimes if I don’t hit the blog in a while, I can’t tell which “Edge Rails” entries refer to the current Edge or versions that have since gone into production. I wonder if you could add the version number somewhere in those entries?

    Keep up the great writing!

  9. Ryan DaigleSeptember 24, 2008 @ 07:29 AM

    Michael – great suggestion, I’ll try to keep track of this in the future.

  10. KeeKeeSeptember 30, 2008 @ 10:39 AM

    Isn’t it just amazing how simple some people can make things seem when the rest of us go all around the world to do the same thing. Thanks for reminding me to KISS. (Keep It Simple Stupid)


  11. YudiOctober 05, 2008 @ 09:19 PM

    well, twitter.com needs a code refactor now :-)

  12. ChrisOctober 25, 2008 @ 12:06 PM

    Nick, what do you mean my MT mode? Multi Threaded? If so, how do you run rails in this mode? Jruby?