12

I noted that manage.py runserver takes a lot of time to start the development web server for a Django project I'm working on. I'm wondering if there's a way to understand what part of the startup requires so much resources, being eventually able to collect enough information to fix the problem.

Anyone has an idea about what could I do?

Paolo
  • 20,112
  • 21
  • 72
  • 113
  • http://stackoverflow.com/questions/582336/how-can-you-profile-a-python-script this may give you a starting point for profiling runserver. However, runserver reloads files when they're edited so generally I find I only need to start it once or twice a day. – Stephen Paulger Mar 27 '11 at 18:54
  • Sorry, my question is not accurate. I missed to explicitly say that the same performance problem also verifies when reloading file (but after all, doesn't "reload file" mean restart the web server? Thenks for the link. – Paolo Mar 27 '11 at 19:01
  • Can't you try [this](http://stackoverflow.com/questions/4295799/how-to-improve-performance-of-this-code/4299378#4299378)? It's [this technique](http://stackoverflow.com/questions/375913/what-can-i-use-to-profile-c-code-in-linux/378024#378024). – Mike Dunlavey Mar 27 '11 at 19:19
  • While using Vagrant, move `virtualenv` folder away from `/vagrant`. See [my answer for similar question](https://stackoverflow.com/a/27997903/1993670). – proxy Jan 17 '15 at 09:19

1 Answers1

16

I found an easy and effective solution doing this:

python -m cProfile manage.py runserver > profiled

Further details about Python profilers here (official docs).

I'd also post a link to a video introduction to Python profiling and related tools (PyCon 2009)

Paolo
  • 20,112
  • 21
  • 72
  • 113
  • 7
    I'm having the same problem. Could you share what was it that's causing your project to load longer even in local? – Marconi Jun 02 '12 at 00:25