1

I have an electron app, with a module in which I need to send multiple (5000) successive requests to a restful Endpoint. Testing the successive requests to this Endpoint from the browser window yields response times of 80 ms, but now I need to implement it in Electron side (Node.js), and when I run a test with 100 Requests with the code below, the response times are no less than 500ms and increases as I send more.
I tested this with Axios also, and the response times are the same (> 500ms).

testHttp() {
const buffer = Buffer.alloc(5 * 1024, 1);

const agent = new https.Agent({
  keepAlive: true
});
agent.maxSockets = 1000000;
const post_options = {
  hostname: this.baseUrl.substr(8),
  path: '/status/welcome',
  method: 'POST',
  port: 443,
  agent: agent,
  headers: {}
};

for (let i = 0; i < 100; i++) {
  // Set up the request
  let prepTime = 0;
  const post_req = https.request(post_options, function (res) {
    let rawResponse = '';
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
      console.log(post_req.reusedSocket);
      rawResponse += chunk;
    });
    res.on('end', () => {
      try {
        const parsedData = JSON.parse(rawResponse);
        console.log('Time Elapsed for Status Welcome : ' + (new Date().getTime() - prepTime) + ' ms');
      } catch (e) {
        console.error(e.message);
      }
    });
  });
  // post the data
  prepTime = new Date().getTime();
  post_req.write(buffer);
  post_req.end();
}

}

0 Answers0