This repository was archived by the owner on Sep 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
create one keepalive agent per pool #22
Open
Matt-Esch
wants to merge
1
commit into
master
Choose a base branch
from
me.keepalive.perpool
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,12 @@ | |
| var GO, // GO is global object, for passing to a REPL or finding in a core dump | ||
| EventEmitter = require("events").EventEmitter, | ||
| Stream = require("stream"), | ||
| inherits = require("util").inherits; | ||
| inherits = require("util").inherits, | ||
| http = require('http'); | ||
|
|
||
| // Pool - manages a set of equivalent endpoints and distributes requests among them | ||
| // | ||
| // http: which endpoint HTTP module to use, either http.js or https.js | ||
| // protocol: which endpoint HTTP module to use, either http.js or https.js | ||
| // endpoints: array of strings formatted like "ip:port" | ||
| // options: { | ||
| // max_pending: number of pending requests allowed (1000) | ||
|
|
@@ -21,14 +22,14 @@ var GO, // GO is global object, for passing to a REPL or finding in a core dump | |
| // max_retries: number (default = 5) | ||
| // agent_options: {} an object for passing options directly to the HTTP(S) Agent | ||
| // } | ||
| function Pool(http, endpoints, options) { | ||
| if (!http || !http.request || !http.Agent) { | ||
| function Pool(protocol, endpoints, options) { | ||
| if (!protocol || !protocol.request || !protocol.Agent) { | ||
| throw new Error("invalid http module"); | ||
| } | ||
| if (! Array.isArray(endpoints)) { | ||
| throw new Error("endpoints must be an array"); | ||
| } | ||
| this.http = http; | ||
| this.protocol = protocol; | ||
|
|
||
| options = options || {}; | ||
| options.retry_filter = options.retry_filter || options.retryFilter; | ||
|
|
@@ -52,6 +53,8 @@ function Pool(http, endpoints, options) { | |
| this.max_pending = options.max_pending || options.maxPending || 1000; | ||
| this.endpoints = []; | ||
| this.endpoints_by_name = {}; | ||
| this.keep_alive = options.keep_alive || options.keepAlive; | ||
| this.agent_options = options.agent_options || options.agentOptions; | ||
|
|
||
| this.length = 0; | ||
| for (var i = 0; i < endpoints.length; i++) { | ||
|
|
@@ -62,6 +65,17 @@ function Pool(http, endpoints, options) { | |
| throw new Error("no valid endpoints"); | ||
| } | ||
|
|
||
|
|
||
| if (this.keep_alive) { | ||
| if (protocol === http) { | ||
| this.agent = new GO.KeepAliveAgent.HTTP(this.agent_options); | ||
| } else { | ||
| this.agent = new GO.KeepAliveAgent.HTTPS(this.agent_options); | ||
| } | ||
| } else { | ||
| this.agent = new protocol.Agent(this.agent_options); | ||
| } | ||
|
|
||
| // this special endpoint is returned when the pool is overloaded | ||
| this.overloaded_endpoint = new GO.PoolEndpoint({Agent: Object}, null, null, {timeout: 0}); | ||
| this.overloaded_endpoint.special_endpoint = "overloaded"; | ||
|
|
@@ -309,7 +323,7 @@ Pool.prototype.add_endpoint = function (host_port) { | |
| var ip = ip_port[0]; | ||
| var port = +ip_port[1]; | ||
| if (port > 0 && port < 65536) { | ||
| var endpoint = new GO.PoolEndpoint(this.http, ip, port, this.options); | ||
| var endpoint = new GO.PoolEndpoint(this.protocol, ip, port, this.options); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems like you intended for |
||
| endpoint.on("health", this.endpoint_health_changed.bind(this)); | ||
| endpoint.on("timeout", this.endpoint_timed_out.bind(this)); | ||
| this.endpoints.push(endpoint); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: property name
httpis more clearly a module to me thanprotocolwhich sounds like it is going to be a string"http"or"https"