-
Notifications
You must be signed in to change notification settings - Fork 14
✨ [#538] Improve performance and add tests #596
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ca721b5
:white_check_mark: [#538] Add PyInstrumentMiddleware profile middleware
danielmursa-dev 00ad87f
:heavy_plus_sign: [#538] Set and run CI concurrent requests test with…
danielmursa-dev 08b27bd
:zap: [#538] Fix get_queryset with select_related
danielmursa-dev b8e445c
:zap: [#538] Fix ObjectUrlField with cache
danielmursa-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| locustfile = performance_test/test_locust.py | ||
| headless = true | ||
| host = http://localhost:8000 | ||
| users = 100 | ||
| spawn-rate = 10 | ||
| run-time = 10s | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| from locust import HttpUser, task | ||
|
|
||
| OBJECTS_LIST = "/api/v2/objects" | ||
| AUTH_HEADERS = {"Authorization": "Token secret"} | ||
|
|
||
|
|
||
| class GetObjectsList(HttpUser): | ||
| params = { | ||
| "pageSize": 1000, | ||
| "type": "http://localhost:8001/api/v2/objecttypes/f1220670-8ab7-44f1-a318-bd0782e97662", | ||
| "data_attrs": "kiemjaar__exact__1234", | ||
| "ordering": "-record__data__contactmoment__datumContact", | ||
| } | ||
|
|
||
| @task | ||
| def get(self): | ||
| self.client.get(OBJECTS_LIST, params=self.params, headers=AUTH_HEADERS) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,4 +15,4 @@ whitenoise | |
| sphinx | ||
| sphinx-rtd-theme | ||
| sphinx-tabs | ||
| recommonmark | ||
| recommonmark | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import logging | ||
| import os | ||
|
|
||
| from django.http import HttpResponse | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class PyInstrumentMiddleware: # pragma:no cover | ||
| """ | ||
| Middleware that's included in dev environments if `USE_PYINSTRUMENT=true`, | ||
| allows profiling of the request/response cycle. Profiling results can be viewed | ||
| at `/_profiling` | ||
| """ | ||
|
|
||
| def __init__(self, get_response): | ||
| self.get_response = get_response | ||
| self.profiler_output_path = "/tmp/pyinstrument_profile.html" | ||
|
|
||
| def __call__(self, request): | ||
| if request.path.startswith("/_profiling"): | ||
| return self._serve_profile() | ||
|
|
||
| # Local import to avoid having to install this in production environments | ||
| from pyinstrument import Profiler | ||
|
|
||
| profiler = Profiler() | ||
| profiler.start() | ||
|
|
||
| response = self.get_response(request) | ||
|
|
||
| profiler.stop() | ||
|
|
||
| # Save the profile to an HTML file | ||
| with open(self.profiler_output_path, "w") as f: | ||
| f.write(profiler.output_html()) | ||
|
|
||
| return response | ||
|
|
||
| def _serve_profile(self): | ||
| """Serve the latest profiling report""" | ||
| if os.path.exists(self.profiler_output_path): | ||
| with open(self.profiler_output_path, "r") as f: | ||
| return HttpResponse(f.read(), content_type="text/html") | ||
| return HttpResponse("No profiling report available yet.", status=404) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.