autocannon
autocannon copied to clipboard
How to use autocannon for testing self signed certificates
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.
Please post the test config.
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();
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.
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.
@hrishikeshgjoshi i think you can run your tests like this
NODE_TLS_REJECT_UNAUTHORIZED=0 node runTest.js