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

How to use autocannon for testing self signed certificates #309

Open
hrishikeshgjoshi opened this issue Nov 30, 2020 · 5 comments
Open

How to use autocannon for testing self signed certificates #309

hrishikeshgjoshi opened this issue Nov 30, 2020 · 5 comments

Comments

@hrishikeshgjoshi
Copy link

I am using autocannon to test WebServer performance and it trows error after test is executed before it provides request status as follows.
http-parser.js:126
throw err;
^

Error: Cannot use a destroyed histogram
at Object.get (/opt/HTTPClient/node_modules/hdr-histogram-js/dist/wasm/index.js:67:15)
at WasmHistogram.recordValue (/opt/HTTPClient/node_modules/hdr-histogram-js/dist/wasm/index.js:141:29)
at Client.onResponse (/opt/HTTPClient/node_modules/autocannon/lib/run.js:298:21)
at Client.emit (events.js:315:20)
at HTTPParser.nextRequest (/opt/HTTPClient/node_modules/http-parser-js/http-parser.js:178:43)
at HTTPParser.Client.parser. (/opt/HTTPClient/node_modules/autocannon/lib/httpClient.js:113:10)
at HTTPParser.BODY_SIZED (/opt/HTTPClient/node_modules/http-parser-js/http-parser.js:434:10)
at HTTPParser.execute (/opt/HTTPClient/node_modules/http-parser-js/http-parser.js:120:27)
at TLSSocket. (/opt/HTTPClient/node_modules/autocannon/lib/httpClient.js:153:17)

@salmanm
Copy link
Collaborator

salmanm commented Nov 30, 2020

Please post the test config.

@hrishikeshgjoshi
Copy link
Author

Here is the test script for the same.

"use strict";

const autocannon = require("autocannon");

const loadSpec = {
loadingInfo: {
connections: 4, //default
pipelining: 10, // default
duration: 900, // default
maxConnectionSizeLimit: 512,
connectionIncrementFactor: 2,
},
urls: [
"https://apache.mycompany.com/test.html",
"https://tomcat.mycompany.com:8443/test.html",
"https://nginx.mycompany.com/test.html",
"https://apache.mycompany.com/PartReport.pdf",
"https://tomcat.mycompany.com:8443/TestReport.pdf",
"https://nginx.mycompany.com/TestReport.pdf",
],
titles: [
"Apache-70K HTTPS Tests",
"Tomcat-70K HTTPS Tests",
"Nginx-70K HTTPS Tests",
"Apache-61M HTTPS Tests",
"Tomcat-61M HTTPS Tests",
"Nginx-61M HTTPS Tests",
],
tableTitle: {
average: "Average",
mean: "Mean",
stddev: "Standerd Deviation",
min: "Min",
max: "Max",
total: "Total",
totalCount: "Total",
sent: "Sent",
},
};

// async/await
async function runTest() {
console.log("Test duration per server");
console.log(loadSpec.loadingInfo.duration);
for (var j = 0; j < loadSpec.urls.length; j++) {
console.log(loadSpec.titles[j] + "," + loadSpec.urls[j]);
}
for (
var i = loadSpec.loadingInfo.connections;
i <= loadSpec.loadingInfo.maxConnectionSizeLimit;
i = i * loadSpec.loadingInfo.connectionIncrementFactor
) {
console.log("Number of concurrent connections," + i);
const results = [];
for (var j = 0; j < loadSpec.urls.length; j++) {
const result = await autocannon({
url: loadSpec.urls[j],
connections: i,
pipelining: loadSpec.loadingInfo.pipelining,
duration: loadSpec.loadingInfo.duration,
});
result.title = loadSpec.titles[j];
results.push(result);
}
printReportInCSV(results);
}
}
function printReportInCSV(results) {
let printHeader = true;
results.map((element) => {
printResultData(element, "requests", "Requests", "Req/Sec", printHeader);
printHeader = false;
});

printHeader = true;
results.map((element) => {
printResultData(
element,
"throughput",
"Throughput",
"Bytes/Sec",
printHeader
);
printHeader = false;
});

printHeader = true;
results.map((element) => {
printResultData(element, "latency", "Latency", "Milliseconds", printHeader);
printHeader = false;
});

printHeader = true;
results.map((element) => {
if (printHeader) {
console.log("Sever, Total Number of Requests, Errors");
}
printRequestSummery(element);
printHeader = false;
});
}

function printRequestSummery(result) {
let dataLabel = result.title.substring(0, result.title.indexOf(" "));
console.log(dataLabel + "," + result.requests.total + "," + result.errors);
}

function printResultData(
result,
requestDataType,
requestDataTypeLabel,
statsLabel,
printHeader
) {
var requestsKeys = printHeader ? [] : null;
const resultValues = toCSVFy(result[requestDataType], requestsKeys);
if (printHeader) {
console.log(requestDataTypeLabel + ", Stats, " + requestsKeys);
}
let dataLabel = result.title.substring(0, result.title.indexOf(" "));
console.log(dataLabel + "," + statsLabel + "," + resultValues);
}

function toCSVFy(result, resultKeys) {
var resultValues = [];
for (var key in result) {
if (resultKeys) {
var label = loadSpec.tableTitle[key] ? loadSpec.tableTitle[key] : key;
if (key.startsWith("p")) {
label = key.substr(1).replace("_", ".");
label = label + "%";
}
resultKeys.push(label);
}
resultValues.push(result[key]);
}
return resultValues;
}
runTest();

@salmanm
Copy link
Collaborator

salmanm commented Dec 1, 2020

How is this related to testing a server with self signed certificate? Do you mean that you don't see this error when the same test is run against a different http server?

Also, it'd be great help in debugging if you could post a reproducible repo as an example.

@hrishikeshgjoshi
Copy link
Author

Yes if I run this test code to use http url. I do not see this error. Do you see any obvious mistake in code posted above. I will try to provide some reproducible repo soon.

@trycontrolmymind
Copy link

@hrishikeshgjoshi i think you can run your tests like this
NODE_TLS_REJECT_UNAUTHORIZED=0 node runTest.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants