9

How can I profile a Django application while running on gunicorn using python cProfile.

I can profile in development mode: python -m cProfile -o sample.profile manage.py runserver

But what should I do when it is running in production server using gunicorn?

Ramin Mir.
  • 784
  • 1
  • 7
  • 18
  • Thought `web: args` works in foreman but guess what `I'm not` ...! – Raja Simon Jan 22 '15 at 13:27
  • I don't think there's any good way to use cProfile to profile a django app running under gunicorn. What is it you need to figure out? I've found it most useful to use the logging system to track how long my views take to execute. – molecule Apr 03 '16 at 00:33
  • You can take a look at this profiler for Django : https://github.com/django-silk/silk It uses cProfile internally. – Nitin Labhishetty Jun 29 '17 at 04:35

1 Answers1

4

You can run it this way using gunicorn.

$ DJANGO_SETTINGS_MODULE=myapp.settings python -m cProfile -o output_file ../env/bin/gunicorn --workers=8 --bind 127.0.0.1:8000 myapp.wsgi:application 
Anonymous
  • 86
  • 1
  • 7