From dd1918dc360dc0f9553c35c82f3f0f93ac3bfb46 Mon Sep 17 00:00:00 2001 From: indexzero Date: Fri, 17 Sep 2010 13:09:43 -0400 Subject: [PATCH] [debug] Better debug messages to try to determine if pool is slowly losing clients to forever busy --- lib/node-http-proxy.js | 4 ++-- vendor/pool/main.js | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/node-http-proxy.js b/lib/node-http-proxy.js index 15c629b..ac84ba9 100644 --- a/lib/node-http-proxy.js +++ b/lib/node-http-proxy.js @@ -30,7 +30,7 @@ var sys = require('sys'), pool = require('./../vendor/pool/main'), eyes = require('eyes'), min = 0, - max = 100; + max = 10; // Setup the PoolManager var manager = pool.createPoolManager(); @@ -146,7 +146,7 @@ HttpProxy.prototype = { // Open new HTTP request to internal resource with will act as a reverse proxy pass var p = manager.getPool(port, server); - sys.puts('current pool count for ' + req.headers.host + ":" + port + ' ' +p.clients.length); + sys.puts('Current pool count for ' + req.headers.host + ":" + port + ' ' + p.clients.length + ', Busy: ' + p.getBusy() + ', Free: ' + p.getFree()); p.on('error', function (err) { // Remark: We should probably do something here diff --git a/vendor/pool/main.js b/vendor/pool/main.js index 8229ab1..51c256f 100644 --- a/vendor/pool/main.js +++ b/vendor/pool/main.js @@ -84,6 +84,14 @@ Pool.prototype.onFree = function (client) { if (this.pending.length > 0) this.pending.shift()(client); }; +Pool.prototype.getFree = function () { + return this.clients.filter(function (client) { return !client.busy }).length; +}; + +Pool.prototype.getBusy = function () { + return this.clients.filter(function (client) { return client.busy }).length; +}; + Pool.prototype.setMinClients = function (num) { this.minClients = num; if (this.clients.length < num) { @@ -98,6 +106,7 @@ Pool.prototype.setMinClients = function (num) { Pool.prototype.setMaxClients = function (num) { this.maxClients = num; }; + Pool.prototype.end = function () { this.clients.forEach(function (c) {c.end()}); };