'Node.js benchmarking with autocannon npm
I have a api that define liveness by checking sended video file. I want to check server strongness by bencmarking with autocannon. I want to send n requests by n concurrent connections(I mean every connection send 1 request per second). it should do this every seconds. But it doesn't this.Autocannon waits for the previous request to finish before starting the new on for every connection. But I want send n requests every per seconds . How to do this with autocannon
import * as autocannon from 'autocannon';
import * as dotenv from 'dotenv';
import FakeData from './mockData';
dotenv.config();
async function startBenchmark() {
const livenessMockData = await FakeData()
const url = "http://localhost:5060";
const numConnections = parseInt(process.env.NUM_CONNECTIONS) || 10;
// const maxConnectionRequests = parseInt(process.env.MAX_COUNT_CONNECTION_REQUESTS) || 10000;
const connectionRateForEveryConnection = 1;
let requestNumber = 0;
const instance = await autocannon(
{
url,
connections: numConnections,
connectionRate: connectionRateForEveryConnection,
duration:20,
// amount: 20,
timeout:20,
headers: {
'Content-Type': 'application/json'
},
requests: [
{
method: "POST",
path: '/check/response',
headers: {
'Content-type': 'application/json',
},
setupRequest: function (request: any) {
request.body = JSON.stringify(livenessMockData[requestNumber]);
console.log('------------ request body -------------')
console.log(requestNumber + 1, livenessMockData[requestNumber])
console.log('------------ request body -------------\n')
requestNumber++
return request;
}
},
]
},
finishedBench
);
function finishedBench(err: any, res: any) {
console.log('Finished bench: ', res);
}
autocannon.track(instance);
}
startBenchmark();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|