Created a nodejs library which makes an https request with client certificates(.crt,.key files) to a different server to get the response. For making a request I used the "request" npm module.
While benchmarking the library, I was making 2000 requests to my library to make a request but the library couldn't handle more than 150-200 simultaneously. Suppose, I used Http server then library throughput has been increased with 1800-1850 simultaneously. what I observed is while making https request, I think the event loop is blocked. so that it couldn't able to handle or accept the requests.
I have also tried using the https core module, node-fetch, axios npm modules. There is no difference in the throughput of my library.
Also, we have tried using the cluster concept of nodejs. but it's not suitable for my library.
Please help me with what should I do, to increase the throughput of my library.
My Code:
const request = require('request');
const fs = require('fs');
const path = require('path');
function makeRequest() {
let headers = {'Content-Type':'application/json'};
let body = '{name:'library'}';
let options = {
url: 'https://IP:PORT/CONTEXT',
method: 'POST',
headers: headers,
body: body,
agentOptions:
{
cert: fs.readFileSync(path.resolve(__dirname, 'ssl/my.crt')),
key: fs.readFileSync(path.resolve(__dirname, 'ssl/my.key')),
passphrase: '123456'
}
}
request(options, (err, response, body) => {
if (err) {
console.log('err :>> ', err);
} else {
console.log('response :>> ', response.statusCode);
}
})
}