8

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

silk show image

enter image description here

Dan Bonachea
  • 2,408
  • 5
  • 16
  • 31
Ramsey
  • 103
  • 7
  • trying out `django-silk` and seeing the same issue... setting `SILKY_PYTHON_PROFILER_RESULT_PATH` doesn't seem to resolve the issue. – monkut Sep 08 '21 at 07:06

3 Answers3

5

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/'
user3723763
  • 366
  • 2
  • 9
  • I'm working on windows and as a short note: `SILKY_PYTHON_PROFILER_RESULT_PATH = os.path.join('C:\\', 'temp')` does work, but `SILKY_PYTHON_PROFILER_RESULT_PATH = 'C:/temp/'` does not. – Gnietschow Jan 26 '22 at 15:37
0

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.

Ref: https://github.com/jazzband/django-silk#installation

KhaledMohamedP
  • 5,000
  • 3
  • 28
  • 26
0

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;
dia na
  • 1