Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit node http agent socket pool to 25 #336

Merged
merged 1 commit into from
Sep 21, 2016
Merged

Conversation

SimonWoolf
Copy link
Member

Having a reasonable limit on the max number of parallel TCP connections for doing rest requests with (by default there's no limit) seems to eliminate the TCP errors and timeouts we were seeing when hundreds of rest requests are fired off in parallel.

I'm open to input on the exact value. With 50 I was still seeing a couple TCP spurious retransmissions with 500 parallel publishes; with 25, no TCP errors; and a socket pool of 25 is large enough for reasonable parallelism (500 simple publishes end up with starting times spread out over around around 2 seconds, which seems not unreasonable).

@paddybyers
Copy link
Member

So assuming a round trip time of 500ms, and a max number of in-flight requests of 25 - that's a hard-coded maximum sustainable throughput of 50 requests per second from a single library instance. Is it reasonable to have a limit in this way?

@SimonWoolf
Copy link
Member Author

After discussion with Paddy, increased limit from 25 to 40, and made a hidden restAgentOptions clientOption.

@mattheworiordan
Copy link
Member

That looks good to me 👍

@@ -144,7 +145,8 @@ this.Http = (function() {
* @param callback (err, response)
*/
Http.postUri = function(rest, uri, headers, body, params, callback) {
var postOptions = {headers:headers, body:body, encoding:null, forever: true};
var agentOptions = (rest && rest.options.restAgentOptions) || Defaults.restAgentOptions;
var postOptions = {headers:headers, body:body, encoding:null, forever: true, agentOptions: agentOptions};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer a space after the colon, but at least be consistent :)

Copy link
Member

@paddybyers paddybyers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with comment

@SimonWoolf SimonWoolf merged commit 7d7831e into master Sep 21, 2016
@SimonWoolf SimonWoolf deleted the limit-parallel-tcp branch October 11, 2017 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants