0

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));
            });
        });
Mary123
  • 11
  • 4
  • They're both accurate options for what they measure. – Evert Jun 13 '22 at 18:26
  • Thanks for your reply @Evert. I am concerned about option 1 when there are multiple parallel requests. Is it possible that timer is started but request is not sent out because there are other callbacks from other requests and node is processing those. – Mary123 Jun 13 '22 at 18:52
  • Usually any 'synchronous' work is initiated, this typically includes the first steps to opening the socket. But this does not include the request being fully sent out. When you are doing a load test like this, you are dealing with *lots* of things that dont perform exactly the same in parallel as sequential, including the network stack, client computer. If you're really worried that those few ms are going to skew the result why don't you measure both and look at the difference. – Evert Jun 13 '22 at 19:06

0 Answers0