szmarczak / http-timer

🕐 Performance timings for HTTP requests
MIT License
192 stars 18 forks source link

Sometimes timings.phases.dns is not lookup duration #35

Open Motiveko opened 1 year ago

Motiveko commented 1 year ago

I use got http client and I use option {dnsCache: true}.

In http-timer packages, theres's two code to calculate dns duration.

  1. on socket's lookup event listener https://github.com/szmarczak/http-timer/blob/62f6b38f7cfaf9936fe2f432e648cf65860c8d17/source/index.ts#L93-L98

  2. deferToConnect()'s connect callback function https://github.com/szmarczak/http-timer/blob/62f6b38f7cfaf9936fe2f432e648cf65860c8d17/source/index.ts#L102-L110

When use got with dnsCache, once hostname resolved, then until ttl, no lookup event emitted on the socket, so lookup time should be 0.

But above the code 2, dns never be 0 but tcp(connection time) will be 0.

When Server got a lot of traffic and got's socket connection delayed, value of tcp will not increased ( this always be 0 ), but value of dns increased.

I think this is causing confusion and needs to be fixed

MartinKolarik commented 6 months ago

This is also a problem when the request is made directly to an IP. There's obviously no DNS resolution in that case, but the timings report it.