sdepold/sequelize — pull request #146 by megshark (2012-03-27 01:20:57+00:00)
Title: Added option to use a connection pool with mysql

Now that the connection leakage issue is solved, I noticed that we were being *very* aggressive in closing connections which causes a lot of open/close to happen, which is not ideal for performance. I added the generic-pool module (I'm already using it for memcache connection pooling & so far, so good) to the dependencies. I got it so that all the interaction with the pool stays within the connection manager, but setting the mysql client acquired from the pool on the query is structured less-than-ideally since I didn't want to change the ConnectionManager.query call to require a callback. Ideally, I would have liked to pass the client into the Query constructor, but instead I set it on the asynchronous enqueue().

I changed the test config parameters to show how to set up pooling. Basically, I have added a new option to the sequelize config called "pool".

Example configuration:

new Sequelize('database', 'username', 'password', {
// custom host; default: localhost
host: 'my.server.tld',

// custom port; default: 3306
port: 12345,

// if you're using connection pool, I would increase the max # of concurrent queries
maxConcurrentQueries: 250,

// connection pooling is only supported for mysql -- will be ignored for sqlite
dialect: 'mysql',

// these are the default settings so you can get these by specifying an empty curly (pool: {})
// maxIdleTime is in millis. we can consider exposing more pooling options later if desired.
pool: { maxConnections: 10, maxIdleTime: 30000 }

}

I changed the tests under mysql to pass in the pooling configuration (with maxConnections set to 5). The tests all pass. I am currently running my app with pooling in my dev/staging environment and everything is looking good.

Let me know if you want any other changes or if you have feedback!
Meg