Skip to content

Bug 1492768 - Optimize alert summary queries executed from graphs view#4050

Merged
wlach merged 1 commit intomozilla:masterfrom
wlach:stop-the-bleeding
Sep 20, 2018
Merged

Bug 1492768 - Optimize alert summary queries executed from graphs view#4050
wlach merged 1 commit intomozilla:masterfrom
wlach:stop-the-bleeding

Conversation

@wlach
Copy link
Copy Markdown
Contributor

@wlach wlach commented Sep 20, 2018

Not a complete solution but hopefully this will improve things enough
to stop the timeouts we're seeing.

Not a complete solution but hopefully this will improve things enough
to stop the timeouts we're seeing.
@wlach wlach temporarily deployed to treeherder-prototype September 20, 2018 15:09 Inactive
class PerformanceSignatureSerializer(serializers.ModelSerializer):
framework_id = serializers.SlugRelatedField(
slug_field="id", source="framework",
queryset=PerformanceFramework.objects.all())
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This resulted in a query which was expensive and unnecessary, since we have the framework id already.

repository__active_status='active').select_related(
'repository').prefetch_related(
'alerts',
'alerts__classifier',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can prefetch the classifier to save a bunch of queries when we serialize.

'alerts__series_signature__option_collection__option')
queryset = PerformanceAlertSummary.objects.filter(
repository__active_status='active').select_related(
'repository').prefetch_related(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since repository is a foreign key on the alert summary table, it makes more sense to put the fetch in a selected_related clause. More or less cleanup.

@wlach
Copy link
Copy Markdown
Contributor Author

wlach commented Sep 20, 2018

This seems to improve query times by a factor of 2 on stage. There's still a ridiculous number of queries, but that's a little harder to fix (we may want to consider either using a custom endpoint which looks up alert summaries based on alerts or using graphql here)

@wlach wlach merged commit 2806e50 into mozilla:master Sep 20, 2018
@wlach wlach deleted the stop-the-bleeding branch September 20, 2018 15:45
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.

2 participants