I'm looking for a way to log the amount of time it takes for a connection to be acquired from the connection pool so that I can get an idea of whether my pool size needs to be increased or not.
I was looking at the connect event, but there doesn't seem to be any properties that I can use there. Is there another way I can determine this?
There is no special support for this. You can only do it as a separate test:
var start = Date.now();
db.connect()
.then(obj=> {
var duration = Date.now() - start;
console.log(duration);
obj.done();
});
Ah, yeah that's what I was doing in the meantime. Would this be difficult to implement? Possible feature request for a future version?
It is possible, but nobody asked for it yet.
You know, you can always hack into the API directly, by overriding pgp.pg.connect and provide your version that would log the duration ;)
@RyanMcDonald
Here's how you can hack into the pg connection pool used by the library, to log the duration:
var prevConnect = pgp.pg.connect;
pgp.pg.connect = function (cn, cb) {
var start = Date.now();
return prevConnect.call(this, cn, function (err, client, done) {
if (!err) {
var duration = Date.now() - start;
console.log(duration);
}
cb(err, client, done);
});
};
@vitaly-t Beautiful, thank you! 馃槃