brianc / node-pg-pool

A connection pool for node-postgres
MIT License
180 stars 64 forks source link

Get number of active clients #69

Closed chiluap closed 7 years ago

chiluap commented 7 years ago

Hi there,

nice work with the pg-pool.

just a thought:

for getting the number of active clients you suggest keeping a counter on the connect callback. I suggest counting the number of active clients via something like:

showConnections() {  
        logger.notice('PgPool.openConnections: ', {rw: this.pool._clients.length});
        setTimeout(_.bind(this.showConnections, this), 30000); 
}

(b.t.w: I'am using the pool in an es2015 wrapper class. so don't mind the this.pool it is an instance of the pg-pool)

... just a thought.

keep up the good work

chiluap

brianc commented 7 years ago

You can actually use pool.totalCount to get the number of connections in pg-pool@2.0. Where do I suggest counting? I'd like to go update that documentation.

vitaly-t commented 7 years ago

It would be great to be able to monitor how connections are used, with a notification callback like this:

onConnectionCountChange(newCount) {
}

This will help planning the strategy for the size of the pool to be configured, or a change in how connections are used.

brianc commented 7 years ago

if you want to get a callback whenever a connection is created use the pool.on('connect') event. That + checking pool.totalCount should be all you need to monitor connection counts changing. 😄