-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
clients(lightrider): always get transferSize from X-TotalFetchedSize header #7478
Conversation
even the comment in the PR itself is a better PR description than this one :P :P fixed it |
Didn't want to repeat myself ;) |
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.
Seems fine to me! I'm not surprised that this is now buggy. This entire workaround was done hastily in response to devtools logs that had all 0 transfer size records without being able to reproduce or explained at the time by DT folks 😆
I had thought that in WRS loaders there was no incremental loading on the Chrome side and it always appeared to showup in one big chunk over the protocol, or at least that's what early devtools logs appeared to show, so if that wasn't true, it certainly explains the troubles we see now. |
That is true. Orthogonal to how many dataReceived events are seen is - whether or not encodedDataLength is set on them. The weird pattern of |
Copying from the internal thread... Here's how I understand things.. "Correct" pattern (we see in desktop chrome regardless of NS) when data is received in one chunk:
Old WRS:
ToT WRS:
This seems correct to everyone? if so... Due to reasons, we can't have encodedDataLength populated correctly in WRS, so we have to accept a lie. So we have to handle the special situation here on the LH side.
Proposal: If this is Lightrider and we receive that header, then we use that as our |
In practice I see,
seems fine to me 👍 |
Ah I see. loadingFinished's value should override the sum of dataReceived's. I guess we'd use the dataReceived ones if it was loadingFailed or some other weird situation. mkay. Okay in that case, let's continue to set LR transferSize here in loadingFinished, but let's add a shitton of comments that explain this shit so we don't have to research it so hard next time. YES? YES. |
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.
plz add so many more comments on the sequencing and where we expect the data
Yupper
It seems we could remove the call to options as I see it;
|
Can we keep the changes for lightrider limited to a single place? What happened to
Seems like the new behavior is the same as in 8406bc9 (disregard normal way of setting We should also get some tests in for this. |
I'd strongly prefer to just have |
doneski :) |
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.
just to make the testing more work, can we pick a site with fewer requests? :)
Or we can trim down to just the requests we care about? It seems fine to rely on this fixture just for checking this issue
@@ -246,6 +247,18 @@ module.exports = class NetworkRequest { | |||
|
|||
this.responseReceivedTime = timestamp; | |||
|
|||
this.responseHeadersText = response.headersText || ''; |
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.
move these lines back?
// a value via the accumulation. | ||
// In Lightrider, we do not have true value for encodedDataLength, and we get the actual size | ||
// of the encoded data via a special response header. Because the values are totally bogus, | ||
// we do no accumulation. |
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.
move comment down to _updateTransferSizeForLightrider
?
like ... json.filter(entry => {
return entry.method.startsWith('Network') &&
['B38A026891F997E88601C20D85DC4616', '1000170085.13'].includes(entry.params.requestId);
}); ? :) |
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.
it's a beauty
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.
can you also leave a comment on L70 that says go read the _updateTransferSizeForLightrider
comment?
|
||
// The total length of the encoded data is spread out among multiple events. The sum of the | ||
// values in onResponseReceived and all the onDataReceived events will equal the value | ||
// seen on the onLoadingFinished event. As we process onResonseReceived and onDataReceived |
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 sum of the
// values in onResponseReceived and all the onDataReceived events will equal the value
// seen on the onLoadingFinished event.
I don't know exactly what leads to a situation when the loadingFinished total is different than the sum of the parts, but apparently it does happen.
I just tried against 6 saved devtoolslogs i have. (Disclaimer: the artifacts were collected months ago definitely without networkservice, though I wouldn't expect it to matter)... There's, 320 network requests in total and nearly all of them have a sum that matches (or the sum was 0).. But I found 3 requests where this wasn't the case.
encodedSum | encodedTotalInLoadingFinished | url |
---|---|---|
108 | 12640 | http://localhost:10200/dobetterweb/dbw_tester.html |
139 | 144 | http://localhost:10200/dobetterweb/empty_module.js?delay=500 |
650 | 714 | https://s.amazon-adsystem.com/x/da2e6c890e6e3636 |
Again.. don't know what leads to this situation, but it happens. I'm happy with admitting that in the comment or we can ask caseq/network people about the circumstances..
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.
ooh that is funky. With NS off, it's good. But on it was off by 5 for "empty_module?delay=500". And there was no dataReceived
event!
// we accumulate the total encodedDataLength. When we process onLoadingFinished, we override | ||
// the accumulated total. We do this so that if the request is aborted or fails, we still get | ||
// a value via the accumulation. | ||
// In Lightrider, we do not have true value for encodedDataLength, and we get the actual size |
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.
we do no accumulation.
Looks like we do, as of now.. We just override the transferSize in loadingFinished
Thank you VERY MUCH for writing all this shit out. These comments are so Good.
here's a very small rewrite of this second para for clarity:
In Lightrider, due to instrumentation limitations, our values for encodedDataLength are bogus and not valid. However the resource's true
encodedDataLength
/transferSize
is shared via a special response header,X-TotalFetchedSize
. In this situation, we read this value from responseReceived, use it for thetransferSize
and ignore the encodedDataLength values in both dataReceived and loadingFinished.
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.
oops thanks for the revisions ❤️
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.
two nits
thanks for digging in on this!
* 'X-TotalFetchedSize' is the canonical transfer size in LR. Nothing should supersede it. | ||
* | ||
* The total length of the encoded data is spread out among multiple events. The sum of the | ||
* values in onResponseReceived and all the onDataReceived events will equal the value |
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.
will equal => typically equals
and add
In <1% of cases we see the values differ.
_updateTransferSizeForLightRiderIfNecessary() { | ||
// Bail if we're not in LightRider, this only applies there. | ||
if (!global.isLightRider) return; | ||
_updateTransferSizeForLightrider() { |
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.
can you also leave a comment on L70 that says go read the _updateTransferSizeForLightrider comment?
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.
sorrrrrryy I'm late to the party
* The total length of the encoded data is spread out among multiple events. The sum of the | ||
* values in onResponseReceived and all the onDataReceived events typically equals the value | ||
* seen on the onLoadingFinished event. In <1% of cases we see the values differ. As we process | ||
* onResonseReceived and onDataReceived we accumulate the total encodedDataLength. When we |
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.
typo onResponseReceived
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.
sent a pr
* | ||
* The total length of the encoded data is spread out among multiple events. The sum of the | ||
* values in onResponseReceived and all the onDataReceived events typically equals the value | ||
* seen on the onLoadingFinished event. In <1% of cases we see the values differ. As we process |
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.
fwiw in ~70% of cases in my local devtoolslog of a run I just did the final encodedDataLength
differs from the sum of the events, not sure if I'm broken or the something else has changed :)
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.
interesting. could you or paul share your test scripts / LH code diff / devtool logs? We should control for what logs we are using + NS + Chrome version so we know what's actually happening.
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.
oh I just looked at the last latest-run/defaultPass.devtoolslog.json I had, so it's probably fairly old
* seen on the onLoadingFinished event. In <1% of cases we see the values differ. As we process | ||
* onResonseReceived and onDataReceived we accumulate the total encodedDataLength. When we | ||
* process onLoadingFinished, we override the accumulated total. We do this so that if the | ||
* request is aborted or fails, we still get a value via the accumulation. |
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.
or fails
did we decide not to override for onLoadingFailed
?
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.
_updateTransferSizeForLightrider
is being called on failed now, or did you mean something else?
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.
oh I just missed it and comment didn't mention it so I got confused, we're all good :)
After inspecting the devtools log locally with the NS on and off, I'm mostly convinced that Chrome is right, and LH needs to be tweaked
The pattern dataLength=x,encodedDataLength=0 + dataLength=0,encodedDataLength=y only happens for resources that load in one chunk. And x = y only when the content is not compressed. It seems that if all the data for a resource comes in one chunk, the first "dataReceived" event always has 0 for encodedLength, but the second event will have the entire encoded length. If the resource is loaded in multiple chunks, the first dataReceived event has some of the total encoded length, the next won't have much or any, and the remaining unreported encoded length is on the last event. Inspecting the logic in the code linked in
#3
seems to support this.I think the behavior before could be considered incorrect, and the "bugged" version is what should be expected. An encodedDataLength of zero doesn't really make sense, but we were depending on it :) In other words, no issue with Chrome, let's fix LH.
Fixes internal bug b/123996856. Googlers, see internal changes cl/238109521.