Skip to content

Commit

Permalink
Merge pull request #199 from pelias/configurable-max-sockets
Browse files Browse the repository at this point in the history
feat: Support configuration of max TCP sockets
  • Loading branch information
orangejulius authored May 28, 2020
2 parents 0c8ecff + 7de03b0 commit 916d3d4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fuzzy-tester -t dev
* `-q` Enable quiet mode. Only test failures (not successes) are printed
* `-t` Select a test 'type' to filter on. This is a free-text value that can be added to each test, to allow running a subset of tests
* `-r` Set a limit of the number of requests that can be sent per second when running tests. This is useful to avoid overloading a small Pelias server
* `-m` Set a limit on the maximum number of requests that can be in progress simultaneously (default 1). Higher values can be faster, but can overload a small Pelias server.

## Test Case Files
Test-cases are expected to live in `test_cases/`, and are split into test
Expand Down
6 changes: 6 additions & 0 deletions lib/processArguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ function setUpCommander() {
'The maxium number of requests per second (RPS) to allow',
100
)
.option(
'-m, --max-sockets <int>',
'The maxium number of network sockets to open. Higher values can be faster, but can overload small servers.',
1
)
.option(
'-o, --output <type>',
outputGeneratorHelp,
Expand Down Expand Up @@ -118,6 +123,7 @@ function getConfig() {
url: apiUrl,
name: commander.endpoint
},
maxSockets: commander.maxSockets,
rate: commander.rate,
outputGenerator: outputGenerator,
testType: commander.testType,
Expand Down
5 changes: 3 additions & 2 deletions lib/request_urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ function shouldRetryRequest(res) {
}

function request_urls(config, urls, callback) {
const maxSockets = config.maxSockets || 1;
var total_length = urls.length;
var responses = {};
var httpAgent = new http.Agent({keepAlive: true, maxSockets: 1});
var httpsAgent = new https.Agent({keepAlive: true, maxSockets: 1});
var httpAgent = new http.Agent({keepAlive: true, maxSockets: maxSockets});
var httpsAgent = new https.Agent({keepAlive: true, maxSockets: maxSockets});
var intervalId;
const interval = 1000 / config.rate; // the number of miliseconds to delay between requests
var test_interval = new ExponentialBackoff(interval, 5, interval, 20000);
Expand Down

0 comments on commit 916d3d4

Please sign in to comment.