Permalink
Browse files

use agentkeepalive module for endpoint keep-alive support

  • Loading branch information...
dannycoates committed Nov 15, 2012
1 parent 634d9bc commit 20fa515707d2a1aefdf950878e74adefd6a86102
Showing with 20 additions and 5 deletions.
  1. +16 −4 lib/endpoint.js
  2. +1 −0 lib/pool.js
  3. +3 −1 package.json
View
@@ -1,4 +1,6 @@
var Stream = require('stream')
+var http = require('http')
+var KeepAlive = require('agentkeepalive')
module.exports = function (inherits, EventEmitter) {
var MAX_COUNT = Math.pow(2, 31) // largest smi value
@@ -16,20 +18,30 @@ module.exports = function (inherits, EventEmitter) {
// maxSockets: max concurrent open sockets (20)
// timeout: default request timeout in ms (60000)
// resolution: how often timeouts are checked in ms (1000)
+ // keepAlive: use an alternate Agent that does keep-alive properly (boolean) default false
// }
- function Endpoint(http, ip, port, options) {
+ function Endpoint(protocol, ip, port, options) {
options = options || {}
- this.http = http
+ this.http = protocol
this.ip = ip
this.port = port
this.healthy = true
this.name = this.ip + ':' + this.port
this.address = this.ip
this.pingPath = options.ping
this.pingTimeout = options.pingTimeout || 2000
-
- this.agent = new http.Agent()
+ if (options.keepAlive) {
+ if (protocol === http) {
+ this.agent = new KeepAlive()
+ }
+ else {
+ this.agent = new KeepAlive.HttpsAgent()
+ }
+ }
+ else {
+ this.agent = new protocol.Agent()
+ }
this.agent.maxSockets = options.maxSockets || 20
this.requests = {}
View
@@ -12,6 +12,7 @@ module.exports = function (inherits, EventEmitter, Endpoint, RequestSet) {
// ping: ping path (default = no ping checks)
// retryFilter: function (response) { return true to reject response and retry }
// retryDelay: number (milliseconds) default 20
+ // keepAlive: use an alternate Agent that does keep-alive properly (boolean) default false
// name: string (optional)
// }
function Pool(http, nodes, options) {
View
@@ -10,7 +10,9 @@
"url": "http://github.com/dannycoates/poolee.git"
},
"engines" : { "node": ">=0.6.0" },
- "dependencies": {},
+ "dependencies": {
+ "agentkeepalive": "*"
+ },
"devDependencies": {
"mocha": "*",
"optimist": "*",

0 comments on commit 20fa515

Please sign in to comment.