From 86b617f98d00acd8cf3e4bbd34b09d59d8092110 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Thu, 6 Feb 2014 13:24:50 -0700 Subject: [PATCH] switch to forever-agent --- docs/configuration.asciidoc | 7 +++---- package.json | 6 +++--- src/lib/connectors/http.js | 18 +++++++++--------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/docs/configuration.asciidoc b/docs/configuration.asciidoc index 708e9f13d..529994bfb 100644 --- a/docs/configuration.asciidoc +++ b/docs/configuration.asciidoc @@ -104,17 +104,16 @@ Default::: `30000` -`maxSockets`:: `Number` -- Number of sockets each connection should keep to it's corresponding node. This will also be the maximum number of concurrent requests that could be made to that node. These sockets are currently kept alive using https://github.com/TBEDP/agentkeepalive[agentkeepalive]. +`maxSockets`:: `Number` -- Number of sockets each connection should keep to it's corresponding node. This will also be the maximum number of concurrent requests that could be made to that node. Default::: `10` -`maxKeepAliveTime`:: `Number, false` -- Milliseconds of inactivity before the socket is destroyed - -Default::: `60000` +`forever`:: `Boolean` -- Should the connections to the node be kept open forever? This behavior is recommended when you are connecting directly to Elasticsearch. +Default::: `true` diff --git a/package.json b/package.json index 42ba79bf1..e8c52a2af 100644 --- a/package.json +++ b/package.json @@ -67,16 +67,16 @@ "dependencies": { "when": "~2.6.0", "lodash": "~2.3.0", - "agentkeepalive": "~0.1", "chalk": "~0.3.0", - "event-stream": "~3.1.0" + "event-stream": "~3.1.0", + "forever-agent": "~0.5.2" }, "repository": { "type": "git", "url": "http://github.com/elasticsearch/elasticsearch-js.git" }, "scripts": { - "test": "grunt test", + "test": "node scripts/generate --branch default && grunt test", "generate": "node scripts/generate" }, "engines": { diff --git a/src/lib/connectors/http.js b/src/lib/connectors/http.js index e5f8990d5..ef392d076 100644 --- a/src/lib/connectors/http.js +++ b/src/lib/connectors/http.js @@ -14,7 +14,7 @@ var handles = { }; var _ = require('../utils'); var qs = require('querystring'); -var KeepAliveAgent = require('agentkeepalive'); +var ForeverAgent = require('forever-agent'); var ConnectionAbstract = require('../connection'); /** @@ -34,17 +34,17 @@ function HttpConnector(host, config) { } config = _.defaults(config || {}, { - maxSockets: 10, - maxKeepAliveRequests: 0, - maxKeepAliveTime: 3e5 // 5 minutes + forever: true, + maxSockets: 10 }); - var KeepAliveAgent_ = this.host.protocol === 'https' ? KeepAliveAgent.HttpsAgent : KeepAliveAgent; + var Agent = this.hand.Agent; // the class + if (config.forever) { + Agent = this.host.protocol === 'https' ? ForeverAgent.SSL : ForeverAgent; + } - this.agent = new KeepAliveAgent_({ - maxSockets: config.maxSockets, - maxKeepAliveRequests: config.maxKeepAliveRequests, - maxKeepAliveTime: config.maxKeepAliveTime + this.agent = new Agent({ + maxSockets: config.maxSockets }); } _.inherits(HttpConnector, ConnectionAbstract);