Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django is very slow on my machine

Tags:

python

django

dns

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
like image 657
luntain Avatar asked Dec 12 '08 13:12

luntain


People also ask

Why is my Django site so 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.

Which environment is best for Django?

The Django developer team itself recommends that you use Python virtual environments!

Are Django websites fast?

Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel. It's free and open source. Ridiculously fast.


2 Answers

Firefox has a problem browsing to localhost on some Windows machines. You can solve it by switching off ipv6, which isn't really recommended. Using 127.0.0.1 directly is another way round the problem.

like image 101
fuzzyman Avatar answered Oct 12 '22 23:10

fuzzyman


None of these posts helped me. In my specific case, Justin Carmony gave me the answer.

Problem

I was mapping [hostname].local to 127.0.0.1 in my /etc/hosts file for easy development purposes and dns requests were taking 5 seconds at to resolve. Sometimes they would resolve quickly, other times they wouldn't.

Solution

Apple is using .local to do some bonjour magic on newer Snow Leopard builds (I think i started noticing it after updating to 10.6.8) and Mac OS X Lion. If you change your dev hostname to start with local instead of end with local you should be all set. Additionally, you can pretty much use any TLD besides local and it will work without conflict.

Example

test.local could become:

  • local.test.com
  • test.dev
  • test.[anything but local]

and your hosts file entry would read:

local.test.com  127.0.0.1

Note: This solution has the added benefit of being a subdomain of [hostname].com which makes it easier to specify an app domain name for Facebook APIs, etc.

Might also want to run dscacheutil -flushcache in the terminal for good measure after you update /etc/hosts

like image 27
Tyler Brock Avatar answered Oct 13 '22 00:10

Tyler Brock