I am using node http module for testing 100 endpoints in parallel. Each of these endpoints are from different endpoints within my organization (different domains) and I want to calculate tcp connection time and total response time for them. Please find my code below. Since node JS is processing all these endpoints in a single event loop, I understand that time will be shared by multiple requests. However, Is there a gap between the time at which I start timer (See Option 1) and actual opening of connection where node is processing other callbacks. I am wondering if I should start time once socket is open (Option 2) because that is the first step in HTTP lifecycle and endpoint response time should probably start from there. Please advice. I am trying to get the most accurate timings of each of the endpoints.
// **Option 1:** Start time before http.get (my current code)
var startTime = new Date();
var req = http.get(endpoint);
req.on('socket', socket => {
// **Option 2:** Start time when socket is open (Is this more accurate?)
var startTime = new Date()
socket.on('connect', () => {
var tcpConnectionAt = new Date();
console.log("TCP connection time: " + (tcpConnectionAt-startTime));
});
});