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

PLUTON-19231 | Optimize vcl rendering fix #516 #518

Merged
merged 6 commits into from
Oct 24, 2024

Conversation

mgolski
Copy link
Contributor

@mgolski mgolski commented Oct 17, 2024

Previously, related domains and domain mappings for a given cluster were fetched in a loop, performing many small selects.
In this change, two types of of data fetching procedures (acquiring all domain mappings, and static domain mappings for each cluster) have been moved to VclRendererInput, and the smaller chunks needed for rendering steps are obtained locally from simple data structures.

In local testing, this resulted in roughly halving the time of the prepare_redirects rendering phase (from around 2 to around 0.9 seconds)

Previously, related domains and domain mappings for a given cluster were fetched in a loop, performing many small selects
In this change, two types of of data fetching procedures (acquiring all domain mappings, and static domain mappings for each cluster)
have been moved to VclRendererInput, and the smaller chunks needed for rendering steps are obtained locally from simple data structures.

In local testing, this resulted in roughly halving the time of the prepare_redirects rendering phase (from around 2 to around 0.9 seconds)
@mgolski mgolski force-pushed the mg-ms-pluton-19231-optimize-render branch from e3aec29 to 502cce2 Compare October 17, 2024 13:57
@mgolski mgolski changed the title Mg ms pluton 19231 optimize render PLUTON-19231 | Optimize vcl rendering Oct 18, 2024
@@ -112,6 +112,33 @@ services:
networks:
vaas:
ipv4_address: 192.168.199.6
varnish-6.0.2-1:
Copy link
Contributor

Choose a reason for hiding this comment

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

Those extra definitions of varnishes aren't necessary.

@@ -2,5 +2,5 @@
DEBUG=False
TEMPLATE_DEBUG=False
DJANGO_SETTINGS_MODULE=vaas.settings.docker
PROMETHEUS_ENABLE=True
PROMETHEUS_ENABLE=False
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

Copy link
Contributor

Choose a reason for hiding this comment

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

how is this connected with optimization?

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have any of the prometheus mocks, so if you run the dev server, it will try to send the metrics from celery worker about the processed task. It is easy to analyse logs in a terminal.

@collect_processing
def prepare_redirects(self) -> Dict[str, List[VclRedirect]]:
redirects = {}
related_domains = MappingProvider(DomainMapping.objects.all()).provide_related_domains(self.varnish.cluster)
related_domains = self.provide_related_domains(self.varnish.cluster)
destinations_dict = self.filter_cluster_domain_mappings(self.varnish.cluster)
for redirect in self.input.redirects:
Copy link
Contributor

Choose a reason for hiding this comment

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

The better way will be an iteration on the prepared redirects for related domains.
I have prepared a draft PR how it can look like:
#519

@mgolski mgolski force-pushed the mg-ms-pluton-19231-optimize-render branch from f41ec46 to 5b5a967 Compare October 21, 2024 07:58
Draft pull request: #519

This changes the iteration order during prepare_redirects (changing the loop from:
```for redirect in self.input.redirects:
   ...
       for mapped_domain in redirect.src_domain.mapped_domains(self.varnish.cluster):
```
to:
```for related_domain in related_domains:
   ...
       for redirect in self.input.redirects.get(related_domain):
       ...
          for mapped_domain in redirect.src_domain.mapped_domains(self.varnish.cluster):

```
In testing this caused a speedup in the time to prepare redirects from ~0.7 to ~0.1
@mgolski mgolski force-pushed the mg-ms-pluton-19231-optimize-render branch from 5b5a967 to 1dd072b Compare October 21, 2024 08:01
@ziollek ziollek changed the title PLUTON-19231 | Optimize vcl rendering PLUTON-19231 | Optimize vcl rendering fix #516 Oct 21, 2024
condition: req.url ~ "/source_url"
destination: http://mydomain.com/destination_url
action: 301
priority: 250
preserve_query_params: false
- model: router.redirect
Copy link
Contributor

@awmackowiak awmackowiak Oct 22, 2024

Choose a reason for hiding this comment

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

To be sure, should we add this amount of the same redirects for the development environment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the extra redirects in 9630c5a

@ziollek ziollek merged commit 74bed9a into master Oct 24, 2024
4 checks passed
@ziollek ziollek deleted the mg-ms-pluton-19231-optimize-render branch October 24, 2024 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants