Skip to content

Commit

Permalink
Maintain number of in use connections in pool's stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
pekim committed Oct 7, 2012
1 parent 592e42f commit 0864ac7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function ConnectionPool(poolConfig, connectionConfig) {
pool.requestNumber = 0;
pool.stats = {
maxSize: poolConfig.maxSize,
connections: 0
connections: 0,
connectionsInUse: 0
};
pool.inUseConnections = [];
pool.availableConnections = [];
Expand All @@ -48,6 +49,7 @@ function ConnectionPool(poolConfig, connectionConfig) {
});

pool.inUseConnections.splice(pool.inUseConnections.indexOf(connection), 1);
pool.stats.connectionsInUse--;

if (pool.pendingConnectionRequests.length > 0) {
var pendingConnectionRequest = pool.pendingConnectionRequests.shift();
Expand Down Expand Up @@ -79,13 +81,15 @@ function ConnectionPool(poolConfig, connectionConfig) {

function useConnection(connection) {
pool.inUseConnections.push(connection);
pool.stats.connectionsInUse++;

callback(connection);
}
};

return {
requestConnection: pool.requestConnection
requestConnection: pool.requestConnection,
stats: pool.stats
};
};

Expand Down

0 comments on commit 0864ac7

Please sign in to comment.