From 9f4119313715b00b23f8f6467683971d8c91018d Mon Sep 17 00:00:00 2001 From: Bob Ullery Date: Fri, 7 Apr 2017 15:54:56 -0400 Subject: [PATCH 1/9] move auth out of httpOption, add from if --- lib/connection-pool.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/connection-pool.js b/lib/connection-pool.js index cb217ee..d6b6f07 100644 --- a/lib/connection-pool.js +++ b/lib/connection-pool.js @@ -55,11 +55,10 @@ module.exports = { connect: function connect (optionString) { var options = parseStringOptions(optionString) options.forEach(function (e) { - httpOptions.push({ + var option = { httpOpt: { host: e.hostname, port: e.port || 4200, - auth: e.auth || null, path: '/_sql?types', method: 'POST', headers: { @@ -67,7 +66,11 @@ module.exports = { } }, protocol: e.protocol - }) + }; + if(e.auth){ + option.httpOpt.auth = e.auth; + } + httpOptions.push(option) httpOptionsBlob.push(e.protocol + '://' + e.hostname + ':' + e.port + '/_blobs/') }) }, From 710b68edb9910ea98e2bd186054ac76eddc24db1 Mon Sep 17 00:00:00 2001 From: Bob Ullery Date: Fri, 7 Apr 2017 16:14:46 -0400 Subject: [PATCH 2/9] Up maxSockets --- lib/connection-pool.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/connection-pool.js b/lib/connection-pool.js index d6b6f07..ff3ba76 100644 --- a/lib/connection-pool.js +++ b/lib/connection-pool.js @@ -19,7 +19,7 @@ var httpOptionsBlob = [] var lastUsed = 0 // limit number of sockets -//http.globalAgent.maxSockets = 3 +http.globalAgent.maxSockets = 100; http.globalAgent.keepAlive = true; function getNextNodeOptions (type) { From 0bb778c7b62ecce70cac2467e6d054f1445141d5 Mon Sep 17 00:00:00 2001 From: Bob Ullery Date: Fri, 7 Apr 2017 19:53:37 -0400 Subject: [PATCH 3/9] uncaughtException handler --- lib/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/index.js b/lib/index.js index 586ff12..1b077ee 100644 --- a/lib/index.js +++ b/lib/index.js @@ -96,6 +96,9 @@ function executeSql (sql, args, cb, bulk) { response.on('data', function (chunk) { data.push(chunk) }) + response.on('uncaughtException', function (err) { + cb(err, null) + }) response.on('end', function () { var result = {} var json From 657b9155869d14b0d4f2ab9230b54907bc2b8b37 Mon Sep 17 00:00:00 2001 From: Bob Ullery Date: Fri, 7 Apr 2017 19:55:14 -0400 Subject: [PATCH 4/9] error handling --- lib/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/index.js b/lib/index.js index 1b077ee..2eb3b22 100644 --- a/lib/index.js +++ b/lib/index.js @@ -99,6 +99,9 @@ function executeSql (sql, args, cb, bulk) { response.on('uncaughtException', function (err) { cb(err, null) }) + response.on('error', function (err) { + cb(err, null) + }) response.on('end', function () { var result = {} var json From 1f69ab66676814c41ba6185f11b9e1c6ab888e4a Mon Sep 17 00:00:00 2001 From: Bob Ullery Date: Fri, 7 Apr 2017 19:58:48 -0400 Subject: [PATCH 5/9] request error handling --- lib/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/index.js b/lib/index.js index 2eb3b22..0c19922 100644 --- a/lib/index.js +++ b/lib/index.js @@ -141,6 +141,11 @@ function executeSql (sql, args, cb, bulk) { }) } var req = connectionPool.getSqlRequest(callback) + + req.on('error', function(err) { + cb(err, null) + }); + var command = { stmt: sql } From eaffb21c06f9b5f718d29010b0b6bd31d7ecfd9d Mon Sep 17 00:00:00 2001 From: Bob Ullery Date: Fri, 7 Apr 2017 19:59:37 -0400 Subject: [PATCH 6/9] put httpOpt.auth back into main object --- lib/connection-pool.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/connection-pool.js b/lib/connection-pool.js index ff3ba76..a1e967d 100644 --- a/lib/connection-pool.js +++ b/lib/connection-pool.js @@ -59,6 +59,7 @@ module.exports = { httpOpt: { host: e.hostname, port: e.port || 4200, + auth: e.auth || null, path: '/_sql?types', method: 'POST', headers: { @@ -67,9 +68,7 @@ module.exports = { }, protocol: e.protocol }; - if(e.auth){ - option.httpOpt.auth = e.auth; - } + httpOptions.push(option) httpOptionsBlob.push(e.protocol + '://' + e.hostname + ':' + e.port + '/_blobs/') }) From c98bb86435856c85f62cfc83cb92da26243ef365 Mon Sep 17 00:00:00 2001 From: Bob Ullery Date: Wed, 12 Apr 2017 10:39:30 -0400 Subject: [PATCH 7/9] keep alive off --- lib/connection-pool.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/connection-pool.js b/lib/connection-pool.js index a1e967d..b38c2e3 100644 --- a/lib/connection-pool.js +++ b/lib/connection-pool.js @@ -19,8 +19,8 @@ var httpOptionsBlob = [] var lastUsed = 0 // limit number of sockets -http.globalAgent.maxSockets = 100; -http.globalAgent.keepAlive = true; +http.globalAgent.maxSockets = 250; +http.globalAgent.keepAlive = false; function getNextNodeOptions (type) { lastUsed += 1 From 4d1fc4b337be2fb5ca74750613d312e7d11fd6de Mon Sep 17 00:00:00 2001 From: Bob Ullery Date: Wed, 12 Apr 2017 10:47:27 -0400 Subject: [PATCH 8/9] http keepAlive to true and reduce maxSockets --- lib/connection-pool.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/connection-pool.js b/lib/connection-pool.js index b38c2e3..8e9cb25 100644 --- a/lib/connection-pool.js +++ b/lib/connection-pool.js @@ -19,8 +19,8 @@ var httpOptionsBlob = [] var lastUsed = 0 // limit number of sockets -http.globalAgent.maxSockets = 250; -http.globalAgent.keepAlive = false; +http.globalAgent.maxSockets = 10; +http.globalAgent.keepAlive = true; function getNextNodeOptions (type) { lastUsed += 1 From 28d1a00889136b611eaee87506b4d6886e8b74a9 Mon Sep 17 00:00:00 2001 From: Bob Ullery Date: Wed, 12 Apr 2017 11:52:40 -0400 Subject: [PATCH 9/9] logging option for debug --- lib/connection-pool.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/connection-pool.js b/lib/connection-pool.js index 8e9cb25..94455d3 100644 --- a/lib/connection-pool.js +++ b/lib/connection-pool.js @@ -68,7 +68,7 @@ module.exports = { }, protocol: e.protocol }; - + console.log("Crate Option: ", option); httpOptions.push(option) httpOptionsBlob.push(e.protocol + '://' + e.hostname + ':' + e.port + '/_blobs/') })