Search code examples
pythondjangoprofilergunicorncprofile

How can I use python's cProfile to profile a django app while running on gunicorn


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?


Solution

  • 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