Skip to content

Commit

Permalink
http: Allow embedding tools to configure http.globalAgent.maxSockets
Browse files Browse the repository at this point in the history
This commit adds support such that setting the `NODE_HTTP_MAX_SOCKETS`
environment variable will allow Trireme to override the default
`http.globalAgent.maxSockets` value of `5` with whatever value is in
the aforementioned environment variable.
  • Loading branch information
whitlockjc authored and gbrail committed Dec 1, 2017
1 parent c94d6ce commit d27f215
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ exports.get = NodeHttp.get;
exports.Client = NodeHttp.Client;
exports.createClient = NodeHttp.createClient;

/*
* Allow the tool embedding Trireme to configure the default
* http.globalAgent.maxSockets.
*/
var customMaxSockets = toNumber(process.env.NODE_HTTP_MAX_SOCKETS);

if (customMaxSockets) {
exports.globalAgent.maxSockets = customMaxSockets;
}

if (HttpWrap.hasServerAdapter()) {
var util = require('util');
var net = require('net');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,27 @@ public void testBasicHttp()
runTest("basichttptest.js");
}

@Test
public void testHttpCustomDefaultMaxSockets()
throws InterruptedException, ExecutionException, NodeException, IOException
{
runTest("httpcustomdefaultmaxsockets.js");
}

@Test
public void testHttpDefaultMaxSockets()
throws InterruptedException, ExecutionException, NodeException, IOException
{
runTest("httpdefaultmaxsockets.js");
}

@Test
public void testHttpInvalidCustomDefaultMaxSockets()
throws InterruptedException, ExecutionException, NodeException, IOException
{
runTest("httpinvalidcustomdefaultmaxsockets.js");
}

@Test
public void testHttpPolicy()
throws InterruptedException, ExecutionException, NodeException, IOException
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var customMaxSockets = process.env.NODE_HTTP_MAX_SOCKETS = 10;

var http = require('http');
var assert = require('assert');

assert.equal(http.globalAgent.maxSockets, customMaxSockets);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var http = require('http');
var assert = require('assert');

assert.equal(http.globalAgent.maxSockets, 5);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var customMaxSockets = process.env.NODE_HTTP_MAX_SOCKETS = "invalid";

var http = require('http');
var assert = require('assert');

assert.equal(http.globalAgent.maxSockets, 5);

0 comments on commit d27f215

Please sign in to comment.