Django开发服务器重新加载需要太长时间 [英] Django development server reload takes too long
问题描述
自从升级到OSX Lion以来,这是我的问题:每当我在Django项目中更改文件时,runserver重新加载,需要相当长的时间才能再次开始服务。
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.
即使在新创建的Django 1.4项目中也会发生这种情况。在雪豹上没有这个问题。
This happens even in a newly created Django 1.4 project. Didn't have this problem though on Snow Leopard.
我使用cProfile,这是大部分时间花费的时间:
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}
...
但我不明白为什么?
推荐答案
(对于仍然搜索答案的人)
(for guys still googling the answer)
我使用Vagrant Windows主机)。对于我来说,解决方案是从同步的 / vagrant
移动 virtualenv
文件夹。同步的文件夹的默认设置使用VirtualBox提供程序,这是问题。我们可以从 Vagrant官方文档的另一种同步方法中阅读: / p>
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:
在某些情况下,默认的共享文件夹实现(如VirtualBox共享文件夹)具有高性能惩罚。如果您看到同步文件夹的性能不太理想,NFS可以提供解决方案。
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.
和
SMB是内置到Windows机器,并提供了一些更高性能的替代其他机制,如VirtualBox共享文件夹。
SMB is built-in to Windows machines and provides a higher performance alternative to some other mechanisms such as VirtualBox shared folders.
请参阅 Vagrant共享文件夹基准测试额外的信息。
这篇关于Django开发服务器重新加载需要太长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!