New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timings: Tracks 'lookup', adds 'wait' time, fixes connection re-use #2566
Conversation
@Huachao and @FredKSchott would appreciate you taking a look! |
if (!self.timings.connect) { | ||
self.timings.connect = self.timings.lookup | ||
} | ||
if (!self.timings.response) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: in which case self.timings.response
is blank, or response
event is not triggered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it's even possible, but I added it here for consistency and to protect against edge cases.
README.md
Outdated
- `response`: Timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_response) module's `response` event fires. This happens when the first bytes are received from the server. | ||
- `end`: Timestamp when the last bytes of the response are received. | ||
- `dns`: Duration of DNS lookup (`timings.socket` - `timings.start`) | ||
- `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property. The start time of the request (in Unix Epoch milliseconds via `Date`) is saved as `timingStart`. The `responseStartTime` property is also available to indicate the timestamp when the response begins. In addition, there is a `timings` object available with timestamps in millisecond resolution relative to `timingStart`. If there were redirects, the properties reflect the timings of the final request in the redirect chain: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's important to emphasize the elapsedTime
and responseStartTime
is deprecated in README
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I've reorganized the description here a bit to be a list of all properties added.
tests/test-timing.js
Outdated
t.equal((res.timings.start > 0), true) | ||
t.equal((res.timings.socket >= res.timings.start), true) | ||
t.equal((res.timings.socket >= 0), true) | ||
t.equal((res.timings.lookup >= res.timings.socket), true) | ||
t.equal((res.timings.connect >= res.timings.socket), true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
res.timing.lookup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch.
Thanks for the work @nicjansma, I'll be mostly offline until Monday but would love to take a look at this once back |
README.md
Outdated
- `timings` Contains event timestamps in millisecond resolution relative to `timingStart`. If there were redirects, the properties reflect the timings of the final request in the redirect chain: | ||
- `socket` Relative timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_socket) module's `socket` event fires. This happens when the socket is assigned to the request. | ||
- `lookup` Relative timestamp when the [`net`](https://nodejs.org/api/net.html#net_event_lookup) module's `lookup` event fires. This happens when the DNS has been resolved. | ||
- `connect`: Relative timestamp when the [`http`](https://nodejs.org/api/http.html#http_event_connect) module's `connect` event fires. This happens when the server acknowledges the TCP connection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the connect event is not the one in http
module, it's the one in net
of Socket
class, the doc url should be https://nodejs.org/api/net.html#net_event_connect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, fixed
Once CI passes I would like to get this in because it fixes a leak introduced in the last release. Is anyone still in the middle of reviews that would object? |
Wow, there's a big falloff in code coverage. |
-0.35% overall. It seems like it's just due to 4 lines in the new patch that aren't run (which cover error conditions): If you're worried about it, I can see if I can create test cases for those scenarios in a followup PR (though tomorrow at the earliest). |
Oh i see, was reading that wrong. Merging this to fix the bug. Would love a followup with more tests :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
PR Checklist:
npm test
locally and all tests are passing.PR Description
Feedback from @mcorb in #2452 found a few items with the new
.timings
object.Changes:
net
'lookup'
event is now tracked, which is the correct event to track DNS lookup time..timingStart
property that is based onDate.now()
..timings.*
timestamps are relative to.timingStart
(usingnow()
)..timings
object now only containssocket
,lookup
,connect
,response
andend
(moving the durations to.timingPhases
).timings.start
is no longer needed, since it will always in effect be0
.wait
,dns
,tcp
, etc were moved to.timingPhases
..timingPhases.wait
delta is added, which tracks the time fromstart->socket
.timingPhases.dns
calculation is changed fromstart->socket
tosocket->lookup
.NaN
s or negative numbers. This is resolved by assuming any events (such aslookup
) that did not happen (due to re-use) are "filled in" using the timestamp of the previous phase (such assocket
), resulting in a0
ms delta.Here is an example of the current properties:
Tests have been added.