Using django 2.2.14 and django-silk 3.0. Just return overall time but the queries are all 0.Is some wrong about the version of django-silk or django?How can I solve the bizarre issus.
Package Version Django 2.2.14 django-silk 3.0.2
Using django 2.2.14 and django-silk 3.0. Just return overall time but the queries are all 0.Is some wrong about the version of django-silk or django?How can I solve the bizarre issus.
Package Version Django 2.2.14 django-silk 3.0.2
Quick answer
Set SILKY_PYTHON_PROFILER_RESULT_PATH
in your settings.py
for example:
SILKY_PYTHON_PROFILER_RESULT_PATH = "/var/profiler"
You must ensure the specified directory exists. In the documentation of silk says It supposed to use media folder if it's not set but somehow is not working.
# If this is not set, MEDIA_ROOT will be used.
SILKY_PYTHON_PROFILER_RESULT_PATH = '/path/to/profiles/'
There are few things you need to ensure are set.
The main important one is adding the following env flags before your run your application.
In your .env
add:
SILKY_PYTHON_PROFILER=True
If you do have SILKY_INTERCEPT_FUNC
method in your settings.py
ensure it returns the correct boolean value based on the request e.g.
def SILKY_INTERCEPT_FUNC(request):
"""log only session has recording enabled."""
return 'record_requests' in request.session
In addition, ensure you add the silk middleware in the correct order
In settings.py
add the following:
MIDDLEWARE = [
...
'silk.middleware.SilkyMiddleware',
...
]
INSTALLED_APPS = (
...
'silk'
)
Note: The middleware placement is sensitive. If the middleware before silk.middleware.SilkyMiddleware returns from process_request then SilkyMiddleware will never get the chance to execute. Therefore you must ensure that any middleware placed before never returns anything from process_request. See the django docs for more information on this.
I had a similar problem with an endpoint that had a long loading time.
Notised that MySQL
aborted connection with Error 1153 - Got a packet bigger than 'max_allowed_packet' bytes
To fix it update the my.cnf
in /etc/mysql/
net_buffer_length=1000000
max_allowed_packet=1000000000
or run:
set global net_buffer_length=1000000;
set global max_allowed_packet=1000000000;