Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django development server reload takes too long

Tags:

python

django

This has been my problem since I've upgraded to OSX Lion: Whenever the runserver reloads when I change a file in my Django project, it takes quite a while before it starts serving again.

This happens even in a newly created Django 1.4 project. Didn't have this problem though on Snow Leopard.

I used cProfile and this is where it spent most of its time:

Ordered by: cumulative time

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    1    0.001    0.001   48.068   48.068 manage.py:2(<module>)
    1    0.000    0.000   48.033   48.033 __init__.py:431(execute_manager)
    1    0.000    0.000   48.032   48.032 __init__.py:340(execute)
    1    0.000    0.000   47.908   47.908 base.py:182(run_from_argv)
    1    0.000    0.000   47.907   47.907 base.py:193(execute)
    1    0.000    0.000   47.814   47.814 runserver.py:39(handle)
    1    0.000    0.000   47.814   47.814 runserver.py:69(run)
    1    0.001    0.001   47.814   47.814 autoreload.py:129(main)
    1    0.000    0.000   47.813   47.813 autoreload.py:107(python_reloader)
    1    0.000    0.000   47.813   47.813 autoreload.py:96(restart_with_reloader)
    1    0.000    0.000   47.813   47.813 os.py:565(spawnve)
    1    0.000    0.000   47.813   47.813 os.py:529(_spawnvef)
    1   47.812   47.812   47.812   47.812 {posix.waitpid}
    ...

But I don't understand why?

like image 825
Marconi Avatar asked Jul 11 '12 05:07

Marconi


People also ask

Why is Django server slow?

Django sites can be slow if you use the convenience naively. If a Django application is noticeably slow it is almost always inefficient use of the ORM, which can be fixed in an afternoon with a profile or debug toolbar. If it is okayish but not fast then it is usually because of a lack of cache strategy.

What is the command to start Django's built in development server?

By default, the runserver command starts the development server on the internal IP at port 8000. 0 is a shortcut for 0.0.0.0. Full docs for the development server can be found in the runserver reference.


1 Answers

(for guys still googling the answer)

I had similar problem using Vagrant (on Windows host machine). Solution for me was move virtualenv folder away from synced /vagrant. Default settings of synced folders uses VirtualBox provider and that's the problem. We can read about this in another sync methods from Vagrant official documentation:

In some cases the default shared folder implementations (such as VirtualBox shared folders) have high performance penalties. If you're seeing less than ideal performance with synced folders, NFS can offer a solution.

and

SMB is built-in to Windows machines and provides a higher performance alternative to some other mechanisms such as VirtualBox shared folders.

See Vagrant shared folders benchmark for extra info.

like image 132
proxy Avatar answered Oct 21 '22 06:10

proxy