-
Notifications
You must be signed in to change notification settings - Fork 30
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
Conversation
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)
e3aec29
to
502cce2
Compare
docker-compose.dev.yml
Outdated
@@ -112,6 +112,33 @@ services: | |||
networks: | |||
vaas: | |||
ipv4_address: 192.168.199.6 | |||
varnish-6.0.2-1: |
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.
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 |
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.
❤️
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.
how is this connected with optimization?
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 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.
vaas/vaas/vcl/renderer.py
Outdated
@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: |
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 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
f41ec46
to
5b5a967
Compare
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
5b5a967
to
1dd072b
Compare
vaas/vaas/resources/dev-data.yaml
Outdated
condition: req.url ~ "/source_url" | ||
destination: http://mydomain.com/destination_url | ||
action: 301 | ||
priority: 250 | ||
preserve_query_params: false | ||
- model: router.redirect |
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.
To be sure, should we add this amount of the same redirects for the development environment?
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.
Removed the extra redirects in 9630c5a
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)