feat: extract server timings and measure individual retrievals #332
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pulls the
Server-Timing
response header logic into it's own file and updates the retrieval event parsing to get timing on individual retrieval attempts. This tracks the individual events that occur on a per retrieval basis, whereas before we were treating "retrieval" as a phase and tracking all events under that phase. This was problematic since the second event of any type, for example during a second concurrent retrieval, would overwrite any previous event and it's timings.The following is an example of the
Server-Timing
response header when fetchingbafybeic56z3yccnla3cutmvqsn5zy3g24muupcsjtoyp3pu5pm5amurjx4/birb.mp4
via the daemon. I've added newlines for each comma delimited item.Explaination
Due to the caveat explained below, all the "dur" fields are actually the time since the
started-fetch
event, while the individual metric extras are the duration since the beginning of that metric in nanoseconds.Caveats
We are unable to get the duration of the entire fetch/successful retrievals due to the way in which the headers are written. Since the headers are written before an http
Write
occurs, we can only collect info about the retrievals until afirst-byte-received
event that results in data being written to the client. The httpWrite
ends up occurring before the success and finished events are emitted, therefore cutting off the trailing events that occur for any given retrieval. Because of this, thestarted-fetch
,success
, andfinished
events are not processed.