diff --git a/Readme.md b/Readme.md index 01c7c2e1d..5fc8b48bb 100644 --- a/Readme.md +++ b/Readme.md @@ -190,9 +190,9 @@ fails assumed to be plaintext strings. The `ssl` option in the connection options takes a string or an object. When given a string, it uses one of the predefined SSL profiles included. The following profiles are included: -* `"Amazon RDS"`: this profile is for connecting to an Amazon RDS server and contains the - ca from https://rds.amazonaws.com/doc/rds-ssl-ca-cert.pem - +* `"Amazon RDS"`: this profile is for connecting to an Amazon RDS server and contains the + ca from https://rds.amazonaws.com/doc/rds-ssl-ca-cert.pem + When connecting to other servers, you will need to provide an object of options, in the same format as [crypto.createCredentials](http://nodejs.org/api/crypto.html#crypto_crypto_createcredentials_details). Please note the arguments expect a string of the certificate, not a file name to the @@ -319,6 +319,23 @@ up to 100 connections, but only ever use 5 simultaneously, only 5 connections will be made. Connections are also cycled round-robin style, with connections being taken from the top of the pool and returning to the bottom. +Once the number of active connections reaches `connectionLimit` (see blelow) +the connection will be queued and the pool will emit a `queue` event with +the number of queued connections as the first argument to the callback. + +```js +var mysql = require('mysql'); +var pool = mysql.createPool(...); + +pool.on('queue',function(queuedConnections) { + // Do something i.e. log to console + console.error('connectionLimit reached, '+queuedConnections+' connections in the queue'); +}); + +// Create and use more than connectionLimit connections + +``` + When a previous connection is retrieved from the pool, a ping packet is sent to the server to check if the connection is still good. diff --git a/lib/Pool.js b/lib/Pool.js index 34e00295e..42cc0950c 100644 --- a/lib/Pool.js +++ b/lib/Pool.js @@ -62,9 +62,11 @@ Pool.prototype.getConnection = function (cb) { return cb(new Error('Queue limit reached.')); } - if (cb && process.domain) + if (cb && process.domain) { cb = process.domain.bind(cb); + } this._connectionQueue.push(cb); + this.emit('queue',this._connectionQueue.length); }; Pool.prototype.acquireConnection = function acquireConnection(connection, cb) {