-
Notifications
You must be signed in to change notification settings - Fork 919
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
Bedrock performance tooling and initial optimisations #15513
base: main
Are you sure you want to change the base?
Changes from all commits
d9a93e8
f04e774
b6b234b
ecb0281
8867fa8
858c264
9e6ee0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
from django.conf import settings | ||
from django.core.cache import cache | ||
from django.http.response import Http404 | ||
from django.shortcuts import get_object_or_404 | ||
from django.views.generic import DetailView, ListView | ||
|
@@ -62,10 +64,17 @@ class BenefitsView(L10nTemplateView): | |
|
||
|
||
class PositionListView(LangFilesMixin, RequireSafeMixin, ListView): | ||
queryset = Position.objects.exclude(job_locations="Remote") | ||
template_name = "careers/listings.html" | ||
context_object_name = "positions" | ||
|
||
def get_queryset(self): | ||
_key = "careers_position_listing_qs" | ||
qs = cache.get(_key) | ||
if qs is None: | ||
qs = Position.objects.exclude(job_locations="Remote") | ||
cache.set(_key, qs, settings.CACHE_TIME_SHORT) | ||
return qs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we cache the queryset or cache the list of objects? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally yeah, we'd cache the objects, not the qs, but it's a bit more fiddly than I expected. Because these are CBVs, cacheing the queryset in Later, even though we don't use pagination in these pages, the list view runs the data through What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for sharing that. It's a bit more complex than first glance. I'm actually a bit surprised we can cache the queryset objects, which seems more complex. I suppose they get pickled? But this is fine with me, I was mostly curious about your thoughts on the consideration. Thanks! |
||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
context["form"] = PositionFilterForm() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
"""Request a selection of pages that are populat on www.m.o from your local | ||
runserver, so that django-silk can capture performance info on them. | ||
|
||
Usage: | ||
|
||
1. In your .env set ENABLE_DJANGO_SILK=True | ||
2. Start your runserver on port 8000 | ||
3. python profiling/hit_popular_pages.py | ||
3. View results at http://localhost:8000/silk/ | ||
|
||
""" | ||
|
||
import sys | ||
import time | ||
|
||
import requests | ||
|
||
paths = [ | ||
"/en-US/firefox/126.0/whatsnew/", | ||
"/en-US/firefox/", | ||
"/en-US/firefox/windows/", | ||
"/en-US/firefox/new/?reason=manual-update", | ||
"/en-US/firefox/download/thanks/", | ||
"/en-US/firefox/new/?reason=outdated", | ||
"/en-US/firefox/features/", | ||
"/en-US/firefox/all/", | ||
"/en-US/firefox/welcome/18/", | ||
"/en-US/", | ||
"/en-US/firefox/installer-help/?channel=release&installer_lang=en-US", | ||
"/en-US/firefox/download/thanks/?s=direct", | ||
"/en-US/firefox/welcome/19/", | ||
"/en-US/firefox/enterprise/?reason=manual-update", | ||
"/en-US/products/vpn/", | ||
"/en-US/firefox/browsers/windows-64-bit/", | ||
"/en-US/firefox/mac/", | ||
"/en-US/about/", | ||
"/en-US/firefox/android/124.0/releasenotes/", | ||
"/en-US/firefox/browsers/mobile/get-app/", | ||
"/en-US/firefox/browsers/", | ||
"/en-US/firefox/nightly/firstrun/", | ||
"/en-US/firefox/developer/", | ||
"/en-US/account/", | ||
"/en-US/contribute/", | ||
"/en-US/firefox/browsers/mobile/android/", | ||
"/en-US/privacy/archive/firefox-fire-tv/2023-06/", | ||
"/en-US/firefox/121.0/system-requirements/", | ||
"/en-US/firefox/browsers/mobile/", | ||
"/en-US/firefox/releases/", | ||
"/en-US/MPL/", | ||
"/en-US/firefox/enterprise/", | ||
"/en-US/security/advisories/", | ||
"/en-US/firefox/browsers/what-is-a-browser/", | ||
"/en-US/firefox/channel/desktop/?reason=manual-update", | ||
"/en-US/firefox/pocket/", | ||
"/en-US/firefox/channel/desktop/", | ||
"/en-US/firefox/welcome/17b/", | ||
"/en-US/firefox/welcome/17c/", | ||
"/en-US/firefox/welcome/17a/", | ||
"/en-US/firefox/set-as-default/thanks/", | ||
"/en-US/careers/listings/", | ||
"/en-US/firefox/browsers/chromebook/", | ||
"/en-US/firefox/nothing-personal/", | ||
"/en-US/newsletter/existing/", | ||
"/en-US/about/legal/terms/firefox/", | ||
"/en-US/firefox/linux/", | ||
"/en-US/firefox/browsers/mobile/focus/", | ||
"/en-US/products/vpn/download/", | ||
"/en-US/about/manifesto/", | ||
"/en-US/stories/joy-of-color/", | ||
"/en-US/contact/", | ||
"/en-US/about/legal/defend-mozilla-trademarks/", | ||
] | ||
|
||
|
||
def _log(*args): | ||
sys.stdout.write("\n".join(args)) | ||
|
||
|
||
def hit_pages(paths, times=3): | ||
_base_url = "http://localhost:8000" | ||
|
||
for path in paths: | ||
for _ in range(times): | ||
time.sleep(0.5) | ||
url = f"{_base_url}{path}" | ||
requests.get(url) | ||
|
||
_log("All done") | ||
|
||
|
||
if __name__ == "__main__": | ||
hit_pages(paths) |
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.
for bonus points you could test that the db call doesn't get triggered on a 2nd call to the wrapped methods.
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.
Yeah - good call. Time to break out
assertNumQueries
!