Skip to content
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

Collect request stats #9633

Merged
merged 11 commits into from
Apr 12, 2024
Merged

Collect request stats #9633

merged 11 commits into from
Apr 12, 2024

Conversation

benjervis
Copy link
Contributor

↪️ Pull Request

In order to get a picture of the cache performance in our application, we want to get the request stats and the number of visited asset_groups out of each Parcel build.

These get loggered, to be read by a custom reporter.

let requestTypeEntries = {};
type RequestTypes = Array<$Keys<typeof requestTypes>>;

for (let key of (Object.keys(requestTypes): RequestTypes)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/nit you could just create this mapping at the top of the file so it's done once, and it could be more idiomatic using Object.entries

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True about top of the file. However we used keys because the flow types to get entries happy was super ugly.

@@ -385,6 +385,7 @@ export default class Parcel {
},
};

this.#requestTracker.flushStats();
Copy link
Contributor

@MonicaOlejniczak MonicaOlejniczak Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we want to go down this rabbit hole, but it's pretty common for success events to store stats regarding the build. Instead of having flushStats, you could add the stats directly to build success under a new key and then get the reporter to log it.

That way the RequestTracker does not have to care about how to report the info, it just gives it to whatever wants to consume it. This is similar to what @marcins noted before, but can be extended to other stats we want to measure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree this would be nicer. We opted not to do it that way to avoid adding Parcel public API that would be a breaking change to remove or modify in future. Thoughts?

Copy link
Contributor

@MonicaOlejniczak MonicaOlejniczak Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, I'm looking at adding high-level (and potentially more granular) perf metrics and am starting to explore options. Having a stats object or something similar to that would be useful.

In regards to the public API, you could name the field as unstable_stats to make no guarantees to consumers. Or in a similar fashion, expose that there is a stats object but type it as a record with any value. That way, we are saying we will provide it but make no guarantees about what's in there. We'd probably need something internal to give us types we know about to make logs or w/e on them, but it doesn't need to be exposed.

@devongovett
Copy link
Member

What's the difference between this and tracing? They seem to have similar goals. Maybe the tracer could track requests in a similar way?

@@ -66,14 +66,14 @@ export default (new Reporter({
case 'buildSuccess':
case 'buildFailure':
nullthrows(tracer).flush();
tracer = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcins This actually fixes a race condition that showed up in the tests where it's possible that the tracer isn't cleared quick enough.

@mattcompiles
Copy link
Contributor

@devongovett I believe tracing has a performance overhead and is used for in depth analysis of one-off builds. This is something we want to measure across all builds. The visitedAssetGroupsCount is pretty unideal but allows us to create an exact cache ratio for transforms and packaging.

@mattcompiles mattcompiles merged commit 4cd9467 into v2 Apr 12, 2024
14 of 17 checks passed
@mattcompiles mattcompiles deleted the req-stats branch April 12, 2024 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants