django is very slow on my machine

2020-05-25 07:09发布

I have a fresh install of django 1.0 and a simple page served from it takes 5 secs to load. On my colleague's computer it takes almost no time.

I start the server using

python manage.py testserver

I can see each GET request (PNGs and style sheets) take about half a second.

Another weird thing, which I think is related, is that the functional tests for the app run much slower on my machine with MySQL (on order of 100 times slower than on my colleague's machine). When I set the app to use sqlite, they run pretty quickly. I would like to exclaim that sqlite doesn't much change the time it takes to load a page, but it does speed up server startup.

It looks like IO problem, but I don't see general performance problems on my machine, apart from django at least.

Django runs on python2.4, I'm running Vista. I have also checked python2.5.

Thanks ΤΖΩΤΖΙΟΥ, It must totaly be a DNS problem, because the page loads up quickly as soon as instead of http://localhost:8000/app I go to http://127.0.0.1:8000/app.

But what could it be caused by? My host file has only two entries:

127.0.0.1   localhost
::1         localhost

14条回答
手持菜刀,她持情操
2楼-- · 2020-05-25 07:57

Upgrade to Django 1.3 or newer.

If you still have this problem in 2012 (using Chrome), make sure you're upgrading. In 1.3, a bug was fixed related to slowness when the dev server was single threaded.

Upgrading solved my issues. I was running Django 1.2 since that's the default on Debian Squeeze.

查看更多
迷人小祖宗
3楼-- · 2020-05-25 07:57

To completely bypass localhost without altering the hosts file or any settings in Firefox you can install the addon Redirector and make a rule to redirect from localhost to 127.0.0.1. Use these settings

Include pattern : http://localhost*
Redirect to     : http://127.0.0.1$1

Leave the other fields empty.

查看更多
Explosion°爆炸
4楼-- · 2020-05-25 07:59

Slow Loading of Static Files

If you notice that static and media files (images, style sheets, etc.) are particularly slow to load, the problem might be Django's development server (python manage.py runserver). As noted by hassen, that server is not optimized for speed.

You can try using django-extensions runserver_plus command with the --threaded option as a replacement for Django's runserver command. Under the hood, it uses Werkzeug as the threaded WSGI server. You may notice a huge improvement in loading times for static files.

Also see: Making Django development server faster at serving static media

查看更多
等我变得足够好
5楼-- · 2020-05-25 08:07

I have had the same problem in the past. It can be solved by removing the following line from your hosts file.

::1         localhost

Once that's gone you should be able to use localhost again, quickly.

查看更多
迷人小祖宗
6楼-- · 2020-05-25 08:09

Had the same problem too, I've noticed it with Firefox on Vista and Windows 7 machines. Accessing the development server 127.0.0.1:8000 solved the problem.

查看更多
萌系小妹纸
7楼-- · 2020-05-25 08:09

And if all else fails, you can always cProfile your application and see where exactly is the bottleneck.

查看更多
登录 后发表回答