From: Brian Candler Date: 2009-06-22T21:37:04+09:00 Subject: Re: ActiveRecord.connection_pool separate connections for each p I don't believe this will work as it stands. If you create a pool of 5 connections and then fork, each child process will have a copy of the same pool. When one process 'takes' the first connection, the other children won't be updated, so every other process will also 'take' the same connection out of the pool. As a result, they'll all end up sharing the same mysql connection socket, which is very dangerous here (e.g. commands from the two processes could be intermingled, and responses could be delivered to the wrong client) As for when a child exits: this has been reported here before. It seems that the mysql client sends a 'close' message down the socket in its finalizer; that is, when the connection object is destroyed. So if two processes really are sharing the same socket, when one terminates, the server will be told to disconnect, so the other process will see a disconnection too. So you need to either: 1. Rewrite your code to use Ruby threads, instead of forking. The connection pool will be fine then. 2. Fork first, *then* connect to the database. Then each process will have its own separate connection. If you are worried about the overhead of reconnecting frequently, then start N worker processes, each of which opens a connection, and then loops around picking jobs from a Queue. HTH, Brian. -- Posted via http://www.ruby-forum.com/.